:root {
    color-scheme: light;
    --ink: #172a30;
    --muted: #526267;
    --paper: #f5f4ee;
    --line: #d4dcd5;
    --green: #205a3c;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; border-radius: 8px; }
button { cursor: pointer; touch-action: manipulation; min-height: 48px; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, input:focus-visible { outline: 3px solid #267eaa; outline-offset: 2px; }
input { min-height: 48px; min-width: 0; color: var(--ink); border: 1px solid #abb7b6; background: white; }
input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
[hidden] { display: none !important; }
.shell { max-width: 940px; margin: auto; padding: 12px; }
.stage-bar { background: #e8ece4; border: 1px solid #d7dfd3; border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; }
#stage-form { display: flex; align-items: center; gap: 6px; }
#max-points { width: clamp(86px, 24vw, 110px); text-align: center; font-size: 21px; font-weight: 750; }
.button { padding: 10px 18px; font-weight: 700; border: 0; }
.secondary { background: var(--ink); color: white; min-width: 48px; padding: 10px 12px; }
.stage-button { margin-right: auto; background: transparent; color: var(--ink); border: 1px solid #81958a; font-size: 14px; font-weight: 800; padding: 6px 8px; white-space: nowrap; }
.workspace { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; align-items: start; }
.panel { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.hit-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 58px; border-bottom: 1px solid #e4e9e2; padding: 4px 0; }
#hit-controls .hit-row:last-child { border-bottom: 0; }
.zone { display: flex; align-items: center; gap: 10px; }
.zone-letter { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; font-size: 22px; font-weight: 800; background: #edf1e9; }
.alpha .zone-letter { color: var(--green); background: #e1eee5; }
.penalty .zone-letter { color: #924419; background: #fcf0e6; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 56px; height: 48px; font-size: 26px; font-weight: 700; border: 0; background: var(--ink); color: white; }
.stepper button:not(:disabled):active { background: #34545e; }
.stepper input { width: 54px; text-align: center; font-size: 24px; font-weight: 750; border: 0; padding: 0; background: transparent; }
.alpha-count { width: 172px; text-align: center; }
.alpha-count output { font-size: 27px; font-weight: 750; }
/* Occupied zones receive a strong color cue as well as their numeric count. */
.hit-row.has-hits:not(.alpha) .zone-letter { background: var(--zone-color); color: var(--zone-text, white); }
.hit-row.has-hits:not(.alpha) input { color: var(--zone-color); }
.hit-row[data-zone="C"] { --zone-color: #217044; }
.hit-row[data-zone="D"] { --zone-color: #397850; }
.hit-row[data-zone="M"] { --zone-color: #ffc107; --zone-text: #302500; }
.hit-row[data-zone="M"].has-hits input { color: #805000; }
.hit-row[data-zone="NS"] { --zone-color: #b52331; }
.result-panel { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr) 58px; align-items: center; background: var(--ink); border-radius: 12px; color: white; padding: 12px; gap: 8px; }
.time-section, .result-section { min-width: 0; }
#result-title { display: block; font-size: 14px; font-weight: 650; margin-bottom: 7px; }
.time-section { display: flex; align-self: stretch; }
.time-section input { width: 100%; min-height: 56px; font-size: clamp(22px, 6.5vw, 29px); font-weight: 650; padding: 4px 8px; text-align: center; background: #243e45; border: 1px solid #809793; color: white; font-variant-numeric: tabular-nums; }
.time-section input::placeholder { color: #aabcb9; }
.result-section { text-align: center; }
#hf { display: block; font-size: clamp(24px, 8vw, 36px); font-weight: 750; letter-spacing: -1.2px; line-height: 1.3; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-meta { color: #c6d5d2; font-size: 11px; margin-top: 2px; }
.result-meta strong { color: white; }
.save-button { align-self: stretch; background: #ff845f; color: #14262d; display: flex; justify-content: center; align-items: center; font-size: clamp(14px, 4.3vw, 18px); font-weight: 800; padding: 4px; }
.save-button:disabled { opacity: 1; background: #3e555b; color: #bfcdca; }
.history-section { margin-top: 8px; }
.empty-history { text-align: center; padding: 18px 10px; border: 1px dashed #c7d0c7; border-radius: 10px; color: var(--muted); font-size: 13px; margin: 0; }
.history-item { position: relative; min-height: 48px; display: grid; grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: 10px; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.history-item.is-best { background: #e8f3e8; border: 2px solid var(--green); padding: 7px 9px; }
.run-number { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; font-size: 17px; font-weight: 800; }
.run-hits { display: flex; align-items: center; gap: 5px; }
.hit-badge { display: inline-flex; align-items: center; justify-content: center; gap: 5px; border: 1px solid var(--badge-color); border-radius: 6px; color: var(--ink); background: white; min-height: 32px; padding: 3px 4px; font-size: 15px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hit-badge b { font-size: inherit; font-weight: inherit; }
.hit-badge.a { --badge-color: #155538; }
.hit-badge.c { --badge-color: #217044; }
.hit-badge.d { --badge-color: #397850; }
.hit-badge.m { --badge-color: #ffc107; --badge-ink: #302500; }
.hit-badge.ns { --badge-color: #b52331; }
.hit-badge.has-hits { background: var(--badge-color); color: var(--badge-ink, white); font-weight: 800; }
.run-result { display: grid; justify-items: end; gap: 0; white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 0; }
.run-result strong { font-size: 22px; line-height: 1.2; }
.run-time { font-size: 11px; line-height: 1.3; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.run-details-trigger { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; min-height: 0; background: transparent; border: 0; border-radius: inherit; }
.run-overlay { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px; border-radius: inherit; background: rgb(255 255 255 / 88%); }
.history-item.is-best .run-overlay { background: rgb(232 243 232 / 88%); }
.delete-run { background: white; border: 1px solid #a7b8ab; font-size: 22px; color: var(--ink); width: 32px; height: 32px; min-height: 32px; padding: 0; }
.notice { font-size: 13px; background: #fff0d2; padding: 10px; border-radius: 10px; margin-bottom: 8px; line-height: 1.4; }
.notice button { background: transparent; border: 0; font-weight: 700; text-decoration: underline; }
.error { font-size: 12px; color: #b33819; margin: 6px 0 0; }
#time-error { grid-column: 1 / -1; color: #ffbba6; }
.toast { position: fixed; bottom: max(12px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: #172a30; color: white; padding: 6px 10px 6px 14px; border: 1px solid #71847c; border-radius: 10px; box-shadow: 0 8px 40px #0003; display: flex; align-items: center; gap: 14px; font-size: 13px; max-width: calc(100% - 24px); width: max-content; z-index: 10; }
.toast button { color: #ffae8f; border: 0; background: transparent; font-weight: 750; }
@media (max-width: 759px) {
    .shell { max-width: 520px; padding: 8px; }
    .workspace { grid-template-columns: 1fr; gap: 8px; }
    .stage-bar { padding: 6px 10px; }
    .result-panel { padding: 10px; gap: 6px; }
    .history-item { gap: 4px; padding: 4px 6px; }
    .history-item.is-best { padding: 3px 5px; }
    .run-number { font-size: 14px; }
    .run-hits { gap: 2px; min-width: 0; }
    .hit-badge { flex: 1; padding: 3px 2px; gap: 2px; font-size: 14px; }
    .run-result strong { font-size: 18px; }
}
@media (max-width: 359px) {
    .hit-badge { font-size: 11px; }
    .run-result strong { font-size: 16px; }
    .stepper button { width: 54px; }
    .stepper input { width: 52px; }
    .alpha-count { width: 168px; }
}

#stage-confirmation { width: min(360px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--paper); box-shadow: 0 20px 70px #0005; }
#stage-confirmation::backdrop { background: rgb(14 32 37 / 60%); }
.confirmation-card { padding: 24px; }
.confirmation-card h2 { margin: 0 0 12px; font-size: 22px; }
.confirmation-card p { margin: 0 0 24px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.confirmation-actions { display: flex; justify-content: flex-end; gap: 10px; }
.confirmation-actions .stage-button { margin-right: 0; }
