/* RLHF Trainer — FunSlop.com
   Train a wandering agent with thumbs up/down. Watch it reward-hack.
   Self-contained neon-on-near-black styling. */

:root {
    --bg-dark: #090b10;
    --bg-panel: #11141f;
    --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.14), transparent 45%),
        radial-gradient(circle at 86% 84%, rgba(5, 217, 232, 0.12), transparent 47%);
}

/* Ambient floating 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.14;
    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;
    justify-content: flex-start;
    user-select: none;
    -webkit-user-select: none;
}

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

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

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

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

.level-label { color: var(--cyan); }
.budget-label { color: var(--text-primary); }
.budget-label.low {
    color: var(--pink);
    border-color: rgba(255, 42, 109, 0.5);
    box-shadow: 0 0 12px rgba(255, 42, 109, 0.35);
    animation: pulse-budget 0.6s ease-in-out infinite;
}
.best-label { color: var(--gold); }

@keyframes pulse-budget {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.objective {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0 auto 1rem;
    max-width: 460px;
    min-height: 2.6em;
}

.objective strong { color: var(--neon-green); }
.objective em { color: var(--cyan); font-style: normal; }
.objective .trap-note { color: var(--pink); font-size: 0.9rem; }

/* Canvas board */
.canvas-wrapper {
    width: min(86vw, 380px);
    margin: 0 auto;
    position: relative;
}

#canvas {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    background: #0b0e16;
    border: 1px solid rgba(5, 217, 232, 0.25);
    box-shadow:
        0 0 26px rgba(189, 0, 255, 0.25),
        inset 0 0 16px rgba(5, 217, 232, 0.1);
    touch-action: none;
}

/* True-reward meter */
.reward-meter {
    margin-top: 0.7rem;
    height: 14px;
    width: 100%;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    position: relative;
}

.reward-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--cyan), var(--neon-green));
    box-shadow: 0 0 14px rgba(57, 255, 20, 0.5);
    transition: width 0.35s ease, background 0.3s ease;
}

.reward-meter.hacked .reward-fill {
    background: linear-gradient(90deg, var(--gold), var(--pink));
    box-shadow: 0 0 14px rgba(255, 42, 109, 0.6);
}

/* Live feedback line */
.feedback-line {
    font-size: 1.05rem;
    color: var(--text-primary);
    margin: 1rem auto 0.5rem;
    min-height: 2.6em;
    max-width: 460px;
    line-height: 1.4;
}

.feedback-line.new-action {
    animation: feedback-pop 0.3s ease-out;
}

@keyframes feedback-pop {
    0% { transform: scale(0.96); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* Thumbs buttons */
.feedback-buttons {
    display: flex;
    gap: 1.1rem;
    justify-content: center;
    margin-top: 0.5rem;
}

.fb-btn {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-family: var(--font-body);
    padding: 0.85rem 1.6rem;
    border-radius: 16px;
    cursor: pointer;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.04);
    transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s, filter 0.15s;
    min-width: 120px;
}

.state-playing .fb-btn { display: inline-flex; }

.fb-icon {
    font-size: 2rem;
    line-height: 1;
}

.fb-key {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
}

.fb-up { border-color: rgba(57, 255, 20, 0.35); }
.fb-up:hover {
    border-color: var(--neon-green);
    box-shadow: 0 0 22px rgba(57, 255, 20, 0.35);
    filter: brightness(1.08);
}

.fb-down { border-color: rgba(255, 42, 109, 0.35); }
.fb-down:hover {
    border-color: var(--pink);
    box-shadow: 0 0 22px rgba(255, 42, 109, 0.35);
    filter: brightness(1.08);
}

.fb-btn:active { transform: scale(0.94); }

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

.fb-btn.flash {
    animation: fb-flash 0.3s ease-out;
}

.fb-up.flash { box-shadow: 0 0 30px rgba(57, 255, 20, 0.7); }
.fb-down.flash { box-shadow: 0 0 30px rgba(255, 42, 109, 0.7); }

@keyframes fb-flash {
    0% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Start / next button */
.start-btn {
    margin-top: 1.1rem;
    font-family: var(--font-display);
    background: linear-gradient(135deg, var(--neon-green), var(--cyan));
    color: #04130a;
    border: none;
    padding: 0.9rem 2.4rem;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 0 22px rgba(57, 255, 20, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: none;
}

.state-idle .start-btn,
.state-levelclear .start-btn,
.state-gameover .start-btn,
.state-win .start-btn {
    display: inline-block;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 32px rgba(57, 255, 20, 0.6);
}
.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);
}

/* during a run let players restart from scratch via the start button */
.state-playing .start-btn {
    display: inline-block;
    margin-top: 0.9rem;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.45rem 1.2rem;
    box-shadow: none;
    border: 1px solid var(--glass-border);
}
.state-playing .start-btn:hover {
    transform: none;
    color: var(--text-primary);
    box-shadow: none;
}

/* Verdict line for end states */
.verdict {
    font-size: 1rem;
    color: var(--text-muted);
    margin: 0.9rem auto 0;
    max-width: 460px;
    line-height: 1.5;
    min-height: 1.2em;
}

.state-levelclear .verdict { color: var(--neon-green); }
.state-win .verdict { color: var(--gold); text-shadow: 0 0 12px rgba(255, 213, 74, 0.4); }
.state-gameover .verdict { color: var(--pink); }

.state-levelclear .feedback-line,
.state-win .feedback-line {
    color: var(--neon-green);
}
.state-gameover .feedback-line { color: var(--pink); }

/* Hide SEO content during active play / end screens to keep focus */
.state-playing .how-to-play,
.state-playing .related-games,
.state-levelclear .how-to-play,
.state-levelclear .related-games,
.state-gameover .how-to-play,
.state-gameover .related-games,
.state-win .how-to-play,
.state-win .related-games {
    display: none;
}

/* SEO / how-to content */
.how-to-play {
    text-align: left;
    margin: 2.75rem auto 0;
    max-width: 480px;
    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.5rem;
    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.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: 1.75rem auto 0;
    max-width: 480px;
    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);
}

/* 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;
    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; }
    .objective { font-size: 0.95rem; }
    .feedback-line { font-size: 0.98rem; }
    .fb-btn {
        padding: 0.75rem 1.2rem;
        min-width: 104px;
    }
    .fb-icon { font-size: 1.7rem; }
    .start-btn { padding: 0.8rem 2rem; font-size: 1.05rem; }
}

@media (max-width: 360px) {
    .feedback-buttons { gap: 0.7rem; }
    .fb-btn { min-width: 92px; padding: 0.7rem 0.9rem; }
}
