:root {
    --stone-1: #e8c8a0;
    --stone-2: #c0833e;
    --board-1: #c9853f;
    --board-2: #a3642c;
    --board-shadow: #7a481c;
    --tile: #f0b962;
    --tile-hi: #f7ce8c;
    --tile-shadow: #c08633;
    --x-color: #5a3620;
    --x-color-2: #7a4a2b;
    --o-ring: #3a2414;
    --cream: #241905;
    --cream-2: #fff9f0;
    --navy: #233457;
    --navy-2: #3a527d;
    --pink-1: #f4c9d6;
    --pink-2: #f8dbe4;
    --pink-3: #ffe9ee;
    --ink: #fff;
    --ink-soft: #fff;
    --success: #4f9d5c;
    --danger: #c65b45;
    --shadow-lg: 0 18px 40px rgba(90, 54, 32, .28);
}

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

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overscroll-behavior: none;
    font-family: 'Nunito', sans-serif;
    color: var(--ink);
    background-image: url('bg.png');
    /* your image path */
    background-size: cover;
    /* fill the screen */
    background-position: center;
    /* center the image */
    background-repeat: no-repeat;
    background-attachment: fixed;
    /* optional */

    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#bgCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.stones {
    position: fixed;
    inset: 0;
    z-index: 0;
    opacity: .35;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 12% 22%, rgba(150, 120, 90, .18) 0 40px, transparent 41px),
        radial-gradient(circle at 78% 15%, rgba(150, 120, 90, .15) 0 55px, transparent 56px),
        radial-gradient(circle at 60% 85%, rgba(150, 120, 90, .16) 0 70px, transparent 71px),
        radial-gradient(circle at 8% 78%, rgba(150, 120, 90, .14) 0 45px, transparent 46px);
}

#preloader {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    background: linear-gradient(160deg, var(--stone-1), var(--stone-2));
    transition: opacity .55s ease, visibility .55s ease;
}

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

.loaderMark {
    position: relative;
    width: 88px;
    height: 88px;
}

.loaderMark svg {
    width: 100%;
    height: 100%;
    animation: spin 1.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loaderTitle {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 26px;
    color: var(--ink);
    letter-spacing: .5px;
}

.loaderBarTrack {
    width: 200px;
    height: 8px;
    border-radius: 99px;
    background: rgba(90, 54, 32, .14);
    overflow: hidden;
}

.loaderBarFill {
    height: 100%;
    width: 0%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--board-2), var(--tile));
    transition: width .25s ease;
}

.loaderSub {
    font-size: 13px;
    color: var(--ink-soft);
    font-weight: 700;
    letter-spacing: .3px;
}

#app {
    position: relative;
    z-index: 2;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 26px 16px 34px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .6s ease, transform .6s ease;
}

#app.show {
    opacity: 1;
    transform: translateY(0);
}

header.gameHeader {
    text-align: center;
}

h1.title {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: clamp(34px, 8vw, 42px);
    margin: 0;
    color: #f7aa14;
    letter-spacing: .5px;
    text-shadow: 0 2px 0 rgba(255, 255, 255, .35), 0 10px 24px rgba(122, 72, 28, .18);
}

.subtitle {
    margin: 2px 0 14px;
    font-weight: 700;
    color: var(--ink-soft);
    font-size: 14px;
    letter-spacing: .2px;
}

.datePill {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--cream);
    border-radius: 22px;
    padding: 8px 22px;
    box-shadow: 0 8px 18px rgba(122, 72, 28, .18), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.datePill .d {
    font-weight: 900;
    color: var(--navy);
    font-size: 14px;
    letter-spacing: .4px;
}

.datePill .f {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 700;
    color: var(--ink);
    font-size: 16px;
}

.statsBar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 18px 0 14px;
    flex-wrap: wrap;
    justify-content: center;
}

.statChip {
    background: var(--cream);
    border-radius: 14px;
    padding: 8px 14px;
    min-width: 74px;
    text-align: center;
    box-shadow: 0 6px 14px rgba(122, 72, 28, .14), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.statChip .lbl {
    font-size: 10px;
    font-weight: 800;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: .8px;
}

.statChip .val {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 700;
    font-size: 19px;
    color: var(--ink);
}

.iconBtn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(122, 72, 28, .14), inset 0 1px 0 rgba(255, 255, 255, .6);
    transition: transform .12s ease, filter .12s ease;
    color: var(--ink);
}

.iconBtn:hover {
    filter: brightness(1.04);
}

.iconBtn:active {
    transform: scale(.9);
}

.iconBtn svg {
    width: 20px;
    height: 20px;
}

.boardWrap {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 4px auto 8px;
    filter: drop-shadow(0 20px 30px rgba(90, 54, 32, .28));
}

#gameCanvas {
    width: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
    border: 7px solid #66330e;
    border-radius: 16px;
    background: #cc8844;
    box-shadow: 0 4px 0 #1a1a1a, 0 8px 16px rgba(0, 0, 0, 0.45), inset 0 2px 4px rgba(255, 255, 255, 0.08), inset 0 -2px 4px rgba(0, 0, 0, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.actionRow {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.pillBtn {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: .2px;
    border: none;
    cursor: pointer;
    padding: 12px 18px;
    border-radius: 30px;
    color: var(--cream-2);
    background: linear-gradient(160deg, var(--board-1), var(--board-2));
    box-shadow: 0 10px 20px rgba(122, 72, 28, .28), inset 0 1px 0 rgba(255, 255, 255, .25);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform .12s ease, filter .12s ease;



}

.pillBtn.secondary {
    background: var(--cream);
    color: var(--ink);
    box-shadow: 0 8px 16px rgba(122, 72, 28, .16), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.pillBtn:hover {
    filter: brightness(1.05);
}

.pillBtn:active {
    transform: scale(.95);
}

.pillBtn:disabled {
    opacity: .70;
    cursor: default;
    filter: none;
    transform: none;
}

.pillBtn svg {
    width: 16px;
    height: 16px;
}

.hint {
    margin-top: 14px;
    font-size: 12.5px;
    color: var(--ink-soft);
    font-weight: 700;
    text-align: center;
    max-width: 420px;
}

/* Modals */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(43, 32, 20, .42);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    padding: 18px;
}

.overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modalCard {
    background: #000000;
    border-radius: 30px;
    padding: 35px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 30px 60px rgba(60, 30, 15, .35);
    transform: translateY(18px) scale(.96);
    transition: transform .3s cubic-bezier(.2, 1.4, .4, 1);
    text-align: center;
    position: relative;
    max-height: 88vh;
    overflow-y: auto;
}

.overlay.open .modalCard {
    transform: translateY(0) scale(1);
}

.modalCard h2 {
    font-family: 'Baloo 2', sans-serif;
    margin: 2px 0 6px;
    font-size: 26px;
    color: var(--ink);
}

.modalCard p {
    margin: 4px 0 14px;
    color: var(--ink-soft);
    font-weight: 700;
    font-size: 14.5px;
}

.closeX {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: rgba(90, 54, 32, .08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
}

.howList {
    text-align: left;
    margin: 6px 0 16px;
    padding: 0 4px;
}

.howList li {
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.4;
}

.legendRow {
    display: flex;
    justify-content: center;
    gap: 34px;
    margin: 14px 0 18px;
}

.legendCol {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.legendIcons {
    display: flex;
    gap: 5px;
}

.legendLbl {
    font-size: 12px;
    font-weight: 800;
    color: var(--ink-soft);
}

#howCanvas {
    width: 100%;
    max-width: 340px;
    border-radius: 16px;
    margin: 4px auto 6px;
    display: block;
}

.resultEmoji {
    font-size: 44px;
    margin-bottom: 2px;
}

.resultStats {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 16px 0;
    flex-wrap: wrap;
}

.resultStat {
    background: var(--cream);
    border-radius: 14px;
    padding: 10px 16px;
    min-width: 82px;
}

.resultStat .n {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 700;
    font-size: 20px;
    color: var(--ink);
}

.resultStat .l {
    font-size: 10px;
    font-weight: 800;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: .6px;
}

.streakLine {
    font-weight: 800;
    font-size: 13.5px;
    color: var(--board-2);
    margin: 2px 0 14px;
}

.modalActions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.toast {
    position: fixed;
    left: 50%;
    top: 5px;
    transform: translate(-50%, -140%);
    z-index: 60;
    background: #000000;
    color: var(--cream-2);
    font-weight: 800;
    font-size: 13.5px;
    padding: 10px 18px;
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .28);
    transition: transform .3s cubic-bezier(.2, 1.4, .4, 1);
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    transform: translate(-50%, 0);
}

@media (max-width:420px) {
    .statChip {
        min-width: 64px;
        padding: 7px 10px;
    }

    .pillBtn {
        padding: 11px 14px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}

#soundBtn,
#helpBtn {
    background: #1c1406;
    border: 2px solid #7c4617;
    box-shadow: none;
    border-radius: 30px;
    color: #f0d8a8;
}