:root {
  --felt: #1c4f49; --felt-hi: #27665c; --felt-deep: #0f2f2d;
  --bg: #123834; --bg2: #1a4a45; --panel: #17413d; --line: rgba(255,255,255,.16);
  --ink: #f6f0e1; --ink2: #a9c6bc;
  --accent: #ffb547; --accent-ink: #2a1c05; --accent-deep: #b56500; --accent-edge: #b97a1b;
  --good: #3ad29f; --bad: #ff7a7a;
  --card-edge: #d9cba9;
  --radius: 18px; --tap: 48px;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
  --pm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M4 4h11c-2 3 0 7 5 7s7-4 5-7h11v11c-3-2-7 0-7 5s4 7 7 5v11H25c2-3 0-7-5-7s-7 4-5 7H4V25c3 2 7 0 7-5s-4-7-7-5z'/%3E%3C/svg%3E");
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fredoka", "Nunito", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--felt-deep); color: var(--ink); font-family: var(--font); font-size: 17px; }
body { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-text-size-adjust: 100%; }
input { -webkit-user-select: text; user-select: text; }
.hidden { display: none !important; }
button { font: inherit; touch-action: manipulation; }
.screen { position: fixed; inset: 0; }
#home, #lobby, #game { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 .09'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"), radial-gradient(120% 95% at 50% 36%, var(--felt-hi) 0%, var(--felt) 46%, var(--felt-deep) 100%); }

/* cream card stock: anything that sits on the felt as a card or box lid */
.home-card, .panel, .done-card, .help-card, .jingle-pop {
  --ink: #22312e; --ink2: #5c6c67; --line: #e1d5ba; --bg: #fffdf8; --bg2: #f2e9d3; --panel: #fbf4e4; --bad: #c43c3c;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 2px 0 rgba(255,255,255,.9) inset, 0 8px 0 var(--card-edge), 0 26px 44px rgba(0,0,0,.38);
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--bg2); color: var(--ink);
  border-radius: 999px; min-height: var(--tap); padding: 0 20px; font-weight: 800; font-size: 17px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .08s ease;
}
@media (hover: hover) { .btn:hover { border-color: var(--accent); } .btn.primary:hover { background: #ffc266; } }
.btn:active { transform: translateY(2px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 4px 0 var(--accent-edge); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-edge); }
.btn.big { min-height: 58px; padding: 0 32px; font-size: 21px; font-family: var(--display); font-weight: 600; letter-spacing: .2px; }
.btn.ghost { background: transparent; }
.btn.tiny { min-height: 44px; padding: 0 16px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.tool { min-height: 44px; padding: 0 16px; font-size: 16px; background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.16); }
.btn.tool svg { width: 20px; height: 20px; flex: none; }
.btn.tool small { color: var(--ink2); font-weight: 700; font-size: 13px; }
.btn.tool.on { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.icon { padding: 0 12px; }

/* ---------- home ---------- */
#home { display: grid; place-items: center; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab)); overflow: hidden; }
.scatter { position: absolute; inset: 0; pointer-events: none; }
.scatter span { position: absolute; width: var(--s, 150px); aspect-ratio: 1; transform: rotate(var(--r, 0deg));
  filter: drop-shadow(0 12px 12px rgba(0,0,0,.38)); animation: piece-in .8s cubic-bezier(.2,1.25,.35,1) both; animation-delay: calc(var(--i, 0) * 80ms + 120ms); }
.scatter i { display: block; width: 100%; height: 100%; background: var(--c);
  background: linear-gradient(155deg, color-mix(in srgb, var(--c) 78%, #fff) 0%, var(--c) 48%, color-mix(in srgb, var(--c) 82%, #000) 100%);
  -webkit-mask: var(--pm) center/contain no-repeat; mask: var(--pm) center/contain no-repeat; }
@keyframes piece-in { from { opacity: 0; transform: translateY(-70vh) rotate(calc(var(--r, 0deg) - 70deg)); } }
@media (prefers-reduced-motion: reduce) { .scatter span { animation: none; } }
@media (max-width: 700px) { .scatter span { width: calc(var(--s, 150px) * .55); } }
.home-card { position: relative; z-index: 1; width: min(460px, 100%); border-radius: 28px; padding: 34px 32px 28px; }
.logo { font-family: var(--display); font-weight: 700; font-size: 46px; line-height: 1; display: flex; align-items: center; gap: 12px; letter-spacing: .2px; }
.logo.small { font-size: 27px; gap: 10px; }
.logo-mark { width: 48px; height: 48px; flex: none; display: inline-block;
  background: conic-gradient(from 45deg, #ff6b57 0 25%, #1fb5a6 0 50%, #8b5cf6 0 75%, #f5a524 0);
  -webkit-mask: var(--pm) center/contain no-repeat; mask: var(--pm) center/contain no-repeat; }
.logo.small .logo-mark { width: 32px; height: 32px; }
.tagline { color: var(--ink2); margin: 10px 0 24px; font-size: 18px; font-weight: 700; }
.field { display: grid; gap: 7px; margin-bottom: 16px; font-weight: 800; color: var(--ink2); font-size: 15px; }
input { font: inherit; color: var(--ink); background: var(--bg); border: 2px solid var(--line); border-radius: 14px; padding: 0 16px; min-height: 54px; font-size: 19px; font-weight: 700; outline: none; }
input::placeholder { color: #b3ab97; font-weight: 600; }
input:focus { border-color: var(--accent); }
#create { width: 100%; }
.or { display: flex; align-items: center; gap: 10px; color: var(--ink2); font-size: 15px; font-weight: 700; margin: 22px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row .btn { min-height: 54px; padding: 0 26px; }
#code { flex: 1; text-transform: uppercase; letter-spacing: 8px; font-family: var(--display); font-weight: 600; font-size: 22px; text-align: center; min-width: 0; }
#code::placeholder { letter-spacing: 6px; }
.check { display: inline-flex; align-items: center; gap: 10px; margin-top: 10px; min-height: 44px; color: var(--ink2); font-size: 16px; font-weight: 700; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--accent-deep); }

/* ---------- lobby ---------- */
#lobby { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 14px;
  padding: calc(14px + var(--sat)) max(18px, var(--sar)) calc(14px + var(--sab)) max(18px, var(--sal)); }
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; width: 100%; max-width: 1240px; margin: 0 auto; flex: none; }
#lobby .lobby-head { padding-right: 0; }
.room-pill { background: rgba(6,24,23,.5); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px 6px 20px; display: flex; gap: 12px; align-items: center; font-weight: 700; color: var(--ink2); }
.room-pill b { font-family: var(--display); font-size: 27px; letter-spacing: 5px; color: var(--accent); }
.room-pill .btn { background: rgba(255,255,255,.1); }
.room-pill .pill-tools { gap: 8px; }
.room-pill .pill-tools .round { width: 44px; height: 44px; font-size: 19px; }
.lobby-grid { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); gap: 16px; width: 100%; max-width: 1240px; margin: 0 auto; flex: 1; min-height: 0; padding-bottom: 10px; }
.panel { border-radius: 24px; padding: 20px; min-width: 0; min-height: 0; }
.panel h2 { font-family: var(--display); font-weight: 600; margin: 0 0 12px; font-size: 23px; line-height: 1.1; }
.panel h3 { font-size: 16px; color: var(--ink2); margin: 16px 0 8px; font-weight: 800; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 12px; background: var(--bg2); border-radius: 14px; padding: 0 14px; min-height: 52px; font-weight: 800; font-size: 18px; }
.players .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.players .tag { margin-left: auto; font-size: 14px; color: var(--ink2); font-weight: 700; }
.players li.away { opacity: .5; }
.hint { color: var(--ink2); font-size: 16px; line-height: 1.4; font-weight: 600; }
.panel.picture { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 14px 22px; }
.panel.picture:has(.picker.hidden) { grid-template-columns: minmax(0, 1fr); }
.pic-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.picker { min-width: 0; min-height: 0; overflow: auto; }
.preview-wrap { position: relative; border-radius: 14px; overflow: hidden; background: #e7dcc3; aspect-ratio: 4/3; width: 100%; max-width: min(100%, 68vh); box-shadow: 0 0 0 5px #fff, 0 6px 14px 4px rgba(60,40,10,.22); margin: 5px; }
.panel.picture:has(.picker.hidden) .preview-wrap { max-width: min(100%, 78vh); }
.preview-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-label { font-family: var(--display); font-weight: 600; font-size: 21px; margin: 14px 0 0; }
.busy { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; justify-items: center; background: rgba(251,244,228,.86); font-weight: 800; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent-deep); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { color: var(--bad); font-weight: 700; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.preset { border: 0; border-radius: 12px; overflow: hidden; padding: 0; cursor: pointer; background: var(--bg2); position: relative; outline: 3px solid transparent; outline-offset: 0; transition: outline-color .15s ease, transform .08s ease; }
.preset:active { transform: scale(.97); }
.preset img { width: 100%; display: block; aspect-ratio: 4/3; object-fit: cover; }
.preset span { display: block; padding: 7px 4px 8px; font-size: 14px; font-weight: 800; color: var(--ink); line-height: 1.15; }
.preset.sel { outline-color: var(--accent-deep); }
.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme { border: 1px solid var(--line); background: var(--bg2); color: var(--ink); border-radius: 999px; min-height: 44px; padding: 0 16px; font-weight: 700; cursor: pointer; font-size: 16px; }
.theme:active { transform: scale(.97); }
@media (hover: hover) { .theme:hover { border-color: var(--accent-deep); } }
.theme:disabled { opacity: .5; cursor: default; }
.start-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 14px; border-top: 2px solid var(--line); }
.diff { background: var(--bg2); border-radius: 999px; padding: 8px 16px; font-weight: 800; color: var(--ink2); font-size: 16px; }
@media (max-width: 940px) {
  .panel.picture { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
  .preview-wrap { max-width: min(100%, 46vh); }
}
@media (max-width: 700px) { .lobby-grid { grid-template-columns: minmax(0, 1fr); } .room-pill b { font-size: 22px; letter-spacing: 3px; } }

/* ---------- game ---------- */
#game { display: flex; flex-direction: column; padding-bottom: var(--sab); }
.bar { display: flex; align-items: center; gap: 12px; flex: none; position: relative; z-index: 2;
  padding: calc(8px + var(--sat)) max(12px, var(--sar)) 8px max(12px, var(--sal));
  background: rgba(6,22,21,.66); border-bottom: 1px solid rgba(255,255,255,.09); }
.bar-left { display: flex; align-items: center; gap: 14px; flex: none; }
.timer { font-family: var(--display); font-weight: 700; font-size: 31px; line-height: 1; min-width: 90px; font-variant-numeric: tabular-nums; }
.code-chip { color: var(--ink2); font-size: 15px; font-weight: 700; }
.code-chip b { color: var(--ink); letter-spacing: 2px; }
.chips { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips li { flex: none; display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.09); border-radius: 999px; padding: 4px 14px 4px 5px; min-height: 38px; font-weight: 800; font-size: 15px; }
.chips li:not(:has(.dot)) { padding-left: 14px; }
.chips .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 15px; color: #14201e; }
.chips small { color: var(--ink2); font-weight: 700; font-size: 13px; }
.chips li.away { opacity: .45; }
.bar-right { display: flex; gap: 8px; flex: none; align-items: center; }
.stage { flex: 1; position: relative; min-height: 0; touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.done { position: absolute; inset: 0; z-index: 3; background: rgba(6,22,21,.14); pointer-events: none; }
.done-card { pointer-events: auto; position: absolute; left: clamp(min(256px, 50%), var(--px, 50%), max(calc(100% - 256px), 50%)); top: clamp(min(250px, 50%), var(--py, 50%), max(calc(100% - 250px), 50%)); translate: -50% -50%; width: min(480px, calc(100% - 32px)); max-height: calc(100% - 24px); overflow: auto; border-radius: 28px; padding: 26px; text-align: center; animation: pop .45s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.done-title { font-family: var(--display); font-size: 29px; font-weight: 600; }
.done-time { font-family: var(--display); font-size: 68px; font-weight: 700; color: var(--accent-deep); line-height: 1.05; font-variant-numeric: tabular-nums; }
.done-sub { color: var(--ink2); font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.bars { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 9px; text-align: left; }
.bars li { display: grid; grid-template-columns: 100px 1fr 34px; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.bars .track { height: 14px; background: var(--bg2); border-radius: 7px; overflow: hidden; }
.bars .fill { display: block; height: 100%; border-radius: 7px; transition: width .8s ease; }
.awards { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.awards li { background: var(--bg2); border-radius: 12px; padding: 8px 13px; font-size: 15px; font-weight: 700; }
.awards b { color: var(--accent-deep); }
.done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }

/* ---------- round buttons, help, toasts ---------- */
.corner { position: fixed; top: calc(14px + var(--sat)); right: max(14px, var(--sar)); z-index: 40; display: flex; gap: 10px; }
.round { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.1); color: #f6f0e1;
  display: grid; place-items: center; padding: 0; cursor: pointer; font-family: var(--display); font-weight: 700; font-size: 21px; line-height: 1;
  transition: transform .08s ease, border-color .15s ease, color .15s ease; flex: none; }
@media (hover: hover) { .round:hover { border-color: var(--accent); color: var(--accent); } }
.round:active { transform: scale(.92); }
.round.muted { color: #a9c6bc; }
.round.muted::after { content: ""; position: absolute; width: 28px; height: 3px; border-radius: 2px; background: #ff7a7a; transform: rotate(45deg); }
.room-pill .btn + .btn { margin-left: -6px; }
.help { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab)); background: rgba(6,22,21,.74); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.help-card { width: min(860px, 100%); max-height: calc(100% - 12px); overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 26px; padding: 20px; display: flex; flex-direction: column; gap: 14px; animation: pop .3s cubic-bezier(.2,1.3,.4,1); }
.help-card > * { flex: none; }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.help-head h2 { font-family: var(--display); font-weight: 600; font-size: 27px; margin: 0; }
.help-video { position: relative; border-radius: 14px; overflow: hidden; background: #0b1a19; aspect-ratio: 16 / 9; width: min(100%, calc(54vh * 16 / 9)); margin: 0 auto; }
.help-video video { width: 100%; height: 100%; display: block; background: #0b1a19; }
.help-play { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; border: 0; cursor: pointer; color: #f6f0e1; font: inherit; font-weight: 800; font-size: 18px;
  background: radial-gradient(520px 320px at 50% 40%, #27665c 0%, #0f2f2d 80%); }
.help-play span { width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 30px; padding-left: 5px; box-shadow: 0 5px 0 var(--accent-edge); }
.help-novideo { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; margin: 0; color: #a9c6bc; font-weight: 700; }
.help-steps { margin: 0; padding-left: 24px; display: grid; gap: 7px; color: var(--ink2); font-size: 17px; line-height: 1.45; font-weight: 600; }
.help-steps b { color: var(--ink); }
.btn:focus-visible, .round:focus-visible, .help-play:focus-visible, .preset:focus-visible, .theme:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.toasts { position: fixed; left: 50%; bottom: calc(20px + var(--sab)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #0a2422; border: 1px solid rgba(255,255,255,.18); color: #f6f0e1; padding: 12px 20px; border-radius: 999px; font-weight: 700; font-size: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: toast-in .25s ease; text-align: center; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }
@media (max-width: 900px) {
  .bar { flex-wrap: wrap; row-gap: 6px; }
  .chips { order: 3; flex-basis: 100%; }
  .bar-right { margin-left: auto; }
}
@media (max-width: 640px) {
  .bar { gap: 8px; }
  .code-chip { display: none; }
  .timer { font-size: 25px; min-width: 72px; }
  .btn.tool { padding: 0 12px; }
  .btn.tool .lbl, .btn.tool small { display: none; }
  .logo { font-size: 38px; } .logo-mark { width: 40px; height: 40px; }
  .home-card { padding: 28px 22px 22px; }
}

.diffs{display:inline-flex;gap:6px;flex-wrap:wrap}.diffs button{min-height:44px;min-width:84px;padding:6px 12px;border-radius:12px;border:2px solid var(--line);background:transparent;color:inherit;font:700 15px var(--font);cursor:pointer;display:flex;flex-direction:column;align-items:center;line-height:1.15}.diffs button small{font-weight:500;font-size:11px;opacity:.7}.diffs button.sel{background:var(--accent);border-color:var(--accent);color:var(--accent-ink)}.diffs button:disabled{cursor:default}.diffs button:disabled:not(.sel){opacity:.45}.custom-row{display:flex;gap:8px;margin-top:10px}.custom-row input{flex:1;min-width:0;min-height:44px;padding:8px 12px;border-radius:12px;border:2px solid var(--line);font:500 15px var(--font);background:#fff;color:#222}.custom-row .btn,.upload-btn{min-height:44px}.upload-btn{display:inline-flex;align-items:center;cursor:pointer}
