:root {
    --accent: #fb923c;
    --accent-dark: #c2410c;
    --brand-dark: #1a202c;
    --theme-light: #fffaf3;
    --bg: #fb923c;
    --surface: #ffffff;
    --muted: #6b7280;
    --radius-lg: 8px;
    --radius-sm: 6px;
    --border: 3px solid var(--brand-dark);
    --border-thin: 2px solid var(--brand-dark);
    --font-body: 'IBM Plex Mono', 'Courier New', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-display: 'Atkinson Hyperlegible', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    outline: none;
    max-width: 100%;
    font-family: var(--font-body);
    color: var(--brand-dark);
}

h1, h2, h3 { font-family: var(--font-display); }

html, body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    height: 100%;
    background: #fb923c;
}

/* ---- Mobile-first safe areas ----
   viewport-fit=cover lets the canvas fill edge to edge, but that also puts the
   fixed HUD and floating controls under the notch / Dynamic Island / home
   indicator. These custom props carry the inset the rest of the layout offsets
   by; on hardware without insets env() is 0, so nothing changes on desktop. */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

a {
    text-decoration: none;
}

.container {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.container.active {
    display: flex;
}


/* Menu toggle is now an icon-btn in .floating-controls (bottom-left). */

input {
    background:none;
    padding:10px;
    border: #3f3d56;
    margin-left: 70px;
    position:relative;
    display:block;
    font-size:1em;
}

label {
    font-size:0.8em;
    text-transform: uppercase;
    margin-top: 10px;
}

input + .border {
    margin-bottom:10px;
    height:1px;
    width:0px;
    position:absolute;
    background:#fff;
    transform:translateY(-1px);
    transition:0.5s all;
}

input:focus + .border {
    width:calc(100% - 20px);
}

button {
    margin-top:10px;
    background: var(--accent);
    border-radius: 6px;
    border: 3px solid var(--brand-dark);
    color: var(--brand-dark);
    font-size:0.85em;
    font-weight: 700;
    text-transform: none;
    padding: 10px 14px;
    width:100%;
    transition: background 120ms ease, color 120ms ease, transform 100ms ease;
    cursor:pointer;
}

/* Global hover for all buttons (geekly style) */
button:hover { background: var(--accent-dark); color: #fff; transform: translate(-1px, -1px); }
button:active { transform: translate(1px, 1px); }

canvas {
    opacity:0;
    transition:none;
    transform:translateY(-20px);
}

canvas.active {
    transition:1s all;
    opacity:1;
    transform:none;
}

.streak-flame { margin-left: 8px; font-weight: 600; }

/* Floating controls (audio toggle + leaderboard) sit bottom-left so they never overlap the HUD */
.floating-controls {
    position: fixed;
    bottom: calc(16px + var(--safe-bottom));
    left: calc(16px + var(--safe-left));
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
}
.icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    background: var(--brand-dark);
    color: #fff;
    border: 3px solid var(--brand-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18);
    cursor: pointer;
}
.icon-btn:hover { background: var(--accent-dark); border-color: var(--brand-dark); color: #fff; transform: translate(-1px, -1px); }
.icon-btn:active { transform: translate(1px, 1px); }
/* Force SVG icon color to follow the button (the universal `* { color: var(--brand-dark) }` rule
   above otherwise paints icons the same as the dark button background, making them invisible). */
.icon-btn svg, .icon-btn svg * { color: #fff; stroke: #fff; display: block; }
.icon-btn:hover svg, .icon-btn:hover svg * { color: #fff; stroke: #fff; }
.win-percentile { text-align: center; color: #16A086; font-weight: 600; margin: 0 0 8px; }
.ad-slot { min-height: 0; margin: 8px 0; }
.ad-slot:not(:empty) { min-height: 100px; }
.players-online { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 8px; }

/* ----------- Modern HUD ----------- */
.hud-modern {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    padding: 6px 8px;
}
.hud-stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.hud-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    background: var(--surface);
    border: var(--border);
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--brand-dark);
}
.hud-pill .hud-icon { font-size: 14px; line-height: 1; }
.hud-pill.hud-hints { cursor: pointer; transition: background 120ms ease, color 120ms ease, transform 100ms ease; }
.hud-pill.hud-hints:hover { background: var(--accent-dark); color: white; transform: translate(-1px, -1px); }
.hud-pill.hud-points { background: var(--accent); color: white; border-color: var(--brand-dark); }
.hud-pill.hud-points * { color: white; }
.hud-bonuses { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.hud-chip {
    padding: 2px 8px;
    background: rgba(255,255,255,0.85);
    border: 1px solid var(--brand-dark);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.hud-chip.ok { background: #d1fae5; color: #065f46; border-color: #065f46; }
.hud-chip.dim { opacity: 0.5; }

/* Mobile / small screens: HUD becomes a horizontal bar above the tiles */
@media (max-width: 768px) {
    .hud {
        top: calc(8px + var(--safe-top));
        left: calc(8px + var(--safe-left));
        right: calc(8px + var(--safe-right));
        width: auto;
        border-radius: 10px;
        padding: 8px 12px;
        background: rgba(255,255,255,0.92);
        box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    }
    .hud-modern {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }
    .hud-stats {
        justify-content: center;
        flex-wrap: nowrap;
        width: 100%;
        gap: 4px;
    }
    .hud-pill {
        padding: 3px 7px;
        font-size: 11px;
        gap: 4px;
        flex: 0 1 auto;
        min-width: 0;
    }
    .hud-pill .hud-icon svg { width: 12px; height: 12px; }
    .hud-bonuses { justify-content: center; width: 100%; }
    #modeLabel { display: none; }
    /* Push the canvas/game below the HUD so it's not obscured */
    #game { padding-top: calc(64px + var(--safe-top)); box-sizing: border-box; }
    .floating-controls { bottom: calc(12px + var(--safe-bottom)); left: calc(12px + var(--safe-left)); gap: 8px; }
    .icon-btn { width: 40px; height: 40px; }
}

/* ----------- Win modal points block ----------- */
.win-points-block {
    text-align: center;
    margin: 8px 0 12px;
    padding: 12px;
    background: rgba(251, 146, 60, 0.08);
    border: var(--border);
    border-radius: var(--radius-lg);
}
.points-headline { font-size: 28px; font-weight: 700; color: var(--accent-dark); font-family: var(--font-display); }
.points-breakdown { font-size: 12px; color: var(--muted); margin: 4px 0; }
.points-balance { font-size: 13px; font-weight: 500; }
.win-ad-actions { display: flex; gap: 8px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.win-ad-actions button { width: auto; padding: 6px 14px; }

/* ----------- Pattern picker ----------- */
.pattern-picker .pattern-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px; margin-top: 12px;
}
.pattern-card {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px;
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    width: auto;
}
.pattern-card .swatch {
    width: 48px; height: 48px; border-radius: 50%;
    border: var(--border);
    display: inline-flex; align-items: center; justify-content: center;
}
.pattern-card .swatch .bar { width: 26px; height: 4px; border-radius: 2px; }
.pattern-card .pname { font-size: 12px; font-weight: 500; color: var(--brand-dark); }
.pattern-card:hover { transform: translateY(-2px); }

/* ----------- Levels grid ----------- */
.levels-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
    gap: 8px; margin-top: 10px;
    max-height: 60vh; overflow-y: auto; padding: 4px;
}
.level-card {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 4px;
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    width: auto;
    position: relative;
    color: var(--brand-dark);
}
.level-card.done { background: #fff7ed; }
.level-card.locked { opacity: 0.55; cursor: pointer; }
.level-card .level-id { font-size: 18px; font-weight: 700; font-family: var(--font-display); }
.level-card .level-stars { font-size: 11px; color: var(--accent-dark); letter-spacing: 1px; }
.level-card .level-size { font-size: 10px; color: var(--muted); }
.level-card .level-skip { position: absolute; top: 4px; right: 4px; font-size: 10px; }
.level-card:hover:not(:disabled) { transform: translateY(-2px); }
