:root {
    color-scheme: light;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --ink: #17233c;
    --text: #46536a;
    --muted: #66738a;
    --page: #f6f8fc;
    --surface: #ffffff;
    --line: #dce3ee;
    --primary: #9c2f20;
    --primary-dark: #742217;
    --amber: #f6b73c;
    --amber-soft: #fff4d6;
    --wood: #efb663;
    --wood-dark: #c6792d;
    --head: #b42318;
    --head-dark: #7f1d16;
    --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 10% 0%, rgba(246, 183, 60, 0.17), transparent 30rem),
        radial-gradient(circle at 100% 35%, rgba(156, 47, 32, 0.10), transparent 28rem),
        var(--page);
}

button,
input,
select {
    font: inherit;
}

button,
select,
input[type="number"] {
    min-height: 44px;
}

button {
    cursor: pointer;
    touch-action: manipulation;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

:focus {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.game-shell {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 2.5rem) 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);
    font-size: 0.78rem;
    font-weight: 800;
    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.4rem);
    line-height: 0.98;
    letter-spacing: -0.045em;
}

.subtitle {
    max-width: 48rem;
    margin: 0.65rem 0 0;
    color: var(--text);
    font-size: clamp(1rem, 2.2vw, 1.25rem);
}

.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.86);
    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: 800;
}

.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.95);
    box-shadow: var(--shadow);
}

.setup-card {
    padding: clamp(1.1rem, 4vw, 2.25rem);
}

.section-heading {
    max-width: 48rem;
    margin-bottom: 1.6rem;
}

.section-heading h2,
.play-topbar h2 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(1.5rem, 4vw, 2.35rem);
    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 {
    position: relative;
    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(156, 47, 32, 0.12);
}

.choice-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(156, 47, 32, 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(--amber);
    border-radius: 0 0.75rem 0.75rem 0;
    color: var(--ink);
    background: var(--amber-soft);
    font-weight: 650;
}

.validation-message {
    margin: 0.85rem 0 0;
    color: var(--primary-dark);
    font-weight: 700;
}

.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(156, 47, 32, 0.18);
}

.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(3, minmax(0, 1fr));
    border-bottom: 1px solid var(--line);
    background: #fbfcff;
}

.score-strip > div {
    display: grid;
    gap: 0.15rem;
    padding: 0.85rem 1rem;
    text-align: center;
}

.score-strip > div + div {
    border-left: 1px solid var(--line);
}

.score-strip span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.score-strip strong {
    color: var(--ink);
    font-size: 1.25rem;
}

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

.table-surface {
    min-height: 250px;
    display: grid;
    place-items: center;
    padding: clamp(1.2rem, 4vw, 2.4rem);
    background:
        linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
        repeating-linear-gradient(90deg, rgba(198, 121, 45, 0.10) 0 2px, transparent 2px 16px);
}

.matches-grid {
    width: min(100%, 760px);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: clamp(0.28rem, 1.2vw, 0.65rem);
}

.matchstick {
    position: relative;
    width: 9px;
    width: clamp(7px, 1.6vw, 11px);
    height: 74px;
    height: clamp(58px, 10vw, 88px);
    flex: 0 0 auto;
    border: 1px solid rgba(117, 69, 22, 0.45);
    border-radius: 999px;
    background: linear-gradient(90deg, var(--wood-dark), var(--wood) 45%, #ffd08b 75%, var(--wood-dark));
    box-shadow: 0 5px 8px rgba(23, 35, 60, 0.12);
    transform-origin: bottom;
    animation: match-arrive 220ms ease-out both;
}

.matchstick::before {
    content: "";
    position: absolute;
    width: 165%;
    height: 18px;
    aspect-ratio: 0.8;
    left: 50%;
    top: -5%;
    transform: translate(-50%, -25%);
    border-radius: 55% 55% 48% 48%;
    background: radial-gradient(circle at 38% 30%, #e56b57, var(--head) 47%, var(--head-dark) 78%);
    box-shadow: 0 2px 4px rgba(75, 18, 12, 0.3);
}

@keyframes match-arrive {
    from { opacity: 0; transform: translateY(-8px) rotate(-3deg); }
    to { opacity: 1; transform: translateY(0) rotate(0); }
}

.move-panel {
    padding: 1.2rem clamp(1rem, 4vw, 2rem);
    border-top: 1px solid var(--line);
    text-align: center;
}

.move-panel h3 {
    margin: 0 0 0.9rem;
    color: var(--ink);
    font-size: 1rem;
}

.take-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.55rem;
}

.take-option {
    min-width: 52px;
    min-height: 52px;
    border: 1px solid #aeb9c9;
    border-radius: 0.85rem;
    color: var(--ink);
    background: var(--surface);
    font-size: 1.05rem;
    font-weight: 850;
}

.take-option:hover:not(:disabled) {
    border-color: var(--primary);
}

.take-option[aria-pressed="true"] {
    border-color: var(--primary);
    color: #fff;
    background: var(--primary);
}

.take-button {
    width: min(100%, 320px);
    margin-top: 0.85rem;
}

.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.2rem);
}

.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:last-child {
        grid-column: 1 / -1;
        border-top: 1px solid var(--line);
        border-left: 0;
    }
}

@media (max-width: 420px) {
    .game-shell {
        width: min(100% - 1rem, 1120px);
    }

    .language-picker {
        width: 100%;
    }

    .language-picker button {
        flex: 1 1 25%;
    }

    .number-control {
        grid-template-columns: 1fr;
    }

    .table-surface {
        min-height: 220px;
        padding-inline: 0.65rem;
    }

    .score-strip strong {
        font-size: 1.05rem;
    }

    .result-actions > *,
    .play-topbar .secondary-button {
        width: 100%;
    }
}

@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;
    }
}
