/* Beam Search — FunSlop.com
   Canvas-based beam-search decoding puzzle. Neon-on-near-black, self-contained. */

:root {
    --bg-dark: #090b10;
    --bg-canvas: #0b0e15;
    --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, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Space Grotesk', var(--font-body);
    --radius-md: 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% 16%, rgba(189, 0, 255, 0.16), transparent 44%),
        radial-gradient(circle at 86% 84%, rgba(5, 217, 232, 0.14), transparent 46%),
        radial-gradient(circle at 50% 60%, rgba(255, 213, 74, 0.05), transparent 60%);
}

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

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

.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 {
    width: 100%;
    max-width: 560px;
    padding: 1.5rem 1.1rem 6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Header: title + HUD pills */
.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}

.title {
    font-family: var(--font-display);
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(45deg, var(--cyan), var(--gold));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hud {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.hud-pill {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--cyan);
    background: rgba(5, 217, 232, 0.08);
    border: 1px solid rgba(5, 217, 232, 0.3);
    border-radius: 999px;
    padding: 0.3rem 0.75rem;
    white-space: nowrap;
}

.hud-pill.beams {
    color: var(--neon-purple);
    background: rgba(189, 0, 255, 0.08);
    border-color: rgba(189, 0, 255, 0.35);
}

/* Status line */
.status {
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text-primary);
    text-align: center;
    min-height: 2.6em;
    margin: 0.35rem 0 0.7rem;
    transition: color 0.2s;
}

/* Canvas */
.canvas-wrapper {
    width: 100%;
    max-width: 520px;
    height: min(58vh, 460px);
    min-height: 300px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(5, 217, 232, 0.25);
    box-shadow:
        0 0 28px rgba(189, 0, 255, 0.22),
        inset 0 0 18px rgba(5, 217, 232, 0.1);
    background: var(--bg-canvas);
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--bg-canvas);
    touch-action: none;
    cursor: pointer;
}

/* Readout under canvas */
.readout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    margin: 0.85rem 0 0.25rem;
    text-align: center;
}

.score-line {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.best-line {
    font-size: 0.9rem;
    color: var(--gold);
    min-height: 1.2em;
}

/* Action buttons */
.action-row {
    display: flex;
    gap: 0.7rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.9rem;
    width: 100%;
}

.game-btn {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.3px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    padding: 0.85rem 1.9rem;
    color: #04130a;
    transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease, opacity 0.15s;
}

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

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

/* Advance button — cyan, only active when exactly K kept */
.advance-btn {
    background: rgba(5, 217, 232, 0.15);
    color: var(--cyan);
    border: 1px solid rgba(5, 217, 232, 0.4);
    box-shadow: 0 0 12px rgba(5, 217, 232, 0.18);
}

.advance-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.advance-btn.ready {
    background: linear-gradient(135deg, var(--cyan), var(--neon-green));
    color: #04130a;
    border-color: transparent;
    box-shadow: 0 0 22px rgba(57, 255, 20, 0.45);
    animation: ready-pulse 1.4s ease-in-out infinite;
}

@keyframes ready-pulse {
    0%, 100% { box-shadow: 0 0 22px rgba(57, 255, 20, 0.4); }
    50% { box-shadow: 0 0 30px rgba(57, 255, 20, 0.7); }
}

/* Start / continue button — green/gold */
.start-btn {
    background: linear-gradient(135deg, var(--neon-green), var(--gold));
    box-shadow: 0 0 22px rgba(57, 255, 20, 0.35);
}

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

.hint {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.85rem;
    min-height: 1.3em;
}

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

/* Idle: hide advance + score, show start */
.state-idle .advance-btn,
.state-idle .readout {
    display: none;
}

/* Playing: hide start, show advance */
.state-playing .start-btn {
    display: none;
}

/* Cleared / gameover: hide advance, show start */
.state-cleared .advance-btn,
.state-gameover .advance-btn {
    display: none;
}

/* New best celebration */
.state-cleared.new-best .score-line,
.state-gameover.new-best .score-line {
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255, 213, 74, 0.55);
    animation: score-pop 0.4s ease-out;
}

@keyframes score-pop {
    0% { transform: scale(0.85); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Hide gameplay-only chrome states cleanly — keep how-to visible when idle */

/* ---- SEO / how-to content ---- */
.how-to-play {
    text-align: left;
    margin: 2.5rem auto 0;
    max-width: 540px;
    width: 100%;
    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.08rem;
    margin: 1.2rem 0 0.45rem;
    color: var(--cyan);
}

.how-to-play p {
    font-weight: 300;
    line-height: 1.6;
    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; }

.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.15rem;
    padding: 0.9rem 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: 1.8rem auto 0;
    max-width: 540px;
    width: 100%;
    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(5, 217, 232, 0.08);
    border: 1px solid rgba(5, 217, 232, 0.25);
    border-radius: 999px;
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.related-game-link:hover {
    border-color: var(--cyan);
    color: var(--cyan);
    box-shadow: 0 0 16px rgba(5, 217, 232, 0.3);
}

/* Hide SEO content during active play to keep focus on the tree */
.state-playing .how-to-play,
.state-playing .related-games,
.state-cleared .how-to-play,
.state-cleared .related-games,
.state-gameover .how-to-play,
.state-gameover .related-games {
    display: none;
}

/* Home link */
.home-link {
    position: fixed;
    bottom: 1.1rem;
    bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1.1rem;
    background: rgba(17, 20, 31, 0.85);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
    z-index: 200;
}

.home-link:hover {
    border-color: var(--neon-purple);
    color: var(--neon-purple);
    box-shadow: 0 0 18px rgba(189, 0, 255, 0.3);
}

.home-link:active { transform: translateX(-50%) scale(0.95); }

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

/* Responsive */
@media (max-width: 600px) {
    .title { font-size: 1.55rem; }
    .status { font-size: 0.92rem; }
    .game-btn { padding: 0.75rem 1.4rem; font-size: 0.98rem; }
    .score-line { font-size: 0.92rem; }
    .canvas-wrapper { height: min(56vh, 420px); }
}

@media (max-height: 680px) {
    .content { padding-top: 0.9rem; }
    .canvas-wrapper { height: min(50vh, 380px); }
    .status { min-height: 2.4em; margin-bottom: 0.5rem; }
}
