:root {
    --game-bg: #f5f7fb;
    --game-surface: rgba(255,255,255,.92);
    --game-surface-strong: #ffffff;
    --game-line: rgba(15, 23, 42, .10);
    --game-text: #172033;
    --game-muted: #5d6880;
    --game-primary: #1b5cff;
    --game-primary-dark: #0f3fc9;
    --game-shadow: 0 18px 50px rgba(15, 23, 42, .12);
    --game-radius: 24px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; overflow-x: hidden; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--game-text);
    background:
        radial-gradient(circle at top left, rgba(27,92,255,.11), transparent 28%),
        radial-gradient(circle at 80% 10%, rgba(33, 150, 243, .09), transparent 24%),
        var(--game-bg);
}
button, input { font: inherit; }

a.text-link {
    color: var(--game-muted);
    font-weight: 700;
    padding: .45rem 0;
}

a.text-link:hover { color: var(--game-text); }

.game-shell { padding-top: 1.4rem; }
.tool-hero-game {
    background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,255,255,.88));
}
.game-actions { align-items: center; }

.game-card {
    width: min(100%, 760px);
    margin: 0 auto;
    background: var(--game-surface);
    border: 1px solid rgba(255,255,255,.7);
    border-radius: 28px;
    box-shadow: var(--game-shadow);
    padding: 1.2rem;
    display: grid;
    gap: 1rem;
}

.topbar h2 {
    margin: 0;
    font-size: clamp(1.5rem, 3vw, 2rem);
}

.eyebrow {
    margin: 0 0 .5rem;
    color: var(--game-primary);
    font-size: .85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.subtitle {
    margin: .5rem 0 0;
    color: var(--game-muted);
    line-height: 1.6;
}

.board-wrap {
    position: relative;
    background: linear-gradient(180deg, #f8fbff, #eef4ff);
    border: 1px solid var(--game-line);
    border-radius: 24px;
    padding: 10px;
}

#gameCanvas {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: min(56dvh, 560px);
    margin: 0 auto;
    background:
        linear-gradient(180deg, rgba(255,255,255,.8), rgba(241,246,255,.95)),
        #edf3ff;
    border-radius: 18px;
    box-shadow: inset 0 0 0 1px rgba(27,92,255,.08);
}

.overlay {
    position: absolute;
    inset: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(23, 32, 51, .16);
    border-radius: 18px;
}

.overlay.hidden { display: none; }

.overlay-box {
    width: min(92%, 360px);
    background: rgba(255,255,255,.97);
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 22px;
    padding: 22px;
    text-align: center;
    box-shadow: var(--game-shadow);
}

.overlay-box h2 { margin: 0 0 10px; }
.overlay-box p {
    margin: 0 0 16px;
    color: var(--game-muted);
    line-height: 1.55;
}

.record-form {
    display: grid;
    gap: 10px;
    text-align: left;
    margin-bottom: 14px;
}
.record-form.hidden { display: none; }
.record-form label { font-size: .95rem; font-weight: 700; }
.record-form input {
    width: 100%;
    border: 1px solid var(--game-line);
    border-radius: 14px;
    padding: 12px 14px;
    background: #fff;
    color: var(--game-text);
    outline: none;
}
.record-form input:focus { border-color: var(--game-primary); }

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-box {
    background: rgba(255,255,255,.92);
    border: 1px solid var(--game-line);
    border-radius: 20px;
    padding: 12px 14px;
}

.stat-label {
    display: block;
    color: var(--game-muted);
    font-size: .9rem;
    margin-bottom: 8px;
}

.stat-box strong { font-size: 1.1rem; }
.controls-row { display: flex; gap: 12px; }

.btn {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 800;
    transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(180deg, var(--game-primary), var(--game-primary-dark));
    color: #fff;
    box-shadow: 0 14px 28px rgba(27,92,255,.24);
}

.btn-secondary {
    background: rgba(255,255,255,.86);
    color: var(--game-text);
    border: 1px solid var(--game-line);
}

.mobile-controls { padding-bottom: max(0px, env(safe-area-inset-bottom)); }
.controls-grid {
    width: min(100%, 260px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.ctrl-btn,
.ctrl-center {
    height: clamp(52px, 8dvh, 64px);
    border-radius: 18px;
}

.ctrl-btn {
    border: 1px solid var(--game-line);
    background: #fff;
    color: var(--game-text);
    font-size: 1.35rem;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 8px 18px rgba(15,23,42,.06);
}
.ctrl-btn:active { transform: scale(.98); }
.ctrl-center {
    border: 1px dashed rgba(27,92,255,.16);
    background: rgba(27,92,255,.05);
}

.hint,
.footer-links {
    color: var(--game-muted);
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: .6rem;
    flex-wrap: wrap;
    font-size: .95rem;
}

@media (max-width: 760px) {
    .game-actions { gap: .7rem; }
    .game-actions .button { width: 100%; }
    .game-actions .text-link { width: 100%; }
    .game-card { padding: 1rem; }
}
