/* Quantize — FunSlop.com
   Lossy compression as art. Paint a target sprite under a strict bit budget,
   then face the judge. Self-contained: no shared theme stylesheet required. */

:root {
    --bg-dark: #090b10;
    --bg-panel: #0e111a;
    --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', 'Outfit', system-ui, sans-serif;
    --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);
}

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

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

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

/* HUD row */
.hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 1rem;
    min-height: 1.5em;
}

.level-label {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    flex-basis: 100%;
}

.budget-label {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--cyan);
    text-shadow: 0 0 12px rgba(5, 217, 232, 0.5);
    padding: 0.15rem 0.7rem;
    border-radius: 999px;
    background: rgba(5, 217, 232, 0.08);
    border: 1px solid rgba(5, 217, 232, 0.25);
}

.budget-label.budget-empty {
    color: var(--pink);
    background: rgba(255, 42, 109, 0.08);
    border-color: rgba(255, 42, 109, 0.35);
    text-shadow: 0 0 12px rgba(255, 42, 109, 0.6);
}

.budget-label.budget-deny {
    animation: deny 0.3s ease-in-out;
}

.budget-label.budget-refund {
    animation: refund 0.35s ease-out;
}

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

@keyframes refund {
    0% { transform: scale(1); }
    50% { transform: scale(1.18); color: var(--neon-green); }
    100% { transform: scale(1); }
}

.score-label {
    font-size: 1rem;
    font-weight: 500;
    color: var(--gold);
}

/* Stage: target + canvas side by side (stack on narrow screens) */
.stage {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: stretch;
    margin-bottom: 1rem;
}

.panel {
    position: relative;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1.6rem 0.7rem 0.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.panel-tag {
    position: absolute;
    top: 0.45rem;
    left: 0.7rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.target-panel {
    flex: 0 0 38%;
    max-width: 220px;
}

.canvas-panel {
    flex: 1 1 auto;
    max-width: 360px;
}

/* Target preview rendered as a crisp DOM grid */
.target-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid, 8), 1fr);
    width: 100%;
    aspect-ratio: 1;
    background: #0b0e16;
    border: 1px solid rgba(189, 0, 255, 0.3);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 14px rgba(189, 0, 255, 0.12);
}

.tcell {
    width: 100%;
    height: 100%;
    background: transparent;
}

/* Player canvas */
.canvas-wrapper {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(5, 217, 232, 0.3);
    box-shadow:
        0 0 24px rgba(5, 217, 232, 0.2),
        inset 0 0 14px rgba(189, 0, 255, 0.1);
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #0b0e16;
    touch-action: none;
    cursor: crosshair;
}

.state-judging #canvas,
.state-verdict #canvas,
.state-gameover #canvas,
.state-idle #canvas {
    cursor: default;
}

/* Palette swatches */
.palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: center;
    margin-bottom: 1rem;
    min-height: 0;
}

.swatch {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.swatch:hover {
    transform: translateY(-2px);
}

.swatch:active {
    transform: scale(0.92);
}

.swatch.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-dark), 0 0 16px rgba(240, 244, 248, 0.5);
    transform: translateY(-2px);
}

.swatch.swatch-dark {
    border-color: rgba(255, 255, 255, 0.35);
}

.swatch-erase {
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.06),
        rgba(255, 255, 255, 0.06) 6px,
        rgba(255, 255, 255, 0.02) 6px,
        rgba(255, 255, 255, 0.02) 12px
    );
}

.swatch-key {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    color: rgba(9, 11, 16, 0.85);
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    padding: 0 0.3rem;
    line-height: 1.4;
    pointer-events: none;
}

.swatch-dark .swatch-key,
.swatch-erase .swatch-key {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.55);
}

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

/* Verdict block */
.verdict {
    min-height: 3.2em;
    margin-bottom: 0.5rem;
}

.verdict-title {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    min-height: 1.3em;
    transition: color 0.2s;
}

.verdict-detail {
    font-size: 0.98rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 0.35rem;
    max-width: 460px;
    margin-left: auto;
    margin-right: auto;
}

.state-verdict.new-best .verdict-title,
.state-gameover.new-best .verdict-title {
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255, 213, 74, 0.5);
    animation: pop 0.4s ease-out;
}

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

.best-label {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    min-height: 1.2em;
}

/* Buttons */
.buttons {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.game-btn {
    font-family: var(--font-display);
    padding: 0.9rem 2rem;
    font-size: 1.1rem;
    font-weight: 700;
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
    color: #04130a;
}

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

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

.btn-primary {
    background: linear-gradient(135deg, var(--cyan), var(--neon-green));
    box-shadow: 0 0 20px rgba(5, 217, 232, 0.3);
}

.btn-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 0 30px rgba(5, 217, 232, 0.5);
}

.btn-clear {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
}

.btn-clear:hover {
    color: var(--pink);
    border-color: rgba(255, 42, 109, 0.4);
}

/* Disable / hide controls based on state */
.state-idle .clear-only,
.state-idle .hud {
    /* keep HUD present for layout, hide via empty text */
}

/* The clear button only makes sense while painting. */
.state-idle #clear-btn,
.state-judging #clear-btn,
.state-verdict #clear-btn,
.state-gameover #clear-btn {
    display: none;
}

/* Hide palette + target when not in a level. */
.state-idle .stage .target-panel,
.state-gameover .stage .target-panel {
    visibility: hidden;
}

.state-idle .palette,
.state-judging .palette,
.state-verdict .palette,
.state-gameover .palette {
    opacity: 0.4;
    pointer-events: none;
}

.state-idle .palette {
    display: none;
}

.state-judging .swatch,
.state-verdict .swatch {
    cursor: default;
}

/* Pulse the action button when it's the obvious next move */
.state-idle .btn-primary,
.state-verdict .btn-primary,
.state-gameover .btn-primary {
    animation: btn-glow 2s ease-in-out infinite;
}

@keyframes btn-glow {
    0%, 100% { box-shadow: 0 0 20px rgba(5, 217, 232, 0.3); }
    50% { box-shadow: 0 0 34px rgba(5, 217, 232, 0.6); }
}

.state-judging .btn-primary {
    filter: grayscale(0.5) brightness(0.8);
    cursor: progress;
}

/* SEO / how-to content */
.how-to-play {
    text-align: left;
    margin: 3rem 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 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(--cyan);
    color: var(--cyan);
}

/* Hide SEO content during active play / judging for focus */
.state-playing .how-to-play,
.state-playing .related-games,
.state-judging .how-to-play,
.state-judging .related-games {
    display: none;
}

/* 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 — stack the target above the canvas on narrow screens */
@media (max-width: 540px) {
    .title { font-size: 1.85rem; }

    .stage {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }

    .target-panel,
    .canvas-panel {
        flex: 1 1 auto;
        width: 100%;
        max-width: 320px;
    }

    .target-panel {
        max-width: 200px;
    }

    .swatch {
        width: 44px;
        height: 44px;
    }

    .verdict-title { font-size: 1.12rem; }

    .game-btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }
}

@media (max-width: 360px) {
    .swatch {
        width: 40px;
        height: 40px;
    }
}
