:root {
    --accent: #3b82f6;
    --accent-ink: #0a1a3e;
    --warn: #f2c14e;
    --bad: #e0584f;
    --panel: rgba(14, 16, 22, 0.88);
    --panel-2: rgba(255, 255, 255, 0.05);
    --line: rgba(255, 255, 255, 0.1);
    --text: #eef0f4;
    --muted: #9fa8b8;
    --safe: #2ec495;
    --it: #e0584f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e1016; color: var(--text); font-family: 'Inter', system-ui, sans-serif; -webkit-user-select: none; user-select: none; }
#c { display: block; width: 100vw; height: 100vh; touch-action: none; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
.display { font-family: 'Bungee', 'Inter', sans-serif; }
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.screen.dim { background: radial-gradient(ellipse at center, rgba(8,10,14,0.35), rgba(8,10,14,0.72)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; backdrop-filter: blur(10px); box-shadow: 0 24px 70px rgba(0,0,0,0.45); }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-weight: 700; font-size: 0.95rem; padding: 11px 18px; border-radius: 12px; transition: transform 0.12s, background-color 0.2s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 800; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { width: 100%; font-size: 1.02rem; padding: 14px 20px; }
.field { width: 100%; font: 600 1rem 'Inter', sans-serif; color: var(--text); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; -webkit-user-select: text; user-select: text; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.18); }
.kicker { color: var(--accent); font-weight: 800; font-size: 0.75rem; letter-spacing: 0.2em; text-transform: uppercase; }
.status { min-height: 1.3em; color: var(--muted); font-size: 0.88rem; }
.status.error { color: #ff8a80; }
body.is-host .client-only { display: none !important; }
body:not(.is-host) .host-only { display: none !important; }

.menu-panel { width: 100%; max-width: 420px; padding: 30px 26px; text-align: center; }
.logo { font-family: 'Bungee', sans-serif; font-size: clamp(2.4rem, 10vw, 3.4rem); line-height: 0.95; color: #fff; text-shadow: 0 4px 0 #1a3a6e, 0 10px 30px rgba(0,0,0,0.4); }
.logo span { display: block; color: var(--bad); text-shadow: 0 4px 0 #6e1a1a, 0 10px 30px rgba(0,0,0,0.4); }
.tagline { color: var(--muted); margin: 14px auto 20px; max-width: 330px; line-height: 1.5; }
.menu-form { display: grid; gap: 10px; text-align: left; margin-bottom: 10px; }
.menu-form label { font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.join-row { display: flex; gap: 8px; }
.join-row .field { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 800; text-align: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.15em; margin: 6px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.invite { background: rgba(242,193,78,0.12); border: 1px solid rgba(242,193,78,0.4); color: #ffe2a0; border-radius: 12px; padding: 10px 12px; font-weight: 600; font-size: 0.9rem; margin-bottom: 14px; }

.lobby-panel { width: 100%; max-width: 440px; padding: 22px; }
.room-box { background: rgba(0,0,0,0.3); border: 1px dashed rgba(255,255,255,0.2); border-radius: 14px; padding: 12px; text-align: center; margin-bottom: 14px; }
.room-box small { color: var(--muted); font-weight: 800; font-size: 0.68rem; letter-spacing: 0.15em; text-transform: uppercase; }
.room-code { font-family: 'Bungee', sans-serif; font-size: 2rem; letter-spacing: 0.12em; color: var(--warn); margin: 2px 0 8px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; margin-bottom: 8px; }
.section-title small { color: var(--muted); font-weight: 700; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; margin-bottom: 14px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--panel-2); border: 1px solid transparent; font-size: 0.9rem; }
.player.me { border-color: rgba(59,130,246,0.5); }
.player .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.player .who { flex: 1; }
.player .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 0.64rem; font-weight: 800; padding: 3px 7px; border-radius: 6px; background: rgba(255,255,255,0.08); color: var(--muted); text-transform: uppercase; }
.badge.ok { background: rgba(59,130,246,0.18); color: var(--accent); }
.badge.host { background: rgba(242,193,78,0.16); color: var(--warn); }
.kick { margin-left: 6px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 0.66rem; font-weight: 800; padding: 3px 7px; border-radius: 6px; }
.kick:hover { color: #ff8a80; border-color: #ff8a80; }
.lobby-actions { display: grid; gap: 8px; }
.chip { background: rgba(0,0,0,0.45); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; font-weight: 800; font-size: 0.85rem; color: var(--muted); }
.chip b { color: #fff; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-tl { position: absolute; top: 12px; left: max(12px, env(safe-area-inset-left)); display: grid; gap: 6px; justify-items: start; }
.role-badge { font-family: 'Bungee', sans-serif; font-size: 1.25rem; padding: 4px 14px; border-radius: 12px; display: inline-block; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }
.role-badge.runner { background: rgba(10,60,42,0.85); color: #6bffb0; border: 2px solid var(--safe); }
.role-badge.tagger { background: rgba(110,16,12,0.9); color: #ffb4a8; border: 2px solid var(--it); animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 18px var(--it); } }
.survivor-count { font-weight: 800; font-size: 0.8rem; background: rgba(10,14,22,0.75); border-radius: 8px; padding: 3px 9px; color: var(--muted); }
.survivor-count b { font-size: 0.95rem; margin-right: 2px; }
.survivor-count b.safe { color: #6bffb0; }
.survivor-count b.it { color: #ff8a7a; margin-left: 6px; }
.player-tags { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; width: 250px; }
.ptag { display: flex; align-items: center; gap: 5px; min-width: 0; font-size: 0.78rem; font-weight: 800; padding: 4px 7px; border-radius: 8px; background: rgba(10,14,22,0.78); border-left: 3px solid var(--safe); color: #fff; }
.ptag i { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); }
.ptag b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptag em { font-style: normal; font-size: 0.7rem; color: var(--muted); }
.ptag.it { border-left-color: var(--it); background: rgba(110,18,14,0.85); }
.ptag.it em { color: #ffb4a8; }
.ptag.me { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.75); }
.hud-timer { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; min-width: 96px; padding: 4px 16px 6px; border-radius: 16px; background: rgba(10,14,22,0.78); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,0.25); }
.hud-timer small { font-size: 0.6rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.hud-timer small b { color: #fff; }
#timer { font-family: 'Bungee', sans-serif; font-size: 2rem; line-height: 1.05; color: var(--warn); }
.hud-timer.low { border-color: var(--it); }
.hud-timer.low #timer { color: #ff6a5a; animation: tick 0.5s infinite alternate; }
@keyframes tick { to { transform: scale(1.12); } }
#center-msg { position: absolute; top: 22%; left: 0; right: 0; padding: 0 16px; text-align: center; }
#center-msg .cm-main { font-family: 'Bungee', sans-serif; font-size: clamp(2rem, 8.5vw, 5rem); line-height: 1.05; color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,0.45), 0 8px 30px rgba(0,0,0,0.5); overflow-wrap: anywhere; }
#center-msg.count .cm-main { font-size: clamp(4rem, 18vw, 8.5rem); }
#center-msg.it .cm-main { color: #ff5a48; }
#center-msg.good .cm-main { color: #5ff0ae; }
#center-msg.info .cm-main { color: #9fd8ff; }
#center-msg .cm-sub { display: inline-block; margin-top: 10px; padding: 6px 14px; border-radius: 999px; background: rgba(10,14,22,0.78); font-weight: 800; font-size: clamp(0.85rem, 3.4vw, 1.1rem); color: #fff; }
#center-msg.show { animation: pop 0.45s cubic-bezier(0.2,1.6,0.4,1); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#flash { position: absolute; inset: 0; opacity: 0; }
#flash.it { background: radial-gradient(ellipse at center, rgba(255,40,20,0.12) 35%, rgba(255,30,10,0.7)); animation: flash 1s ease-out forwards; }
#flash.hit { background: radial-gradient(ellipse at center, rgba(255,255,255,0.5), rgba(255,240,200,0.25)); animation: flash 0.4s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
#offarrow { position: absolute; left: 0; top: 0; width: 0; height: 0; display: none; align-items: center; justify-content: center; }
#offarrow-rot { position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; left: 0; top: 0; }
#offarrow svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }
#offarrow.threat path { fill: #ff4a3a; stroke: #fff; stroke-width: 1.5; }
#offarrow.prey path { fill: #3ee89c; stroke: #fff; stroke-width: 1.5; }
#offarrow-d { position: absolute; transform: translate(-50%, -50%); font-size: 0.62rem; font-weight: 900; color: #fff; background: rgba(10,14,22,0.8); padding: 1px 5px; border-radius: 6px; margin-top: 30px; white-space: nowrap; }

.hud-bottom { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 18px; }
.stamina-bar { position: relative; width: 160px; height: 14px; background: rgba(10,14,22,0.75); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.stamina-fill { height: 100%; background: linear-gradient(90deg, var(--safe), #8ff0cf); border-radius: 7px; transition: width 0.1s; width: 100%; }
.stamina-bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.55rem; font-weight: 800; color: rgba(255,255,255,0.85); }
.ring { position: relative; width: 42px; height: 42px; }
.ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.5rem; font-weight: 900; color: var(--muted); }
#dodge-cd { display: flex; align-items: center; gap: 8px; background: rgba(10,14,22,0.75); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 6px; }
#dodge-cd b { font-size: 0.85rem; }
#powerup-hud { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); background: rgba(10,14,22,0.8); padding: 6px 14px; border-radius: 10px; border: 1px solid #9fd8ff; color: #9fd8ff; font-weight: 800; font-size: 0.9rem; }

.results-panel { width: 100%; max-width: 500px; padding: 26px; text-align: center; }
.results-panel h2 { font-family: 'Bungee', sans-serif; font-size: clamp(1.6rem, 5vw, 2.2rem); margin: 6px 0 16px; }
.results-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; text-align: left; }
.results-list li { display: grid; grid-template-columns: 40px 14px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--panel-2); }
.results-list li.me { background: rgba(59,130,246,0.16); outline: 1px solid rgba(59,130,246,0.5); }
.results-list .place { font-family: 'Bungee', sans-serif; font-size: 1.3rem; text-align: center; color: var(--muted); }
.results-list li:nth-child(1) .place { color: #ffd166; }
.results-list li:nth-child(2) .place { color: #dfe6ee; }
.results-list li:nth-child(3) .place { color: #e0a068; }
.results-list .dot { width: 12px; height: 12px; border-radius: 50%; }
.results-list .score { font-weight: 800; font-size: 0.85rem; color: var(--muted); }
.results-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; align-items: center; }
.corner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; z-index: 20; }
.corner .btn { padding: 7px 12px; font-size: 0.8rem; background: rgba(0,0,0,0.45); display: inline-flex; align-items: center; }
.corner svg { width: 16px; height: 16px; }
body.in-game .corner { left: auto; right: max(12px, env(safe-area-inset-right)); transform: none; }
#toasts { position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 30; pointer-events: none; justify-items: center; }
.toast { background: rgba(10,14,22,0.82); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 0.88rem; animation: toast 3.2s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* Touch */
#joy { position: fixed; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.28); display: none; }
#joy.on { display: block; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: rgba(59,130,246,0.9); border: 2px solid rgba(255,255,255,0.5); }
#touch-dodge { position: absolute; right: max(22px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom)); width: 84px; height: 84px; border-radius: 50%; background: rgba(37,99,235,0.55); border: 3px solid #bcd4ff; color: #fff; font-family: 'Bungee', sans-serif; font-size: 0.72rem; pointer-events: auto; touch-action: none; display: none; box-shadow: 0 6px 18px rgba(0,0,0,0.3); transition: opacity 0.15s; }
#touch-dodge.cooling { opacity: 0.45; }
#touch-sprint { position: absolute; right: calc(max(22px, env(safe-area-inset-right)) + 96px); bottom: max(34px, env(safe-area-inset-bottom)); width: 68px; height: 68px; border-radius: 50%; background: linear-gradient(to top, rgba(234,179,8,0.75) var(--fill, 100%), rgba(10,14,22,0.55) var(--fill, 100%)); border: 3px solid #ffe2a0; color: #fff; font-family: 'Bungee', sans-serif; font-size: 0.6rem; pointer-events: auto; touch-action: none; display: none; box-shadow: 0 6px 18px rgba(0,0,0,0.3); }
body.touch #touch-dodge { display: block; }
body.touch #touch-sprint { display: block; }
body.touch .hud-bottom { display: none; }
body.touch #powerup-hud { bottom: 130px; }
body.touch #toasts { bottom: 140px; }

@media (max-width: 600px) {
    .role-badge { font-size: 1rem; padding: 3px 10px; }
    .player-tags { width: 176px; gap: 3px; }
    .ptag { font-size: 0.68rem; padding: 3px 5px; }
    .ptag em { font-size: 0.62rem; }
    .hud-timer { min-width: 76px; padding: 3px 12px 4px; }
    #timer { font-size: 1.6rem; }
}
@media (max-height: 450px) {
    .hud-tl { top: 8px; gap: 4px; display: flex; flex-wrap: wrap; align-items: center; width: min(360px, calc(50vw - 70px)); }
    .role-badge { font-size: 0.95rem; padding: 2px 10px; }
    .survivor-count { padding: 2px 8px; }
    .player-tags { flex-basis: 100%; width: auto; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; }
    .ptag { font-size: 0.64rem; padding: 2px 4px; gap: 3px; }
    .ptag em { font-size: 0.58rem; }
    .hud-timer { top: 6px; padding: 2px 12px 3px; }
    #timer { font-size: 1.5rem; }
    #center-msg { top: 16%; }
    #touch-dodge { width: 74px; height: 74px; bottom: 20px; }
    #touch-sprint { width: 60px; height: 60px; bottom: 24px; right: calc(max(22px, env(safe-area-inset-right)) + 86px); }
    body.in-game #toasts { top: 60px; bottom: auto; }
    .toast { font-size: 0.78rem; padding: 6px 12px; }
}
@media (min-width: 601px) and (min-height: 451px) {
    body.in-game #toasts { top: 86px; bottom: auto; }
}
