:root { --c1: #ff8a1f; --c2: #3df2ff; --gold: #ffe14a; --red: #ff3b5c; --green: #36e05b; --bg: #0b0d18; --panel: rgba(14, 16, 30, .9); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: #fff;
  font-family: "Russo One", system-ui, sans-serif; touch-action: none; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- экраны ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top)); background: radial-gradient(ellipse at center, rgba(11,13,24,.25) 0%, rgba(11,13,24,.8) 75%);
  z-index: 10; overflow-y: auto; touch-action: pan-y; }
.panel { width: min(400px, 100%); background: var(--panel); border: 2px solid rgba(255,138,31,.35); border-radius: 22px;
  padding: 22px 18px 16px; text-align: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 0 60px rgba(255,138,31,.15); animation: pop .35s ease-out; margin: auto; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.logo { font-size: 50px; letter-spacing: 1px; line-height: 1; color: var(--c1);
  text-shadow: 0 4px 0 #8a3d00, 0 0 24px rgba(255,138,31,.6); animation: wobble 2.4s ease-in-out infinite; }
.logo span { font-size: 24px; color: #fff; text-shadow: 0 3px 0 #555; }
@keyframes wobble { 0%, 100% { transform: rotate(-1.5deg) scale(1); } 50% { transform: rotate(1.5deg) scale(1.04); } }
.tag { color: #ffc98f; font-size: 13px; letter-spacing: 3px; text-transform: uppercase; margin: 10px 0 16px; }
input[type=text], #nick, #code { font: inherit; color: #fff; background: rgba(255,255,255,.07); border: 2px solid rgba(255,138,31,.4);
  border-radius: 14px; padding: 12px; outline: none; user-select: text; -webkit-user-select: text; text-align: center; }
#nick { width: 100%; font-size: 20px; }
#nick:focus, #code:focus { border-color: var(--c1); box-shadow: 0 0 18px rgba(255,138,31,.35); }
#colors { display: flex; justify-content: center; gap: 8px; margin: 12px 0 14px; flex-wrap: wrap; }
#colors button { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(0,0,0,.5); padding: 0; }
#colors button.on { border-color: #fff; box-shadow: 0 0 14px currentColor; transform: scale(1.18); }
.big { width: 100%; font-size: 24px; letter-spacing: 1px; color: #fff; border: 0; border-radius: 16px; padding: 14px;
  background: linear-gradient(180deg, #ff9d3d, #e6600b); box-shadow: 0 5px 0 #8a3d00, 0 8px 30px rgba(255,138,31,.4);
  text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #8a3d00; }
.big:disabled { filter: grayscale(1) brightness(.6); }
#joinBox .big { margin-bottom: 10px; background: linear-gradient(180deg, #4cff7a, #18a83f); box-shadow: 0 5px 0 #0b5a20, 0 8px 30px rgba(54,224,91,.4); }
.ghost { width: 100%; margin-top: 10px; font-size: 16px; color: #fff; background: rgba(61,242,255,.1);
  border: 1px solid rgba(61,242,255,.5); border-radius: 14px; padding: 12px; }
.ghost:active { background: rgba(61,242,255,.25); }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row #code { width: 45%; font-size: 20px; letter-spacing: 4px; text-transform: uppercase; }
.row .ghost { margin: 0; flex: 1; }
.sub { margin: 16px 0 6px; font-size: 13px; color: #8f97bd; letter-spacing: 2px; text-transform: uppercase; }
#rooms { display: grid; gap: 6px; max-height: 170px; overflow-y: auto; touch-action: pan-y; }
#rooms button { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 15px; color: #fff;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 10px 12px; }
#rooms button small { color: #8f97bd; font-family: system-ui, sans-serif; }
#rooms .empty { font-family: system-ui, sans-serif; font-size: 13px; color: #8f97bd; padding: 6px; }
.how { margin-top: 14px; font-family: system-ui, sans-serif; font-size: 13px; color: #c9cfee; text-align: left; }
.how summary { font-family: "Russo One", sans-serif; color: #ffc98f; cursor: pointer; text-align: center; list-style: none; }
.how div { margin-top: 6px; }
.how b { font-family: "Russo One", sans-serif; font-weight: normal; color: #fff; }
#online { margin-top: 12px; font-size: 13px; color: var(--c2); }
#langBtn { position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; z-index: 12; font-size: 14px; color: #fff;
  background: rgba(14,16,30,.8); border: 1px solid rgba(255,255,255,.2); border-radius: 12px; padding: 8px 10px; }

.dtitle { font-size: 30px; color: var(--red); text-shadow: 0 0 20px rgba(255,59,92,.5); line-height: 1.1; }
.place { font-size: 20px; color: var(--gold); margin: 6px 0 12px; font-family: system-ui, sans-serif; font-weight: 700; }
.best { color: var(--gold); min-height: 20px; margin: 10px 0; font-size: 14px; }
#resTable { display: grid; gap: 4px; max-height: 42vh; overflow-y: auto; text-align: left; touch-action: pan-y; }
#resTable .r { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 10px;
  background: rgba(255,255,255,.05); border-radius: 10px; font-size: 15px; }
#resTable .r.me { background: rgba(255,138,31,.2); outline: 1px solid rgba(255,138,31,.6); }
#resTable .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #000; }
#resTable small { color: #9aa3c9; font-family: system-ui, sans-serif; font-size: 12px; }
#resTable .st { font-size: 13px; }
.tipbody { font-family: system-ui, sans-serif; font-size: 16px; line-height: 1.8; text-align: left; margin: 14px 0; }
.tipbody b { font-family: "Russo One", sans-serif; font-weight: normal; color: var(--gold); }
.sh { display: inline-block; background: #2a6cff; border-radius: 6px; padding: 0 5px; }

/* ---------- комната (лобби) ---------- */
#roomPanel { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(440px, 100%); z-index: 8;
  background: var(--panel); border: 2px solid rgba(255,138,31,.35); border-bottom: 0; border-radius: 20px 20px 0 0;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); animation: up .3s ease-out; }
@keyframes up { from { transform: translate(-50%, 40px); opacity: 0; } }
.rhead { display: flex; gap: 8px; align-items: center; }
.rhead > div { flex: 1; text-align: left; line-height: 1; }
.rhead small { display: block; font-size: 10px; color: #8f97bd; letter-spacing: 2px; }
.rhead b { font-size: 30px; font-weight: normal; letter-spacing: 4px; color: var(--gold); }
.rhead .ghost { width: auto; margin: 0; padding: 10px 12px; font-size: 15px; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: #fff; font-size: 18px; }
#roomPanel.fold #rBody { display: none; }
#roomPanel.fold #rFold { transform: rotate(180deg); }
#rPlayers { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; max-height: 140px; overflow-y: auto; touch-action: pan-y; }
#rPlayers button { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #fff; background: rgba(255,255,255,.07);
  border: 2px solid transparent; border-radius: 12px; padding: 7px 10px; }
#rPlayers button.g { border-color: #4d7dff; background: rgba(60,100,255,.25); }
#rPlayers button.me { box-shadow: inset 0 0 0 1px rgba(255,255,255,.4); }
#rPlayers .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #000; }
.rrow { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; justify-content: center; }
.rrow.small { font-family: system-ui, sans-serif; font-size: 13px; color: #c9cfee; }
#rNg { display: flex; gap: 4px; }
#rNg button, .chip { min-width: 38px; height: 34px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.06); color: #fff; font-size: 15px; }
#rNg button.on { background: #4d7dff; border-color: #9db6ff; }
.chip { padding: 0 10px; }
.rhint { font-family: system-ui, sans-serif; font-size: 12px; color: #8f97bd; margin: 2px 0 6px; }
#rStart { margin-top: 6px; }
#rWait { font-family: system-ui, sans-serif; font-size: 14px; color: #c9cfee; padding: 6px 0 2px; }
#rWait b { font-family: "Russo One", sans-serif; font-weight: normal; color: var(--gold); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center;
  background: rgba(14,16,30,.72); border: 1px solid rgba(255,255,255,.15); border-radius: 14px; padding: 5px 10px; white-space: nowrap; }
#time { font-size: 20px; min-width: 52px; }
#time.low { color: var(--red); animation: blink .6s infinite; }
@keyframes blink { 50% { opacity: .35; } }
#quests { display: flex; gap: 3px; pointer-events: auto; }
#quests span { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: rgba(255,255,255,.08); filter: grayscale(.6); position: relative; }
#quests span.done { background: rgba(54,224,91,.35); filter: none; box-shadow: 0 0 10px rgba(54,224,91,.6); }
#quests span.done::after { content: "✓"; position: absolute; right: -2px; bottom: -4px; font-size: 12px; color: #6dff8e; text-shadow: 0 0 3px #000; }
#quests span.pop { animation: qpop .6s; }
@keyframes qpop { 40% { transform: scale(1.6); } }
#gateC { font-size: 16px; color: var(--gold); }
#gateC.open { color: var(--green); animation: blink .8s infinite; }
#role { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 46px); left: 50%; transform: translateX(-50%); font-size: 13px; letter-spacing: 1px;
  padding: 3px 10px; border-radius: 10px; background: rgba(14,16,30,.6); white-space: nowrap; }
#hint { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 72px); left: 50%; transform: translateX(-50%); width: min(92vw, 520px); text-align: center;
  font-family: system-ui, sans-serif; font-size: 14px; font-weight: 600; text-shadow: 0 1px 4px #000, 0 0 2px #000; }
#effects { position: absolute; left: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 8px); display: grid; gap: 4px; justify-items: start; }
#effects div { background: rgba(14,16,30,.8); border: 2px solid currentColor; border-radius: 10px; padding: 3px 8px; font-size: 13px; animation: pop .2s ease-out; }
#mini { position: absolute; right: 8px; top: calc(max(8px, env(safe-area-inset-top)) + 0px); width: 150px; height: 108px; border-radius: 10px;
  border: 2px solid rgba(255,255,255,.2); background: rgba(0,0,0,.5); }
#useBtn, #dashBtn { --p: 0%; pointer-events: auto; position: absolute; border-radius: 50%; border: 0; padding: 0; color: #fff; touch-action: none; }
#useBtn { right: 22px; bottom: calc(150px + env(safe-area-inset-bottom)); width: 112px; height: 112px; font-size: 15px;
  background: conic-gradient(var(--green) var(--p), rgba(255,255,255,.18) 0); box-shadow: 0 0 26px rgba(54,224,91,.55); animation: pop .2s; }
#useBtn b { position: absolute; inset: 7px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: normal;
  background: radial-gradient(circle, rgba(54,224,91,.55), rgba(10,40,20,.95)); }
#useBtn i { font-style: normal; font-size: 32px; line-height: 1.1; }
#useBtn.on { transform: scale(.94); }
#dashBtn { right: 30px; bottom: calc(30px + env(safe-area-inset-bottom)); width: 96px; height: 96px; font-size: 15px;
  background: conic-gradient(var(--c1) var(--p), rgba(255,255,255,.14) 0); box-shadow: 0 0 22px rgba(255,138,31,.5); }
#dashBtn b { position: absolute; inset: 6px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: normal;
  background: radial-gradient(circle, rgba(255,138,31,.55), rgba(50,20,0,.95)); }
#dashBtn.cd { box-shadow: none; }
#dashBtn.cd b { background: rgba(20,16,30,.92); color: #8f97bd; }
#dashBtn.g { background: conic-gradient(#4d7dff var(--p), rgba(255,255,255,.14) 0); box-shadow: 0 0 22px rgba(77,125,255,.6); }
#dashBtn.g b { background: radial-gradient(circle, rgba(77,125,255,.6), rgba(10,15,50,.95)); }
#dashBtn:active { transform: scale(.94); }
#emoBtn { pointer-events: auto; position: absolute; right: 136px; bottom: calc(40px + env(safe-area-inset-bottom)); width: 50px; height: 50px; border-radius: 50%;
  font-size: 24px; border: 1px solid rgba(255,255,255,.25); background: rgba(14,16,30,.7); }
#emos { pointer-events: auto; position: absolute; right: 110px; bottom: calc(100px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 46px); gap: 6px;
  background: rgba(14,16,30,.9); border: 1px solid rgba(255,255,255,.2); border-radius: 14px; padding: 8px; }
#emos button { height: 46px; font-size: 24px; border-radius: 10px; border: 0; background: rgba(255,255,255,.08); }
#keys { position: absolute; left: 12px; bottom: 12px; font-family: system-ui, sans-serif; font-size: 12px; color: #8f97bd; }
#keys b { color: #fff; font-weight: normal; font-family: "Russo One", sans-serif; }
body.touch #keys { display: none; }
body:not(.touch) #useBtn { width: 92px; height: 92px; bottom: 130px; }
body:not(.touch) #dashBtn { width: 80px; height: 80px; }
body.lobby #useBtn, body.lobby #top, body.lobby #role { display: none; }
body.lobby #mini { display: none; }
body.lobby #emoBtn { bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 4px); right: 10px; }
body.lobby #emos { bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 60px); right: 10px; }
body.lobby #dashBtn { bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 64px); right: 10px; width: 64px; height: 64px; font-size: 11px; }
body.lobby #hint { top: calc(max(8px, env(safe-area-inset-top)) + 8px); }
body.watch #useBtn, body.watch #dashBtn, body.watch #emoBtn { display: none; }

#announce { position: fixed; top: 30%; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 7; }
#announce div { font-size: 40px; letter-spacing: 1px; text-shadow: 0 3px 0 rgba(0,0,0,.6), 0 0 26px currentColor; animation: ann 2.4s forwards; padding: 0 10px; }
#announce small { display: block; font-size: 16px; color: #fff; text-shadow: 0 2px 6px #000; margin-top: 6px; font-family: system-ui, sans-serif; font-weight: 700; }
@keyframes ann { 0% { transform: scale(2.2); opacity: 0; } 12% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
#toast { position: fixed; left: 50%; bottom: calc(24% + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(14,16,30,.92); border: 1px solid rgba(255,255,255,.2);
  padding: 9px 16px; border-radius: 12px; font-size: 15px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 30; text-align: center; width: max-content; max-width: 90vw; }
#toast.show { opacity: 1; }
#conn { position: fixed; top: 40%; left: 50%; transform: translateX(-50%); background: rgba(14,16,30,.92); padding: 14px 22px; border-radius: 14px; z-index: 40; }
#mute { position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 10px; z-index: 12; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2);
  background: rgba(14,16,30,.7); font-size: 18px; }
body.playing #mute { bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 116px); right: 8px; left: auto; }
body.lobby #mute { top: auto; bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 136px); right: 22px; }

@media (max-width: 520px) {
  #top { gap: 5px; padding: 4px 7px; left: 8px; transform: none; }
  #time { font-size: 16px; min-width: 40px; }
  #quests span { width: 22px; height: 22px; font-size: 12px; border-radius: 6px; }
  #gateC { font-size: 12px; }
  #mini { width: 96px; height: 69px; top: max(8px, env(safe-area-inset-top)); }
  #role { left: 8px; transform: none; top: calc(max(8px, env(safe-area-inset-top)) + 40px); font-size: 11px; }
  #hint { top: calc(max(8px, env(safe-area-inset-top)) + 84px); font-size: 13px; width: calc(100vw - 20px); }
  #effects { top: calc(max(8px, env(safe-area-inset-top)) + 122px); left: 8px; }
  #effects div { font-size: 11px; }
  body.playing #mute { top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); left: 10px; right: auto; width: 34px; height: 34px; font-size: 15px; }
  body.lobby #mute { top: calc(max(8px, env(safe-area-inset-top)) + 136px); bottom: auto; right: 22px; left: auto; }
  #announce div { font-size: 30px; }
}
body.lobby #toast { bottom: auto; top: 22%; }
