/* Backprop Detective — FunSlop.com
   Credit assignment as deduction. Trace the gradient of blame to the one
   corrupted weight. Neon-on-near-black, self-contained. */

:root {
    --bg-dark: #090b10;
    --bg-panel: #0e111a;
    --neon-green: #39ff14;
    --cyan: #05d9e8;
    --neon-purple: #bd00ff;
    --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, sans-serif;
    --font-display: 'Space Grotesk', 'Outfit', system-ui, sans-serif;
}

* {
    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% 16%, rgba(189, 0, 255, 0.13), transparent 44%),
        radial-gradient(circle at 86% 84%, rgba(5, 217, 232, 0.12), transparent 46%);
}

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

@keyframes float {
    0% { transform: translate(0, 0); }
    100% { transform: translate(120px, 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: 620px;
    width: 100%;
    margin: 0 auto;
}

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

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

.hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    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.35rem 0.85rem;
}

.hud-pill strong {
    font-family: var(--font-display);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.level-pill strong { color: var(--neon-purple); }
.probe-pill strong { color: var(--gold); }
.solved-pill strong { color: var(--neon-green); }

.probe-pill.depleted {
    border-color: rgba(255, 42, 109, 0.4);
}
.probe-pill.depleted strong { color: var(--pink); }

/* Verdict / live narration line */
.verdict {
    font-size: 1.02rem;
    color: var(--text-primary);
    margin-bottom: 0.7rem;
    min-height: 1.4em;
    line-height: 1.4;
    transition: color 0.2s;
}

.verdict.good { color: var(--neon-green); }
.verdict.bad { color: var(--pink); }
.verdict.hint { color: var(--cyan); }

/* Expected vs actual readout */
.readout {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 0.9rem;
    flex-wrap: wrap;
}

.readout-item {
    font-size: 0.95rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.5rem 1rem;
}

.readout-item strong {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin-left: 0.4rem;
}

.readout-item.expected strong { color: var(--neon-green); }
.readout-item.actual strong { color: var(--pink); }

/* Canvas — the network graph */
.canvas-wrapper {
    width: 100%;
    max-width: 560px;
    aspect-ratio: 4 / 3;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(5, 217, 232, 0.22);
    background: var(--bg-panel);
    box-shadow:
        0 0 26px rgba(189, 0, 255, 0.18),
        inset 0 0 18px rgba(5, 217, 232, 0.08);
    touch-action: none;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
    touch-action: none;
}

.instruction {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin: 0.85rem 0 0.6rem;
    min-height: 1.3em;
    line-height: 1.4;
}

/* Probe / Accuse mode toggle */
.action-row {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.mode-btn {
    font-family: var(--font-body);
    padding: 0.7rem 1.5rem;
    font-size: 1rem;
    font-weight: 700;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    transition: transform 0.1s, box-shadow 0.15s, color 0.15s, border-color 0.15s, background 0.15s;
    min-width: 130px;
}

.mode-btn:active { transform: scale(0.96); }

.mode-btn:focus-visible {
    outline: 3px solid var(--cyan);
    outline-offset: 2px;
}

#probe-mode-btn.active {
    color: var(--bg-dark);
    background: var(--gold);
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(255, 213, 74, 0.4);
}

#accuse-mode-btn.active {
    color: var(--bg-dark);
    background: var(--pink);
    border-color: var(--pink);
    box-shadow: 0 0 18px rgba(255, 42, 109, 0.4);
}

/* Start / next / retry button */
.start-btn {
    font-family: var(--font-display);
    background: linear-gradient(135deg, var(--cyan), var(--neon-purple));
    color: #04130a;
    border: none;
    padding: 0.95rem 2.6rem;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 0 22px rgba(5, 217, 232, 0.32);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.start-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 0 30px rgba(189, 0, 255, 0.5);
}

.start-btn:active { transform: scale(0.97); }

.start-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(5, 217, 232, 0.6);
}

/* ---- State-driven visibility ---- */

/* idle: only the start button + verdict, hide play chrome */
.state-idle .hud,
.state-idle .readout,
.state-idle .instruction,
.state-idle .action-row {
    display: none;
}

/* playing: hide the big button, show the controls */
.state-playing .start-btn {
    display: none;
}

/* solved / gameover: keep board visible, show button again */
.state-solved .action-row,
.state-gameover .action-row {
    display: none;
}

.state-solved .start-btn,
.state-gameover .start-btn {
    animation: rise 0.35s ease-out;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Celebrate a new best */
.state-gameover.new-best .verdict {
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255, 213, 74, 0.5);
}

/* Hide SEO content while actively playing/resolving */
.state-playing .how-to-play,
.state-playing .related-games,
.state-solved .how-to-play,
.state-solved .related-games,
.state-gameover .how-to-play,
.state-gameover .related-games {
    display: none;
}

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

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

.how-to-play h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    margin: 1.25rem 0 0.5rem;
    color: var(--cyan);
}

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

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

.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.25rem;
    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: 560px;
    text-align: center;
}

.related-games h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    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);
}

/* Home link */
.home-link {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1.1rem;
    background: rgba(255, 255, 255, 0.05);
    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; }
    .verdict { font-size: 0.95rem; }
    .readout-item { font-size: 0.85rem; padding: 0.4rem 0.8rem; }
    .readout-item strong { font-size: 1.1rem; }
    .mode-btn {
        padding: 0.6rem 1.1rem;
        font-size: 0.95rem;
        min-width: 110px;
    }
    .start-btn {
        padding: 0.8rem 2rem;
        font-size: 1.05rem;
    }
    .instruction { font-size: 0.85rem; }
}

@media (max-width: 360px) {
    .hud-pill { font-size: 0.78rem; padding: 0.3rem 0.65rem; }
    .mode-btn { min-width: 96px; }
}
