:root {
    color-scheme: light;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f5f6f2;
    color: #182025;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    margin: 0;
    background: #f5f6f2;
}

button,
input,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

.app-shell {
    width: min(760px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 44px;
    margin-bottom: 56px;
}

.back-link {
    color: #126e82;
    font-weight: 750;
    text-decoration: none;
}

.app-name {
    font-size: 14px;
    font-weight: 800;
}

.quiet-button {
    justify-self: end;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #59666b;
}

.setup-header {
    margin-bottom: 32px;
}

.eyebrow {
    margin: 0 0 10px;
    color: #126e82;
    font-size: 13px;
    font-weight: 850;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    letter-spacing: 0;
}

h1 {
    margin: 0;
    font-size: 42px;
    line-height: 1.05;
}

h2 {
    margin: 0;
    font-size: 17px;
}

.game-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 40px;
}

.game-option {
    display: grid;
    gap: 6px;
    min-height: 84px;
    padding: 14px 10px;
    border: 1px solid #c7d0d3;
    border-radius: 6px;
    background: #ffffff;
    color: #253036;
    text-align: left;
}

.game-option strong {
    font-size: 16px;
}

.game-option span {
    color: #68757a;
    font-size: 12px;
    line-height: 1.25;
}

.game-option.active {
    border-color: #126e82;
    background: #e5f3f3;
    box-shadow: inset 0 0 0 1px #126e82;
}

.setup-section {
    padding: 24px 0;
    border-top: 1px solid #cbd2d4;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 18px;
}

label {
    display: grid;
    gap: 7px;
    color: #536168;
    font-size: 13px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #b8c2c6;
    border-radius: 4px;
    background: #ffffff;
    color: #182025;
    font-size: 16px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
    outline: 3px solid #5ac6d0;
    outline-offset: 2px;
}

.setting-note {
    display: grid;
    gap: 6px;
    margin-top: 18px;
    color: #526066;
    line-height: 1.4;
}

.setting-note strong {
    color: #182025;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.text-button {
    min-height: 40px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #126e82;
    font-weight: 750;
}

.player-inputs {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.player-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
}

.remove-player {
    border: 1px solid #c7d0d3;
    border-radius: 4px;
    background: #ffffff;
    color: #67747a;
    font-size: 24px;
}

.primary-button,
.secondary-button {
    width: 100%;
    min-height: 52px;
    border-radius: 4px;
    font-weight: 800;
}

.primary-button {
    border: 1px solid #182025;
    background: #182025;
    color: #ffffff;
}

.secondary-button {
    border: 1px solid #aeb9bd;
    background: transparent;
    color: #344147;
}

.secondary-button:disabled {
    cursor: default;
    opacity: 0.4;
}

.error {
    min-height: 22px;
    margin: 4px 0 10px;
    color: #ad3028;
    font-size: 14px;
    font-weight: 700;
}

.game-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
}

.game-header h1 {
    font-size: 36px;
}

.round-label {
    flex: none;
    margin: 0 0 3px;
    color: #66747a;
    font-size: 14px;
    font-weight: 750;
}

.scoreboard {
    border-top: 1px solid #c4ced1;
}

.score-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 18px;
    padding: 18px 0;
    border-bottom: 1px solid #c4ced1;
}

.score-row.active {
    box-shadow: inset 4px 0 #d4ed4f;
    padding-left: 14px;
}

.score-main {
    display: grid;
    min-width: 0;
    gap: 5px;
}

.score-name {
    overflow-wrap: anywhere;
    font-size: 18px;
    font-weight: 800;
}

.score-meta,
.phase-requirement {
    color: #647278;
    font-size: 13px;
    line-height: 1.35;
}

.score-value {
    align-self: center;
    font-variant-numeric: tabular-nums;
    font-size: 30px;
    font-weight: 850;
}

.phase-requirement {
    grid-column: 1 / -1;
}

.position {
    color: #126e82;
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

.entry-panel {
    margin-top: 28px;
    padding: 24px 0;
    border-top: 3px solid #182025;
    border-bottom: 1px solid #c4ced1;
}

.entry-panel h2 {
    margin-bottom: 18px;
    font-size: 22px;
}

.entry-form {
    display: grid;
    gap: 16px;
}

.inline-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 12px;
}

.inline-fields .primary-button {
    width: auto;
    min-width: 150px;
}

.check-row {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: #334047;
    font-size: 15px;
}

.check-row input {
    width: 22px;
    min-height: 22px;
    margin: 0;
}

.darts-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 4px 14px;
    margin-bottom: 16px;
}

.darts-preview > span {
    color: #647278;
    font-size: 13px;
    font-weight: 750;
}

.darts-preview > strong {
    grid-row: 1 / 3;
    grid-column: 2;
    font-size: 38px;
    font-variant-numeric: tabular-nums;
}

.darts-preview p {
    margin: 0;
    color: #126e82;
    font-size: 14px;
    font-weight: 800;
}

.darts-preview .checkout-hit {
    color: #277239;
}

.dart-slots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.dart-slot {
    display: grid;
    align-content: center;
    min-height: 72px;
    padding: 8px;
    border: 1px solid #c4ced1;
    border-radius: 4px;
    text-align: center;
}

.dart-slot span,
.dart-slot small {
    color: #718087;
    font-size: 11px;
}

.dart-slot strong {
    min-height: 25px;
    font-size: 20px;
}

.dart-slot.filled {
    border-color: #126e82;
    background: #e9f4f3;
}

.multiplier-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.multiplier-picker button,
.dart-key {
    min-height: 46px;
    border: 1px solid #b7c2c6;
    border-radius: 4px;
    background: #ffffff;
    color: #243036;
    font-weight: 800;
}

.multiplier-picker button.active {
    border-color: #126e82;
    background: #126e82;
    color: #ffffff;
}

.dart-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.dart-key {
    min-width: 0;
    font-size: 17px;
}

.dart-key:disabled {
    cursor: default;
    opacity: 0.38;
}

.dart-specials {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 6px;
}

.dart-key.special {
    font-size: 14px;
}

.dart-key.bull {
    border-color: #b73e38;
    color: #a72f2a;
}

.dart-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

.round-entry-list {
    display: grid;
    gap: 12px;
}

.round-entry {
    display: grid;
    grid-template-columns: minmax(110px, 1fr) 110px auto;
    align-items: center;
    gap: 12px;
}

.round-entry-name {
    overflow-wrap: anywhere;
    font-weight: 800;
}

.round-entry input[type="number"] {
    min-width: 0;
}

.phase-check {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #405058;
    font-size: 13px;
    font-weight: 700;
}

.phase-check input {
    width: 22px;
    min-height: 22px;
    margin: 0;
}

.helper {
    margin: 0;
    color: #68757a;
    font-size: 13px;
    line-height: 1.45;
}

.rules-help {
    border-top: 1px solid #d2d8da;
    padding-top: 14px;
}

.rules-help summary {
    color: #126e82;
    cursor: pointer;
    font-weight: 750;
}

.rules-help p {
    margin: 12px 0 0;
    color: #59676d;
    font-size: 13px;
    line-height: 1.5;
}

.winner-panel {
    padding: 8px 0;
}

.winner-panel .winner-name {
    margin: 0 0 8px;
    font-size: 32px;
    font-weight: 850;
    overflow-wrap: anywhere;
}

.winner-panel .helper {
    margin-bottom: 22px;
}

.tie-buttons {
    display: grid;
    gap: 10px;
}

.game-actions {
    padding: 18px 0 8px;
}

.history-section {
    margin-top: 32px;
}

.history-list {
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid #d0d7d9;
}

.history-list li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    padding: 13px 0;
    border-bottom: 1px solid #d0d7d9;
    color: #536168;
    font-size: 14px;
}

.history-list strong {
    color: #263238;
    overflow-wrap: anywhere;
}

.empty-history {
    color: #7b8589;
}

@media (max-width: 560px) {
    .topbar {
        margin-bottom: 42px;
    }

    .game-picker {
        grid-template-columns: 1fr;
    }

    .game-option {
        grid-template-columns: 1fr auto;
        align-items: center;
        min-height: 62px;
    }

    .settings-grid,
    .inline-fields {
        grid-template-columns: 1fr;
    }

    .inline-fields .primary-button {
        width: 100%;
    }

    .round-entry {
        grid-template-columns: minmax(0, 1fr) 90px;
    }

    .phase-check {
        grid-column: 1 / -1;
    }
}

@media (prefers-color-scheme: dark) {
    :root,
    body {
        color-scheme: dark;
        background: #161a1c;
        color: #f1f4f2;
    }

    .game-option,
    input,
    select,
    .remove-player,
    .multiplier-picker button,
    .dart-key {
        border-color: #465156;
        background: #22282b;
        color: #f1f4f2;
    }

    .dart-slot {
        border-color: #465156;
    }

    .dart-slot.filled {
        border-color: #73d2db;
        background: #17373d;
    }

    .multiplier-picker button.active {
        border-color: #73d2db;
        background: #73d2db;
        color: #142023;
    }

    .game-option.active {
        border-color: #73d2db;
        background: #17373d;
        box-shadow: inset 0 0 0 1px #73d2db;
    }

    .game-option span,
    label,
    .quiet-button,
    .score-meta,
    .phase-requirement,
    .round-label,
    .helper,
    .rules-help p,
    .history-list li {
        color: #aeb9bd;
    }

    .eyebrow,
    .back-link,
    .text-button,
    .position,
    .rules-help summary {
        color: #73d2db;
    }

    .setting-note strong,
    .score-name,
    .history-list strong {
        color: #f1f4f2;
    }

    .setup-section,
    .scoreboard,
    .score-row,
    .entry-panel,
    .rules-help,
    .history-list,
    .history-list li {
        border-color: #465156;
    }

    .entry-panel {
        border-top-color: #f1f4f2;
    }

    .primary-button {
        border-color: #d4ed4f;
        background: #d4ed4f;
        color: #141819;
    }

    .secondary-button {
        border-color: #5b686d;
        color: #e1e6e4;
    }
}
