@font-face {
  font-family: 'Fredoka';
  src: url('/assets/fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
:root {
  --ink: #1f2a44; --cream: #fff8e7; --gold: #ffd23f; --gold-dark: #d99a00;
  --robber: #ff8a3d; --robber-dark: #c4571a; --cop: #2f6fe4; --cop-dark: #1d4cb0;
  --green: #3fa86a; --green-dark: #2a7a4b;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  font-family: 'Fredoka', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd06a; color: var(--ink); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.center-note { position: fixed; z-index: 200; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--cream); padding: 16px 22px; border-radius: 18px; font-weight: 600; box-shadow: 0 8px 0 #0002, 0 20px 50px #0003; text-align: center; max-width: min(420px, 90vw); }
[hidden] { display: none !important; }

/* ---------- Title ---------- */
#title { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(ellipse at 50% 0%, #ffffff55, transparent 60%), linear-gradient(180deg, #a6e3ff22, #2a7a4b44); overflow: auto; }
.title-card { width: min(1040px, 100%); display: grid; grid-template-columns: 1.08fr 1fr; background: var(--cream); border-radius: 34px; overflow: hidden;
  border: 6px solid #ffffff; box-shadow: 0 12px 0 #2a7a4b66, 0 30px 80px #0b3d2240; animation: card-in .5s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes card-in { from { transform: translateY(30px) scale(.94); opacity: 0; } }
.hero { position: relative; min-height: 520px; background: linear-gradient(160deg, #8fd06a, #3fa86a); }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-text { position: absolute; left: 0; right: 0; top: 0; padding: 22px 26px 40px; background: linear-gradient(180deg, #1f2a4466, transparent); text-align: center; }
h1 { margin: 0; font-size: clamp(40px, 5.6vw, 66px); line-height: .95; color: #ffffff; font-weight: 700; letter-spacing: -.01em;
  text-shadow: 0 4px 0 var(--robber-dark), 0 7px 0 #0003, 0 10px 24px #0005; transform: rotate(-2deg); }
h1 .amp { color: var(--gold); }
.sub { margin: 8px 0 0; display: inline-block; background: var(--gold); color: #5a3b00; font-weight: 700; font-size: clamp(16px, 2vw, 21px); padding: 6px 16px; border-radius: 999px; box-shadow: 0 4px 0 var(--gold-dark); transform: rotate(1.5deg); }
.pick { padding: 26px 28px 22px; display: flex; flex-direction: column; gap: 14px; }
.pick h2 { margin: 0; font-size: 24px; font-weight: 700; text-align: center; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 10px 12px; border-radius: 22px; border: 4px solid transparent; background: #f1ead7; box-shadow: 0 6px 0 #dccfae; transition: transform .15s, box-shadow .15s; text-align: center; }
.team-card:hover { transform: translateY(-3px); }
.team-card:active { transform: translateY(3px); box-shadow: 0 3px 0 #dccfae; }
.team-card .face { width: 84px; height: 84px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 4px 0 #0002; object-fit: cover; background: #fff; }
.team-card b { font-size: 19px; font-weight: 700; }
.team-card small { font-size: 12.5px; line-height: 1.3; opacity: .8; }
.team-card.robber.selected { background: #ffe2c9; border-color: var(--robber); box-shadow: 0 6px 0 var(--robber-dark); }
.team-card.cop.selected { background: #dbe8ff; border-color: var(--cop); box-shadow: 0 6px 0 var(--cop-dark); }
.team-card.selected .face { animation: wiggle 1.2s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg) scale(1.05); } 50% { transform: rotate(6deg) scale(1.12); } }
.row { display: flex; align-items: center; gap: 10px; }
.label { font-weight: 700; font-size: 15px; white-space: nowrap; }
#swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 3px 0 #0002, 0 0 0 2px #0001; padding: 0; transition: transform .12s; }
.swatch.selected { transform: scale(1.2); box-shadow: 0 0 0 3px var(--ink), 0 3px 0 #0003; }
.name-row input { flex: 1; min-width: 0; font-size: 20px; font-weight: 600; padding: 12px 16px; border-radius: 16px; border: 3px solid #e2d6b8; background: #fff; -webkit-user-select: text; user-select: text; }
#dice { font-size: 26px; width: 56px; height: 54px; border-radius: 16px; border: 0; background: #fff; box-shadow: 0 4px 0 #dccfae; }
#dice:active { transform: rotate(40deg) scale(.95); }
#play { margin-top: 2px; font-size: 30px; font-weight: 700; color: #fff; border: 0; border-radius: 22px; padding: 14px 20px; display: flex; justify-content: center; gap: 12px; align-items: center;
  background: linear-gradient(180deg, #ffa25c, var(--robber)); box-shadow: 0 7px 0 var(--robber-dark), 0 12px 26px #c4571a55; text-shadow: 0 2px 0 #0002; transition: transform .1s; animation: breathe 2.4s ease-in-out infinite; }
body[data-team="cop"] #play { background: linear-gradient(180deg, #5b92ff, var(--cop)); box-shadow: 0 7px 0 var(--cop-dark), 0 12px 26px #1d4cb055; }
#play:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--robber-dark); }
@keyframes breathe { 50% { filter: brightness(1.08) saturate(1.1); } }
.foot { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
#friend-link { border: 0; background: #e6f6dc; color: var(--green-dark); font-weight: 700; padding: 8px 14px; border-radius: 999px; box-shadow: 0 3px 0 #bfe0ae; }
#room-note { font-size: 13px; font-weight: 600; color: var(--green-dark); }
.howto { margin: 0; text-align: center; font-size: 12.5px; line-height: 1.5; opacity: .7; }

/* ---------- HUD ---------- */
#hud, #touch-buttons, #stick, #touch-layer { display: none; }
body.playing #hud { display: block; }
#hud > * { position: fixed; z-index: 20; }
.pill { background: var(--cream); border: 4px solid #fff; border-radius: 999px; box-shadow: 0 5px 0 #0002, 0 10px 24px #0002; font-weight: 700; display: flex; align-items: center; gap: 6px; }
#topbar { top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; pointer-events: none; }
#topbar .score { padding: 4px 14px; font-size: 24px; }
#topbar .score span { font-size: 22px; }
#topbar .cop b { color: var(--cop); } #topbar .robber b { color: var(--robber-dark); }
#topbar .timer { padding: 6px 18px; font-size: 30px; background: var(--ink); color: #fff; border-color: #fff; font-variant-numeric: tabular-nums; min-width: 96px; justify-content: center; }
#topbar .timer.hurry { background: #e63946; animation: throb .5s ease-in-out infinite alternate; }
@keyframes throb { to { transform: scale(1.08); } }
#me-card { top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l)); display: grid; grid-template-columns: auto auto; align-items: center; gap: 2px 10px; background: var(--cream); border: 4px solid #fff; border-radius: 22px; padding: 8px 14px 10px; box-shadow: 0 5px 0 #0002, 0 10px 24px #0002; pointer-events: none; }
#my-badge { width: 48px; height: 48px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 3px 0 #0002; object-fit: cover; }
.me-score b { display: block; font-size: 28px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.me-score small { font-size: 11px; font-weight: 600; opacity: .65; letter-spacing: .05em; text-transform: uppercase; }
#boost-meter { grid-column: 1 / -1; position: relative; height: 18px; width: 150px; border-radius: 999px; background: #e7dcc0; overflow: hidden; margin-top: 4px; }
#boost-fill { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, #ffb000, var(--gold)); border-radius: 999px; transition: width .1s linear; }
#boost-meter span { position: relative; display: block; text-align: center; font-size: 11px; font-weight: 700; line-height: 18px; color: #5a3b00; letter-spacing: .08em; }
#boost-meter.ready { box-shadow: 0 0 0 3px #fff, 0 0 14px 2px var(--gold); animation: ready-glow .8s ease-in-out infinite alternate; }
@keyframes ready-glow { to { box-shadow: 0 0 0 3px #fff, 0 0 22px 6px var(--gold); } }
#objective { top: calc(74px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: #ffffffee; border-radius: 20px; padding: 9px 18px; font-size: 19px; font-weight: 600; box-shadow: 0 5px 0 #0002; white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
#objective:empty { display: none; }
#objective.bounce { animation: bounce-in .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes bounce-in { from { transform: translateX(-50%) scale(.7); } }
#objective b { color: var(--robber-dark); }
body[data-team="cop"] #objective b { color: var(--cop); }
#toasts { top: calc(150px + var(--safe-t)); left: calc(12px + var(--safe-l)); display: flex; flex-direction: column; gap: 6px; width: min(330px, 46vw); pointer-events: none; }
.toast { background: #ffffffe8; border-radius: 14px; padding: 7px 12px; font-size: 14.5px; font-weight: 500; box-shadow: 0 3px 0 #0002; border-left: 6px solid #9aa3ad; animation: toast-in .3s cubic-bezier(.2, 1.4, .4, 1); transition: opacity .4s, transform .4s; }
.toast.robber { border-left-color: var(--robber); } .toast.cop { border-left-color: var(--cop); }
.toast.out { opacity: 0; transform: translateX(-20px); }
@keyframes toast-in { from { transform: translateX(-30px); opacity: 0; } }
#map-wrap { top: calc(10px + var(--safe-t)); right: calc(12px + var(--safe-r)); border: 4px solid #fff; border-radius: 18px; overflow: hidden; box-shadow: 0 5px 0 #0002, 0 10px 24px #0002; line-height: 0; pointer-events: none; }
#minimap { width: 240px; height: 160px; }
#corner-buttons { top: calc(186px + var(--safe-t)); right: calc(12px + var(--safe-r)); display: flex; gap: 6px; }
#corner-buttons button { width: 44px; height: 44px; border-radius: 14px; border: 3px solid #fff; background: var(--cream); font-size: 20px; box-shadow: 0 4px 0 #0002; padding: 0; }
#corner-buttons button.off { opacity: .45; }
#corner-buttons button:active { transform: translateY(3px); box-shadow: 0 1px 0 #0002; }
#keys-hint { bottom: calc(14px + var(--safe-b)); left: calc(14px + var(--safe-l)); background: #ffffffcc; border-radius: 12px; padding: 7px 12px; font-size: 13px; font-weight: 500; pointer-events: none; }
#pop { left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.5); opacity: 0; font-size: clamp(32px, 6vw, 60px); font-weight: 700; color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 4px 0 #1f2a44, 0 -2px 0 #1f2a44, 3px 0 0 #1f2a44, -3px 0 0 #1f2a44, 0 10px 30px #0005; }
#pop.show { animation: pop 1.6s cubic-bezier(.2, 1.5, .4, 1) forwards; }
#pop.gold { color: var(--gold); } #pop.blue { color: #8fc0ff; } #pop.big { font-size: clamp(40px, 8vw, 80px); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%) scale(1); } }
#connection { top: 30%; }
#hidden-glow { position: fixed; inset: 0; z-index: 15; pointer-events: none; opacity: 0; transition: opacity .4s; box-shadow: inset 0 0 120px 40px #2f8f3bcc; }
#hidden-glow.on { opacity: 1; }
#speed-lines { position: fixed; inset: -10%; z-index: 14; pointer-events: none; opacity: 0; transition: opacity .25s;
  background: repeating-conic-gradient(from 0deg at 50% 55%, #ffffff00 0deg 5deg, #ffffff55 5deg 6deg); -webkit-mask: radial-gradient(circle at 50% 55%, transparent 30%, #000 75%); mask: radial-gradient(circle at 50% 55%, transparent 30%, #000 75%); }
body.boosting #speed-lines { opacity: .7; animation: spin-lines 0.4s linear infinite; }
@keyframes spin-lines { to { transform: rotate(6deg); } }

/* ---------- Touch controls ---------- */
body.playing.touch #touch-layer, body.playing.touching #touch-layer { display: block; }
#touch-layer { position: fixed; z-index: 10; left: 0; top: 0; bottom: 0; width: 62%; touch-action: none; }
body.playing.touch #touch-buttons, body.playing.touching #touch-buttons { display: flex; }
body.playing.touch #keys-hint { display: none; }
#stick { position: fixed; z-index: 30; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
body.playing #stick { display: block; }
#stick::before { content: ''; position: absolute; width: 132px; height: 132px; left: -66px; top: -66px; border-radius: 50%; background: #ffffff33; border: 4px solid #ffffffaa; box-shadow: 0 6px 20px #0003; opacity: 0; transition: opacity .15s; }
#stick-knob { position: absolute; width: 64px; height: 64px; left: -32px; top: -32px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #ffe08a 45%, var(--gold) 70%); border: 4px solid #fff; box-shadow: 0 5px 0 var(--gold-dark), 0 8px 20px #0004; opacity: 0; transition: opacity .15s; }
#stick.on::before, #stick.on #stick-knob { opacity: 1; }
#touch-buttons { position: fixed; z-index: 30; right: calc(18px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); align-items: flex-end; gap: 14px; }
#touch-buttons button { border: 5px solid #fff; border-radius: 50%; display: grid; place-items: center; touch-action: none; padding: 0; }
#boost-btn { width: 108px; height: 108px; --fill: 100%; background: conic-gradient(var(--gold) var(--fill), #d8cfb8 0); box-shadow: 0 7px 0 #0003, 0 10px 30px #0003; color: #5a3b00; }
#boost-btn span { font-size: 40px; line-height: 1; margin-top: 8px; }
#boost-btn small { font-size: 13px; font-weight: 700; margin-top: -18px; }
#boost-btn.ready { animation: ready-pulse .7s ease-in-out infinite alternate; }
@keyframes ready-pulse { to { box-shadow: 0 7px 0 #0003, 0 0 0 8px #ffd23f66, 0 0 30px 8px #ffd23f99; } }
#honk-btn { width: 72px; height: 72px; background: var(--cream); box-shadow: 0 6px 0 #0003; font-size: 32px; margin-bottom: 14px; }
#touch-buttons button.down { transform: translateY(5px) scale(.95); box-shadow: 0 2px 0 #0003; }

#touch-hint { display: none; position: fixed; z-index: 25; left: calc(30px + var(--safe-l)); bottom: calc(150px + var(--safe-b)); background: #ffffffee; border-radius: 18px; padding: 10px 16px; font-weight: 700; font-size: 17px; box-shadow: 0 5px 0 #0002; pointer-events: none; }
#touch-hint span { display: inline-block; font-size: 30px; margin-right: 6px; animation: drag-hint 1.4s ease-in-out infinite; }
@keyframes drag-hint { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(26px, -10px); } }
body.playing.touch:not(.touching) #touch-hint { display: block; }

/* ---------- End of round ---------- */
#end-card { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: #1f2a4455; padding: 16px; animation: fade-in .3s; }
@keyframes fade-in { from { opacity: 0; } }
.end-inner { background: var(--cream); border: 6px solid #fff; border-radius: 30px; padding: 22px 28px; text-align: center; min-width: min(420px, 92vw); box-shadow: 0 10px 0 #0003, 0 30px 80px #0005; animation: card-in .5s cubic-bezier(.2, 1.4, .4, 1) both; }
#end-title { margin: 0 0 8px; font-size: clamp(32px, 6vw, 48px); }
#end-card[data-result="win"] #end-title { color: var(--green-dark); }
#end-card[data-result="lose"] #end-title { color: var(--ink); }
#end-scores { display: flex; justify-content: center; gap: 22px; font-size: 30px; font-weight: 700; margin-bottom: 10px; }
#end-scores .cop { color: var(--cop); } #end-scores .robber { color: var(--robber-dark); }
#end-list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
#end-list li { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 14px; padding: 7px 12px; font-size: 18px; box-shadow: 0 3px 0 #0001; }
#end-list .medal { font-size: 24px; } #end-list .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #0002; }
#end-list b { flex: 1; text-align: left; } #end-list em { font-style: normal; font-weight: 700; }
#end-timer { margin: 6px 0 12px; font-weight: 600; opacity: .75; }
#end-switch { border: 0; border-radius: 16px; padding: 10px 18px; font-weight: 700; background: #e6f6dc; color: var(--green-dark); box-shadow: 0 4px 0 #bfe0ae; }

/* ---------- Tablets / narrow laptops ---------- */
@media (max-width: 1100px) and (min-width: 701px) {
  #minimap { width: 180px; height: 120px; }
  #corner-buttons { top: calc(146px + var(--safe-t)); }
  #objective { max-width: calc(100vw - 460px); white-space: normal; text-align: center; font-size: 16px; width: max-content; }
}

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .title-card { grid-template-columns: 1fr; max-width: 520px; }
  .hero { min-height: 0; height: clamp(170px, 30vh, 260px); }
  .hero-text { padding: 12px 16px 26px; }
  .pick { padding: 16px 16px 14px; gap: 11px; }
  .pick h2 { font-size: 19px; }
  .team-card { padding: 10px 6px; } .team-card .face { width: 64px; height: 64px; } .team-card b { font-size: 16px; } .team-card small { font-size: 11px; }
  .row:not(.name-row) { flex-direction: column; align-items: stretch; gap: 6px; } .row .label { text-align: center; } #swatches { justify-content: center; } .swatch { width: 30px; height: 30px; }
  #play { font-size: 26px; padding: 11px; }
}
@media (max-width: 700px) {
  #topbar { top: calc(8px + var(--safe-t)); gap: 5px; }
  #topbar .score { font-size: 18px; padding: 2px 10px; } #topbar .score span { font-size: 16px; }
  #topbar .timer { font-size: 22px; min-width: 70px; padding: 4px 10px; }
  #me-card { top: auto; bottom: calc(150px + var(--safe-b)); right: calc(14px + var(--safe-r)); left: auto; padding: 5px 10px 7px; border-radius: 18px; grid-template-columns: auto auto; }
  #my-badge { width: 34px; height: 34px; } .me-score b { font-size: 20px; } #boost-meter { display: none; }
  #objective { top: calc(56px + var(--safe-t)); font-size: 14px; padding: 7px 12px; white-space: normal; text-align: center; width: max-content; max-width: calc(100vw - 20px); }
  #map-wrap { top: auto; bottom: auto; top: calc(108px + var(--safe-t)); right: calc(8px + var(--safe-r)); border-width: 3px; border-radius: 14px; }
  #minimap { width: 132px; height: 88px; }
  #corner-buttons { top: calc(206px + var(--safe-t)); right: calc(8px + var(--safe-r)); flex-direction: column; gap: 5px; }
  #corner-buttons button { width: 38px; height: 38px; font-size: 17px; border-radius: 12px; }
  #toasts { top: calc(108px + var(--safe-t)); left: calc(8px + var(--safe-l)); width: calc(100vw - 170px); }
  .toast { font-size: 12px; padding: 5px 9px; }
  .toast:nth-child(n+3) { display: none; }
  #boost-btn { width: 92px; height: 92px; } #honk-btn { width: 62px; height: 62px; font-size: 28px; }
}
@media (max-height: 560px) and (min-width: 701px) {
  .hero { min-height: 0; }
  .pick { padding: 14px 20px; gap: 8px; }
  .team-card small, .howto { display: none; }
  #toasts { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
