/* Spec Writer — FunSlop.com
   Write a literal policy; the agent executes it exactly. Neon-on-near-black,
   self-contained, mobile-first. */

:root {
    --bg-dark: #090b10;
    --bg-panel: #0e1119;
    --bg-cell: #10151f;
    --neon-green: #39ff14;
    --neon-purple: #bd00ff;
    --cyan: #05d9e8;
    --pink: #ff2a6d;
    --gold: #ffd54a;
    --text-primary: #f0f4f8;
    --text-muted: #8b9bb4;
    --glass-border: rgba(255, 255, 255, 0.08);
    --font-body: 'Outfit', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Space Grotesk', 'Outfit', system-ui, sans-serif;
    --radius: 14px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body { min-height: 100%; }

body {
    font-family: var(--font-body);
    background: var(--bg-dark);
    color: var(--text-primary);
    background-image:
        radial-gradient(circle at 14% 12%, rgba(189, 0, 255, 0.14), transparent 42%),
        radial-gradient(circle at 86% 88%, rgba(5, 217, 232, 0.12), transparent 46%);
}

/* Ambient drifting glow */
.glow-bg {
    position: fixed;
    top: -90px;
    left: -90px;
    width: 360px;
    height: 360px;
    background: radial-gradient(circle, var(--neon-purple) 0%, transparent 70%);
    opacity: 0.13;
    z-index: -1;
    filter: blur(60px);
    pointer-events: none;
    animation: float 14s infinite alternate;
}

@keyframes float {
    0% { transform: translate(0, 0); }
    100% { transform: translate(110px, 70px); }
}

.game-container {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
}

.content {
    text-align: center;
    padding: 2rem 1rem 6rem;
    max-width: 680px;
    width: 100%;
    margin: 0 auto;
}

.title {
    font-family: var(--font-display);
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 0.65rem;
    background: linear-gradient(45deg, var(--neon-purple), var(--cyan), var(--neon-green));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* HUD */
.hud {
    display: flex;
    gap: 0.55rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}

.hud-item {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 0.32rem 0.8rem;
    font-weight: 500;
}

.level-label { color: var(--neon-purple); border-color: rgba(189, 0, 255, 0.3); }
.solved-label { color: var(--neon-green); border-color: rgba(57, 255, 20, 0.3); }
.best-label { color: var(--gold); border-color: rgba(255, 213, 74, 0.3); }
.best-label:empty { display: none; }

.best-label.flash-best { animation: best-pop 0.8s ease-out; }
@keyframes best-pop {
    0% { transform: scale(0.8); }
    40% { transform: scale(1.18); text-shadow: 0 0 16px rgba(255, 213, 74, 0.8); }
    100% { transform: scale(1); }
}

.level-goal {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    min-height: 1.4em;
    margin-bottom: 1rem;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

/* Stage / canvas */
.stage {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 0 auto 0.85rem;
}

#board {
    display: block;
    margin: 0 auto;
    border-radius: var(--radius);
    border: 1px solid rgba(57, 255, 20, 0.22);
    background: #0b0e15;
    touch-action: none;
    box-shadow:
        0 0 26px rgba(189, 0, 255, 0.22),
        inset 0 0 18px rgba(5, 217, 232, 0.08);
    transition: box-shadow 0.25s, border-color 0.25s;
}

.state-running #board {
    border-color: rgba(189, 0, 255, 0.55);
    box-shadow: 0 0 30px rgba(189, 0, 255, 0.4), inset 0 0 18px rgba(5, 217, 232, 0.1);
}

.state-solved #board {
    border-color: rgba(57, 255, 20, 0.6);
    box-shadow: 0 0 34px rgba(57, 255, 20, 0.45);
}

.state-failed #board {
    border-color: rgba(255, 42, 109, 0.6);
    box-shadow: 0 0 30px rgba(255, 42, 109, 0.4);
    animation: board-shake 0.32s ease-in-out;
}

@keyframes board-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* Status line — the running commentary */
.status-line {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-muted);
    min-height: 2.6em;
    margin: 0 auto 0.9rem;
    max-width: 540px;
    transition: color 0.2s;
}

.state-solved .status-line { color: var(--neon-green); }
.state-failed .status-line { color: var(--pink); }

/* Run controls */
.run-controls {
    display: flex;
    gap: 0.55rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.1rem;
}

.game-btn {
    font-family: var(--font-display);
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    color: var(--bg-dark);
    transition: transform 0.1s, box-shadow 0.15s, filter 0.15s, opacity 0.15s;
}

.game-btn:active { transform: scale(0.95); }
.game-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.game-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-run {
    background: var(--neon-green);
    box-shadow: 0 0 16px rgba(57, 255, 20, 0.35);
}
.btn-run:hover { filter: brightness(1.1); box-shadow: 0 0 24px rgba(57, 255, 20, 0.5); }

.btn-step {
    background: var(--cyan);
    box-shadow: 0 0 16px rgba(5, 217, 232, 0.3);
}
.btn-step:hover { filter: brightness(1.1); }

.btn-reset {
    background: transparent;
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.18);
}
.btn-reset:hover { border-color: var(--text-muted); color: #fff; }

.btn-next {
    background: var(--neon-purple);
    color: #fff;
    box-shadow: 0 0 16px rgba(189, 0, 255, 0.35);
}
.btn-next:hover { filter: brightness(1.15); box-shadow: 0 0 24px rgba(189, 0, 255, 0.55); }

.btn-begin {
    background: linear-gradient(135deg, var(--neon-green), var(--cyan));
    box-shadow: 0 0 20px rgba(57, 255, 20, 0.4);
    padding: 0.8rem 2.4rem;
}
.btn-begin:hover { transform: scale(1.04); box-shadow: 0 0 30px rgba(57, 255, 20, 0.6); }

/* Button visibility per state */
.btn-run, .btn-step, .btn-reset, .btn-next { display: none; }
.btn-begin { display: inline-block; }

.state-editing .btn-run,
.state-editing .btn-step,
.state-editing .btn-reset,
.state-failed .btn-run,
.state-failed .btn-step,
.state-failed .btn-reset,
.state-running .btn-run,
.state-running .btn-step,
.state-running .btn-reset { display: inline-block; }

.state-editing .btn-begin,
.state-running .btn-begin,
.state-solved .btn-begin,
.state-failed .btn-begin { display: none; }

.state-solved .btn-next { display: inline-block; }
.state-solved .btn-reset { display: inline-block; }

.state-running .btn-run { opacity: 0.4; pointer-events: none; }

/* ===== Editor ===== */
.editor {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: left;
    margin-bottom: 1rem;
}

/* Hide the editor on the idle splash. */
.state-idle .editor { display: none; }
.state-idle .run-controls .btn-run,
.state-idle .run-controls .btn-step,
.state-idle .run-controls .btn-reset,
.state-idle .run-controls .btn-next { display: none; }

.editor-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.6rem;
}

.program-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.program-count {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.program {
    list-style: none;
    counter-reset: line;
    min-height: 2.5rem;
    margin-bottom: 0.5rem;
}

.program-empty-hint {
    font-size: 0.88rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0.4rem 0.2rem 0.6rem;
    line-height: 1.4;
}

.line {
    counter-increment: line;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.35rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    position: relative;
}

.line::before {
    content: counter(line);
    font-family: var(--font-display);
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 1.3rem;
    text-align: right;
    opacity: 0.7;
}

.line:hover { border-color: rgba(255, 42, 109, 0.4); }
.line:active { transform: scale(0.99); }

.line.is-running {
    border-color: var(--neon-green);
    background: rgba(57, 255, 20, 0.1);
    box-shadow: 0 0 14px rgba(57, 255, 20, 0.3);
}

.line-glyph {
    font-family: var(--font-display);
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.line-text {
    font-family: var(--font-display);
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.line-num-edit {
    font-family: var(--font-display);
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--bg-dark);
    background: var(--gold);
    border: none;
    border-radius: 6px;
    padding: 0.05rem 0.4rem;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(255, 213, 74, 0.4);
}
.line-num-edit:active { transform: scale(0.9); }

.line-tools {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.line-up, .line-down {
    background: rgba(255, 255, 255, 0.06);
    border: none;
    color: var(--text-muted);
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 7px;
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.line-up:hover, .line-down:hover { color: var(--cyan); background: rgba(5, 217, 232, 0.12); }
.line-up:active, .line-down:active { transform: scale(0.9); }

.line-x {
    color: var(--pink);
    font-size: 1.05rem;
    font-weight: 700;
    width: 1.4rem;
    text-align: center;
    opacity: 0.7;
}
.line:hover .line-x { opacity: 1; }

/* op color accents on lines & palette */
.op-step .line-glyph, .pal-btn.op-step .pal-glyph { color: var(--cyan); }
.op-turn .line-glyph, .pal-btn.op-turn .pal-glyph { color: var(--neon-purple); }
.op-grab .line-glyph, .pal-btn.op-grab .pal-glyph { color: var(--gold); }
.op-cond .line-glyph, .pal-btn.op-cond .pal-glyph { color: var(--pink); }
.op-loop .line-glyph, .pal-btn.op-loop .pal-glyph { color: var(--neon-green); }

/* Palette */
.palette-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-muted);
    margin: 0.9rem 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.pal-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.pal-btn .pal-glyph { font-size: 1rem; }
.pal-btn:hover {
    border-color: rgba(57, 255, 20, 0.5);
    background: rgba(57, 255, 20, 0.06);
    box-shadow: 0 0 14px rgba(57, 255, 20, 0.18);
}
.pal-btn:active { transform: scale(0.94); }
.pal-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* When running/solved, dim the palette so editing feels locked */
.state-running .palette,
.state-solved .palette {
    opacity: 0.4;
    pointer-events: none;
}
.state-solved .line { cursor: default; }
.state-solved .line:hover { border-color: var(--glass-border); }

/* ===== How-to / SEO ===== */
.how-to-play {
    text-align: left;
    margin: 2.5rem auto 0;
    max-width: 580px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.6rem;
}

.how-to-play h2 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    margin-bottom: 0.7rem;
    color: var(--text-primary);
}

.how-to-play h3 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    margin: 1.2rem 0 0.45rem;
    color: var(--cyan);
}

.how-to-play p {
    font-weight: 300;
    line-height: 1.65;
    color: var(--text-muted);
    margin-bottom: 0.7rem;
}

.how-to-play strong { color: var(--text-primary); font-weight: 500; }
.how-to-play em { color: var(--neon-green); font-style: normal; font-weight: 500; }

.how-to-play ol {
    margin: 0.5rem 0 0.75rem 1.25rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.fun-fact {
    margin-top: 1.2rem;
    padding: 1rem;
    border-left: 3px solid var(--neon-purple);
    background: rgba(189, 0, 255, 0.06);
    border-radius: 0 10px 10px 0;
}
.fun-fact p { margin: 0; }
.fun-fact strong { color: var(--neon-purple); }

.related-games {
    margin: 2rem auto 0;
    max-width: 580px;
    text-align: center;
}

.related-games h3 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    margin-bottom: 0.7rem;
    color: var(--text-muted);
}

.related-games-list {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
}

.related-game-link {
    text-decoration: none;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    transition: border-color 0.2s, color 0.2s;
}
.related-game-link:hover { border-color: var(--neon-green); color: var(--neon-green); }

/* Hide SEO content during active gameplay (keep on idle splash) */
.state-running .how-to-play,
.state-running .related-games {
    display: none;
}

/* Home link */
.home-link {
    position: fixed;
    bottom: 1.1rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1.1rem;
    background: rgba(14, 17, 25, 0.85);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    transition: border-color 0.2s, color 0.2s;
    z-index: 10;
}
.home-link:hover { border-color: var(--neon-purple); color: var(--neon-purple); }
.home-link:active { transform: translateX(-50%) scale(0.95); }
.home-link:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* Responsive */
@media (max-width: 600px) {
    .title { font-size: 1.7rem; }
    .level-goal { font-size: 0.92rem; }
    .game-btn { padding: 0.6rem 1rem; font-size: 0.9rem; }
    .btn-begin { padding: 0.7rem 1.8rem; }
    .pal-btn { font-size: 0.78rem; padding: 0.45rem 0.7rem; }
    .line-text { font-size: 0.85rem; }
    .editor { padding: 0.8rem; }
}

@media (max-width: 360px) {
    .run-controls { gap: 0.4rem; }
    .game-btn { padding: 0.55rem 0.8rem; font-size: 0.85rem; }
    .pal-btn { font-size: 0.72rem; }
}
