/* Rubik (OFL), self-hosted so every platform gets the same rounded voice (system ui-rounded only exists on Apple) */
@font-face { font-family: Rubik; src: url(fonts/rubik-latin.woff2) format('woff2'); font-weight: 400 900; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Rubik; src: url(fonts/rubik-latin-ext.woff2) format('woff2'); font-weight: 400 900; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+20A0-20AB, U+20AD-20C4, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: Rubik; src: url(fonts/rubik-cyrillic.woff2) format('woff2'); font-weight: 400 900; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
:root {
  --bg: #070c1c; --panel: #0e1630; --line: #22305a; --text: #eef2ff; --dim: #8b97bd;
  --red: #ff4d6d; --blue: #3fb8ff; --green: #7dffa8; --gold: #ffd23f;
  --font: Rubik, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: dark; accent-color: var(--gold); caret-color: var(--gold);
}
* { 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; }
::selection { background: var(--gold); color: #1a1300; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.screen { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
html[data-env]::after { content: attr(data-env); position: fixed; left: 8px; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 20; padding: 3px 8px; border-radius: 6px; background: #ff4d6d; color: #fff; font: 900 10px/1.2 var(--font); letter-spacing: .12em; text-transform: uppercase; pointer-events: none; }
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 > .gear { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
#setup, #over { padding-top: 64px; } /* the card never slides under the settings gear */
@media (hover: hover) { .ico:hover, .seg.lang button:not(.on):hover { color: var(--text); } }
.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.6, .5, 1); } /* deliberate game overshoot: the point lands */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.45); } 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: rise .45s var(--ease-out); }
@keyframes rise { from { opacity: .35; transform: translateY(10px) scale(.985); } } /* starts visible: never a blank menu if frames stall */
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; }
#modes { display: grid; grid-template-columns: 72px 1fr 1fr; } /* 4 modes: 2x2 so labels fit at 360px */
#modes legend { grid-row: span 2; }

/* Party: the menu (name, create / join) and a room's lobby reuse the setup card */
.pm, .lb { display: none; gap: 10px; }
#setup:not(.lobby):has(input[value=party]:checked) .pm, #setup.lobby .lb { display: grid; }
#setup:has(input[value=party]:checked) :is(#nRow, #play), #setup:not(.lobby):has(input[value=party]:checked) .cfg,
#setup.lobby:not(.host) .cfg, #setup.lobby :is(.how, #modes), #setup:not(.host) #start, #rmsg:empty, #pmsg:empty { display: none; }
.pm input, #sname { min-width: 0; font: inherit; font-size: 16px; font-weight: 800; color: var(--text); background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 11px 14px; }
.pm input:focus, #sname:focus { outline: none; border-color: var(--gold); }
.pm input::placeholder { color: var(--dim); }
#pcode { flex: 1; text-align: center; text-transform: uppercase; letter-spacing: .3em; }
.lb small { text-align: center; color: var(--dim); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
#rcode { text-align: center; font-size: 64px; line-height: 1; letter-spacing: .14em; padding-left: .14em; color: var(--gold); text-shadow: 0 4px 0 #b38f00; }
#rplayers { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#rplayers li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); font-weight: 800; overflow-wrap: anywhere; }
#rplayers li::before { content: ''; flex: none; width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; opacity: .45; }
#rplayers li.on::before { background: currentColor; box-shadow: 0 0 8px currentColor; opacity: 1; }
#rplayers i { margin-left: auto; font-style: normal; font-size: 10px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: var(--gold); color: #1a1300; }
#rmsg, #pmsg, #ovWait { margin: 0; text-align: center; color: var(--dim); font-weight: 700; font-size: 14px; }
#net { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; z-index: 7; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); color: var(--gold); font-size: 12px; font-weight: 800; pointer-events: 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 button { min-height: 48px; }
#askB .def { outline: 3px solid var(--text); outline-offset: 3px; }

/* Settings: a centered panel (full width minus the gutter on phones); rows go label | control | value on short landscape screens,
   and the screen scrolls if it still doesn't fit */
:is(#set, #ask) { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
:is(#set, #ask) .card { width: min(460px, 100%); gap: clamp(10px, 2.2vh, 16px); padding: clamp(16px, 4vw, 28px); background: var(--bg); border: 2px solid var(--line); border-radius: 22px; box-shadow: 0 20px 60px #000a; }
:is(#set, #ask) h2 { font-size: clamp(24px, 6vw, 32px); }
#set :is(button, input[type=range]):focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.opt { display: grid; grid-template: "l v" auto "c c" auto / 1fr auto; align-items: center; gap: 4px 12px; }
.opt > :first-child { grid-area: l; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.opt > output { grid-area: v; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; min-width: 3ch; }
.opt > :last-child { grid-area: c; }
.opt > .seg { justify-self: start; }
.opt > input { width: 100%; }
.seg.lang button { padding: 10px 20px; font-size: 15px; }
/* Volume sliders: thin gold-filled track, big thumb, 44px tall hit area. --v (0..100) is set from JS. */
.opt input[type=range] { -webkit-appearance: none; appearance: none; height: 44px; margin: 0; border-radius: 10px; background: none; cursor: pointer; --fill: calc(14px + (100% - 28px) * var(--v, 50) / 100); }
.opt input[type=range]::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--gold) var(--fill), var(--line) 0); }
.opt input[type=range]::-moz-range-track { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--gold) var(--fill), var(--line) 0); }
.opt input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; box-sizing: border-box; width: 28px; height: 28px; margin-top: -8px; border-radius: 50%; background: var(--text); border: 4px solid var(--gold); box-shadow: 0 3px 0 #b38f00; transition: transform .1s; }
.opt input[type=range]::-moz-range-thumb { box-sizing: border-box; width: 28px; height: 28px; border-radius: 50%; background: var(--text); border: 4px solid var(--gold); box-shadow: 0 3px 0 #b38f00; transition: transform .1s; }
@media (hover: hover) {
  .opt input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.1); }
  .opt input[type=range]:hover::-moz-range-thumb { transform: scale(1.1); }
}
.opt input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
.opt input[type=range]:active::-moz-range-thumb { transform: scale(1.15); }
@media (max-height: 500px) {
  #set .card { gap: 8px; padding-block: 14px; }
  #set h2 { font-size: 22px; }
  .opt { grid-template: "l c v" auto / 8.5em 1fr 3ch; }
}

#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; }

/* Tablet + desktop HUD: the × / gear get their own column (they used to squeeze the right player's name), and each player
   reads as two lines, score | name / stones + hammer, so long names keep their room. Type grows a little on big screens. */
@media (min-width: 641px) {
  #hud { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr) auto; grid-template-areas: "s0 hint s1 tools"; gap: 8px 14px; padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }
  #hud.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; grid-template-areas: "s0 s1 s2 tools" "hint hint hint hint"; }
  #tools { grid-area: tools; display: flex; gap: 6px; align-self: center; }
  #hint { padding: 0 8px; }
  #hint .q { font-size: clamp(22px, 1.1vw + 14px, 30px); }
  #hint .sub { font-size: clamp(13px, .4vw + 10px, 15px); }
  .side { display: grid; grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "sc nm nm" "sc dots hm"; gap: 2px 10px; align-items: center; justify-self: start; max-width: 100%; padding: 8px 14px; } /* the active outline hugs its player */
  #side1, #side2 { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "nm nm sc" "hm dots sc"; justify-self: end; }
  #hud.n3 #side1 { grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "sc nm nm" "sc dots hm"; justify-self: center; }
  .side .sc { grid-area: sc; font-size: clamp(30px, 1.6vw + 14px, 42px); }
  .side .nm { grid-area: nm; font-size: clamp(12px, .3vw + 10px, 15px); }
  .side .dots { grid-area: dots; }
  .side .hm { grid-area: hm; justify-self: start; }
  #side1 .hm, #side2 .hm { justify-self: end; }
  #hud.n3 #side1 .hm { justify-self: start; }
  #status { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .card, #hint.flash, .side.pop .sc { animation: none; }
  button, fieldset span, .side, #toast { transition: 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; }
}
