:root {
    --bg: #0b0d16;
    --bg-2: #12151f;
    --panel: rgba(18, 21, 31, 0.82);
    --panel-solid: #141824;
    --border: rgba(255, 255, 255, 0.08);
    --text: #e6e8ef;
    --muted: #8a90a3;
    --accent: #6c8cff;
    --accent-2: #57e0c8;
    --danger: #ff6b6b;
    --radius: 12px;
    font-synthesis: none;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    height: 100dvh; /* track mobile browser chrome (address bar) */
    overflow: hidden;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

#viewport {
    position: fixed;
    inset: 0;
    z-index: 0;
}
#viewport canvas { display: block; }

/* ---------- Corner HUD ---------- */
#hud {
    position: fixed;
    left: 16px;
    bottom: 16px;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(340px, 80vw);
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
    color: var(--accent-2);
    filter: drop-shadow(0 0 8px rgba(87, 224, 200, 0.5));
}
.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(90deg, #fff, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hud-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.hud-hint {
    font-size: 12px;
    line-height: 1.6;
    color: var(--muted);
}
.hud-hint kbd {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-family: ui-monospace, monospace;
    font-size: 11px;
}
.stats {
    font-family: ui-monospace, 'SF Mono', monospace;
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
    white-space: pre-wrap;
    min-height: 1em;
}
.stats b { color: var(--text); font-weight: 600; }
.repo-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.repo-link:hover { text-decoration: underline; }

/* ---------- Overlay ---------- */
#overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 40%, #161a28, var(--bg));
    transition: opacity 0.4s;
}
#overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 40px;
    text-align: center;
}
.overlay-card .logo-text { font-size: 32px; }
.overlay-card .logo-mark { font-size: 34px; }
.spinner-line { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#overlay-error {
    max-width: 460px;
    padding: 18px 22px;
    border: 1px solid rgba(255, 107, 107, 0.35);
    border-radius: var(--radius);
    background: rgba(255, 107, 107, 0.08);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}
#overlay-error .muted { color: var(--muted); font-size: 12px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- lil-gui placement ---------- */
.lil-gui.root {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 12;
    --background-color: var(--panel-solid);
    --widget-color: #232838;
    --focus-color: var(--accent);
    --font-size: 12px;
    --title-background-color: #1a1f2e;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
    .lil-gui.root { top: 10px; right: 10px; max-height: 70dvh; }
    #hud { max-width: min(340px, 62vw); font-size: 11px; }
}
