/**
 * Token Merge — FunSlop.com
 * Dark neon reskin of a 2048-style puzzle. Tiles ramp from dim/cool
 * (small models) to bright/hot (AGI and beyond).
 */

:root {
    --bg: #090b10;
    --bg-panel: #11141d;
    --bg-cell: #161a26;
    --neon-green: #39ff14;
    --neon-purple: #bd00ff;
    --cyan: #05d9e8;
    --pink: #ff2a6d;
    --gold: #ffd54a;
    --text: #f0f4f8;
    --muted: #8b9bb4;
    --border: #20263a;
    --radius-md: 14px;
    --radius-sm: 8px;
    --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-head: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    font-weight: 300;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 16% 18%, rgba(189, 0, 255, 0.16), transparent 44%),
        radial-gradient(circle at 84% 82%, rgba(5, 217, 232, 0.14), transparent 46%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
}

.game-container {
    width: 100%;
    max-width: 440px;
    padding: 1.25rem 1rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.title-block {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.title {
    font-family: var(--font-head);
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
    color: var(--neon-green);
    text-shadow: 0 0 16px rgba(57, 255, 20, 0.45);
}

.tagline {
    font-size: 0.78rem;
    color: var(--muted);
    max-width: 14rem;
}

.scores {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.score-box {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.85rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 66px;
}

.score-box .label {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.score-box .value {
    font-family: var(--font-head);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--cyan);
    text-shadow: 0 0 10px rgba(5, 217, 232, 0.5);
}

/* Controls hint */
.controls-block {
    width: 100%;
    display: flex;
    justify-content: center;
}

.control-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.74rem;
    color: var(--muted);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
}

.control-pill .key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.3rem;
    padding: 0 0.3rem;
    border-radius: 5px;
    background: var(--bg-cell);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.8rem;
}

.control-pill .swipe {
    width: 1.4rem;
    height: 0.55rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--neon-purple), var(--cyan));
    box-shadow: 0 0 8px rgba(189, 0, 255, 0.5);
}

.desktop-only { display: flex; }
.mobile-only { display: none; }

@media (hover: none) and (pointer: coarse) {
    .desktop-only { display: none; }
    .mobile-only { display: flex; }
}

/* Grid container */
.grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    width: 100%;
    aspect-ratio: 1;
    box-shadow:
        0 0 32px rgba(189, 0, 255, 0.12),
        inset 0 0 40px rgba(0, 0, 0, 0.5);
}

/* Background cells - empty token slots */
.cell-bg {
    background: var(--bg-cell);
    border-radius: var(--radius-sm);
    aspect-ratio: 1;
}

/* Animated tiles */
.tile {
    position: absolute;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: var(--font-head);
    font-weight: 700;
    color: var(--text);
    background: var(--bg-cell);
    z-index: 10;
    overflow: hidden;
}

.tile-num {
    font-size: 2rem;
    line-height: 1;
}

.tile-label {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 0.25rem;
    opacity: 0.9;
}

/* Slide animation with subtle bounce */
.tile-moving {
    transition: top 150ms ease-out, left 150ms ease-out;
}

/* New tile pop-in */
.tile-new {
    animation: tile-appear 200ms ease-out;
}

@keyframes tile-appear {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Merged tile bounce */
.tile-merged {
    animation: tile-bounce 200ms ease-out;
}

@keyframes tile-bounce {
    0% { transform: scale(1); }
    30% { transform: scale(1.15); }
    60% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* ---- Tile color ramp: dim/cool small models -> bright/hot AGI ---- */
.tile[data-value="2"] {
    background: #1b2233;
    color: #aebfd6;
    border: 1px solid #2a3450;
}
.tile[data-value="4"] {
    background: #1f2a44;
    color: #c2d2ec;
    border: 1px solid #314265;
}
.tile[data-value="8"] {
    background: linear-gradient(145deg, #123a52, #0c2c40);
    color: var(--cyan);
    box-shadow: 0 0 14px rgba(5, 217, 232, 0.25);
}
.tile[data-value="16"] {
    background: linear-gradient(145deg, #0d4f5a, #0a3a45);
    color: #7af3ff;
    box-shadow: 0 0 16px rgba(5, 217, 232, 0.32);
}
.tile[data-value="32"] {
    background: linear-gradient(145deg, #2a1655, #1c0e3c);
    color: #d49bff;
    box-shadow: 0 0 16px rgba(189, 0, 255, 0.32);
}
.tile[data-value="64"] {
    background: linear-gradient(145deg, #3d1170, #260a4a);
    color: #e2b6ff;
    box-shadow: 0 0 20px rgba(189, 0, 255, 0.42);
}
.tile[data-value="128"] {
    background: linear-gradient(145deg, #14513a, #0c3a29);
    color: var(--neon-green);
    box-shadow: 0 0 20px rgba(57, 255, 20, 0.3);
}
.tile[data-value="128"] .tile-num,
.tile[data-value="256"] .tile-num { font-size: 1.7rem; }
.tile[data-value="256"] {
    background: linear-gradient(145deg, #1c6b3f, #0f4a2b);
    color: #74ff5a;
    box-shadow: 0 0 24px rgba(57, 255, 20, 0.42);
}
.tile[data-value="512"] {
    background: linear-gradient(145deg, #5a1140, #3a0a2a);
    color: var(--pink);
    box-shadow: 0 0 26px rgba(255, 42, 109, 0.45);
}
.tile[data-value="512"] .tile-num,
.tile[data-value="1024"] .tile-num { font-size: 1.45rem; }
.tile[data-value="1024"] {
    background: linear-gradient(145deg, #7a1320, #50101a);
    color: #ff7b9c;
    box-shadow: 0 0 30px rgba(255, 42, 109, 0.55);
}
.tile[data-value="2048"] {
    background: linear-gradient(145deg, #8a6a10, #5c4708);
    color: var(--gold);
    box-shadow: 0 0 34px rgba(255, 213, 74, 0.6);
}
.tile[data-value="2048"] .tile-num { font-size: 1.45rem; }

/* AGI and beyond — full hot glow */
.tile[data-value="4096"],
.tile[data-value="8192"],
.tile[data-value="16384"],
.tile[data-value="32768"],
.tile[data-value="65536"],
.tile[data-value="131072"] {
    background: linear-gradient(145deg, var(--gold), #ff8a3c);
    color: #1a1205;
    box-shadow: 0 0 40px rgba(255, 213, 74, 0.7);
}

.tile[data-value="4096"] .tile-num,
.tile[data-value="8192"] .tile-num,
.tile[data-value="16384"] .tile-num,
.tile[data-value="32768"] .tile-num,
.tile[data-value="65536"] .tile-num,
.tile[data-value="131072"] .tile-num { font-size: 1.2rem; }

/* Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(9, 11, 16, 0.86);
    backdrop-filter: blur(3px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 1rem;
}

.overlay.hidden { display: none; }

.overlay-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: var(--radius-md);
    text-align: center;
    max-width: 340px;
    box-shadow: 0 0 40px rgba(189, 0, 255, 0.25);
}

.overlay-content h2 {
    font-family: var(--font-head);
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--pink);
    text-shadow: 0 0 16px rgba(255, 42, 109, 0.5);
    margin-bottom: 0.6rem;
}

.overlay-content p {
    font-size: 1.05rem;
    color: var(--text);
    margin-bottom: 0.4rem;
}

.overlay-content .verdict {
    font-size: 0.85rem;
    color: var(--cyan);
    margin: 0.4rem 0 1.4rem;
    min-height: 1.2em;
}

.restart-btn {
    background: transparent;
    color: var(--neon-green);
    border: 2px solid var(--neon-green);
    border-radius: 999px;
    padding: 0.85rem 2rem;
    font-family: var(--font-head);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    text-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
    transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}

.restart-btn:hover {
    background: rgba(57, 255, 20, 0.12);
    box-shadow: 0 0 18px rgba(57, 255, 20, 0.45);
}

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

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

/* How to play */
.how-to-play {
    width: 100%;
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.how-to-play h2 {
    font-family: var(--font-head);
    font-size: 1.2rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.how-to-play h3 {
    font-family: var(--font-head);
    font-size: 1rem;
    color: var(--neon-purple);
    margin: 1rem 0 0.4rem;
    text-shadow: 0 0 10px rgba(189, 0, 255, 0.35);
}

.how-to-play p { margin-bottom: 0.6rem; }
.how-to-play strong { color: var(--text); }

.how-to-play ol {
    margin: 0.4rem 0 0.6rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.fun-fact {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 3px solid var(--cyan);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.fun-fact strong { color: var(--cyan); }

/* Home link */
.home-link {
    margin-top: 1.25rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s;
}

.home-link:hover { color: var(--neon-green); }

.home-link:focus-visible {
    outline: 2px solid var(--neon-green);
    outline-offset: 2px;
}

/* Responsive */
@media (max-width: 420px) {
    .game-container { padding: 1rem 0.75rem 1.75rem; }
    .title { font-size: 1.9rem; }
    .tile-num { font-size: 1.5rem; }

    .tile[data-value="128"] .tile-num,
    .tile[data-value="256"] .tile-num,
    .tile[data-value="512"] .tile-num { font-size: 1.25rem; }

    .tile[data-value="1024"] .tile-num,
    .tile[data-value="2048"] .tile-num { font-size: 1.05rem; }

    .tile[data-value="4096"] .tile-num,
    .tile[data-value="8192"] .tile-num,
    .tile[data-value="16384"] .tile-num,
    .tile[data-value="32768"] .tile-num,
    .tile[data-value="65536"] .tile-num,
    .tile[data-value="131072"] .tile-num { font-size: 0.9rem; }

    .tile-label { font-size: 0.52rem; }
}
