@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #1e302c;
  --muted: #707b72;
  --paper: #f3f2eb;
  --panel: #fffefa;
  --line: #dfe2d8;
  --green: #244c3e;
  --green-deep: #18392f;
  --lime: #d9ed75;
  --coral: #df765d;
  --blue: #a9c6d2;
  --shadow: 0 18px 55px rgb(30 48 44 / 8%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(#d8dbd0 0.7px, transparent 0.7px);
  background-size: 17px 17px;
  font-size: 18px;
  font-family: 'DM Sans', 'Segoe UI', sans-serif;
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.page-shell { max-width: 1120px; min-height: 100vh; margin: 0 auto; padding: 0 42px; }
.topbar { height: 82px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgb(36 76 62 / 14%); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--green-deep); font-family: Manrope, sans-serif; font-size: 21px; font-weight: 800; text-decoration: none; }
.brand-light { font-weight: 500; }
.brand-mark { width: 26px; height: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 4px; transform: rotate(-8deg); border-radius: 8px 8px 8px 2px; background: var(--green); }
.brand-mark span { border-radius: 5px 2px; background: var(--lime); }
.brand-mark span:last-child { background: var(--coral); }
.local-save { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: #7aa96b; box-shadow: 0 0 0 3px rgb(122 169 107 / 15%); }

.intro { display: flex; align-items: end; justify-content: space-between; gap: 32px; padding: 51px 0 32px; }
.eyebrow { margin: 0 0 12px; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: 1.5px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Manrope, 'Segoe UI', sans-serif; font-size: clamp(42px, calc(6vw + 2px), 64px); font-weight: 800; line-height: .99; }
h1 span { color: var(--green); }
.intro-copy { max-width: 270px; margin: 0 4px 5px 0; color: var(--muted); font-size: 16px; line-height: 1.7; }

.workspace { max-width: 760px; margin: 0 auto; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 15px; margin: 0 auto 18px; }
.step { display: flex; align-items: center; gap: 8px; color: #9aa198; font-size: 14px; }
.step span { width: 25px; height: 25px; display: grid; place-items: center; border: 1px solid #cdd2c8; border-radius: 50%; font-size: 11px; font-weight: 700; }
.step b { font-weight: 600; }
.step.active { color: var(--green-deep); }
.step.active span, .step.complete span { border-color: var(--green); color: var(--panel); background: var(--green); }
.step.complete { color: var(--green); }
.step-line { width: clamp(20px, 9vw, 72px); height: 1px; background: #d5d9d0; }
.setup-panel { min-height: 310px; padding: 35px 40px 32px; border: 1px solid rgb(36 76 62 / 9%); border-radius: 5px; background: var(--panel); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 27px; }
.format-panel-heading { align-items: center; }
.format-heading-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.reset-button { min-height: 34px; padding: 0 10px; font-size: 14px; }
.reset-button svg { width: 14px; height: 14px; }
.team-panel-actions { margin-top: 8px; }
.team-panel-actions > .shuffle-button { min-height: 38px; display: flex; margin-left: auto; padding: 0 12px; font-size: 13px; }
.team-panel-actions .panel-actions { margin-top: 8px; }
.form-error.team-step-error { min-height: 0; margin: 3px 0 0; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button:disabled:hover { transform: none; border-color: transparent; }
.panel-heading h2, .tournament-toolbar h2 { margin: 0 0 7px; font-family: Manrope, sans-serif; font-size: 25px; font-weight: 800; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.step-kicker { padding: 7px 10px; border-radius: 3px; color: var(--green); background: #edf2e8; font-size: 12px; font-weight: 700; white-space: nowrap; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.field label, .field-label { display: block; margin-bottom: 8px; color: #43534b; font-size: 14px; font-weight: 700; }
.field input { width: 100%; height: 47px; padding: 0 13px; border: 1px solid #d9ded4; border-radius: 3px; outline: 0; color: var(--ink); background: #fff; transition: border-color .18s, box-shadow .18s; }
.field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(36 76 62 / 10%); }
.field input::placeholder { color: #a5aca3; }
.field-hint { margin: 7px 0 0; color: #879087; font-size: 13px; }
.draw-setting { grid-column: 1 / -1; padding-top: 2px; }
.checkbox-option { display: inline-flex; align-items: center; gap: 9px; color: #43534b; font-size: 14px; font-weight: 700; cursor: pointer; }
.checkbox-option input { width: 17px; height: 17px; margin: 0; accent-color: var(--green); }
.draw-setting .field-hint { margin-left: 26px; }
.form-error { min-height: 18px; margin: 13px 0 0; color: #b24631; font-size: 14px; }
.panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 22px; }
.button { min-height: 43px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 17px; border: 1px solid transparent; border-radius: 3px; font-size: 14px; font-weight: 700; transition: transform .16s, background-color .16s, border-color .16s; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible { outline: 3px solid rgb(223 118 93 / 45%); outline-offset: 2px; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { background: var(--green-deep); }
.button-primary svg, .button-secondary svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.button-secondary { border-color: var(--line); color: var(--green); background: transparent; }
.button-secondary:hover { border-color: var(--green); background: #f5f7f1; }
.text-button { padding: 8px 0; border: 0; color: var(--muted); background: transparent; font-size: 14px; font-weight: 600; }
.text-button:hover { color: var(--green); }
.privacy-note { margin: 14px 0 0; color: #7c867d; text-align: center; font-size: 13px; }
.privacy-note span { margin-right: 5px; color: #84a76e; font-size: 10px; }

.court-list { display: grid; gap: 10px; }
.court-row { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 12px; }
.court-index { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 3px; color: var(--green); background: #eef1e8; font-size: 13px; font-weight: 800; }
.team-input-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.team-input-table .team-name-column { width: 34%; }
.team-input-table thead th { padding: 0 5px 8px; color: var(--muted); text-align: left; font-size: 12px; font-weight: 700; white-space: nowrap; }
.team-input-table tbody th, .team-input-table tbody td { padding: 7px 4px; border-top: 1px solid #edf0e9; }
.team-input-table tbody tr:first-child th, .team-input-table tbody tr:first-child td { border-top: 0; }
.team-input-table input { display: block; width: 100%; min-width: 0; height: 39px; padding: 0 7px; border: 1px solid #d9ded4; border-radius: 3px; color: var(--ink); background: white; font-size: 14px; }
.team-input-table input:focus { border-color: var(--green); outline: 2px solid rgb(36 76 62 / 10%); }
.team-input-table input[data-team-field="name"] { font-weight: 700; }
.list-scroll { max-height: 340px; overflow: auto; padding-right: 5px; }

.tournament-view { max-width: 900px; margin: 0 auto; animation: rise-in .35s ease both; }
.tournament-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 26px 0 22px; border-bottom: 1px solid rgb(36 76 62 / 18%); }
.tournament-toolbar .eyebrow { margin-bottom: 8px; }
.tournament-toolbar h2 { font-size: 30px; }
.tournament-meta { margin: 0; color: var(--muted); font-size: 14px; }
.tournament-tabs { display: flex; gap: 6px; margin-top: 18px; border-bottom: 1px solid var(--line); }
.tournament-tab { min-width: 92px; min-height: 42px; padding: 0 15px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-size: 14px; font-weight: 700; }
.tournament-tab:hover { color: var(--green); background: rgb(36 76 62 / 4%); }
.tournament-tab.active { border-bottom-color: var(--coral); color: var(--green-deep); }
.tournament-tab:focus-visible, .standings-table button:focus-visible { outline: 2px solid var(--coral); outline-offset: -2px; }
.tournament-panel { min-width: 0; }
.standings-share-toolbar { display: flex; justify-content: flex-end; margin-top: 14px; }
.standings-share-toolbar .button { min-height: 38px; }
.round-list { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding-top: 20px; }
.round { overflow: hidden; border: 1px solid rgb(36 76 62 / 12%); border-radius: 4px; background: var(--panel); box-shadow: 0 6px 22px rgb(30 48 44 / 4%); animation: rise-in .35s ease both; }
.round-active { border-color: #c94c36; outline: 2px solid #c94c36; outline-offset: 1px; box-shadow: 0 0 0 4px rgb(201 76 54 / 24%), 0 6px 22px rgb(30 48 44 / 8%); }
.round-active .round-heading { border-bottom: 3px solid var(--lime); background: var(--green-deep); }
.round-completed { border-color: #c9cec8; background: #e8ebe7; box-shadow: 0 5px 18px rgb(30 48 44 / 4%); }
.round-completed .round-heading { background: #79827c; }
.round-completed .match-card { background: #eff1ed; }
.round-completed .match-teams, .round-completed .match-court-line, .round-completed .match-status-badge, .round-completed .match-result, .round-completed .bye-note { filter: grayscale(1); }
.round-completed .set-score-values input { color: var(--ink); background: #fff; opacity: 1; }
.round-heading { display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; color: white; background: var(--green); }
.round-heading h3 { margin: 0; font-family: Manrope, sans-serif; font-size: 15px; font-weight: 800; }
.round-heading span { color: #d8edbd; font-size: 12px; font-weight: 600; }
.match-card { padding: 14px 15px; border-top: 1px solid #edf0e9; }
.match-row { display: grid; gap: 10px; }
.match-teams { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-rows: auto auto; align-items: stretch; gap: 3px 9px; font-size: 14px; }
.match-side { display: grid; grid-row: 1 / span 2; min-width: 0; }
.match-side:last-child { text-align: right; }
.match-winner-content { width: fit-content; max-width: 100%; height: 100%; display: grid; align-content: space-between; gap: 3px; border-radius: 3px; }
.match-side:last-child .match-winner-content { justify-self: end; text-align: right; }
.match-side-winner .match-winner-content { outline: 2px solid var(--coral); outline-offset: 2px; background: #f9e9e3; }
.match-side-winner .match-team-name { color: var(--green-deep); }
.match-side-winner .match-players { color: #52645a; font-weight: 600; }
.match-side-draw .match-winner-content { outline: 2px solid #4d8bb7; outline-offset: 2px; background: #e7f1f8; }
.match-side-draw .match-team-name { color: #285878; }
.match-side-draw .match-players { color: #45677d; font-weight: 600; }
.match-team-name { font-weight: 700; }
.match-players { color: var(--muted); font-size: 12px; font-weight: 500; overflow-wrap: anywhere; }
.match-versus { display: flex; grid-row: 1 / span 2; flex-direction: column; align-items: center; justify-content: space-between; }
.match-versus-label { color: #899189; font-size: 11px; font-weight: 700; }
.match-court-line { display: flex; flex-direction: column; align-items: center; gap: 3px; padding-top: 9px; border-top: 1px solid #edf0e9; }
.court-tag { min-width: 100px; padding: 7px 14px; border-radius: 3px; color: var(--green-deep); background: #e8efdd; text-align: center; font-size: 14px; font-weight: 800; }
.match-slot { margin: 0; color: var(--muted); font-size: 11px; font-weight: 600; }
.match-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 12px; }
.match-status-badge { min-height: 14px; display: inline-flex; align-items: center; padding: 0 6px; border: 1px solid transparent; border-radius: 3px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-pending .match-status-badge { border-color: #e7dfc4; color: #76663c; background: #f8f3e3; }
.status-in-progress .match-status-badge { border-color: #d4e2e3; color: #315d63; background: #edf5f4; }
.status-completed .match-status-badge { border-color: #d2e1d0; color: var(--green); background: #edf4e9; }
.sets-score-group { min-width: 0; }
.match-result { min-height: 14px; margin: 7px 0 0; color: var(--green-deep); text-align: center; font-size: 15px; font-weight: 800; }
.match-result:empty { display: none; }
.match-result-error { color: #b24631; }
.standings-table-scroll { width: min(100%, 580px); overflow-x: auto; margin-top: 20px; border: 1px solid var(--line); background: var(--panel); }
.standings-table { width: 580px; min-width: 580px; table-layout: fixed; border-collapse: collapse; text-align: right; }
.standings-team-column { width: 160px; }
.standings-table th, .standings-table td { padding: 12px 13px; border-bottom: 1px solid #edf0e9; font-size: 13px; white-space: nowrap; }
.standings-table thead { color: white; background: var(--green); }
.standings-table thead th { padding-top: 0; padding-bottom: 0; }
.standings-table thead tr:first-child th { height: 31px; border-bottom: 1px solid rgb(255 255 255 / 22%); text-align: center; }
.standings-table thead tr:first-child > th:first-child, .standings-table thead tr:first-child > th:nth-child(2), .standings-table thead tr:last-child > th:nth-child(3), .standings-table tbody tr > :first-child, .standings-table tbody tr > :nth-child(4) { border-right: 2px solid #b8c8b7; }
.standings-table thead tr:first-child > th:nth-child(2) { border-right-color: #d9e5d9; }
.standings-table thead tr:first-child .standings-team-heading { text-align: left; }
.standings-table thead tr:last-child th { height: 38px; }
.standings-table thead th button { min-height: 43px; display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; color: inherit; background: transparent; font: inherit; font-weight: 700; white-space: nowrap; }
.standings-table thead th button:hover { color: var(--lime); }
.standings-table .standings-team-heading, .standings-table .standings-team { text-align: left; }
.standings-table .standings-team-heading { padding: 12px 13px; }
.standings-table .standings-team { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.standings-table tbody tr:last-child th, .standings-table tbody tr:last-child td { border-bottom: 0; }
.standings-table tbody tr:hover { background: #f7f8f2; }
.standings-team-name, .standings-players { display: block; }
.standings-team-name { color: var(--ink); font-size: 14px; font-weight: 700; }
.standings-players { margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; }
.standings-difference { font-weight: 800; }
.standings-difference.positive { color: var(--green); }
.standings-difference.negative { color: #b24631; }
.set-scores { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }
.set-score { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-rows: auto auto; align-items: center; gap: 4px 9px; }
.set-label { grid-column: 1 / -1; grid-row: 1; margin: 0; color: var(--muted); text-align: center; font-size: 11px; font-weight: 700; }
.set-score-values { display: contents; }
.set-score-values input[data-score-side="home"] { grid-column: 1; grid-row: 2; }
.set-score-values > span { grid-column: 2; grid-row: 2; }
.set-score-values input[data-score-side="away"] { grid-column: 3; grid-row: 2; }
.set-score-values input { width: 100%; min-width: 0; height: 34px; padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: white; text-align: center; font-size: 14px; font-weight: 700; }
.set-score-values input:focus { border-color: var(--green); outline: 2px solid rgb(36 76 62 / 12%); }
.set-score-values input[aria-invalid="true"] { border-color: #b24631; }
.set-score-values > span { color: var(--muted); font-size: 12px; }
.bye-note { padding: 10px 15px; border-top: 1px solid #edf0e9; color: #747f75; background: #fafaf6; font-size: 12px; }
.tournament-view > .privacy-note { margin: 18px 0 0; }
.footer { display: flex; justify-content: space-between; padding: 50px 0 23px; color: #929b91; font-size: 11px; font-weight: 700; letter-spacing: 1.2px; }

@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 650px) {
  .page-shell { padding: 0 16px; }
  .topbar { height: 68px; }
  .intro { align-items: start; flex-direction: column; gap: 14px; padding: 38px 0 25px; }
  h1 { font-size: 50px; }
  .intro-copy { max-width: 330px; font-size: 15px; }
  .stepper { gap: 8px; }
  .step { gap: 5px; font-size: 12px; }
  .step span { width: 23px; height: 23px; }
  .step-line { width: clamp(11px, 6vw, 35px); }
  .setup-panel { min-height: 0; padding: 22px 16px 20px; }
  .panel-heading { margin-bottom: 18px; }
  .format-panel-heading { align-items: flex-start; }
  .panel-heading h2 { font-size: 22px; }
  .field-grid { gap: 12px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .team-panel-heading { align-items: stretch; flex-direction: column; gap: 12px; }
  .team-panel-actions > .shuffle-button { width: 100%; min-height: 42px; justify-content: center; }
  .team-input-table thead th { padding-right: 3px; padding-left: 3px; font-size: 11px; }
  .team-input-table tbody th, .team-input-table tbody td { padding: 7px 3px; }
  .team-input-table input { height: 42px; padding: 0 6px; font-size: 13px; }
  .list-scroll { max-height: 390px; }
  .round-list { grid-template-columns: 1fr; gap: 11px; }
  .round { min-width: 0; }
  .round-heading { padding: 11px 12px; }
  .round-heading h3 { font-size: 17px; }
  .round-heading span { font-size: 14px; }
  .match-card { padding: 12px 11px; }
  .match-teams { gap: 3px 6px; font-size: 16px; }
  .match-team-name { font-size: 15px; }
  .match-players { font-size: 13px; }
  .match-versus-label { font-size: 13px; }
  .match-status-badge { padding: 0 4px; font-size: 12px; }
  .court-tag { min-width: 0; max-width: 100%; padding: 7px 10px; font-size: 15px; overflow-wrap: anywhere; }
  .match-slot { font-size: 13px; }
  .match-result { font-size: 17px; }
  .bye-note { font-size: 14px; }
  .set-label { font-size: 13px; }
  .set-score-values input { height: 42px; font-size: 16px; }
  .set-score-values > span { font-size: 14px; }
  .tournament-toolbar { align-items: start; flex-direction: column; }
  .tournament-toolbar h2 { font-size: 26px; }
  .standings-table-scroll { width: 100%; overflow-x: hidden; }
  .standings-table { width: 100%; min-width: 0; }
  .standings-team-column { width: 34%; }
  .standings-table th, .standings-table td { padding: 8px 3px; font-size: 14px; }
  .standings-table .standings-team-heading { padding: 8px 4px; }
  .standings-table thead tr:first-child th { height: 28px; }
  .standings-table thead tr:last-child th { height: 34px; }
  .standings-table thead th button { min-height: 34px; gap: 2px; font-size: 13px; }
  .standings-table .standings-team { padding-right: 4px; padding-left: 4px; }
  .standings-team-name { font-size: 15px; }
  .standings-players { font-size: 13px; overflow-wrap: anywhere; }
  .footer { padding-top: 37px; font-size: 10px; }
}

@media (max-width: 380px) {
  .page-shell { padding: 0 14px; }
  .local-save { font-size: 12px; }
  .setup-panel { padding-right: 12px; padding-left: 12px; }
  .field-grid { grid-template-columns: 1fr; }
  .stepper { justify-content: space-between; }
  .step-line { flex: 1; }
  .step b { font-size: 11px; }
  .team-input-table .team-name-column { width: 32%; }
  .standings-table .standings-team-heading { padding-right: 2px; padding-left: 2px; }
  .standings-table th, .standings-table td { padding-right: 2px; padding-left: 2px; font-size: 13px; }
  .standings-table thead th button { gap: 1px; font-size: 12px; }
  .standings-table .standings-team-name { font-size: 14px; }
  .match-controls { grid-template-columns: 1fr; gap: 9px; }
  .set-scores { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}