/* Office Chair Race — dumbshit.app */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg: #09090b;
    --bg-2: #18181b;
    --bg-3: #27272a;
    --border: #3f3f46;
    --text: #fafafa;
    --text-dim: #a1a1aa;
    --text-mute: #71717a;
    --accent: #46e0a0;
    --accent-hov: #6bf0bb;
    --gold: #f5c542;
    --silver: #c8c8d0;
}

html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

kbd, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* topbar */
.topbar { padding: 20px 24px 6px; max-width: 1180px; margin: 0 auto; }
.back { color: var(--text-mute); text-decoration: none; font-family: ui-monospace, monospace; font-size: 12px; }
.back:hover { color: var(--text); }
.topbar h1 { margin: 10px 0 4px; font-size: clamp(26px, 4vw, 38px); font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { margin: 0; color: var(--text-dim); font-size: 14px; }

.app { max-width: 1180px; margin: 0 auto; padding: 12px 24px 36px; }

/* screens */
.screen { display: block; }

/* cards */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 22px;
    max-width: 460px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.card.wide { max-width: 940px; }
.card.center { text-align: center; align-items: center; }
.card h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.hint { margin: 0; color: var(--text-mute); font-size: 12px; font-family: ui-monospace, monospace; }

/* spinner */
.spinner {
    width: 38px; height: 38px;
    border: 4px solid var(--bg-3);
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* form fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.lbl {
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 11px;
    color: var(--text-mute);
}
input[type=text] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 11px 13px;
    transition: border-color 0.15s;
}
input[type=text]:focus { outline: none; border-color: var(--accent); }
input[type=text]::placeholder { color: var(--text-mute); }

/* tabs */
.tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.tab {
    flex: 1; appearance: none; border: 0; background: transparent;
    color: var(--text-dim); font-family: inherit; font-size: 13px; font-weight: 600;
    padding: 8px; border-radius: 7px; cursor: pointer; transition: all 0.12s;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--bg-3); color: var(--text); }
.pane { display: flex; flex-direction: column; gap: 12px; }

/* checkboxes / toggles */
.chk { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; user-select: none; }
.chk:hover { color: var(--text); }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
.toggles { display: flex; gap: 8px 18px; flex-wrap: wrap; }

/* buttons */
.btn {
    appearance: none; border: 1px solid var(--border); background: var(--bg-3);
    color: var(--text); font-family: inherit; font-weight: 600; font-size: 13px;
    padding: 10px 16px; border-radius: 8px; cursor: pointer; transition: all 0.15s;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: var(--accent); color: #06251a; border-color: var(--accent);
    padding: 11px 22px; font-size: 14px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hov); border-color: var(--accent-hov); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-3); }

/* solo row */
.solo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 14px; }
.konami-flag { margin: 0; color: var(--gold); font-family: ui-monospace, monospace; font-size: 11px; }

/* lobby list */
.lobby-head { display: flex; justify-content: space-between; font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.06em; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 999px; background: var(--accent); margin-left: 4px; animation: pulse-dot 1.6s ease-in-out infinite; }
@keyframes pulse-dot { 50% { opacity: 0.3; } }
.count { color: var(--text); }
.lobby-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.lobby-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; }
.lobby-list li.empty { justify-content: center; color: var(--text-mute); font-size: 13px; font-family: ui-monospace, monospace; }
.lobby-row-name { font-size: 14px; font-weight: 600; }
.lobby-row-age { color: var(--text-mute); font-size: 11px; font-family: ui-monospace, monospace; margin-left: 8px; }

/* join screen */
.join-sub { margin: 0; color: var(--text-dim); font-size: 14px; }
.join-error { margin: 0; color: #fca5a5; font-size: 13px; line-height: 1.45; }

/* ===== room / pre-race ===== */
.room-card { max-width: 720px; gap: 14px; }
.room-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.room-head h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.room-sub {
    font-family: ui-monospace, monospace; font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-mute);
}
.room-grid { display: grid; grid-template-columns: 1fr 238px; gap: 18px; align-items: stretch; }
.room-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; justify-content: space-between; }
.cfg-host { display: flex; flex-direction: column; gap: 16px; }
.field-group { display: flex; flex-direction: column; gap: 8px; }

.share-block { display: flex; flex-direction: column; gap: 7px; }
.share-row { display: flex; gap: 6px; }
.share-row input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 12px; }
.waiting-status { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text-dim); font-size: 13px; }
.waiting-status.is-ready { color: var(--accent); }
.waiting-status.is-ready .pulse { animation: none; }
.pulse { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); flex: none; animation: pulse-dot 1.4s ease-in-out infinite; }
.cfg-readonly { margin: 0; color: var(--text-mute); font-size: 12px; font-family: ui-monospace, monospace; }

/* track picker — option cards with a route icon */
.track-picker { display: flex; gap: 8px; }
.track-opt {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 12px 8px 9px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text-mute); cursor: pointer;
    font-family: inherit; transition: border-color 0.13s, background 0.13s, color 0.13s;
}
.track-opt:hover { border-color: var(--text-mute); }
.track-opt.is-active {
    border-color: var(--accent); color: var(--accent);
    background: color-mix(in srgb, var(--accent) 13%, var(--bg));
}
.track-icon { width: 46px; height: 36px; }
.track-name { font-size: 13px; font-weight: 700; color: var(--text); }
.track-desc { font-size: 11px; color: var(--text-mute); font-family: ui-monospace, monospace; }

/* segmented lap selector */
.seg { display: inline-flex; align-self: flex-start; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg .chip { border: 0; border-right: 1px solid var(--border); border-radius: 0; background: var(--bg); padding: 9px 20px; }
.seg .chip:last-child { border-right: 0; }
.seg .chip.is-active { background: var(--accent); color: #06251a; }

/* right column — controls reference / chat */
.room-side { display: flex; flex-direction: column; min-width: 0; }
.room-help {
    display: flex; flex-direction: column; gap: 10px; height: 100%;
    background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.key-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.key-list li { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-dim); }
.key-list em { font-style: normal; color: var(--text-mute); }
.keycap { display: inline-flex; gap: 3px; flex: none; }
.help-tip {
    margin: auto 0 0; font-size: 11.5px; line-height: 1.55; color: var(--text-mute);
    border-top: 1px solid var(--border); padding-top: 10px;
}
.room-chat { flex: 1; display: flex; min-height: 300px; }

/* footer action bar */
.room-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    flex-wrap: wrap; padding-top: 15px; border-top: 1px solid var(--border);
}
.room-actions { display: flex; gap: 8px; }
.room-hint { text-align: right; margin: 0; min-height: 14px; }

kbd {
    display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px;
    color: var(--text); background: var(--bg-3);
    border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
}
.btn-lg { padding: 12px 30px; font-size: 15px; }

/* color picker */
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
    width: 44px; height: 44px; border-radius: 11px; cursor: pointer;
    border: 2px solid transparent; transition: transform 0.1s, border-color 0.1s;
    position: relative; box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.swatch:hover { transform: translateY(-2px); }
.swatch.is-active { border-color: var(--text); }
.swatch.is-active::after {
    content: '✓'; position: absolute; inset: 0; display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 16px; text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    appearance: none; border: 1px solid var(--border); background: var(--bg);
    color: var(--text-dim); font-family: inherit; font-size: 13px; font-weight: 600;
    padding: 7px 13px; border-radius: 999px; cursor: pointer; transition: all 0.12s;
}
.chip:hover { color: var(--text); border-color: var(--text-mute); }
.chip.is-active { background: var(--accent); color: #06251a; border-color: var(--accent); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* ================= GAME STAGE ================= */
.stage {
    position: relative;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    touch-action: none;
}
#canvas { display: block; width: 100%; height: 100%; outline: none; }

/* HUD overlay */
.hud { position: absolute; inset: 0; pointer-events: none; font-family: ui-monospace, "SF Mono", monospace; }
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px; }
.hud-lap {
    display: flex; flex-direction: column; gap: 2px;
    background: rgba(9,9,11,0.66); border: 1px solid var(--border);
    border-radius: 10px; padding: 7px 12px;
}
#hudLap { font-size: 14px; font-weight: 700; }
.hud-time { font-size: 19px; color: var(--accent); letter-spacing: 0.02em; }
.hud-pos {
    background: rgba(9,9,11,0.66); border: 1px solid var(--border);
    border-radius: 10px; padding: 7px 14px; font-size: 20px; font-weight: 800;
}
.hud-pos.is-1st { color: var(--gold); border-color: var(--gold); }
.hud-pos.is-2nd { color: var(--silver); }

.hud-bottom { position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 12px 14px; }
.hud-speed, .hud-map { background: rgba(9,9,11,0.6); border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
#miniMap { display: block; }

/* center messages + countdown */
.hud-center {
    position: absolute; top: 38%; left: 0; right: 0; text-align: center;
    font-size: clamp(26px, 5vw, 52px); font-weight: 900; letter-spacing: -0.01em;
    color: var(--text); text-shadow: 0 3px 18px rgba(0,0,0,0.9);
}
.hud-center.flash { animation: pop 0.4s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.countdown {
    position: absolute; inset: 0; display: grid; place-items: center;
    font-size: clamp(80px, 18vw, 200px); font-weight: 900; color: var(--accent);
    text-shadow: 0 6px 30px rgba(0,0,0,0.9);
}
.countdown span { animation: cd 1s ease-out; display: block; }
@keyframes cd { 0% { transform: scale(2.2); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(0.7); opacity: 0; } }

/* hud buttons */
.hud-btn {
    position: absolute; pointer-events: auto;
    appearance: none; background: rgba(9,9,11,0.66); border: 1px solid var(--border);
    color: var(--text); border-radius: 9px; cursor: pointer;
    font-family: ui-monospace, monospace; font-size: 14px; padding: 7px 10px;
}
.hud-btn:hover { background: var(--bg-3); }
.cam-btn { top: 58px; right: 14px; width: 46px; font-weight: 700; }
.mute-btn { top: 58px; right: 68px; }
.exit-btn { top: 58px; left: 14px; font-weight: 700; }

/* wasd hint */
.wasd-hint {
    position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px;
    background: rgba(9,9,11,0.6); border: 1px solid var(--border); border-radius: 8px;
    padding: 6px 12px; font-size: 11px; color: var(--text-dim);
}
.wasd-hint b { color: var(--text); }
.wasd-hint.fade { opacity: 0; transition: opacity 0.6s; }

/* debug panel */
.debug-panel {
    position: absolute; top: 96px; left: 14px; margin: 0;
    background: rgba(9,9,11,0.82); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; font-size: 11px; line-height: 1.5; color: var(--accent);
    white-space: pre; pointer-events: none;
}

/* touch controls */
.touch { position: absolute; inset: 0; pointer-events: none; }
.joy {
    position: absolute; left: 22px; bottom: 88px; width: 120px; height: 120px;
    border-radius: 999px; background: rgba(9,9,11,0.5); border: 2px solid var(--border);
    pointer-events: auto; touch-action: none;
}
.joy-knob {
    position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
    margin: -26px 0 0 -26px; border-radius: 999px;
    background: var(--accent); opacity: 0.85;
}
.touch-btns { position: absolute; right: 22px; bottom: 88px; display: flex; flex-direction: column; gap: 12px; }
.tbtn {
    pointer-events: auto; appearance: none; border: 2px solid var(--border);
    width: 92px; height: 64px; border-radius: 14px; font-family: ui-monospace, monospace;
    font-weight: 800; font-size: 14px; color: var(--text); cursor: pointer;
}
.tbtn-push { background: rgba(70,224,160,0.25); }
.tbtn-brake { background: rgba(252,165,165,0.22); }
.tbtn:active { transform: scale(0.94); }

/* overlays */
.overlay {
    position: absolute; inset: 0; background: rgba(0,0,0,0.78);
    display: grid; place-items: center; padding: 20px; z-index: 20;
    animation: modal-fade 0.2s ease-out both;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
    background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px;
    padding: 26px 24px; max-width: 380px; width: 100%; text-align: center;
    animation: modal-pop 0.32s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes modal-pop { 0% { opacity: 0; transform: translateY(14px) scale(0.95); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
.overlay-card h2 { margin: 0 0 8px; font-size: 26px; font-weight: 900; }
.overlay-card p { margin: 0 0 12px; color: var(--text-dim); font-size: 14px; }
.overlay-eyebrow { font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--text-mute); margin-bottom: 4px; }
.overlay-times { font-family: ui-monospace, monospace; font-size: 13px; color: var(--text-dim); line-height: 1.7; margin: 10px 0 16px; }
.overlay-times b { color: var(--text); }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; }

/* game shell layout: stage + side chat */
.game-chat { position: absolute; top: 14px; right: 14px; width: 240px; max-height: calc(100% - 28px); z-index: 15; }

/* footer */
.foot {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 12px; padding: 24px; max-width: 1180px; margin: 0 auto;
    color: var(--text-mute); font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: 0.04em;
}
.bmc-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-mute); text-decoration: none; transition: color 0.15s; }
.bmc-link:hover { color: #FFDD00; }

/* responsive */
@media (max-width: 720px) {
    .room-grid { grid-template-columns: 1fr; }
    .room-chat { min-height: 220px; }
    .game-chat { width: 180px; }
    .wasd-hint { display: none; }
}
@media (max-width: 520px) {
    .game-chat { display: none; }
    .hud-center { font-size: 30px; }
}

/* ================= MOBILE / TOUCH ================= */
/* On a touch device the 16:9 letterbox is unplayable — the race takes the
   whole screen, the info HUD compacts into a top strip, and the bottom
   corners are left clear for the joystick / action thumbs. */
.rotate-notice { display: none; }

@media (pointer: coarse) {
    #game:not(.hidden) .stage {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        margin: 0;
        border: 0;
        border-radius: 0;
        aspect-ratio: auto;
        z-index: 60;
    }

    /* lap / time / position — compact */
    .hud-top { padding: 7px 9px; }
    .hud-lap { padding: 5px 9px; }
    #hudLap { font-size: 11px; }
    .hud-time { font-size: 15px; }
    .hud-pos { font-size: 15px; padding: 5px 11px; }

    /* speed gauge dropped on mobile — you feel speed, and it just adds clutter */
    .hud-speed { display: none; }

    /* minimap: small, parked top-centre, clear of the thumb zones */
    .hud-bottom {
        top: 6px; bottom: auto;
        left: 50%; right: auto; transform: translateX(-50%);
        width: auto; padding: 0; justify-content: center;
    }
    .hud-map { padding: 4px; }
    #miniMap { width: 78px; height: 78px; }

    /* corner buttons: smaller, tucked under the lap / pos boxes */
    .hud-btn { font-size: 12px; padding: 6px 9px; }
    .cam-btn { top: 52px; right: 9px; width: auto; }
    .mute-btn { top: 52px; right: 58px; }
    .exit-btn { top: 52px; left: 9px; }
    .debug-panel { top: 88px; font-size: 9px; }

    /* touch controls in the natural bottom-corner thumb reach */
    .joy { left: 18px; bottom: 20px; width: 116px; height: 116px; }
    .joy-knob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
    .touch-btns { right: 18px; bottom: 20px; gap: 14px; }
    .tbtn { width: 98px; height: 72px; font-size: 15px; }

    .hud-center { font-size: clamp(26px, 7vw, 46px); }
    .countdown { font-size: clamp(72px, 22vw, 150px); }
}

/* portrait phones — a corridor racer wants landscape */
@media (pointer: coarse) and (orientation: portrait) {
    #game:not(.hidden) .rotate-notice {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 80;
        align-items: center;
        justify-content: center;
        background: var(--bg);
        text-align: center;
    }
}
.rotate-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px; }
.rotate-icon {
    font-size: 58px;
    color: var(--accent);
    animation: rotate-hint 2.4s ease-in-out infinite;
}
@keyframes rotate-hint { 0%, 50%, 100% { transform: rotate(0); } 72% { transform: rotate(-90deg); } }
.rotate-inner p { margin: 0; font-size: 20px; font-weight: 800; }
.rotate-inner span { color: var(--text-mute); font-size: 13px; max-width: 260px; }
