:root {
    --bg: #120c22;
    --ink: #f6eefe;
    --muted: #cbb9e8;
    --card: rgba(24, 16, 42, 0.82);
    --accent: #d7b4ff;
    --accent-2: #9b6dff;
    --gap: #1a1230;
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: none;
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(1200px 600px at 50% -10%, #2a1848 0%, transparent 55%),
    var(--bg);
}

.app {
    max-width: 480px;
    height: 100%;
    margin: 0 auto;
    padding: 8px 14px 24px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0 2px;
}

.top h1 {
    font-size: 1.05rem;
    font-weight: 650;
}

.back, .icon-btn {
    color: var(--muted);
    text-decoration: none;
    background: var(--card);
    border: 1px solid rgba(215, 180, 255, 0.18);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 0.85rem;
    min-width: 44px;
    text-align: center;
    color: var(--ink);
    cursor: pointer;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.stat {
    background: var(--card);
    border: 1px solid rgba(215, 180, 255, 0.12);
    border-radius: 14px;
    padding: 8px 6px;
    text-align: center;
}

.stat .label {
    display: block;
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat .value {
    display: block;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    font-size: 1.15rem;
    font-weight: 650;
}

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

.hint.bad {
    color: #ff9aa8;
}

.hint.ok {
    color: #7dffb3;
}

.board-wrap {
    display: flex;
    justify-content: center;
    flex: 0 0 auto;
    margin: auto 0;
}

.board {
    width: min(92vw, 420px);
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    background: var(--gap);
    border-radius: 18px;
    box-shadow: var(--shadow);
    touch-action: none;
}

.tile {
    border: 0;
    border-radius: 12px;
    font-weight: 700;
    font-size: clamp(0.95rem, 5vw, 1.45rem);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tile.empty {
    background: rgba(255, 255, 255, 0.03);
    cursor: default;
    pointer-events: none;
}

.tile.selected {
    transform: scale(0.94);
    box-shadow: 0 0 0 3px #fff, 0 0 16px rgba(215, 180, 255, 0.6);
}

.tile.reject {
    animation: shake 0.28s ease;
}

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

.tile.pop {
    animation: pop 0.2s ease;
}

@keyframes pop {
    0% {
        transform: scale(0.6);
    }
    100% {
        transform: scale(1);
    }
}

/* Wood */
.skin-wood .tile {
    color: #3b220e;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.skin-wood .tile:not(.empty) {
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.2), transparent 40%),
    repeating-linear-gradient(90deg, #c68642 0 2px, #b87432 2px 5px, #c68642 5px 8px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 2px 0 #7a4318;
}

/* Digits */
.skin-digits .tile:not(.empty) {
    background: #221635;
    color: var(--ink);
    border: 1px solid rgba(215, 180, 255, 0.28);
    font-family: ui-monospace, Menlo, monospace;
}

/* Neon */
.skin-neon .tile:not(.empty) {
    background: #1a1030;
    color: #e9d7ff;
    box-shadow: 0 0 0 1px rgba(215, 180, 255, 0.35), 0 0 12px rgba(155, 109, 255, 0.3);
    text-shadow: 0 0 10px rgba(215, 180, 255, 0.8);
}

.skin-neon .v4 {
    color: #b7f0ff;
}

.skin-neon .v8 {
    color: #9dffc8;
}

.skin-neon .v16 {
    color: #ffe08a;
}

.skin-neon .v32 {
    color: #ffb36b;
}

.skin-neon .v64 {
    color: #ff8aa0;
}

.skin-neon .v128, .skin-neon .v256 {
    color: #fff;
    font-size: clamp(0.8rem, 4vw, 1.2rem);
}

.skin-neon .v512, .skin-neon .v1024, .skin-neon .v2048 {
    color: #fff6b0;
    font-size: clamp(0.7rem, 3.6vw, 1.05rem);
}

.skins, .actions {
    flex-shrink: 0;
}

.skins {
    display: flex;
    gap: 8px;
}

.skin {
    flex: 1;
    border: 1px solid rgba(215, 180, 255, 0.18);
    background: var(--card);
    color: var(--muted);
    border-radius: 999px;
    padding: 8px 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

.skin.active {
    color: #1a1028;
    background: var(--accent);
    border-color: transparent;
    font-weight: 650;
}

.actions {
    display: grid;
}

.btn {
    border: 1px solid rgba(215, 180, 255, 0.2);
    background: var(--card);
    color: var(--ink);
    border-radius: 14px;
    padding: 12px 10px;
    font-size: 0.95rem;
    cursor: pointer;
}

.btn.primary {
    background: linear-gradient(180deg, #e4c6ff, var(--accent-2));
    color: #1a1028;
    border: 0;
    font-weight: 700;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 5, 16, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}

.overlay.hidden {
    display: none;
}

.modal {
    width: min(92vw, 360px);
    background: #1c1432;
    border: 1px solid rgba(215, 180, 255, 0.2);
    border-radius: 18px;
    padding: 22px 18px;
    text-align: center;
}

.modal h2 {
    margin-bottom: 8px;
}

.modal p {
    color: var(--muted);
    margin-bottom: 16px;
    line-height: 1.4;
}

.modal .btn {
    width: 100%;
}
