:root {
  color-scheme: dark;
  --page: #0c0e12;
  --panel: #191c22;
  --panel-light: #282d35;
  --text: #ffffff;
  --muted: #b8bec8;
  --line: rgba(255, 255, 255, 0.13);
  --accent: #f28a24;
  --accent-light: #ffad52;
  --team-a: #df3542;
  --team-b: #347bd1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% -20%, #343942, transparent 56%), var(--page);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.tournament-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.association-logo { display: block; width: 48px; height: 48px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.brand { color: var(--text); font-weight: 750; letter-spacing: .02em; }
.brand span, .back-link { color: var(--muted); font-weight: 500; }
.back-link { font-size: .92rem; }
.back-link:hover { color: var(--text); }

.panel { background: linear-gradient(145deg, rgba(40, 44, 52, .96), rgba(24, 27, 33, .98)); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 40px rgba(0, 0, 0, .22); }
.login-panel { width: min(480px, 100%); margin: 11vh auto 0; padding: 34px; }
.login-panel h1, .page-heading h1 { margin: 8px 0; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.login-panel p, .page-heading p { color: var(--muted); line-height: 1.65; }
.eyebrow { color: var(--accent-light); font-size: .76rem; font-weight: 800; letter-spacing: .13em; }
label { display: grid; gap: 8px; color: #e6ebed; font-size: .88rem; font-weight: 650; }
input, textarea { width: 100%; min-width: 0; padding: 11px 12px; color: var(--text); background: rgba(0, 0, 0, .32); border: 1px solid var(--line); border-radius: 8px; outline: none; }
select { width: 100%; min-width: 0; padding: 11px 12px; color: var(--text); background: #14171c; border: 1px solid var(--line); border-radius: 8px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent-light); box-shadow: 0 0 0 3px rgba(242, 138, 36, .18); }
select:focus { border-color: var(--accent-light); box-shadow: 0 0 0 3px rgba(242, 138, 36, .18); }
.login-row { display: flex; gap: 10px; margin-top: 9px; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; padding: 10px 16px; cursor: pointer; font-weight: 750; transition: background .15s, transform .15s; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: #ff9a38; }
.button-quiet { border-color: var(--line); background: rgba(255,255,255,.045); }
.button-quiet:hover { background: rgba(255,255,255,.1); }
.button-danger { color: #ffc9c3; border-color: rgba(255, 100, 87, .3); background: rgba(181, 29, 24, .18); }
.form-error, .error-text { color: #ffb0a7 !important; }
.form-error { margin-bottom: 0; font-size: .9rem; }

.notice { margin: 24px 0; padding: 14px 16px; border: 1px solid rgba(255, 190, 94, .35); border-radius: 10px; background: rgba(117, 75, 24, .25); color: #f5dfbd; font-size: .9rem; line-height: 1.55; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding: 28px 0 20px; }
.page-heading p { max-width: 700px; margin-bottom: 0; }
.tabs { display: flex; gap: 8px; margin: 6px 0 20px; border-bottom: 1px solid var(--line); }
.tab { padding: 12px 18px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); cursor: pointer; font-weight: 750; }
.tab.active { border-bottom-color: var(--accent); color: white; }
.section-title { margin-bottom: 20px; }
.section-title h2 { margin: 5px 0 0; font-size: 1.35rem; }
#tournament-form > .panel { padding: 22px; margin-bottom: 16px; }
.metadata-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.teams-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.team-panel { overflow: hidden; }
.team-heading { display: flex; align-items: center; gap: 14px; padding: 19px; background: rgba(223, 53, 66, .18); border-bottom: 1px solid var(--line); }
.team-b .team-heading { background: rgba(52, 123, 209, .2); }
.team-mark { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; border-radius: 10px; background: var(--team-a); font-size: 1.1rem; font-weight: 850; }
.team-b .team-mark { background: var(--team-b); }
.team-heading label { flex: 1; }
.captain-field { padding: 16px 19px; }
.players-heading, .player-row { display: grid; grid-template-columns: minmax(90px, .7fr) minmax(0, 2fr) minmax(92px, .85fr); gap: 9px; align-items: center; }
.players-heading { padding: 10px 19px; background: rgba(10, 15, 17, .25); color: var(--muted); font-size: .76rem; font-weight: 750; }
.players-heading span:last-child { grid-column: 3; }
.player-row { padding: 8px 19px; border-top: 1px solid rgba(255,255,255,.055); }
.player-name-field { min-width: 0; }
.player-suggestion-status { display: block; margin-top: 5px; color: var(--muted); font-size: .72rem; font-weight: 400; line-height: 1.35; }
.player-row input { padding: 9px; font-size: .86rem; }
.slot-label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.notes-field { max-width: 700px; }
textarea { resize: vertical; }
.help-text { margin: 12px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 20px; }
.save-status { color: #cbdcf5; font-size: .87rem; }

.scoreboard-heading { padding: 24px; text-align: center; }
.scoreboard-heading h2 { margin: 7px 0 18px; font-size: clamp(1.4rem, 3.5vw, 2.2rem); }
.scoreboard-heading h2 span { color: var(--muted); font-weight: 400; }
.team-score-line { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; width: min(620px, 100%); margin: 0 auto; padding: 16px; border-radius: 10px; background: linear-gradient(110deg, var(--team-a), var(--team-b)); }
.team-total { display: flex; justify-content: flex-end; align-items: center; gap: 12px; font-size: 1.1rem; font-weight: 750; text-align: right; }
.team-total strong { min-width: 42px; padding: 5px 10px; border-radius: 5px; background: rgba(0,0,0,.24); font-size: 1.6rem; }
.team-total-right { justify-content: flex-start; text-align: left; }
.score-divider { font-size: 1.7rem; font-weight: 800; }
.score-summary { display: flex; justify-content: center; gap: 24px; margin-top: 14px; color: var(--muted); font-size: .9rem; }
.score-summary strong { color: var(--text); }
.score-help { padding: 16px 3px 10px; color: var(--muted); font-size: .9rem; }
.rounds-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: start; }
.round-section { overflow: hidden; }
.round-section h3 { margin: 0; padding: 14px; background: rgba(10, 15, 17, .35); text-align: center; font-size: 1rem; }
.match-card { display: grid; grid-template-columns: 32px minmax(0, 1fr) 76px; gap: 9px; align-items: center; min-height: 77px; padding: 10px; border-top: 1px solid var(--line); }
.match-number { display: grid; width: 30px; height: 42px; place-items: center; border-radius: 5px; background: rgba(255,255,255,.12); font-weight: 800; }
.match-players { display: grid; gap: 5px; min-width: 0; font-size: .84rem; }
.match-players span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-scores { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; }
.score-input { padding: 7px 2px; text-align: center; font-weight: 800; appearance: textfield; }
.score-input::placeholder { color: var(--muted); opacity: 1; }
.score-input::-webkit-inner-spin-button, .score-input::-webkit-outer-spin-button { margin: 0; appearance: none; }
.match-card.winner-a .match-scores input:first-child { border-color: var(--team-a); background: rgba(223,53,66,.2); }
.match-card.winner-b .match-scores input:last-child { border-color: var(--team-b); background: rgba(52,123,209,.2); }
.doubles-playoff { margin-top: 18px; padding: 20px; border-color: rgba(242, 138, 36, .55); }
.doubles-playoff h3 { margin: 0; text-align: center; font-size: 1.25rem; }
.doubles-playoff > p:not(.doubles-outcome) { margin: 8px 0 16px; color: var(--muted); text-align: center; }
.doubles-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.doubles-team { display: grid; gap: 10px; padding: 14px; border-radius: 10px; background: rgba(0, 0, 0, .16); }
.doubles-team strong { text-align: center; }
.doubles-selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.doubles-selectors select { min-width: 0; padding: 9px; color: var(--text); background: #14171c; border: 1px solid var(--line); border-radius: 7px; }
.doubles-score-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px auto 0; }
.doubles-score-row .score-input { width: 64px; }
.doubles-outcome { margin: 12px 0 0; color: var(--accent-light); font-weight: 750; text-align: center; }
.notes-display { margin-top: 16px; padding: 16px; color: var(--muted); white-space: pre-wrap; }
.results-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
.results-status { min-height: 1.2em; text-align: right; }
.standings-panel, .archive-panel { margin-bottom: 16px; padding: 22px; }
.standings-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th, .data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th { background: rgba(0, 0, 0, .24); color: var(--muted); font-size: .78rem; letter-spacing: .03em; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, .035); }
.data-table .team-name-cell { font-weight: 700; }
.data-table .points-cell { color: var(--accent-light); font-weight: 800; }
.empty-state { margin: 16px 0 0; color: var(--muted); font-size: .9rem; }

@media (max-width: 840px) {
  .teams-grid { grid-template-columns: 1fr; }
  .match-card { grid-template-columns: 38px minmax(0, 1fr) 96px; padding: 12px 16px; }
}

@media (max-width: 1000px) {
  .rounds-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .rounds-list { grid-template-columns: 1fr; }
  .doubles-teams { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .tournament-shell { width: calc(100% - 22px); }
  .topbar { padding: 16px 0; }
  .topbar-actions { gap: 8px; }
  .association-logo { width: 42px; height: 42px; }
  .brand { font-size: .92rem; }
  .back-link { font-size: .82rem; }
  .login-panel { margin-top: 7vh; padding: 24px 18px; }
  .login-row { flex-direction: column; }
  .page-heading { align-items: center; }
  .page-heading .button { flex: 0 0 auto; padding: 9px; font-size: .83rem; }
  .metadata-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .standings-filters { grid-template-columns: 1fr; gap: 12px; }
  .standings-panel, .archive-panel { padding: 16px; }
  .data-table th, .data-table td { padding: 10px; font-size: .82rem; }
  #tournament-form > .panel { padding: 16px; }
  .team-heading, .captain-field { padding-right: 13px; padding-left: 13px; }
  .players-heading, .player-row { grid-template-columns: 78px minmax(0, 1fr) 74px; gap: 6px; padding-right: 11px; padding-left: 11px; }
  .player-row input { padding: 8px 6px; font-size: .78rem; }
  .slot-label { font-size: .74rem; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .button { width: 100%; }
  .team-score-line { gap: 8px; padding: 12px 7px; }
  .team-total { gap: 6px; font-size: .9rem; }
  .team-total strong { min-width: 32px; font-size: 1.35rem; }
  .score-summary { gap: 14px; font-size: .82rem; }
}
