:root {
  /* defaults = Commanders; app.js swaps these for the current team's colors (applyTeam) */
  --bg: #2b0909;
  --bg2: #3a0e0e;
  --card: #4a1414;
  --line: #6e2626;
  --text: #fff7ea;
  --muted: #d8b9a0;
  --accent: #ffb612;
  --accent-ink: #2b0909;
  --accent-soft: rgba(255,182,18,.14);
  --glow: #5a1414;
  --good: #4be08f;
  --close: #b5e35d;
  --meh: #ff9a3d;
  --bad: #ff6b6b;
  --radius: 16px;
  --display: "Anton", Impact, "Arial Narrow", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    repeating-linear-gradient(0deg, transparent 0 79px, rgba(255,255,255,.035) 79px 81px),
    radial-gradient(ellipse at 50% -10%, var(--glow) 0%, var(--bg) 62%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: not-allowed; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-weight: 600; }

#app { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 28px 0 20px; }
.hero.small { padding-top: 8px; }
.kicker { text-transform: uppercase; letter-spacing: .18em; font-size: 12px; font-weight: 800; color: var(--accent); }
h1 {
  font-family: var(--display); font-weight: 400; text-transform: uppercase;
  font-size: clamp(42px, 10vw, 84px); line-height: .95; margin: 10px 0 12px; letter-spacing: .01em;
}
h1 span { color: var(--accent); display: inline-block; transform: rotate(-2deg); }
.hero.small h1 { font-size: clamp(36px, 8vw, 64px); }
.sub { color: var(--muted); margin: 0 auto; max-width: 520px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 0 0 12px; }

/* ---------- home ---------- */
#home, #lobby, #final { max-width: 560px; margin: 0 auto; }
.field { display: block; margin: 8px 0 16px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input:not([type=range]) {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; font-size: 18px; outline: none;
}
input:focus { border-color: var(--accent); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.big-btn {
  display: block; width: 100%; padding: 16px 18px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); font-weight: 800; font-size: 18px; transition: transform .08s, background .15s;
}
.big-btn:active { transform: scale(.98); }
.big-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn { padding: 12px 18px; border-radius: 12px; border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.leave { display: block; margin: 24px auto 0; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#join-code { text-transform: uppercase; letter-spacing: .3em; font-family: var(--display); font-size: 24px; text-align: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 16px 0; }
.opt { margin-bottom: 16px; }
.opt > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; gap: 8px; }
.chips.wrap { flex-wrap: wrap; }
.chips button {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--bg2); font-weight: 700; font-size: 15px; white-space: nowrap;
}
.chips.wrap button { flex: 1 1 calc(50% - 8px); white-space: normal; text-align: left; }
.chips button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
/* how-to-play choice: two big cards, then the friends card's host/join toggle */
.ask { margin: 22px 0 10px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 18px 16px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--card);
  transition: transform .08s, border-color .15s, background .15s;
}
.mode:active { transform: scale(.98); }
.mode-ic { font-size: 30px; line-height: 1; margin-bottom: 6px; }
.mode b { font-family: var(--display); font-weight: 400; text-transform: uppercase; font-size: 26px; letter-spacing: .02em; line-height: 1.05; }
.mode small { color: var(--muted); font-size: 14px; line-height: 1.35; }
.mode.on { border-color: var(--accent); background: var(--accent-soft); }
.mode.on b { color: var(--accent); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg2); margin-bottom: 14px; }
.seg button { padding: 10px 8px; border: 0; border-radius: 9px; background: transparent; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
#friends p, #setup p { margin: 0 0 12px; }
.tweak { margin-top: 12px; }
.tweak summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: 6px 0; list-style: none; }
.tweak summary::-webkit-details-marker { display: none; }
.tweak summary::after { content: " ▾"; }
.tweak[open] summary::after { content: " ▴"; }
.tweak[open] summary { margin-bottom: 10px; }
#lobby-start { margin-top: 4px; }
.invite #lobby-how { margin: 0 auto 14px; max-width: 420px; font-size: 14px; }
#lobby-alone { margin: 8px 0 10px; }
@media (max-width: 400px) {
  .mode { padding: 14px 12px; }
  .mode b { font-size: 22px; }
}
.foot { text-align: center; font-size: 13px; margin-top: 28px; color: var(--muted); }

/* ---------- lobby ---------- */
.room-code { font-family: var(--display); font-size: 72px; letter-spacing: .2em; color: var(--accent); line-height: 1.1; margin: 4px 0 12px; padding-left: .2em; }
.plist { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.plist li { background: var(--bg2); border: 1px solid var(--line); padding: 8px 12px; border-radius: 999px; font-weight: 700; }
.plist li.off { opacity: .45; }
.plist em { font-style: normal; font-size: 11px; text-transform: uppercase; color: var(--accent); margin-left: 4px; }
.plist em.you { color: var(--good); }

/* ---------- play ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; font-weight: 800; }
.progress-label { font-family: var(--display); font-size: 22px; text-transform: uppercase; letter-spacing: .03em; }
.room-tag { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.pips { display: flex; gap: 4px; margin: 10px 0 12px; }
.pips i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.pips i.done { background: var(--muted); }
.pips i.now { background: var(--accent); }
.clock { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; margin-bottom: 12px; }
#clock-fill { height: 100%; background: var(--good); width: 100%; transition: width .1s linear; }
.clock.urgent #clock-fill { background: var(--bad); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.photo { margin: 0; position: relative; }
.photo img {
  width: 100%; aspect-ratio: 3 / 4; object-fit: contain; display: block; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); opacity: 0; transition: opacity .3s;
}
.photo img.loaded { opacity: 1; }
.photo figcaption { font-size: 11px; color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.photo figcaption a { color: var(--muted); }

.panel { position: sticky; top: 16px; }
.who { margin-bottom: 18px; }
.meta { color: var(--accent); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; }
.pname { font-family: var(--display); font-size: clamp(34px, 5vw, 52px); text-transform: uppercase; line-height: 1; margin: 6px 0; }
.extra { color: var(--muted); font-weight: 600; }

.readout { font-family: var(--display); font-size: 96px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.readout small, .actual small { font-family: Inter, sans-serif; font-size: 18px; color: var(--muted); margin-left: 6px; font-weight: 800; }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: transparent; margin: 8px 0 0; touch-action: none;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent) 0 var(--pct, 40%), var(--line) var(--pct, 40%) 100%);
}
input[type=range]::-moz-range-track { height: 12px; border-radius: 6px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 12px; border-radius: 6px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 36px; height: 36px; margin-top: -12px; border-radius: 50%;
  background: var(--text); border: 4px solid var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
input[type=range]::-moz-range-thumb { width: 30px; height: 30px; border-radius: 50%; background: var(--text); border: 4px solid var(--accent); }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 600; }
.nudges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.nudges button { padding: 12px 0; border-radius: 10px; border: 2px solid var(--line); background: var(--bg2); font-weight: 800; font-size: 17px; }
.locked { font-size: 22px; font-weight: 800; padding: 18px; text-align: center; background: var(--bg2); border-radius: var(--radius); border: 2px dashed var(--accent); }
.locked b { color: var(--accent); font-family: var(--display); font-size: 34px; font-weight: 400; }
#locked-ui .muted { text-align: center; }
#force-reveal { display: block; margin: 0 auto; }

.actual-label { text-transform: uppercase; letter-spacing: .14em; font-size: 13px; font-weight: 800; color: var(--muted); text-align: center; }
.actual { font-family: var(--display); font-size: 110px; line-height: 1; text-align: center; color: var(--accent); font-variant-numeric: tabular-nums; }
.verdict { text-align: center; font-family: var(--display); text-transform: uppercase; font-size: 30px; margin: 4px 0 8px; }
.verdict span { display: block; font-family: Inter, sans-serif; font-size: 15px; text-transform: none; color: var(--muted); font-weight: 600; }
.perfect, .hit { color: var(--good); }
.close { color: var(--close); }
.meh { color: var(--meh); }
.miss { color: var(--bad); }

.range { position: relative; height: 84px; margin: 12px 14px 16px; }
.range .track { position: absolute; left: 0; right: 0; top: 40px; height: 4px; background: var(--line); border-radius: 2px; }
.range .mark { position: absolute; top: 34px; transform: translateX(-50%); }
.range .mark.g::before { content: ""; display: block; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); border: 2px solid var(--bg); }
.range .mark.g.me::before { background: var(--text); }
.range .mark.g span { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 700; white-space: nowrap; color: var(--muted); }
.range .mark.g span.lo { top: 32px; }
.range .mark.g.me span { color: var(--text); }
.range .actual-mark { top: 0; z-index: 1; }
.range .actual-mark b { display: block; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; padding: 2px 8px; border-radius: 6px; position: relative; }
.range .actual-mark::after { content: ""; display: block; width: 4px; height: 26px; margin: 0 auto; background: var(--accent); }

.rlist { list-style: none; padding: 0; margin: 0 0 16px; }
.rlist li { display: grid; grid-template-columns: 1fr auto 70px 90px; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); align-items: center; }
.rlist li.me { background: var(--accent-soft); border-radius: 10px; }
.rlist .n { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rlist .g { font-family: var(--display); font-size: 20px; }
.rlist .d { font-weight: 800; text-align: right; }
.rlist .t { color: var(--muted); font-size: 13px; text-align: right; }

/* ---------- final ---------- */
.board { list-style: none; padding: 0; margin: 0; }
.board li {
  display: grid; grid-template-columns: 40px 1fr repeat(3, auto); gap: 14px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
}
.board li:first-child { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--card)); }
.board li.me .n::after { content: " (you)"; color: var(--muted); font-weight: 600; }
.board .rank { font-family: var(--display); font-size: 30px; color: var(--accent); text-align: center; }
.board .n { font-weight: 800; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .stat { text-align: right; }
.board .stat b { display: block; font-family: var(--display); font-weight: 400; font-size: 22px; }
.board .stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.recap { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.rc { background: var(--bg2); border-radius: 12px; overflow: hidden; }
.rc img { width: 100%; aspect-ratio: 3/4; object-fit: contain; background: var(--bg); display: block; }
.rc > div { padding: 8px 10px; }
.rc b { display: block; font-size: 14px; line-height: 1.2; }
.rc small { color: var(--muted); font-size: 12px; }
.rw { font-family: var(--display); font-size: 20px; margin-top: 4px; }
.rw span { font-family: Inter, sans-serif; font-size: 12px; font-weight: 700; display: block; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; transition: .2s;
  max-width: calc(100vw - 32px); overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* credits page */
.credits table { width: 100%; border-collapse: collapse; font-size: 14px; }
.credits td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .stage { grid-template-columns: 1fr; gap: 14px; }
  .photo img { aspect-ratio: 3 / 4; max-height: 52vh; width: auto; margin: 0 auto; }
  .panel { position: static; }
  .who { text-align: center; margin-bottom: 6px; }
  .readout { font-size: 72px; }
  .actual { font-size: 84px; }
  .board li { grid-template-columns: 32px 1fr auto auto; }
  .board .stat:nth-of-type(4) { display: none; }
  .rlist li { grid-template-columns: 1fr auto 64px; }
  .rlist .t { display: none; }
  .room-code { font-size: 60px; }
}
@media (max-width: 420px) {
  .choices { grid-template-columns: 1fr; }
  .chips.wrap button { flex-basis: 100%; }
}
