/* Rule Roulette — FunSlop.com
   The win condition swaps every few seconds. Distribution shift, gamified. */

:root {
    --bg-dark: #090b10;
    --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, 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);
    overscroll-behavior: none;
}

/* Ambient neon glow, matching FunSlop's house style */
.glow-bg {
    position: fixed;
    top: -80px;
    left: -80px;
    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 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;
    justify-content: flex-start;
    user-select: none;
    -webkit-user-select: none;
}

.content {
    text-align: center;
    padding: 2.25rem 1.25rem 6rem;
    max-width: 560px;
    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(--pink), var(--gold));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Control hints */
.controls-inline {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.control-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.8rem;
}

.control-pill .key {
    font-weight: 700;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.8rem;
}

.control-pill.action .key { color: var(--neon-green); }
.control-pill.special .key { color: var(--cyan); }

.state-playing .controls-inline,
.state-gameover .controls-inline {
    display: none;
}

/* HUD */
.hud {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.hud-cell {
    flex: 1 1 0;
    max-width: 150px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.5rem 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.hud-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.hud-value {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.hud-value.score { color: var(--cyan); }
.hud-value.lives { color: var(--pink); letter-spacing: 1px; }
.hud-value.combo { color: var(--gold); }

.hud-value.pop { animation: hud-pop 0.25s ease-out; }

@keyframes hud-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.35); }
    100% { transform: scale(1); }
}

.hud-value.lives.drop { animation: life-flash 0.4s ease-out; }

@keyframes life-flash {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.2); color: #fff; }
}

/* Rule banner — the heart of the game */
.rule-banner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    min-height: 3.4rem;
    margin-bottom: 0.5rem;
    padding: 0.7rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.rule-prefix {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    flex-shrink: 0;
}

.rule-text {
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--accent, var(--neon-green));
    text-shadow: 0 0 12px currentColor, 0 0 2px rgba(9, 11, 16, 0.9);
}

/* The flip animation — a hard, glitchy swap to sell the distribution shift */
.rule-banner.flip {
    animation: banner-flip 0.4s ease-out;
}

.rule-banner.flip .rule-text {
    animation: text-flip 0.4s ease-out;
}

@keyframes banner-flip {
    0% { box-shadow: 0 0 0 0 var(--accent, var(--neon-green)); border-color: var(--glass-border); }
    20% {
        box-shadow: 0 0 28px 2px var(--accent, var(--neon-green));
        border-color: var(--accent, var(--neon-green));
        transform: translateX(-4px) skewX(-3deg);
    }
    40% { transform: translateX(5px) skewX(2deg); }
    60% { transform: translateX(-3px) skewX(-1deg); }
    100% {
        transform: translateX(0) skewX(0);
        box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0);
        border-color: var(--glass-border);
    }
}

@keyframes text-flip {
    0% { opacity: 0; transform: translateY(-14px) scale(0.85); filter: blur(3px); }
    100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

/* Countdown bar showing how long until the next flip */
.rule-timer-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
    margin-bottom: 1rem;
}

.rule-timer-fill {
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent, var(--neon-green)), var(--gold));
    transform-origin: left center;
    transform: scaleX(1);
    box-shadow: 0 0 10px var(--accent, var(--neon-green));
}

/* The playfield grid */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.7rem;
    margin: 0 auto 1rem;
    max-width: 460px;
    touch-action: manipulation;
}

.cell {
    position: relative;
    aspect-ratio: 1 / 1;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 16px;
    transition: transform 0.08s, background 0.15s;
}

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

.cell:active { transform: scale(0.94); }

/* The shape inside each cell */
.shape {
    width: var(--shape-size, 60%);
    height: var(--shape-size, 60%);
    background: var(--shape-color, var(--neon-green));
    box-shadow: 0 0 16px var(--shape-color, var(--neon-green));
    transition: transform 0.12s, opacity 0.2s, width 0.12s, height 0.12s;
    transform: scale(1);
}

.shape.sq { border-radius: 14%; }
.shape.circle { border-radius: 50%; }
.shape.tri {
    background: transparent;
    box-shadow: none;
    width: 0;
    height: 0;
    border-left: calc(var(--shape-px, 40px) * 0.5) solid transparent;
    border-right: calc(var(--shape-px, 40px) * 0.5) solid transparent;
    border-bottom: var(--shape-px, 40px) solid var(--shape-color, var(--neon-green));
    filter: drop-shadow(0 0 10px var(--shape-color, var(--neon-green)));
}
.shape.diamond { border-radius: 14%; transform: rotate(45deg); }

/* Feedback states on cells */
.cell.hit .shape { animation: cell-hit 0.3s ease-out; }
.cell.consumed .shape { opacity: 0.18; transform: scale(0.7); }
.cell.consumed.tri .shape { transform: scale(0.7); }

@keyframes cell-hit {
    0% { transform: scale(1); }
    40% { transform: scale(1.35); }
    100% { transform: scale(0.7); }
}

.cell.bad { animation: cell-bad 0.3s ease-in-out; }

@keyframes cell-bad {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-7px); }
    75% { transform: translateX(7px); }
}

/* "next in order" hint glow */
.cell.ordertag::after {
    content: attr(data-order);
    position: absolute;
    top: 6px;
    left: 8px;
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--bg-dark);
    background: var(--gold);
    border-radius: 999px;
    width: 1.15rem;
    height: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 8px var(--gold);
}

.feedback {
    font-size: 1.05rem;
    color: var(--text-primary);
    margin-bottom: 0.35rem;
    min-height: 1.4em;
    font-weight: 500;
}

.feedback.good { color: var(--neon-green); }
.feedback.bad { color: var(--pink); }

.best-score {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    min-height: 1.2em;
}

.hint {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    min-height: 1.2em;
}

/* State-driven visibility */
.state-idle .board,
.state-gameover .board {
    pointer-events: none;
    opacity: 0.5;
}

.state-playing .hint { display: none; }

.state-idle,
.state-gameover { cursor: pointer; }

.state-idle .rule-timer-track,
.state-gameover .rule-timer-track { opacity: 0.25; }

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

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

/* 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 em { color: var(--pink); 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.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; }

.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.85rem; }
    .rule-text { font-size: 1.15rem; }
    .hud-value { font-size: 1.1rem; }
    .board { gap: 0.55rem; }
}

@media (max-width: 360px) {
    .content { padding: 1.75rem 0.85rem 6rem; }
    .rule-text { font-size: 1.02rem; }
    .rule-prefix { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .glow-bg { animation: none; }
    .rule-banner.flip,
    .rule-banner.flip .rule-text,
    .cell.hit .shape,
    .cell.bad { animation: none; }
}
