:root {
    --accent: #ffc94a;
    --accent-ink: #2a1c00;
    --eyes: #38e1ff;
    --legs: #ff9a4a;
    --good: #3cf29a;
    --bad: #ff5a6a;
    --panel: rgba(10, 13, 22, 0.84);
    --panel-2: rgba(255, 255, 255, 0.05);
    --line: rgba(255, 255, 255, 0.11);
    --text: #eef1f8;
    --muted: #a0a8bd;
}
* { box-sizing: border-box; }
html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #040509;
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#c { display: block; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 16px 12px;
    overflow: auto;
}
.screen.dim { background: radial-gradient(ellipse at center, rgba(4, 6, 12, 0.4), rgba(4, 6, 12, 0.8)); }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
    margin: auto;
}
.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, border-color 0.2s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 800; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.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(255, 201, 74, 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, body.solo .client-only { display: none !important; }
body:not(.is-host) .host-only { display: none !important; }
body:not(.solo) .solo-only { display: none !important; }
body.solo .host-only { display: none !important; }

/* ---------- Menu ---------- */
.menu-panel { width: 100%; max-width: 420px; padding: 26px 24px 20px; text-align: center; }
.logo {
    font-family: 'Bungee', sans-serif;
    font-size: clamp(2.6rem, 11vw, 3.7rem);
    line-height: 0.95;
    color: var(--eyes);
    text-shadow: 0 4px 0 #0b3a4a, 0 0 30px rgba(56, 225, 255, 0.35);
}
.logo i { font-style: normal; color: #fff; font-size: 0.6em; vertical-align: 0.25em; text-shadow: none; }
.logo span { display: block; color: var(--accent); text-shadow: 0 4px 0 #6b4d0c, 0 0 30px rgba(255, 201, 74, 0.35); }
.tagline { color: var(--muted); margin: 12px auto 16px; max-width: 340px; 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(255, 201, 74, 0.12);
    border: 1px solid rgba(255, 201, 74, 0.4);
    color: #ffe2a0;
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 14px;
}

/* ---------- Lobby ---------- */
.lobby-panel { width: 100%; max-width: 640px; padding: 22px; display: grid; gap: 16px; }
.lobby-top { display: grid; grid-template-columns: 200px 1fr; gap: 14px; }
.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; display: grid; gap: 6px; align-content: center; }
.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(--accent); }
.room-box .btn { padding: 9px 10px; font-size: 0.85rem; }
.lobby-players { display: grid; gap: 8px; align-content: start; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; }
.section-title small { color: var(--muted); font-weight: 700; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.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; min-height: 50px; }
.player.me { border-color: rgba(255, 201, 74, 0.5); }
.player .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15); }
.player .who { flex: 1; min-width: 0; }
.player .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .who small { color: var(--muted); font-size: 0.75rem; }
.player.empty { opacity: 0.5; border: 1px dashed var(--line); background: none; justify-content: center; font-size: 0.82rem; color: var(--muted); }
.badge { font-size: 0.64rem; font-weight: 800; letter-spacing: 0.08em; padding: 3px 7px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); color: var(--muted); text-transform: uppercase; }
.badge.ok { background: rgba(60, 242, 154, 0.16); color: var(--good); }
.badge.host { background: rgba(255, 201, 74, 0.16); color: var(--accent); }
.kick { border: 1px solid var(--line); background: none; color: var(--muted); font-size: 0.75rem; font-weight: 700; padding: 5px 9px; border-radius: 8px; }
.kick:hover { color: var(--bad); border-color: var(--bad); }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-card { border-radius: 14px; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--line); }
.role-card b { font-family: 'Bungee', sans-serif; font-size: 1.15rem; letter-spacing: 0.04em; }
.role-card p { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.role-card.legs b { color: var(--legs); }
.role-card.eyes b { color: var(--eyes); }
.role-card.legs { border-color: rgba(255, 154, 74, 0.35); }
.role-card.eyes { border-color: rgba(56, 225, 255, 0.35); }
.swap-note { margin: 0; text-align: center; color: #d8def0; font-weight: 600; font-size: 0.9rem; }
.lobby-actions { display: grid; gap: 8px; position: sticky; bottom: -1px; z-index: 2; background: linear-gradient(rgba(10, 13, 22, 0), rgba(10, 13, 22, 0.96) 22%); padding-top: 10px; margin-top: -10px; }
.lobby-actions .status { text-align: center; }
@media (max-width: 620px) {
    .lobby-panel { padding: 16px; gap: 12px; }
    .lobby-top { grid-template-columns: 1fr; }
    .room-box { grid-template-columns: 1fr auto; text-align: left; align-items: center; }
    .room-box small { grid-column: 1 / -1; }
    .room-code { font-size: 1.6rem; }
    .roles { grid-template-columns: 1fr; }
    .role-card p { font-size: 0.78rem; }
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-tl { position: absolute; top: 14px; left: 16px; display: grid; gap: 8px; justify-items: start; }
.role-badge {
    font-family: 'Bungee', sans-serif;
    font-size: 1.5rem;
    line-height: 1;
    padding: 7px 14px 6px;
    border-radius: 12px;
    background: rgba(255, 154, 74, 0.16);
    border: 2px solid var(--legs);
    color: var(--legs);
    text-shadow: 0 0 18px rgba(255, 154, 74, 0.5);
}
body.role-eyes .role-badge { background: rgba(56, 225, 255, 0.14); border-color: var(--eyes); color: var(--eyes); text-shadow: 0 0 18px rgba(56, 225, 255, 0.5); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: rgba(0, 0, 0, 0.5); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; font-weight: 800; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip b { color: #fff; }
.lvname { font-weight: 800; font-size: 0.85rem; color: rgba(255, 255, 255, 0.75); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
#hud-hint {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    max-width: min(560px, calc(100vw - 32px));
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 16px;
    transition: opacity 0.6s;
}
#hud-hint:empty { display: none; }
body.role-eyes #hud-hint { bottom: 96px; }
#center-msg {
    position: absolute;
    top: 26%;
    left: 0;
    right: 0;
    text-align: center;
    font-family: 'Bungee', sans-serif;
    font-size: clamp(2.6rem, 11vw, 6rem);
    line-height: 1;
    color: #fff;
    text-shadow: 0 6px 0 rgba(0, 0, 0, 0.3), 0 10px 40px rgba(0, 0, 0, 0.5);
}
#center-msg small { display: block; font-family: 'Inter', sans-serif; font-size: 1rem; font-weight: 800; letter-spacing: 0.12em; margin-top: 8px; }
#center-msg.pop { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
#center-msg.good { color: var(--good); }
#center-msg.gold { color: var(--accent); }
#center-msg.bad { color: var(--bad); }
#flash { position: absolute; inset: 0; box-shadow: inset 0 0 160px 40px rgba(255, 90, 106, 0); transition: box-shadow 0.5s; }
#flash.on { box-shadow: inset 0 0 160px 40px rgba(255, 90, 106, 0.6); transition: none; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Ping toolbar for the guide */
body:not(.role-eyes) .guide-only { display: none !important; }
body.role-eyes .walker-only { display: none !important; }
#toolbar {
    position: absolute;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    padding: 6px;
    background: rgba(8, 16, 32, 0.82);
    border: 1px solid rgba(56, 225, 255, 0.3);
    border-radius: 18px;
    pointer-events: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
.tool {
    --c: #38e1ff;
    position: relative;
    display: grid;
    justify-items: center;
    gap: 2px;
    width: 72px;
    padding: 8px 4px 6px;
    border-radius: 13px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.04);
    color: var(--c);
    touch-action: none;
}
.tool svg { width: 26px; height: 26px; }
.tool span { font-size: 0.72rem; font-weight: 800; color: #dfe6f5; letter-spacing: 0.03em; }
.tool kbd { position: absolute; top: 3px; right: 6px; font: 800 0.6rem 'Inter', sans-serif; color: rgba(255, 255, 255, 0.4); }
.tool.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--c) 35%, transparent); }
.tool[data-k="stop"] { --c: #ff4d5e; }
.tool[data-k="jump"] { --c: #ffd23f; }
.tool[data-k="go"] { --c: #3cf29a; }
.tool[data-k="danger"] { --c: #ff8a1f; }
.tool.cool { opacity: 0.55; }
#viewbar { position: absolute; top: 14px; right: 16px; display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
#viewbar .btn { padding: 7px 12px; font-size: 0.8rem; background: rgba(0, 0, 0, 0.5); }
#viewbar .btn.on { border-color: var(--eyes); color: var(--eyes); }

/* Edge arrows pointing to off-screen pings */
#edges { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.edge-arrow { position: absolute; left: 0; top: 0; width: 46px; height: 46px; margin: -23px 0 0 -23px; will-change: transform; }
.edge-arrow svg { width: 100%; height: 100%; filter: drop-shadow(0 0 8px currentColor); }

/* Touch controls for the walker */
#joy {
    position: fixed;
    width: 130px;
    height: 130px;
    margin: -65px 0 0 -65px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    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(255, 154, 74, 0.9); border: 2px solid rgba(255, 255, 255, 0.5); }
#btn-jump {
    position: absolute;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(30px, env(safe-area-inset-bottom));
    width: 92px;
    height: 92px;
    border-radius: 50%;
    background: rgba(255, 201, 74, 0.18);
    border: 3px solid var(--accent);
    color: #ffe2a0;
    font-family: 'Bungee', sans-serif;
    font-size: 0.95rem;
    pointer-events: auto;
    touch-action: none;
    display: none;
}
body.touch.role-legs #btn-jump { display: block; }
#btn-jump:active, #btn-jump.down { background: rgba(255, 201, 74, 0.45); }

/* ---------- Intermission ---------- */
#inter { background: radial-gradient(ellipse at center, rgba(4, 6, 12, 0.25), rgba(4, 6, 12, 0.78)); }
.inter-box { text-align: center; }
.inter-role {
    font-family: 'Bungee', sans-serif;
    font-size: clamp(1.6rem, 6vw, 2.6rem);
    margin-top: 10px;
    color: #fff;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
}
.inter-role b { display: block; font-weight: 400; font-size: clamp(3.6rem, 17vw, 8rem); line-height: 1; margin-top: 4px; color: var(--legs); text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 60px rgba(255, 154, 74, 0.55); }
.inter-role.eyes b { color: var(--eyes); text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 60px rgba(56, 225, 255, 0.55); }
#inter-sub { color: #dfe4f2; font-weight: 600; max-width: 460px; margin: 12px auto 0; line-height: 1.45; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8); }
.inter-count { font-family: 'Bungee', sans-serif; font-size: 3.4rem; color: var(--accent); margin-top: 14px; min-height: 1.2em; }
.inter-count.pop { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }

/* ---------- Results ---------- */
.results-panel { width: 100%; max-width: 480px; padding: 26px; text-align: center; }
.results-panel h2 { font-family: 'Bungee', sans-serif; font-size: clamp(1.6rem, 6vw, 2.4rem); margin: 6px 0 12px; }
.stars { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.stars svg { width: 54px; height: 54px; }
.stars.big svg { width: 44px; height: 44px; }
.stars .on path { fill: var(--accent); stroke: #fff3c4; }
.stars svg.on { filter: drop-shadow(0 0 8px rgba(255, 201, 74, 0.55)); overflow: visible; }
.stars .off path { fill: rgba(255, 255, 255, 0.08); stroke: rgba(255, 255, 255, 0.25); }
.stars .on { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.stat-row { display: flex; justify-content: center; gap: 10px; margin-bottom: 14px; }
.stat-row div { flex: 1; max-width: 150px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 2px; }
.stat-row small { color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.stat-row b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.next-up { font-weight: 700; color: #dfe4f2; margin: 0 0 12px; }
.next-up b.legs { color: var(--legs); }
.next-up b.eyes { color: var(--eyes); }
.timer-bar { height: 5px; background: rgba(255, 255, 255, 0.08); border-radius: 99px; overflow: hidden; }
.timer-bar i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.final-panel { max-width: 560px; }
.levels-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 0.86rem; }
.levels-table th { color: var(--muted); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 800; padding: 4px 6px; text-align: left; }
.levels-table td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, 0.06); text-align: left; font-variant-numeric: tabular-nums; }
.levels-table td:first-child { font-weight: 700; }
.levels-table .mini-stars { color: var(--accent); letter-spacing: 1px; white-space: nowrap; }
.levels-table .mini-stars svg { width: 13px; height: 13px; vertical-align: -2px; }
.best { color: var(--accent); font-weight: 700; margin: 0 0 16px; min-height: 1.2em; font-size: 0.9rem; }
.results-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; align-items: center; }

/* ---------- Corner and toasts ---------- */
.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.5); display: inline-flex; align-items: center; }
.corner svg { width: 16px; height: 16px; }
#toasts { position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 30; pointer-events: none; justify-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: rgba(0, 0, 0, 0.78); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 0.88rem; text-align: center; animation: toast 3.2s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- Phones ---------- */
@media (max-width: 560px) {
    .hud-tl { top: 56px; left: 10px; gap: 6px; }
    .role-badge { font-size: 1.15rem; padding: 5px 10px 4px; }
    .chip { font-size: 0.74rem; padding: 4px 8px; }
    .tool { width: 60px; padding: 7px 2px 5px; }
    .tool svg { width: 22px; height: 22px; }
    .tool span { font-size: 0.64rem; }
    .tool kbd { display: none; }
    #viewbar { top: 56px; right: 10px; }
    #viewbar .btn { font-size: 0.72rem; padding: 6px 9px; }
    body.role-eyes #hud-hint { bottom: 86px; font-size: 0.76rem; }
    .stars svg { width: 44px; height: 44px; }
    .levels-table { font-size: 0.78rem; }
}
@media (max-height: 500px) {
    .screen { padding-top: 52px; }
    .hud-tl { top: 8px; left: 10px; gap: 5px; }
    .role-badge { font-size: 1.05rem; padding: 4px 9px 3px; }
    .chip { font-size: 0.72rem; padding: 3px 8px; }
    .lvname { display: none; }
    #viewbar { top: 8px; right: 10px; }
    #viewbar .btn { font-size: 0.72rem; padding: 5px 9px; }
    .corner { top: 8px; }
    #toolbar { bottom: 8px; padding: 4px; }
    .tool { width: 58px; padding: 5px 2px 4px; }
    .tool svg { width: 20px; height: 20px; }
    #hud-hint { bottom: 8px; font-size: 0.74rem; }
    body.role-eyes #hud-hint { bottom: 72px; }
    #btn-jump { width: 80px; height: 80px; bottom: 20px; }
    .inter-count { font-size: 2.4rem; margin-top: 6px; }
    .results-panel { padding: 16px; }
    .results-panel h2 { margin: 2px 0 8px; }
    .stars { margin-bottom: 8px; }
    .stars svg { width: 38px; height: 38px; }
    .lobby-panel { gap: 10px; padding: 14px; max-width: 760px; }
    .lobby-top { grid-template-columns: 220px 1fr; }
    .room-box { padding: 8px; gap: 4px; }
    .room-code { font-size: 1.5rem; }
    .player { min-height: 0; padding: 6px 10px; }
    .role-card { padding: 8px 12px; }
    .role-card p { font-size: 0.72rem; line-height: 1.35; }
    .swap-note { font-size: 0.8rem; }
    .lobby-actions .btn.big { padding: 11px 16px; }
}
/* Portrait phones: keep the walker hint clear of the character */
@media (max-aspect-ratio: 3/4) {
    body.role-legs #hud-hint { bottom: auto; top: 150px; }
}
