:root {
  --bg: #070c1c; --panel: #0e1630; --line: #22305a; --text: #eef2ff; --dim: #8b97bd;
  --red: #ff4d6d; --blue: #3fb8ff; --green: #7dffa8; --gold: #ffd23f;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; font-weight: 800; color: var(--text); background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px 16px; cursor: pointer; transition: transform .08s, background .15s; }
button:active { transform: scale(.95); }
button:disabled { opacity: .4; cursor: default; }
button.big { background: var(--gold); color: #1a1300; border-color: var(--gold); font-size: 18px; letter-spacing: .04em; text-transform: uppercase; padding: 12px 26px; box-shadow: 0 4px 0 #b38f00; }
button.big:active { box-shadow: 0 1px 0 #b38f00; transform: translateY(3px); }
[hidden] { display: none !important; }

#app { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; }
#hud { display: grid; grid-template-columns: 1fr minmax(0, 2.2fr) 1fr; grid-template-areas: "s0 hint s1"; gap: 8px; padding: 8px max(12px, env(safe-area-inset-left)); align-items: center; }
#hud.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "s0 s1 s2" "hint hint hint"; }
#side0 { grid-area: s0; } #side1 { grid-area: s1; } #side2 { grid-area: s2; }
#hint, #tools { grid-area: hint; }
#tools { justify-self: end; align-self: start; display: grid; gap: 2px; z-index: 1; }
.ico { width: 40px; height: 40px; padding: 0; border-radius: 50%; display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--dim); }
.screen > .snd, .screen > .lang { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; }
.screen > .lang { right: 60px; }
.seg.lang button { padding: 7px 9px; font-size: 13px; }
#setup, #over { padding-top: 64px; } /* the card never slides under the EN | УК + speaker controls */
.side { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 14px; border: 2px solid transparent; transition: border-color .2s, background .2s; min-width: 0; }
#side1, #side2 { flex-direction: row-reverse; text-align: right; }
#hud.n3 #side1 { flex-direction: row; justify-content: center; }
.side .nm { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .sc { font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.side .dots { font-size: 13px; letter-spacing: 2px; white-space: nowrap; }
.side .hm { font-style: normal; font-size: 9px; font-weight: 900; letter-spacing: .08em; padding: 2px 5px; border-radius: 6px; background: var(--gold); color: #1a1300; display: none; }
.side.hammer .hm { display: inline; }
#side0 .nm, #side0 .dots, #side0 .sc { color: var(--red); }
#side1 .nm, #side1 .dots, #side1 .sc { color: var(--blue); }
#side2 .nm, #side2 .dots, #side2 .sc { color: var(--green); }
#side0.active { border-color: var(--red); background: #ff4d6d1a; }
#side1.active { border-color: var(--blue); background: #3fb8ff1a; }
#side2.active { border-color: var(--green); background: #7dffa81a; }
.side.pop .sc { animation: pop .5s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.8); } 100% { transform: scale(1); } }

#hint { text-align: center; min-width: 0; min-height: 82px; display: grid; align-content: center; padding: 0 46px; } /* fixed-ish so #stage never resizes mid-end */
#hint.sil { min-height: 128px; }
#hint small { display: block; color: var(--dim); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
#hint .q { font-size: clamp(20px, 5.5vw, 26px); font-weight: 800; line-height: 1.15; }
#hint .q b { color: var(--gold); text-transform: uppercase; }
#hint .sub { color: var(--dim); font-size: 13px; font-weight: 700; }
#hint canvas { width: 200px; height: 110px; display: block; margin: 2px auto 0; }
#hint.flash { animation: flash .6s ease-out; }
@keyframes flash { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

#stage { position: relative; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#toast { position: absolute; left: 50%; bottom: 16px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); font-weight: 800; padding: 8px 14px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; white-space: nowrap; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

#bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px; padding: 8px 16px max(10px, env(safe-area-inset-bottom)); box-sizing: content-box; height: 52px; }
#status { color: var(--dim); font-weight: 700; font-size: 14px; text-align: center; }
.ctl { display: flex; gap: 10px; align-items: center; }
.seg { display: flex; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; text-transform: uppercase; font-size: 14px; color: var(--dim); }
.seg button.on { background: var(--text); color: var(--bg); }

.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow-y: auto; background: radial-gradient(ellipse at 50% 0%, #1a2a5e 0%, #070c1cee 60%); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 5; }
.card { width: min(440px, 100%); display: grid; gap: 12px; animation: flash .4s ease-out; }
h1 { margin: 0; font-size: clamp(44px, 12vw, 68px); letter-spacing: -.02em; line-height: .9; text-align: center; }
h1 span { color: var(--gold); }
.tag { margin: 0 0 6px; text-align: center; color: var(--dim); font-weight: 700; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 6px; }
legend { float: left; width: 72px; padding-top: 10px; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
fieldset label { flex: 1; }
fieldset input { position: absolute; opacity: 0; pointer-events: none; }
fieldset span { height: 100%; display: grid; place-content: center; text-align: center; padding: 9px 4px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); font-weight: 800; font-size: 14px; cursor: pointer; transition: .15s; }
fieldset input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
fieldset input:focus-visible + span { outline: 2px solid var(--gold); }
#setup:not(:has(input[value=bot]:checked)) #botRow { display: none; }
.noise { display: flex; align-items: center; gap: 10px; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.noise input { flex: 1; accent-color: var(--gold); }
.noise output { width: 28px; text-align: right; color: var(--text); font-size: 14px; }
.how { margin: 4px 0 0; color: var(--dim); font-size: 13px; line-height: 1.45; text-align: center; }

.screen h2 { margin: 0; text-align: center; font-size: clamp(34px, 9vw, 52px); line-height: 1; text-transform: uppercase; }
#ovScore { text-align: center; font-size: 64px; font-weight: 900; font-variant-numeric: tabular-nums; }
#ovEnds { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-weight: 700; color: var(--dim); text-align: center; }
#ovStats { margin: 0; text-align: center; font-weight: 700; }
.row { display: flex; gap: 8px; }
.row button { flex: 1; }
#askB .big { flex: 2; } /* 'KEEP PLAYING' on one line at 360px */
#askB button { padding-inline: 6px; } /* 'Червоний' fits a third of 360px */
#askB .def { outline: 3px solid var(--text); outline-offset: 3px; }

#stats { position: fixed; top: 8px; right: 8px; z-index: 9; margin: 0; max-width: min(480px, calc(100vw - 16px)); max-height: 70vh; overflow: auto; padding: 10px 12px; font: 11px/1.45 ui-monospace, Menlo, monospace; background: #000c; border: 1px solid var(--line); border-radius: 10px; white-space: pre-wrap; pointer-events: none; }

@media (max-width: 640px) {
  #hud { grid-template-columns: 1fr 1fr; grid-template-areas: "s0 s1" "hint hint"; padding: 6px 10px; gap: 4px 8px; }
  #hud.n3 .side { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 0 5px; padding: 3px 4px; text-align: center; }
  #hud.n3 .nm { flex-basis: 100%; font-size: 11px; }
  #hud.n3 .dots { font-size: 10px; letter-spacing: 1px; }
  #hud.n3 .side .hm { display: inline; visibility: hidden; font-size: 8px; letter-spacing: 0; padding: 1px 3px; } /* space always reserved: the HUD never changes height mid-end */
  #hud.n3 .side.hammer .hm { visibility: visible; }
  #hint canvas { width: 100%; }
  #bar { height: 76px; align-content: center; }
  .side { padding: 4px 8px; }
  .side .sc { font-size: 24px; }
  #hud.n3 .side .sc { font-size: 22px; }
  button.big { font-size: 16px; padding: 11px 20px; }
}
