:root {
    --wood-dark: #241309;
    --wood-darker: #160b05;
    --frame-wood: #7d4a24;
    --frame-wood-light: #a8703f;
    --frame-wood-dark: #4a2b14;
    --cell-bg: #3a2515;
    --cell-bg-2: #40291a;
    --cell-line: #523620;
    --piece-amber: #e2a75a;
    --piece-amber-dk: #a9743a;
    --piece-maroon: #b7565c;
    --piece-maroon-dk: #7e3a3f;
    --piece-olive: #98a664;
    --piece-olive-dk: #657140;
    --piece-sand: #dcc191;
    --piece-sand-dk: #a9895b;
    --accent-gold: #f2b750;
    --accent-gold-soft: #f2b75055;
    --text-cream: #f4ead9;
    --text-muted: #c8b49b;
    --danger: #e2585f;
    --glass: rgba(255, 255, 255, 0.055);
    --glass-brd: rgba(255, 255, 255, 0.09);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background:
        radial-gradient(ellipse 90% 60% at 50% -10%, #3a2210 0%, transparent 60%),
        radial-gradient(ellipse 100% 80% at 50% 120%, #1c0f06 0%, transparent 55%),
        linear-gradient(180deg, var(--wood-dark) 0%, var(--wood-darker) 100%);
    font-family: 'Outfit', sans-serif;
    color: var(--text-cream);
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------- PRELOADER ---------- */
#preloader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 40%, #2c1808 0%, var(--wood-darker) 70%);
    transition: opacity .6s ease, visibility .6s ease;
}

#preloader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.pl-logo {
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: clamp(28px, 7vw, 46px);
    letter-spacing: 4px;
    color: var(--text-cream);
    text-shadow: 0 0 18px var(--accent-gold-soft), 0 2px 0 #000;
    display: flex;
    gap: 10px;
    margin-bottom: 6px;
}

.pl-logo span {
    display: inline-block;
    opacity: 0;
    transform: translateY(14px) rotate(-6deg);
    animation: plLetter .6s cubic-bezier(.34, 1.56, .64, 1) forwards;
}

@keyframes plLetter {
    to {
        opacity: 1;
        transform: translateY(0) rotate(0);
    }
}

.pl-sub {
    font-size: 12px;
    letter-spacing: 3px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 34px;
}

.pl-plank {
    width: min(70vw, 280px);
    height: 16px;
    border-radius: 9px;
    background: var(--cell-bg);
    border: 2px solid var(--frame-wood-dark);
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, .5);
}

.pl-fill {
    height: 100%;
    width: 0%;
    border-radius: 7px;
    background: linear-gradient(90deg, var(--piece-amber-dk), var(--accent-gold));
    box-shadow: 0 0 10px var(--accent-gold-soft);
    transition: width .25s ease;
}

.pl-pct {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 2px;
}

/* ---------- HEADER ---------- */
#app.ready #preloader {
    display: none;
}

header {
    width: 100%;
    max-width: 560px;
    padding: 14px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeDown .6s ease both;
    animation-delay: .1s;
}

@keyframes fadeDown {
    from {
        opacity: 0;
        transform: translateY(-14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: clamp(18px, 5vw, 24px);
    letter-spacing: 2px;
    color: var(--text-cream);
    text-shadow: 0 2px 0 rgba(0, 0, 0, .4);
}

.title .accent {
    color: var(--accent-gold);
}

.icon-btns {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--glass-brd);
    background: var(--glass);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-cream);
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, .1);
    border-color: var(--accent-gold-soft);
}

.icon-btn:active {
    transform: scale(.9);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

.stats-row {
    display: flex;
    gap: 8px;
}

.stat-card {
    flex: 1;
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--glass);
    border: 1px solid var(--glass-brd);
    backdrop-filter: blur(6px);
    text-align: center;
    box-shadow:
        0 2px 0 rgba(255, 255, 255, 0.35) inset,
        /* top highlight */
        0 -2px 0 rgba(0, 0, 0, 0.18) inset,
        /* bottom inner shadow */
        0 4px 0 rgba(0, 0, 0, 0.20),
        /* bottom border */
        0 8px 18px rgba(0, 0, 0, 0.30),
        /* depth */
        0 0 0 1px rgba(255, 255, 255, 0.08);
    /* outer glow */
}

.stat-label {
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-value {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 18px;
    color: var(--accent-gold);
    margin-top: 2px;
}

/* ---------- BOARD ---------- */
#board-wrap {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px 14px;
    min-height: 0;
    animation: fadeUp .7s ease both;
    animation-delay: .2s;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(18px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#boardCanvas {
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
    filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55));
    border-radius: 18px;
}

#boardCanvas.warn {
    animation: warnPulse 1s ease-in-out infinite;
}

@keyframes warnPulse {

    0%,
    100% {
        filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55)) drop-shadow(0 0 0px rgba(226, 88, 95, 0));
    }

    50% {
        filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55)) drop-shadow(0 0 14px rgba(226, 88, 95, .65));
    }
}

footer {
    width: 100%;
    text-align: center;
    padding: 4px 0 10px;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: .5px;
    opacity: .7;
}

/* ---------- MODALS ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 5, 2, .72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s ease, visibility .3s ease;
    padding: 20px;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: min(420px, 100%);
    max-height: 88vh;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(58, 36, 20, .95), rgba(28, 16, 8, .97));
    border: 1px solid var(--glass-brd);
    border-radius: 22px;
    padding: 26px 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .06);
    transform: translateY(20px) scale(.97);
    transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}

.modal-overlay.show .modal {
    transform: translateY(0) scale(1);
}

.modal h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 20px;
    letter-spacing: 1.5px;
    margin: 0 0 4px;
    color: var(--text-cream);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal .lede {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 18px;
    line-height: 1.5;
}

.howto-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.howto-ico {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--piece-amber), var(--piece-amber-dk));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
}

.howto-ico svg {
    width: 20px;
    height: 20px;
    color: #2a1608;
}

.howto-text b {
    display: block;
    font-size: 14px;
    color: var(--text-cream);
    margin-bottom: 2px;
}

.howto-text span {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.45;
}

.modal-btn {
    width: 100%;
    margin-top: 6px;
    padding: 13px;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 14px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 14.5px;
    letter-spacing: .5px;
    color: #2a1608;
    margin-top: 30px;
    background: linear-gradient(to bottom,
            #ffe59c 0%,
            var(--accent-gold) 30%,
            var(--piece-amber-dk) 100%);

    box-shadow:
        inset 0 2px 2px rgba(255, 255, 255, .55),
        /* glossy top */
        inset 0 -3px 4px rgba(120, 70, 10, .35),
        /* inner bottom */
        0 2px 0 rgba(255, 255, 255, .15),
        /* top edge */
        0 5px 0 #9d6b1d,
        /* 3D bottom edge */
        0 10px 22px rgba(242, 183, 80, .35),
        /* glow */
        0 14px 28px rgba(0, 0, 0, .25);
    /* depth */

    transition: all .15s ease;
    border-color: #9e6a2f;
}

.modal-btn:active {
    transform: scale(.97);
}

.modal-btn.ghost {
    background: transparent;
    border: 1px solid var(--glass-brd);
    color: var(--text-cream);
    box-shadow: none;
    margin-top: 20px;
}

.go-score {
    text-align: center;
    margin: 14px 0 20px;
    padding: 18px;
    border-radius: 16px;
    background: var(--glass);
    border: 1px solid var(--glass-brd);
}

.go-score .big {
    font-family: 'Orbitron', sans-serif;
    font-size: 38px;
    font-weight: 800;
    color: var(--accent-gold);
    line-height: 1.1;
}

.go-score .sub {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-top: 6px;
}

.go-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.go-row .stat-card {
    background: rgba(0, 0, 0, .2);
}

.new-best-badge {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    background: var(--accent-gold);
    color: #2a1608;
    font-weight: 700;
    letter-spacing: 1px;
}

@media (max-height: 620px) {
    header {
        padding: 8px 14px 4px;
    }

    .stats-row {
        display: none;
    }
}