/* Stash: a party game for the TV, plus a phone controller.
   Dark on purpose: it lives on a TV in a lit room and should feel like a show. */
:root {
  --bg: #0E1116; --bg2: #151A22; --surface: #1B212B; --surface2: #242B37; --line: #2E3644;
  --ink: #F5EFE4; --muted: #9AA3AE;
  --t0: #F2B632; --t0-ink: #2A1E00; --t0-soft: rgba(242, 182, 50, .16);
  --t1: #3FC4A8; --t1-ink: #03231C; --t1-soft: rgba(63, 196, 168, .16);
  --coffee: #C98A2E; --right: #4CC27A; --wrong: #F07A6B;
  --f-body: "Readex Pro", "Noto Sans Arabic", system-ui, sans-serif;
  --f-logo: "Bricolage Grotesque", system-ui, sans-serif;
  --r: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { color-scheme: dark; } }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1C2433 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
input { -webkit-user-select: text; user-select: text; }
#app { height: 100dvh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
b { font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; color: var(--ink); background: var(--surface2); border: 1px solid var(--line);
  border-radius: 14px; padding: .8em 1.2em; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, background .2s, opacity .2s; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: linear-gradient(180deg, #F7C64B, #E2A21E); color: #241900; border-color: transparent; box-shadow: 0 8px 24px rgba(242, 182, 50, .25); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.15rem; padding: .95em 1.6em; border-radius: 16px; }
.btn.sm { font-size: .9rem; padding: .55em .9em; }
.btn.xs { font-size: .85rem; padding: .35em .7em; border-radius: 10px; }
.btn.right { background: var(--right); color: #04220F; border-color: transparent; }
.btn.wrong { background: var(--wrong); color: #2B0702; border-color: transparent; }
.t0 { --tc: var(--t0); --tink: var(--t0-ink); --tsoft: var(--t0-soft); }
.t1 { --tc: var(--t1); --tink: var(--t1-ink); --tsoft: var(--t1-soft); }
.btn.team, .btn.award { background: var(--tsoft); border-color: var(--tc); color: var(--ink); }
.btn.award.pref { background: var(--tc); color: var(--tink); }

/* ---------- toast & sheets ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: #F5EFE4; color: #14171A; padding: .7em 1.1em; border-radius: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: end center; z-index: 40; }
.sheet { background: var(--bg2); border: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); width: min(520px, 100%); display: grid; gap: 8px; }
.layer { position: fixed; inset: 0; background: var(--bg); z-index: 30; overflow: auto; padding: 16px; }

/* ---------- logo / home ---------- */
.logo { font-family: var(--f-logo); font-weight: 800; font-size: clamp(3.4rem, 12vw, 6.5rem); letter-spacing: -.04em; line-height: 1; direction: ltr;
  background: linear-gradient(180deg, #FFE3A1, #E2A21E); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo.sm { font-size: 2.6rem; }
.home { height: 100%; overflow: auto; display: grid; align-content: center; justify-items: center; gap: 28px; padding: 24px 16px; text-align: center; }
.home-hero { display: grid; justify-items: center; gap: 10px; }
.tag { font-size: 1.3rem; margin: 0; }
.home-cups { display: flex; gap: 10px; margin-top: 8px; }
.home-cups span { width: 26px; height: 22px; background: linear-gradient(180deg, transparent 35%, var(--coffee) 35%); border: 2px solid #E9DFCC; border-top-width: 3px; border-radius: 2px 2px 10px 10px; animation: bob 2.4s ease-in-out infinite; }
.home-cups span:nth-child(2) { animation-delay: .15s } .home-cups span:nth-child(3) { animation-delay: .3s } .home-cups span:nth-child(4) { animation-delay: .45s } .home-cups span:nth-child(5) { animation-delay: .6s }
@keyframes bob { 50% { transform: translateY(-5px); } }
.home-actions { display: grid; gap: 10px; justify-items: center; width: min(420px, 100%); }
.home-actions .btn.primary { width: 100%; }
.join { display: flex; gap: 8px; width: 100%; margin-top: 8px; }
.join input, .p-join input, .ed-word input, .team-name {
  flex: 1; font: inherit; font-size: 1.05rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: .75em 1em; min-width: 0;
}
.join input { text-align: center; letter-spacing: .3em; text-transform: uppercase; }
.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(860px, 100%); }
.how div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 4px; text-align: start; }
.how b { color: var(--t0); }
.how span { color: var(--muted); font-size: .92rem; }
@media (max-width: 640px) { .how { grid-template-columns: 1fr; } }

/* ---------- lobby ---------- */
.screen-root { height: 100%; }
.lobby { height: 100%; overflow: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: clamp(16px, 4vw, 48px); align-items: center; padding: clamp(16px, 4vw, 48px); max-width: 1200px; margin: 0 auto; }
.lobby-join { display: grid; justify-items: center; text-align: center; gap: 8px; }
.qr { background: #fff; border-radius: 18px; padding: 10px; width: min(300px, 70vw); aspect-ratio: 1; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr.small { width: 160px; }
.lobby-code { display: flex; gap: 10px; align-items: baseline; }
.lobby-code b { font-family: var(--f-logo); font-size: 3rem; letter-spacing: .12em; }
.net-line { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #5B6472; display: inline-block; flex: none; }
.dot.on { background: var(--right); box-shadow: 0 0 0 4px rgba(76, 194, 122, .18); }
.lobby-teams { display: grid; gap: 12px; }
.team-card { background: var(--tsoft); border: 1px solid var(--tc); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; }
.team-name { font-weight: 700; font-size: 1.3rem; background: transparent; border-color: transparent; padding: .2em .3em; color: var(--tc); }
.team-name:focus { border-color: var(--tc); outline: none; background: rgba(0,0,0,.2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; align-items: center; }
.chip { background: rgba(0, 0, 0, .25); border-radius: 999px; padding: .25em .8em; font-size: .92rem; }
.chip.off { opacity: .45; }
.lobby-photos { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); flex-wrap: wrap; }
@media (max-width: 760px) { .lobby { grid-template-columns: 1fr; align-content: start; } .qr { width: min(220px, 60vw); } }

/* ---------- game layout ---------- */
.game { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.game-top { display: flex; align-items: center; gap: 12px; padding: 10px clamp(10px, 2vw, 24px) 0; padding-top: calc(10px + env(safe-area-inset-top)); }
#board { flex: 1; min-width: 0; }
.game-meta { display: flex; gap: 6px; align-items: center; }
.code-chip { font-family: var(--f-logo); font-weight: 700; letter-spacing: .12em; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .25em .6em; font-size: .9rem; }
.q-badge { background: var(--surface); border-radius: 10px; padding: .25em .6em; font-size: .9rem; }
.stage { position: relative; display: grid; place-items: center; padding: clamp(8px, 2vw, 20px); min-height: 0; overflow: hidden; }
.controls { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); min-height: 76px; }
.controls .judge-line { flex-basis: 100%; text-align: center; }

/* finjan scoreboard */
.board { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(8px, 2vw, 28px); }
.board-team { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px 12px 10px; transition: box-shadow .3s, border-color .3s; }
.board-team.hot { border-color: var(--tc); box-shadow: 0 0 0 3px var(--tsoft); }
.board-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.board-name { font-weight: 700; color: var(--tc); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(.95rem, 1.8vw, 1.3rem); }
.board-score { font-weight: 700; font-size: clamp(1rem, 2vw, 1.5rem); }
.board-score small { color: var(--muted); font-weight: 500; font-size: .7em; }
.cups { display: grid; grid-template-columns: repeat(10, 1fr); gap: clamp(1px, .5vw, 6px); margin-top: 4px; }
.cup { width: 100%; height: auto; display: block; overflow: visible; }
.cup-body { fill: rgba(255, 255, 255, .05); stroke: #CFC5B3; stroke-width: 2; }
.cup-rim { stroke: #E9DFCC; stroke-width: 2.5; stroke-linecap: round; }
.cup-fill { fill: var(--tc); transform: translateY(26px); transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
.cup.full .cup-fill { transform: translateY(6px); }
.cup.full .cup-body { stroke: var(--tc); }
.cup.pour { animation: pour .6s ease; }
@keyframes pour { 30% { transform: translateY(-6px) scale(1.12); } }

/* intro / countdown */
.intro { text-align: center; display: grid; gap: 10px; justify-items: center; }
.intro-kicker { color: var(--t0); font-weight: 700; letter-spacing: .04em; font-size: clamp(1rem, 2.5vw, 1.6rem); }
.intro-title { font-size: clamp(1.6rem, 5vw, 3.4rem); font-weight: 700; line-height: 1.2; }
.count { font-family: var(--f-logo); font-size: clamp(4rem, 14vw, 9rem); font-weight: 800; line-height: 1; animation: pop .7s ease infinite; }
@keyframes pop { 0% { transform: scale(1.25); opacity: .3; } 30% { transform: scale(1); opacity: 1; } }

/* One Look scene */
.scene-wrap { position: absolute; inset: clamp(8px, 2vw, 20px); display: grid; place-items: center; gap: 12px; }
.scene { max-width: 100%; max-height: 100%; border-radius: 16px; display: block; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.scene-wrap > .scene { max-height: calc(100% - 8px); object-fit: contain; animation: appear .25s ease; }
@keyframes appear { from { opacity: 0; transform: scale(.98); } }
.ring { position: absolute; top: 14px; inset-inline-start: 14px; width: clamp(44px, 6vw, 72px); height: auto; transform: rotate(-90deg); }
.ring circle { fill: rgba(0, 0, 0, .45); stroke: var(--t0); stroke-width: 4; stroke-dasharray: 120; stroke-dashoffset: 0; animation: ring linear forwards; }
@keyframes ring { to { stroke-dashoffset: 120; } }
.scene-wrap.reveal { grid-template-rows: minmax(0, 1fr) auto; }
.scene-box { position: relative; max-width: 100%; max-height: 100%; min-height: 0; aspect-ratio: 16 / 10; height: 100%; }
.scene-box .scene { width: 100%; height: 100%; object-fit: contain; }
.scene-box.photo { aspect-ratio: auto; width: 100%; height: 100%; }
.scene-box.photo .scene { box-shadow: none; }
.marks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.marks circle { fill: none; stroke: #FFE066; stroke-width: 10; filter: drop-shadow(0 0 10px rgba(255, 224, 102, .8)); stroke-dasharray: 1200; stroke-dashoffset: 1200; animation: draw .7s ease forwards; animation-delay: var(--d); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.answer { display: grid; justify-items: center; text-align: center; gap: 2px; }
.answer b { font-size: clamp(1.6rem, 4.5vw, 3rem); color: #FFE066; line-height: 1.2; }

/* question */
.question { text-align: center; display: grid; gap: 16px; justify-items: center; max-width: 1000px; }
.q-kicker { color: var(--t0); font-weight: 700; }
.q-text { font-size: clamp(1.8rem, 6vw, 4rem); font-weight: 700; line-height: 1.25; animation: appear .3s ease; }
.q-hint { max-width: 560px; }
.banner { font-size: clamp(1.2rem, 3.5vw, 2rem); background: var(--tc); color: var(--tink); padding: .4em 1em; border-radius: 16px; animation: pop2 .35s ease; }
@keyframes pop2 { from { transform: scale(.7); opacity: 0; } }
.zoom .banner { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); white-space: nowrap; animation: none; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }

/* team stop buttons on the screen */
.btn.stop { flex: 1; max-width: 380px; font-size: clamp(1.05rem, 2.6vw, 1.5rem); padding: .8em 1em; background: var(--tsoft); border: 2px solid var(--tc); }
.btn.stop b { color: var(--tc); }

/* Zoom In */
.zoom { position: absolute; inset: clamp(8px, 2vw, 20px); }
.zoom canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 16px; background: #05070A; }
.pts { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; background: rgba(0, 0, 0, .55); padding: 6px 10px 12px; border-radius: 14px; backdrop-filter: blur(6px); }
.pts span { width: 2em; height: 2em; display: grid; place-items: center; border-radius: 10px; color: var(--muted); font-weight: 700; }
.pts span.on { background: #FFE066; color: #241900; }
.pts i { position: absolute; left: 10px; right: 10px; bottom: 5px; height: 3px; background: #FFE066; border-radius: 3px; transform-origin: right; }

.wait { display: flex; gap: 24px; align-items: center; max-width: 760px; }
.end { text-align: center; display: grid; gap: 12px; }
.end-title { font-size: clamp(2.4rem, 8vw, 5rem); font-weight: 700; color: var(--tc, var(--ink)); }

/* ---------- phone controller ---------- */
.player { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.p-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--tsoft); border-bottom: 2px solid var(--tc); }
.p-head b { color: var(--tc); }
.p-score { font-weight: 700; }
.p-main { display: grid; align-content: center; justify-items: center; gap: 22px; padding: 16px; overflow: auto; }
.p-foot { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.p-stop {
  width: min(72vw, 300px); aspect-ratio: 1; border-radius: 50%; border: 0; font: inherit; font-weight: 800; font-size: 2rem;
  color: var(--muted); background: var(--surface); box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .25); transition: transform .08s, background .2s; touch-action: manipulation;
}
.p-stop.live { background: radial-gradient(circle at 50% 35%, #FF6B57, #C8321F); color: #fff; font-size: 2.8rem; box-shadow: inset 0 -12px 0 rgba(0, 0, 0, .25), 0 0 0 10px rgba(240, 90, 70, .18); animation: throb 1s ease-in-out infinite; }
.p-stop.live.pressed, .p-stop:active { transform: scale(.94); }
.p-stop.mine { background: var(--right); color: #04220F; }
.p-stop.theirs { background: var(--surface2); }
.p-stop.look { background: var(--surface2); color: var(--ink); font-size: 1.6rem; }
@keyframes throb { 50% { box-shadow: inset 0 -12px 0 rgba(0, 0, 0, .25), 0 0 0 18px rgba(240, 90, 70, .1); } }
.p-photo { display: grid; gap: 8px; justify-items: center; text-align: center; }
.p-photo-btns { display: flex; gap: 8px; }
.p-hint { background: var(--t0-soft); border: 1px solid var(--t0); border-radius: 14px; padding: .6em 1em; text-align: center; animation: pop2 .3s ease; }
.p-wait { display: grid; justify-items: center; gap: 12px; text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--t0); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.p-join { display: grid; gap: 14px; justify-items: stretch; align-content: center; padding: 24px 20px; height: 100%; width: min(420px, 100%); margin: 0 auto; text-align: center; }
.p-join .logo { justify-self: center; }
.p-join label { display: grid; gap: 6px; text-align: start; }
.p-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.p-teams .btn { padding: 1.2em .6em; font-size: 1.1rem; }
.p-judge { display: grid; gap: 16px; justify-items: center; text-align: center; width: 100%; }
.p-word { font-size: 1.3rem; } .p-word b { color: #FFE066; font-size: 1.6rem; }
.p-judge-q { font-size: 1.4rem; }
.p-judge-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.p-judge-btns .btn { padding: 1.3em; font-size: 1.4rem; }

/* ---------- photo editor ---------- */
.editor { display: grid; gap: 12px; width: min(560px, 100%); margin: 0 auto; padding-bottom: 24px; }
.ed-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; text-align: center; padding: 8px 0; }
.ed-tip { margin: 0; text-align: center; background: var(--surface); border-radius: 14px; padding: .7em 1em; }
.ed-photo { display: grid; place-items: center; }
.ed-photo canvas { border-radius: 12px; touch-action: manipulation; cursor: crosshair; }
.ed-row { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .9rem; }
.ed-row input { flex: 1; accent-color: var(--t0); }
.ed-previews { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-previews figure { margin: 0; display: grid; gap: 6px; }
.ed-previews canvas, .ed-previews img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #000; border-radius: 12px; border: 1px solid var(--line); }
.ed-previews figcaption { font-size: .85rem; color: var(--muted); text-align: center; }
.ed-word { display: grid; gap: 6px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Game screen on a phone held in portrait */
@media (max-width: 640px) {
  .game-top { flex-wrap: wrap; }
  .game-meta { order: -1; width: 100%; justify-content: flex-end; }
  #board { flex-basis: 100%; }
  .board { gap: 8px; }
  .board-team { padding: 6px 8px 8px; }
  .btn.stop { padding: .7em .6em; }
}
