:root {
  --ink: #15261f;
  --muted: #66736d;
  --paper: #f5f4ec;
  --card: #fffef8;
  --line: #d9ded8;
  --green: #146c4a;
  --green-dark: #0d5138;
  --lime: #d9f25f;
  --red: #a13d35;
  --shadow: 0 16px 48px rgba(21, 38, 31, .09);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background-color: var(--paper); background-image: linear-gradient(rgba(245, 244, 236, .52), rgba(245, 244, 236, .52)), url("background.jpg"); background-position: center center; background-size: cover; background-attachment: fixed; background-repeat: no-repeat; color: var(--ink); font-family: "Lato", Arial, Helvetica, sans-serif; line-height: 1.5; }
button, input { font: inherit; }
button { color: inherit; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 99; background: var(--ink); color: white; padding: .7rem 1rem; border-radius: 8px; }
.skip-link:focus { top: 1rem; }

.topbar { height: 80px; padding: 0 clamp(1rem, 4vw, 4rem); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 92%, transparent); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: inherit; font-weight: 800; font-size: 1.05rem; text-decoration: none; width: max-content; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--green); color: var(--lime); font-size: .77rem; letter-spacing: -.04em; }
.steps { display: flex; gap: .2rem; }
.step { border: 0; background: transparent; border-radius: 999px; padding: .5rem .8rem; color: var(--muted); font-weight: 700; cursor: pointer; }
.step span { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: .25rem; border: 1px solid currentColor; border-radius: 50%; font-size: .72rem; }
.step.is-active { background: var(--card); color: var(--green); box-shadow: 0 3px 16px rgba(21,38,31,.07); }
.step:disabled { opacity: .45; cursor: not-allowed; }
.icon-button { justify-self: end; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 1.2rem; }

.shell { width: min(1120px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2.5rem, 7vw, 6rem) 0; min-height: calc(100vh - 150px); }
.hero { max-width: 800px; margin-bottom: 3rem; }
.hero-title { max-width: none; font-size: clamp(2.2rem, 4.2vw, 3.6rem); line-height: 1.05; white-space: nowrap; }
.eyebrow, .section-number { margin: 0 0 .6rem; color: var(--green); font-size: .76rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-family: "Lato", Arial, Helvetica, sans-serif; font-weight: 800; font-size: clamp(2.6rem, 7vw, 5.4rem); line-height: .98; letter-spacing: -.04em; }
h1 span { color: var(--ink); font-style: normal; }
.hero > p:last-child { max-width: none; color: var(--muted); font-size: 1.08rem; white-space: nowrap; }
.panel { background: var(--card); border: 1px solid rgba(21,38,31,.08); border-radius: var(--radius); box-shadow: var(--shadow); }
.setup-panel { padding: clamp(1.25rem, 4vw, 3rem); }
.section-heading { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
h2 { margin: 0; font-family: "Lato", Arial, Helvetica, sans-serif; font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 800; }
.counter, .badge { background: #e9eee9; padding: .32rem .65rem; border-radius: 999px; color: var(--green-dark); font-size: .78rem; font-weight: 750; white-space: nowrap; }
.helper { color: var(--muted); margin: .4rem 0 1.5rem; }
.player-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem; }
.player-field { display: flex; align-items: center; gap: .7rem; padding: .2rem .25rem .2rem .9rem; border: 1px solid var(--line); border-radius: 13px; background: white; }
.player-field:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20,108,74,.12); }
.player-field span { color: var(--muted); font-size: .8rem; font-weight: 800; }
.player-field input { width: 100%; min-width: 0; border: 0; outline: 0; padding: .8rem 0; background: transparent; color: var(--ink); }
.remove-player { border: 0; background: transparent; border-radius: 8px; width: 38px; height: 38px; cursor: pointer; color: var(--muted); }
.remove-player:hover { background: #f3e7e4; color: var(--red); }
.button { min-height: 46px; border: 1px solid transparent; border-radius: 12px; padding: .7rem 1.05rem; font-weight: 780; cursor: pointer; transition: transform .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible, .step:focus-visible, .icon-button:focus-visible, .team-button:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line); background: var(--card); }
.button-quiet { margin-top: 1rem; padding-left: 0; background: transparent; color: var(--green); }
.mode-fieldset { margin: 2.5rem 0 0; padding: 0; border: 0; }
.mode-fieldset legend { width: 100%; margin-bottom: 1rem; font-family: "Lato", Arial, Helvetica, sans-serif; font-size: 1.55rem; font-weight: 800; }
.mode-fieldset legend .section-number { display: inline-block; margin-right: .7rem; font-family: Inter, sans-serif; }
.mode-card { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; border: 1px solid var(--line); border-radius: 14px; padding: 1rem; margin-top: .7rem; cursor: pointer; background: white; }
.mode-card:has(input:checked) { border-color: var(--green); box-shadow: 0 0 0 2px rgba(20,108,74,.1); }
.mode-card input { position: absolute; opacity: 0; }
.radio-ui { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #9aa49f; }
.mode-card input:checked + .radio-ui { border: 6px solid var(--green); }
.mode-card strong, .mode-card small { display: block; }
.mode-card small { color: var(--muted); margin-top: .1rem; }
.setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-top: 1px solid var(--line); margin-top: 2rem; padding-top: 1.5rem; }
.score-setting { display: flex; justify-content: space-between; align-items: center; gap: 2rem; margin-top: 2rem; padding: 1.2rem; border: 1px solid var(--line); border-radius: 14px; background: white; }
.score-setting > div:first-child { flex: 1; min-width: 0; }
.score-setting label { display: block; font-size: 1.15rem; font-weight: 800; }
.score-setting p { max-width: none; margin: .25rem 0 0; color: var(--muted); font-size: .86rem; }
.number-control { display: flex; align-items: center; gap: .55rem; white-space: nowrap; color: var(--muted); font-weight: 700; }
.number-control input { width: 76px; padding: .65rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); text-align: center; font-weight: 800; }
.notice { padding: .8rem 1rem; border-radius: 10px; margin-top: 1rem; }
.notice-error { color: #722820; background: #f8e5e1; border: 1px solid #edc5be; }

.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 2rem; }
.page-heading h1 { color: var(--ink); font-size: clamp(2.2rem, 4.2vw, 3.6rem); line-height: 1.05; white-space: nowrap; }
.progress-wrap { width: min(280px, 40vw); text-align: right; color: var(--muted); font-size: .88rem; }
.progress { height: 7px; margin-top: .5rem; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; background: var(--green); transition: width .25s ease; }
.toolbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.toolbar p { color: var(--muted); }
.match-list { display: grid; gap: .7rem; }
.match-card { display: grid; grid-template-columns: 55px 1fr auto 1fr; align-items: center; gap: .75rem; padding: .75rem; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.match-number { text-align: center; color: var(--muted); font-size: .75rem; font-weight: 800; }
.team-button { min-height: 60px; border: 1px solid transparent; border-radius: 11px; background: #edf0ec; padding: .7rem; cursor: pointer; font-weight: 750; }
.team-button:hover { border-color: #aeb9b3; }
.team-button.is-winner { background: var(--green); color: white; }
.team-button.is-loser { opacity: .46; }
.score-entry { grid-column: 2 / 5; display: flex; align-items: center; justify-content: center; gap: .45rem; padding: .65rem; border-radius: 10px; background: color-mix(in srgb, var(--green) 7%, transparent); color: var(--muted); font-size: .86rem; }
.score-entry[hidden] { display: none; }
.score-entry strong { color: var(--ink); }
.score-entry input { width: 64px; padding: .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); text-align: center; font-weight: 800; }
.score-entry .optional { margin-left: .3rem; font-size: .75rem; }
.versus { color: var(--muted); font-size: .76rem; font-weight: 850; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; min-width: 720px; }
th, td { padding: 1rem 1.05rem; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { width: 72px; padding-left: .85rem; padding-right: .85rem; text-align: center; }
th:nth-child(2), td:nth-child(2) { text-align: left; }
th:nth-child(n + 3), td:nth-child(n + 3) { width: 11%; padding-left: .7rem; padding-right: .7rem; }
th:last-child, td:last-child { padding-right: 1.6rem; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
td:first-child { color: var(--green); font-family: "Lato", Arial, Helvetica, sans-serif; font-size: 1.3rem; }
td:nth-child(2) { font-weight: 800; }
.player-coverage { display: block; margin-top: .15rem; color: var(--muted); font-size: .7rem; font-weight: 500; white-space: nowrap; }
.table-note { color: var(--muted); font-size: .84rem; padding: 1.2rem 1.3rem 1.3rem; }
.table-note strong { display: block; margin-bottom: .35rem; color: var(--ink); font-size: .9rem; }
.table-note p { max-width: none; margin: .35rem 0 0; }
.table-note .coverage-summary { margin-top: .8rem; color: var(--green); font-weight: 800; }
.danger-zone { margin-top: 2rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.3rem; border: 1px solid #e6c9c4; border-radius: 15px; }
.danger-zone strong, .danger-zone span { display: block; }
.danger-zone span { color: var(--muted); font-size: .86rem; }
.button-danger { color: var(--red); border-color: #dab3ad; background: transparent; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 20; padding: .8rem 1rem; border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); }
footer { padding: 1.5rem clamp(1rem,4vw,4rem); display: flex; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
footer span { color: var(--green); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
footer p { margin: 0; }

body.dark { --ink: #eef5ef; --muted: #aab8b0; --paper: #101b16; --card: #17251f; --line: #35443c; --green: #82d2a9; --green-dark: #a7e5c3; --lime: #d9f25f; --red: #f0a096; --shadow: 0 16px 48px rgba(0,0,0,.22); }
body.dark { background-image: linear-gradient(rgba(16, 27, 22, .58), rgba(16, 27, 22, .58)), url("background.jpg"); }
body.dark .player-field, body.dark .mode-card { background: #1c2d25; }
body.dark .score-setting { background: #1c2d25; }
body.dark .counter, body.dark .badge { background: #263b31; }
body.dark .team-button { background: #24372e; }
body.dark .team-button.is-winner { background: #317a58; }
body.dark .notice-error { background: #492925; color: #ffd6cf; border-color: #76423b; }

@media (max-width: 700px) {
  .hero-title { white-space: normal; }
  .hero > p:last-child { white-space: normal; }
  .topbar { height: auto; min-height: 70px; grid-template-columns: 1fr auto; padding: .8rem 1rem; }
  .steps { grid-column: 1 / -1; grid-row: 2; width: 100%; justify-content: center; margin-top: .6rem; border-top: 1px solid var(--line); padding-top: .6rem; }
  .step { padding: .4rem .55rem; font-size: .82rem; }
  .icon-button { grid-column: 2; grid-row: 1; }
  .player-grid { grid-template-columns: 1fr; }
  .setup-actions, .page-heading, .toolbar, .danger-zone { align-items: stretch; flex-direction: column; }
  .score-setting { align-items: flex-start; flex-direction: column; gap: 1rem; }
  .setup-actions .button, .page-heading .button, .toolbar .button { width: 100%; }
  .progress-wrap { width: 100%; text-align: left; }
  .match-card { grid-template-columns: 35px 1fr; }
  .match-card .team-button, .match-card .versus { grid-column: 2; }
  .match-card .score-entry { grid-column: 2; flex-wrap: wrap; }
  .match-number { grid-row: 1 / 4; }
  .versus { text-align: center; }
  footer { flex-direction: column; gap: .4rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
