@font-face { font-family: Russo; src: url(/fonts/russo-cyr.woff2) format('woff2'); unicode-range: U+0400-04FF; font-display: swap; }
@font-face { font-family: Russo; src: url(/fonts/russo-lat.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 400; src: url(/fonts/rubik-cyr-400.woff2) format('woff2'); unicode-range: U+0400-04FF; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 400; src: url(/fonts/rubik-lat-400.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 700; src: url(/fonts/rubik-cyr-700.woff2) format('woff2'); unicode-range: U+0400-04FF; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 700; src: url(/fonts/rubik-lat-700.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 800; src: url(/fonts/rubik-cyr-800.woff2) format('woff2'); unicode-range: U+0400-04FF; font-display: swap; }
@font-face { font-family: Rubik; font-weight: 800; src: url(/fonts/rubik-lat-800.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; font-display: swap; }

:root {
  --red: #d62828; --red2: #9d0208; --yel: #ffd60a; --cream: #fdf0d5; --ink: #3a0c0c; --sky: #8ecae6; --green: #2d6a4f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3f7d20; color: var(--ink);
  font-family: Rubik, system-ui, sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── экраны ── */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); overflow-y: auto; touch-action: pan-y; }
.screen.show { display: flex; }
.card { width: 100%; max-width: 400px; background: var(--cream); border-radius: 22px; padding: 22px 18px;
  box-shadow: 0 10px 0 var(--red2), 0 20px 40px rgba(0,0,0,.35); border: 4px solid var(--ink); margin: auto; animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.85); opacity: 0 } to { transform: none; opacity: 1 } }
#menu, #lobby { background: repeating-conic-gradient(from 0deg at 50% 40%, #d62828 0 10deg, #e85d04 10deg 20deg); }
#end { background: rgba(58, 12, 12, .55); }
label { display: block; font-weight: 700; margin: 10px 0 6px; }
input { width: 100%; font: 700 20px Rubik, sans-serif; padding: 12px 14px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; color: var(--ink); outline: none; }
input:focus { border-color: var(--red); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row > * { flex: 1; }
.row input { flex: 1.2; text-align: center; letter-spacing: 4px; }
.sep { text-align: center; margin: 16px 0 2px; font-size: 13px; opacity: .6; }
.hint { text-align: center; font-size: 14px; opacity: .7; margin: 12px 0; }

.btn { display: block; width: 100%; margin-top: 10px; padding: 14px 12px; border-radius: 16px; border: 3px solid var(--ink);
  background: var(--yel); color: var(--ink); font: 22px Russo, Rubik, sans-serif; letter-spacing: .5px; box-shadow: 0 5px 0 var(--ink);
  transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.alt { background: var(--sky); }
.btn.red { background: var(--red); color: #fff; }
.btn.red.on { background: #ffd60a; color: var(--ink); }
.btn.ghost { background: #fff; font-size: 17px; }
.btn.small { font-size: 16px; padding: 10px; }
.btn.big { font-size: 28px; padding: 18px 12px; }
.btn.pulse { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.btn:disabled { opacity: .5; }

.logo { text-align: center; line-height: 1; margin-bottom: 6px; }
.logo b { display: block; font: 64px Russo, sans-serif; color: var(--red); text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink); letter-spacing: 2px; transform: rotate(-3deg); }
.logo span { display: inline-block; margin-top: 8px; font: 20px Russo, sans-serif; background: var(--ink); color: var(--yel); padding: 4px 10px; border-radius: 8px; transform: rotate(2deg); }
.colors { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.colors button { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--ink); }
.colors button.on { outline: 4px solid var(--red); outline-offset: 2px; }
.rules { margin-top: 16px; background: #fff; border-radius: 14px; padding: 10px 12px; border: 2px dashed var(--ink); font-size: 15px; }
.rules summary { font-weight: 800; cursor: pointer; }
.rules p { margin: 8px 0 0; }

/* лобби */
.lob-head { text-align: center; font: 26px Russo, sans-serif; }
.lob-head b { color: var(--red); font-size: 40px; letter-spacing: 3px; }
.lob-head small { display: block; font: 13px Rubik, sans-serif; opacity: .65; margin-top: 2px; }
#qr { display: block; width: 170px; height: 170px; margin: 10px auto 0; border-radius: 12px; border: 3px solid var(--ink); background: #fff; }
.plist { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; justify-content: center; }
.plist .pl { display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 4px 10px 4px 4px; font-weight: 700; font-size: 15px; animation: pop .3s; }
.plist .pl i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); display: inline-block; }
.plist .pl.off { opacity: .4; }
.plist .pl.me { background: var(--yel); }
.plist .pl small { font-weight: 400; opacity: .6; }
.seg { display: flex; margin-top: 12px; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; }
.seg button { flex: 1; border: 0; padding: 10px 4px; background: #fff; font-weight: 700; font-size: 14px; color: var(--ink); }
.seg button.on { background: var(--ink); color: var(--yel); }

/* итоги */
#eTitle { font: 30px/1.1 Russo, sans-serif; text-align: center; color: var(--red); }
#eSub { text-align: center; margin: 8px 0 12px; font-size: 16px; }
.stats { max-height: 42vh; overflow-y: auto; border-radius: 12px; border: 2px solid var(--ink); background: #fff; }
.stats .r { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid #eee; font-size: 15px; }
.stats .r:last-child { border: 0; }
.stats .r.me { background: #fff3b0; }
.stats .r i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.stats .r .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats .r .v { font-size: 13px; opacity: .8; white-space: nowrap; }
.stats .r .pts { font: 18px Russo, sans-serif; min-width: 36px; text-align: right; }
.medal { text-align: center; margin: 10px 0 0; font-weight: 700; }

/* ── заставка ── */
#intro { background: #c1121f; overflow: hidden; flex-direction: column; }
.rays { position: absolute; left: 50%; top: 42%; width: 260vmax; height: 260vmax; margin: -130vmax 0 0 -130vmax;
  background: repeating-conic-gradient(#d62828 0 9deg, #e85d04 9deg 18deg); animation: spin 40s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.intro-c { position: relative; text-align: center; color: #fff; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 520px; }
.star { width: 110px; height: 110px; animation: starIn 1s cubic-bezier(.2,1.5,.4,1) both, starSpin 6s 1s ease-in-out infinite; filter: drop-shadow(0 6px 0 rgba(0,0,0,.25)); }
@keyframes starIn { from { transform: scale(0) rotate(-270deg); } }
@keyframes starSpin { 50% { transform: rotate(18deg) scale(1.08); } }
.l1 { font: 34px Russo, sans-serif; text-shadow: 3px 3px 0 var(--ink); margin-top: 10px; animation: drop .7s .5s cubic-bezier(.2,1.6,.4,1) both; }
.l2 { font: 22px Russo, sans-serif; color: var(--yel); text-shadow: 2px 2px 0 var(--ink); margin-top: 8px; animation: drop .7s .9s cubic-bezier(.2,1.6,.4,1) both; }
.l3 { font: 58px/1 Russo, sans-serif; margin-top: 6px; white-space: nowrap; }
.l3 span { display: inline-block; color: var(--yel); text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
  animation: letter .6s cubic-bezier(.2,1.8,.4,1) both, wave 2.2s ease-in-out infinite; }
@keyframes letter { from { transform: translateY(-120px) scale(2) rotate(-30deg); opacity: 0; } }
@keyframes wave { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }
@keyframes drop { from { transform: translateY(-60px) scale(.5); opacity: 0; } }
.tie { width: 150px; margin-top: 12px; animation: drop .8s 2.4s cubic-bezier(.2,1.6,.4,1) both, flutter 1.6s 3s ease-in-out infinite; transform-origin: 50% 25%; filter: drop-shadow(0 5px 0 rgba(0,0,0,.25)); }
@keyframes flutter { 50% { transform: rotate(4deg) scaleY(.95); } }
.l4 { font-size: 14px; opacity: .9; margin-top: 6px; animation: drop .6s 2.7s both; }
#bReady { max-width: 300px; margin-top: 22px; animation: drop .6s 3s both, pulse 1.1s 3.6s ease-in-out infinite; }
#bReady.go { background: #fff; transform: scale(1.15); }
.balloons { position: absolute; inset: 0; pointer-events: none; }
.balloons span { position: absolute; bottom: -120px; width: 44px; height: 56px; border-radius: 50% 50% 46% 46%; animation: rise linear infinite; }
.balloons span::after { content: ''; position: absolute; left: 50%; top: 100%; width: 1px; height: 60px; background: rgba(255,255,255,.6); }
@keyframes rise { to { transform: translateY(-130vh) translateX(var(--dx)); } }

/* ── HUD ── */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; left: 10px; right: 10px; top: max(10px, env(safe-area-inset-top)); display: flex; gap: 8px; align-items: center; }
.pill { background: var(--cream); border: 3px solid var(--ink); border-radius: 999px; padding: 4px 12px; font: 22px Russo, sans-serif; color: var(--ink); box-shadow: 0 3px 0 var(--ink); min-width: 78px; text-align: center; }
.pill.icon { min-width: 0; padding: 2px 8px; font-size: 20px; }
#timer.hurry { background: var(--red); color: #fff; animation: pulse .5s infinite; }
.bars { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.gbar { position: relative; height: 30px; background: var(--cream); border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; box-shadow: 0 3px 0 var(--ink); }
#gfill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #ffd60a, #fb8500); transition: width .25s; }
.gbar.fz { height: 24px; }
#ffill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #a2d2ff, #5fa8d3); transition: width .25s; }
#ftext { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 14px Russo, sans-serif; color: var(--ink); }
.gbar.fz.danger { animation: pulse .6s infinite; }
#gtext { position: absolute; inset: 0; white-space: nowrap; overflow: hidden; display: flex; align-items: center; justify-content: center; font: 17px Russo, sans-serif; color: var(--ink); }
#roleChip.cake { background: #ef476f; animation: pulse .5s infinite; }
#roleChip { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 70px); left: 50%; transform: translateX(-50%); background: rgba(58,12,12,.75); color: #fff;
  padding: 5px 12px; border-radius: 999px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.emos { position: absolute; right: 10px; top: calc(max(10px, env(safe-area-inset-top)) + 106px); display: flex; flex-direction: column; gap: 6px; }
.emos button { width: 36px; height: 36px; opacity: .85; border-radius: 50%; border: 2px solid rgba(58,12,12,.6); background: rgba(253,240,213,.8); font-size: 19px; padding: 0; }
.emos button:active { transform: scale(.9); }
#bDash { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); width: 96px; height: 96px; border-radius: 50%;
  border: 4px solid var(--ink); background: var(--yel); box-shadow: 0 6px 0 var(--ink); font-size: 44px; padding: 0; overflow: hidden; }
#bDash span { position: relative; z-index: 2; }
#bDash i { position: absolute; inset: 0; background: conic-gradient(rgba(58,12,12,.55) var(--cd, 0%), transparent 0); z-index: 1; }
#bDash:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }

#banner { position: fixed; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none; font: 52px/1.1 Russo, sans-serif; color: var(--yel);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink); padding: 0 12px; }
#banner small { display: block; font: 22px/1.3 Russo, sans-serif; color: #fff; margin-top: 10px; }
#banner.anim { animation: bannerIn .5s cubic-bezier(.2,1.8,.4,1); }
@keyframes bannerIn { from { transform: scale(2.4); opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(150px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; transition: transform .3s; max-width: 90vw; text-align: center; z-index: 10; }
#toast.show { transform: translateX(-50%); }

@media (max-height: 640px) { .star { width: 70px; height: 70px; } .l1 { font-size: 26px; } .l3 { font-size: 44px; } .tie { width: 100px; } #bReady { margin-top: 10px; } }
@media (max-width: 380px) { .l3 { font-size: 46px; } .logo b { font-size: 52px; } }

/* лобби: выбор игры и карты */
.card.wide { max-width: 520px; }
.sec { font: 15px Russo, sans-serif; margin: 16px 0 6px; color: var(--red2); text-transform: uppercase; letter-spacing: .5px; }
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.games button { display: flex; gap: 8px; align-items: center; text-align: left; padding: 8px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; color: var(--ink); font: 700 15px Rubik, sans-serif; line-height: 1.15; min-height: 64px; }
.games button b { font-size: 28px; font-weight: 400; }
.games button small { display: block; font-weight: 400; font-size: 11.5px; opacity: .7; margin-top: 2px; }
.games button.on { background: var(--yel); box-shadow: 0 4px 0 var(--ink); transform: translateY(-2px); }
.games button:disabled, .maps button:disabled { cursor: default; }
.games button:disabled:not(.on), .maps button:disabled:not(.on) { opacity: .55; }
.maps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.maps button { padding: 4px 4px 6px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font: 700 12.5px Rubik, sans-serif; }
.maps button canvas { display: block; width: 100%; aspect-ratio: 240 / 168; border-radius: 8px; margin-bottom: 4px; }
.maps button.on { background: var(--yel); box-shadow: 0 4px 0 var(--ink); transform: translateY(-2px); }
.rules { margin-top: 10px; font-size: 14px; }
.rules .rt { font: 16px Russo, sans-serif; margin-bottom: 2px; }
.rules p { margin: 5px 0 0; }
#qrBox { text-align: center; }
.glist { text-align: center; font-size: 13px; margin-top: 14px; opacity: .75; }
.gbar.zarnitsa #gfill { background: linear-gradient(90deg, #e63946, #e63946 50%, #457b9d 50%); }
.gbar.svita #gfill { background: linear-gradient(90deg, #90be6d, #43aa8b); }
.gbar.potato #gfill { background: linear-gradient(90deg, #fb8500, #ffd60a); }
#roleChip.cake { background: #ef476f; animation: pulse .5s infinite; }
@media (max-width: 380px) { .games button { font-size: 13.5px; } .games button small { font-size: 10.5px; } }
