:root {
    color-scheme: light;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --ink: #17233c;
    --text: #46536a;
    --muted: #66738a;
    --page: #f5f8fd;
    --surface: #ffffff;
    --line: #d9e2ef;
    --primary: #2f6fed;
    --primary-dark: #1d4fae;
    --teal: #0f766e;
    --teal-soft: #e7f6f3;
    --violet: #6d3ccb;
    --focus: #805300;
    --success: #18794e;
    --shadow: 0 22px 60px rgba(23, 35, 60, 0.12);
}

* { box-sizing: border-box; }

html {
    min-width: 280px;
    background: var(--page);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 0 0, rgba(47, 111, 237, 0.14), transparent 30rem),
        radial-gradient(circle at 100% 30%, rgba(109, 60, 203, 0.11), transparent 28rem),
        var(--page);
}

button, input, select { font: inherit; }
button, select, input[type="number"] { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.game-shell {
    width: min(1080px, calc(100% - 2rem));
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 2.4rem) 0 1.5rem;
}

.game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.4rem;
}

.eyebrow, .step-label, .result-kicker {
    margin: 0 0 0.35rem;
    color: var(--primary-dark);
    font-size: 0.78rem;
    font-weight: 850;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: anywhere; }

h1 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(2rem, 7vw, 4.3rem);
    line-height: 0.98;
    letter-spacing: -0.045em;
}

.subtitle {
    max-width: 50rem;
    margin: 0.65rem 0 0;
    font-size: clamp(1rem, 2.2vw, 1.22rem);
}

.language-picker {
    display: flex;
    flex: 0 0 auto;
    gap: 0.25rem;
    padding: 0.3rem;
    border: 1px solid var(--line);
    border-radius: 0.9rem;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 24px rgba(23, 35, 60, 0.07);
}

.language-picker button {
    min-width: 44px;
    padding: 0.55rem;
    border: 0;
    border-radius: 0.65rem;
    color: var(--ink);
    background: transparent;
    font-weight: 850;
}

.language-picker button:hover { background: var(--page); }
.language-picker button[aria-current="true"] { color: #fff; background: var(--ink); }

.setup-card, .play-card {
    border: 1px solid var(--line);
    border-radius: clamp(1rem, 3vw, 1.75rem);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
}

.setup-card { padding: clamp(1.1rem, 4vw, 2.25rem); }
.section-heading { max-width: 50rem; margin-bottom: 1.6rem; }

.section-heading h2, .play-topbar h2 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(1.5rem, 4vw, 2.3rem);
    letter-spacing: -0.025em;
}

.section-heading p:last-child { margin: 0.55rem 0 0; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend, .field-group > label { margin-bottom: 0.55rem; color: var(--ink); font-weight: 800; }
legend { padding: 0; }
.mode-grid, .settings-grid { display: grid; gap: 0.9rem; }
.mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.choice-card {
    display: flex;
    min-height: 92px;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--surface);
    cursor: pointer;
}

.choice-card:hover { border-color: #aab6c9; }
.choice-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.12); }
.choice-card input { width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; accent-color: var(--primary); }
.choice-card span { display: grid; gap: 0.25rem; }
.choice-card strong { color: var(--ink); }
.choice-card small, .field-group small { color: var(--muted); line-height: 1.45; }

.settings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 1.35rem;
}

.field-group { display: flex; min-width: 0; flex-direction: column; }

.field-group input, .field-group select {
    width: 100%;
    padding: 0.7rem 0.8rem;
    border: 1px solid #b9c3d2;
    border-radius: 0.75rem;
    color: var(--ink);
    background: var(--surface);
}

.field-group small { margin-top: 0.4rem; }
.number-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.45rem; }

.rules-note {
    margin: 1.35rem 0 0;
    padding: 0.9rem 1rem;
    border-left: 4px solid var(--teal);
    border-radius: 0 0.75rem 0.75rem 0;
    color: var(--ink);
    background: var(--teal-soft);
    font-weight: 650;
}

.validation-message { margin: 0.85rem 0 0; color: #8d2218; font-weight: 750; }

.primary-button, .secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.72rem 1rem;
    border-radius: 0.8rem;
    font-weight: 800;
}

.primary-button {
    border: 1px solid var(--primary);
    color: #fff;
    background: var(--primary);
    box-shadow: 0 8px 20px rgba(47, 111, 237, 0.2);
}

.primary-button:hover:not(:disabled) { border-color: var(--primary-dark); background: var(--primary-dark); }
.secondary-button { border: 1px solid #aeb9c9; color: var(--ink); background: var(--surface); }
.secondary-button:hover:not(:disabled) { border-color: var(--ink); background: var(--page); }
.compact-button { white-space: nowrap; }
.start-button { width: 100%; margin-top: 1.25rem; }
.play-card { overflow: hidden; }

.play-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: clamp(1rem, 3vw, 1.5rem);
    border-bottom: 1px solid var(--line);
}

.score-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-bottom: 1px solid var(--line);
    background: #fbfcff;
}

.score-strip > div { display: grid; gap: 0.15rem; padding: 0.85rem 0.65rem; text-align: center; }
.score-strip > div + div { border-left: 1px solid var(--line); }
.score-strip span { color: var(--muted); font-size: 0.73rem; font-weight: 750; text-transform: uppercase; }
.score-strip strong { color: var(--ink); font-size: 1.2rem; }

.turn-message {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: var(--ink);
    background: #edf3ff;
    font-size: clamp(1rem, 2.5vw, 1.22rem);
    font-weight: 800;
    text-align: center;
}

.goal-zone {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: clamp(1.2rem, 5vw, 3rem);
    padding: clamp(1.25rem, 4vw, 2.4rem);
    background: linear-gradient(135deg, #fff, #f7f9ff);
}

.goal-dial {
    --progress: 0%;
    position: relative;
    width: clamp(150px, 24vw, 230px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(var(--primary) var(--progress), #e1e8f4 0);
    box-shadow: inset 0 0 0 1px rgba(23, 35, 60, 0.04), 0 16px 38px rgba(47, 111, 237, 0.13);
}

.goal-dial::before {
    content: "";
    position: absolute;
    inset: 14%;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
}

.goal-dial > div { position: relative; display: flex; align-items: baseline; gap: 0.35rem; color: var(--muted); }
.goal-dial strong { color: var(--ink); font-size: clamp(2.1rem, 7vw, 4rem); letter-spacing: -0.05em; }
.goal-dial b { color: var(--primary-dark); font-size: 1.15rem; }

.progress-copy { min-width: 0; }
.progress-copy p { margin: 0 0 0.7rem; color: var(--ink); font-weight: 750; }
.progress-track { height: 18px; overflow: hidden; border-radius: 999px; background: #dfe6f2; box-shadow: inset 0 1px 3px rgba(23, 35, 60, 0.12); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--violet)); transition: width 280ms ease; }

.move-panel { padding: 1.25rem clamp(1rem, 4vw, 2rem); border-top: 1px solid var(--line); text-align: center; }
.move-panel h3 { margin: 0 0 1rem; color: var(--ink); font-size: 1rem; }
.increment-picker { width: min(100%, 420px); display: grid; grid-template-columns: 52px minmax(0, 1fr) 52px; align-items: end; gap: 0.55rem; margin: 0 auto; }
.step-button { width: 52px; min-height: 52px; border: 1px solid #aeb9c9; border-radius: 0.85rem; color: var(--ink); background: var(--surface); font-size: 1.35rem; font-weight: 850; }
.step-button:hover:not(:disabled) { border-color: var(--primary); background: #edf3ff; }
.increment-field { display: grid; gap: 0.35rem; }
.increment-field label { color: var(--ink); font-size: 0.84rem; font-weight: 750; }
.increment-field input { width: 100%; min-height: 52px; padding: 0.6rem; border: 1px solid #aeb9c9; border-radius: 0.85rem; color: var(--ink); background: #fff; font-size: 1.2rem; font-weight: 850; text-align: center; }
.increment-range { width: min(100%, 420px); min-height: 44px; margin: 0.65rem auto 0; accent-color: var(--primary); }
.add-button { width: min(100%, 320px); margin-top: 0.65rem; }

.result-panel { padding: clamp(1.2rem, 4vw, 2rem); border-top: 1px solid #b8e1cc; background: #edf9f3; text-align: center; }
.result-panel h3 { max-width: 50rem; margin: 0 auto; color: #105e3c; font-size: clamp(1.35rem, 4vw, 2.15rem); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.65rem; margin-top: 1rem; }

.history-panel { padding: 1rem clamp(1rem, 4vw, 2rem) 1.4rem; border-top: 1px solid var(--line); background: #fbfcff; }
.history-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.history-heading h3 { margin: 0; color: var(--ink); font-size: 1rem; }
.history-heading span { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.history-panel > p { margin: 0.65rem 0 0; color: var(--muted); }
.history-panel ol { display: grid; gap: 0.35rem; margin: 0.65rem 0 0; padding-left: 1.5rem; }
.history-panel li::marker { color: var(--primary); font-weight: 800; }
.game-footer { padding: 1rem 0; color: var(--muted); font-size: 0.9rem; text-align: center; }
.game-footer p { margin: 0; }

@media (max-width: 760px) {
    .game-header, .play-topbar { align-items: stretch; flex-direction: column; }
    .language-picker { align-self: flex-start; }
    .mode-grid, .settings-grid { grid-template-columns: 1fr; }
    .score-strip { grid-template-columns: 1fr 1fr; }
    .score-strip > div:nth-child(3) { border-top: 1px solid var(--line); border-left: 0; }
    .score-strip > div:nth-child(4) { border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
    .goal-zone { grid-template-columns: 1fr; justify-items: center; }
    .progress-copy { width: 100%; text-align: center; }
}

@media (max-width: 420px) {
    .game-shell { width: min(100% - 1rem, 1080px); }
    .language-picker { width: 100%; }
    .language-picker button { flex: 1 1 25%; }
    .number-control { grid-template-columns: 1fr; }
    .result-actions > *, .play-topbar .secondary-button { width: 100%; }
    .increment-picker { grid-template-columns: 48px minmax(0, 1fr) 48px; }
    .step-button { width: 48px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
