:root {
    --ink: #2b2236;
    --soft: #6d6378;
    --sand: #fbf4ea;
    --sand-2: #f3e2c7;
    --rock: #c76f4c;
    --rock-dark: #8a3b2c;
    --cactus: #5aa469;
    --cactus-dark: #3f7f4d;
    --sun: #f2b33d;
    --sun-dark: #c98a17;
    --n: 4;
    --cell: 96px;
    --gap: 10px;
    --font: 'Baloo 2', 'Trebuchet MS', 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);
    color: var(--ink);
    background: var(--sand);
    overflow-x: hidden;
}

.scene { position: fixed; inset: 0 0 auto 0; height: 300px; z-index: 0; pointer-events: none; }
.scene svg { width: 100%; height: 100%; display: block; }
.scene::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -60px;
    height: 60px;
    background: linear-gradient(#e9b98a, var(--sand));
}

.home-link, .sound-btn {
    position: fixed;
    top: 12px;
    z-index: 20;
    font: 700 15px/1 var(--font);
    color: #fff;
    text-decoration: none;
    padding: 7px 14px 6px;
    border-radius: 999px;
    background: rgba(42, 26, 61, .45);
    border: 1px solid rgba(255, 255, 255, .25);
    white-space: nowrap;
    cursor: pointer;
}

.home-link { left: 14px; }
.sound-btn { right: 14px; }
.home-link:hover, .sound-btn:hover { background: rgba(42, 26, 61, .7); }

.dig {
    position: relative;
    z-index: 1;
    width: fit-content;
    max-width: calc(100vw - 12px);
    margin: 120px auto 30px;
    background: var(--sand);
    border-radius: 26px;
    box-shadow: 0 18px 50px rgba(42, 26, 61, .25), 0 0 0 4px rgba(255, 255, 255, .6);
    padding: 18px 22px 18px;
}

.head { display: flex; align-items: center; gap: 12px; margin-top: -64px; }
.pip { width: 120px; height: 100px; flex: 0 0 auto; filter: drop-shadow(0 4px 6px rgba(42, 26, 61, .25)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.title-wrap { padding-top: 46px; }
h1 { font-size: clamp(34px, 6vw, 46px); font-weight: 800; line-height: .95; letter-spacing: -.5px; }
h1 span { color: var(--rock); }
.tag { color: var(--soft); font-size: 15px; max-width: 24em; }

.bar { display: flex; gap: 8px; align-items: stretch; }

.score {
    position: relative;
    min-width: 84px;
    padding: 4px 12px 3px;
    border-radius: 14px;
    background: var(--rock-dark);
    color: #fff;
    text-align: center;
}

.score span { display: block; font-size: 12px; font-weight: 700; opacity: .8; text-transform: uppercase; letter-spacing: .5px; }
.score b { font-size: 22px; line-height: 1.1; }

.plus {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    font-style: normal;
    font-weight: 800;
    color: var(--cactus-dark);
    pointer-events: none;
    opacity: 0;
}

.plus.go { animation: plus .8s ease-out; }
@keyframes plus { 0% { opacity: 1; top: 0; } 100% { opacity: 0; top: -34px; } }

.bar-btns { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.btn {
    font: 800 15px/1 var(--font);
    padding: 10px 14px 9px;
    border-radius: 14px;
    cursor: pointer;
    color: var(--rock-dark);
    background: #fff;
    border: 2px solid #ecd6bb;
    box-shadow: 0 3px 0 #ecd6bb;
}

.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #ecd6bb; }
.btn.main { color: #fff; background: var(--cactus); border-color: var(--cactus-dark); box-shadow: 0 3px 0 var(--cactus-dark); }

/* tools */
.tools { display: flex; gap: 8px; margin-top: 12px; }

.tool {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: 800 15px/1 var(--font);
    padding: 8px 8px 7px;
    color: var(--ink);
    background: #fff;
    border: 2px solid #ecd6bb;
    border-radius: 14px;
    box-shadow: 0 3px 0 #ecd6bb;
    cursor: pointer;
}

.tool .ico { font-size: 18px; }
.tool .charge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--sun);
    color: #fff;
    font-size: 13px;
    line-height: 22px;
}

.tool.empty { opacity: .45; }
.tool.empty .charge { background: #c8bcb3; }
.tool.active { background: var(--sun); border-color: var(--sun-dark); box-shadow: 0 3px 0 var(--sun-dark); color: #fff; }
.tool.active .charge { background: #fff; color: var(--sun-dark); }
.tool.earned { animation: earned .8s ease-out; }
@keyframes earned { 30% { transform: scale(1.12); background: #fff3cf; } }

.tool-hint { min-height: 24px; margin: 6px 2px 4px; font-size: 15px; font-weight: 700; color: var(--sun-dark); text-align: center; }

/* board */
.board-wrap { position: relative; display: flex; justify-content: center; }

.board {
    position: relative;
    width: calc(var(--n) * var(--cell) + (var(--n) + 1) * var(--gap));
    height: calc(var(--n) * var(--cell) + (var(--n) + 1) * var(--gap));
    padding: var(--gap);
    border-radius: 18px;
    background:
        repeating-linear-gradient(178deg, transparent 0 22px, rgba(0, 0, 0, .05) 22px 26px),
        #b07a5a;
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, .25), 0 4px 0 #8a5a40;
    touch-action: none;
    user-select: none;
}

.cells, .tiles { position: absolute; inset: var(--gap); }

.cells {
    display: grid;
    grid-template-columns: repeat(var(--n), var(--cell));
    gap: var(--gap);
}

.cells i {
    width: var(--cell);
    height: var(--cell);
    border-radius: 12px;
    background: rgba(255, 240, 220, .22);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, .12);
}

.tile {
    --bg: #f3e2c7;
    position: absolute;
    left: 0;
    top: 0;
    width: var(--cell);
    height: var(--cell);
    border-radius: 12px;
    background:
        repeating-linear-gradient(176deg, transparent 0 14px, rgba(120, 70, 30, .06) 14px 17px),
        var(--bg);
    color: var(--fg, #6f5a3e);
    box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .14), 0 2px 4px rgba(0, 0, 0, .18);
    transform: translate(calc(var(--x) * (var(--cell) + var(--gap))), calc(var(--y) * (var(--cell) + var(--gap))));
    transition: transform .11s ease-in-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: default;
}

.tile svg { width: 84%; height: 52%; margin-top: 1%; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .15)); }
.tile .num { font-size: calc(var(--cell) * .36); font-weight: 800; line-height: .95; letter-spacing: -.02em; }
.tile .num.d3 { font-size: calc(var(--cell) * .32); }
.tile .num.d4 { font-size: calc(var(--cell) * .27); }
.tile .num.d5 { font-size: calc(var(--cell) * .22); }
.tile.top { box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .14), 0 0 18px rgba(242, 179, 61, .9); }

.tile.new { animation: appear .18s ease-out .08s backwards; }
.tile.merged .face { animation: pop .2s ease-out; }
.tile .face { display: contents; }
.tile.merged { z-index: 2; }
.tile.merged::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 12px;
    animation: flash .3s ease-out;
    pointer-events: none;
}

@keyframes appear { from { opacity: 0; scale: .3; } }
@keyframes pop { 50% { scale: 1.16; } }
@keyframes flash { from { background: rgba(255, 255, 255, .6); } to { background: transparent; } }

.tile.pickable { cursor: pointer; }
.tile.pickable:hover { outline: 3px solid var(--sun); outline-offset: -3px; }
.tile.picked { outline: 4px solid #fff; outline-offset: -4px; scale: 1.05; }
.tile.vanish { animation: vanish .35s ease-in forwards; }
@keyframes vanish { to { opacity: 0; scale: .2; rotate: 20deg; } }

.board.quake { animation: quake .4s; }
@keyframes quake { 20% { translate: -6px 2px; } 40% { translate: 5px -2px; } 60% { translate: -4px 1px; } 80% { translate: 3px 0; } }

/* discovery toast */
.toast {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    width: min(360px, 92%);
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(251, 244, 234, .97);
    box-shadow: 0 10px 30px rgba(42, 26, 61, .35);
    z-index: 5;
    animation: rise .3s ease-out;
    pointer-events: none;
}

.toast[hidden] { display: none; }
.toast .t-ico { flex: 0 0 56px; height: 56px; border-radius: 12px; display: grid; place-items: center; }
.toast .t-ico svg { width: 80%; height: 80%; }
.toast b { display: block; font-size: 16px; line-height: 1.15; }
.toast small { display: block; font-size: 13px; line-height: 1.3; color: var(--soft); }
.toast .t-tag { font-size: 11px; font-weight: 800; color: var(--cactus-dark); text-transform: uppercase; letter-spacing: .5px; }
.toast.cheer { width: auto; padding: 8px 16px; font-size: 20px; font-weight: 800; color: var(--rock-dark); }

@keyframes rise { from { opacity: 0; translate: 0 12px; } }

.how { margin-top: 12px; text-align: center; font-size: 14px; color: var(--soft); }

/* modals: game over, win, museum */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(42, 26, 61, .5);
}

.modal[hidden] { display: none; }

.modal-card {
    width: min(480px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    background: var(--sand);
    border-radius: 24px;
    padding: 22px 22px 20px;
    box-shadow: 0 24px 60px rgba(42, 26, 61, .45);
    text-align: center;
    animation: rise .3s ease-out;
}

.modal-card h2 { font-size: 32px; font-weight: 800; line-height: 1.1; color: var(--rock-dark); }
.modal-card p { margin: 6px 0; color: var(--soft); }
.modal-card .big-tile { --cell: 120px; position: relative; margin: 12px auto; transform: none; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }

.museum { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; text-align: left; }

.exhibit {
    font: inherit;
    border: 0;
    border-radius: 14px;
    padding: 8px 6px 6px;
    background: var(--bg);
    color: var(--fg);
    cursor: pointer;
    text-align: center;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12);
}

.exhibit svg { width: 70%; height: 46px; }
.exhibit b { display: block; font-size: 12.5px; line-height: 1.15; }
.exhibit small { display: block; font-size: 11px; opacity: .8; }
.exhibit.locked { --bg: #e3dbd4 !important; --fg: #b3a69c !important; cursor: default; }
.exhibit.locked svg { opacity: .45; filter: grayscale(1) brightness(1.3); }

.fact-box { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: #fff; text-align: left; min-height: 60px; color: var(--ink); }
.fact-box b { color: var(--rock-dark); }

@media (max-width: 560px) {
    :root { --gap: 7px; }
    .scene { height: 200px; }
    .dig { margin: 90px auto 12px; padding: 12px 10px 14px; border-radius: 20px; }
    .head { margin-top: -50px; gap: 4px; }
    .pip { width: 92px; height: 76px; }
    .title-wrap { padding-top: 34px; }
    .tag { font-size: 13.5px; }
    .score { min-width: 64px; padding: 3px 8px; }
    .score b { font-size: 19px; }
    .btn { font-size: 14px; padding: 8px 10px 7px; }
    .tool { font-size: 13px; gap: 4px; padding: 7px 4px 6px; }
    .tool .ico { font-size: 16px; }
}
