/* A calm green-felt table. No neon, no blinking, nothing that moves unless you do something. */
:root {
    --felt-top: #4a6b5c;
    --felt-bottom: #36524a;
    --cream: #f1ead8;
    --muted: #b9c8bd;
    --pill: rgba(241, 234, 216, 0.14);
    --pill-line: rgba(241, 234, 216, 0.3);
    --gold: #e0c377;
    --mint: #8fc9b0;
    --tw: clamp(20px, min(calc((100vw - 20px) / 15.9), calc((100vh - 255px) / 10.9)), 54px);
    --th: calc(var(--tw) * 1.3);
}

@media (prefers-color-scheme: dark) {
    :root {
        --felt-top: #35504a;
        --felt-bottom: #243a36;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 30%, var(--felt-top), var(--felt-bottom) 75%);
    background-attachment: fixed;
    color: var(--cream);
    font-family: ui-rounded, 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    max-width: 980px;
    margin: 0 auto;
    padding: 12px 14px 4px;
}

.top h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 650;
    letter-spacing: 0.04em;
}

.home {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
}

.home:hover,
.home:focus-visible {
    color: var(--cream);
    text-decoration: underline;
}

.stats {
    display: flex;
    gap: 18px;
    margin-left: auto;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 54px;
    font-size: 17px;
    font-variant-numeric: tabular-nums;
}

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

.stat.matches span:last-child {
    color: var(--gold);
    font-weight: 650;
}

/* ---------- Buttons ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 980px;
    margin: 0 auto;
    padding: 6px 14px;
}

.btn {
    font: inherit;
    font-size: 14px;
    color: var(--cream);
    background: var(--pill);
    border: 1px solid var(--pill-line);
    border-radius: 999px;
    padding: 7px 18px;
    cursor: pointer;
    touch-action: manipulation;
}

.btn:hover {
    background: rgba(241, 234, 216, 0.22);
}

.btn:focus-visible,
.tile:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn.primary {
    color: #24382f;
    background: var(--gold);
    border-color: var(--gold);
}

.note {
    min-height: 1.4em;
    margin: 2px 14px 0;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

/* ---------- The tiles ---------- */
.table {
    display: flex;
    justify-content: center;
    padding: 6px 10px 10px;
}

.board {
    position: relative;
    width: calc(var(--tw) * 15.7);
    height: calc(var(--th) * 8.2);
    flex: none;
}

.tile {
    position: absolute;
    left: calc(var(--tw) * (var(--x) / 2 + var(--z) * 0.09));
    top: calc(var(--th) * (var(--y) / 2) - var(--tw) * var(--z) * 0.09 + var(--th) * 0.06);
    width: var(--tw);
    height: var(--th);
    margin: 0;
    padding: 0;
    border: 1px solid #d3c8aa;
    border-radius: calc(var(--tw) * 0.12);
    background: linear-gradient(150deg, #fbf6e8, #eee4cb);
    /* the jade-green edge of the tile gives it thickness */
    box-shadow:
        calc(var(--tw) * -0.07) calc(var(--tw) * 0.08) 0 #6fa68a,
        calc(var(--tw) * -0.07) calc(var(--tw) * 0.08) 0 1px #43705b,
        calc(var(--tw) * -0.1) calc(var(--tw) * 0.14) calc(var(--tw) * 0.12) rgba(0, 0, 0, 0.3);
    cursor: pointer;
    touch-action: manipulation;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.face {
    position: absolute;
    left: 8%;
    top: 7%;
    width: 84%;
    height: 86%;
    display: block;
    pointer-events: none;
}

/* tiles that are still blocked are a little dimmer */
.tile.blocked {
    background: linear-gradient(150deg, #e3dcc6, #d2c9ae);
}

.tile.blocked .face {
    opacity: 0.78;
}

.tile.sel {
    transform: translateY(calc(var(--tw) * -0.1));
    outline: 3px solid var(--gold);
    outline-offset: -2px;
}

.tile.hint {
    outline: 3px solid var(--mint);
    outline-offset: -2px;
}

.tile.leaving {
    opacity: 0;
    transform: scale(0.88);
    pointer-events: none;
}

.tile[hidden] {
    display: none;
}

/* a tile that is not free gives a small, single nudge */
.tile.nudge {
    animation: nudge 0.25s ease;
}

@keyframes nudge {
    25% { translate: calc(var(--tw) * -0.05) 0; }
    75% { translate: calc(var(--tw) * 0.05) 0; }
}

/* ---------- No matches left ---------- */
.stuck {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 14px;
    width: max-content;
    max-width: calc(100% - 28px);
    margin: 0 auto 8px;
    padding: 8px 12px 8px 18px;
    font-size: 14px;
    background: rgba(20, 35, 30, 0.45);
    border: 1px solid var(--pill-line);
    border-radius: 999px;
}

.stuck[hidden] { display: none; }

.help {
    max-width: 640px;
    margin: 4px auto 22px;
    padding: 0 16px;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
}

/* ---------- Card ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(20, 32, 28, 0.5);
}

.overlay[hidden] { display: none; }

/* The start cover is opaque so nobody gets a peek at the tiles before the clock runs */
.overlay.cover {
    background: radial-gradient(ellipse at 50% 30%, var(--felt-top), var(--felt-bottom) 75%);
}

a.btn {
    display: inline-block;
    text-decoration: none;
}

.card {
    width: min(400px, 100%);
    padding: 22px;
    color: #2a3a32;
    background: #f6f0e0;
    border-radius: 14px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.card h2 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 650;
}

.card-text {
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 1.5;
    color: #5d6c63;
}

.row-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.card .btn {
    color: #2a3a32;
    background: #e8dfc8;
    border-color: #cfc4a6;
}

.card .btn.primary {
    color: #24382f;
    background: var(--gold);
    border-color: #c9ab5c;
}

@media (max-width: 560px) {
    .stats { gap: 12px; margin-left: 0; width: 100%; justify-content: space-between; }
    .help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
