:root {
  color-scheme: light;
  --page-background: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f7f9fb;
  --text: #263238;
  --muted: #667481;
  --border: #cbd5df;
  --border-soft: #e2e8ee;
  --primary: #24557a;
  --primary-hover: #173b55;
  --primary-soft: #eaf2f8;
  --subtotal-background: #edf3f7;
  --total-background: #c9e0ef;
  --negative: #b42318;
  --negative-soft: #fff4f2;
  --shadow: 0 8px 24px rgba(38, 50, 56, 0.08);
  --focus-ring: rgba(36, 85, 122, 0.25);
  --score-label-width: 170px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page-background);
  color: var(--text);
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header h1, .panel h2 { margin: 0; }
.site-header h1 { font-size: clamp(1.45rem, 3.5vw, 2.15rem); }
.language-notice { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.95rem; }

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.setup-panel {
  width: min(760px, 100%);
  margin: 2rem auto;
  padding: clamp(1.25rem, 4vw, 2rem);
}

.intro, .save-status { color: var(--muted); }
.intro { margin: 0.5rem 0 1.5rem; }

.saved-game-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 1px solid var(--primary);
  border-radius: 12px;
  background: var(--primary-soft);
}

.saved-game-panel[hidden] { display: none; }
.saved-game-title { margin: 0; font-weight: 800; }
.saved-game-summary { margin: 0.25rem 0 0; color: var(--muted); }

.setup-control {
  display: grid;
  gap: 0.45rem;
  width: min(320px, 100%);
  margin-bottom: 1.25rem;
}

label { font-weight: 650; }

select, .team-name-input, .score-input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

select, .team-name-input {
  width: 100%;
  padding: 0.72rem 0.8rem;
}

select:focus, .team-name-input:focus, .score-input:focus,
.button:focus-visible, .round-toggle:focus-visible, .table-scroll:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.team-name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.team-name-field { display: grid; gap: 0.4rem; }

.setup-actions, .bottom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.button {
  min-height: 44px;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.button-compact {
  min-height: 38px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.button-primary { background: var(--primary); color: #ffffff; }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.button-secondary:hover { background: var(--surface-subtle); border-color: var(--primary); }
.button-danger { background: var(--surface); border-color: var(--negative); color: var(--negative); }
.button-danger:hover { background: var(--negative-soft); }
.button:disabled { cursor: not-allowed; opacity: 0.5; }

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.game-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
}

.save-status { margin: 0.3rem 0 0; font-size: 0.9rem; }
.standings-panel { padding: 1rem 1.25rem; margin-bottom: 1rem; background: var(--primary-soft); }

.section-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.standings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.7rem;
}

.standing-item {
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.standing-label {
  overflow-wrap: anywhere;
  font-weight: 750;
}

.standing-score {
  margin-top: 0.3rem;
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.round-view-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  margin: 0 0 1rem;
}

.rounds-container { display: grid; gap: 1rem; }
.round-card { overflow: hidden; }

.round-card.current-round {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--focus-ring), var(--shadow);
}

.round-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.9rem 1rem;
  border: 0;
  background: var(--surface-subtle);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
}

.round-heading:hover { background: var(--primary-soft); }
.round-card.current-round .round-heading { background: var(--primary-soft); }
.round-heading-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.7rem;
}
.round-title { font-size: 1.15rem; font-weight: 750; }
.round-chevron {
  flex: 0 0 auto;
  color: var(--primary);
  font-size: 0.92rem;
}

.current-round-badge {
  display: none;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 750;
}

.current-round .current-round-badge { display: inline-block; }
.round-card.is-collapsed { box-shadow: 0 4px 14px rgba(38, 50, 56, 0.06); }

.collapsed-round-scroll {
  overflow-x: auto;
  background: var(--surface);
}

.collapsed-round-toggle {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: initial;
}

.collapsed-round-toggle:hover .collapsed-round-header {
  background: var(--primary-soft);
}

.collapsed-round-grid {
  display: grid;
  align-items: stretch;
  width: 100%;
}

.collapsed-round-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.collapsed-round-subtotal {
  background: var(--surface);
}

.collapsed-round-cell {
  min-width: 0;
  padding: 0.8rem 0.6rem;
  overflow-wrap: anywhere;
}

.collapsed-round-title,
.collapsed-round-label {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  box-shadow: 1px 0 0 var(--border);
}

.collapsed-round-title {
  background: var(--surface-subtle);
  color: var(--primary);
  font-size: 1.05rem;
  font-weight: 800;
}

.collapsed-round-label {
  background: var(--surface);
  font-weight: 750;
}

.collapsed-round-team {
  text-align: center;
  font-weight: 750;
}

.collapsed-round-team:last-child {
  padding-right: 3rem;
}

.round-summary-score {
  display: block;
  padding: 0.8rem 1.15rem 0.8rem 0.6rem;
  text-align: right;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.collapsed-round-chevron {
  position: absolute;
  top: 0.92rem;
  right: 1rem;
  color: var(--primary);
  font-size: 0.92rem;
  pointer-events: none;
}

.table-scroll { overflow-x: auto; }

.score-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.score-table th, .score-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border-soft);
  text-align: right;
  vertical-align: middle;
}

.score-table th:first-child, .score-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: var(--score-label-width);
  text-align: left;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}

.score-table thead th {
  background: var(--surface-subtle);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.score-table thead th:first-child { z-index: 2; background: var(--surface-subtle); }
.score-table thead th:not(:first-child) { text-align: center; }

.score-table .subtotal-row th,
.score-table .subtotal-row td {
  background: var(--subtotal-background);
  font-weight: 750;
}
.score-table .subtotal-row th:first-child { background: var(--subtotal-background); }

.score-table .ongoing-row th,
.score-table .ongoing-row td {
  background: var(--total-background);
  font-weight: 900;
  border-top: 2px solid var(--primary);
}
.score-table .ongoing-row th:first-child { background: var(--total-background); }

.score-input {
  width: 100%;
  min-width: 95px;
  padding: 0.5rem 0.55rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.score-input.negative-input { color: var(--negative); font-weight: 650; }

.score-output {
  display: block;
  width: 100%;
  padding: 0.5rem 0.55rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bottom-actions { justify-content: center; margin-bottom: 2rem; }
[hidden] { display: none !important; }

@media (max-width: 700px) {
  .saved-game-panel { align-items: stretch; flex-direction: column; }
  .site-header, .game-toolbar, .section-heading-row { align-items: flex-start; }
  .site-header, .game-toolbar { flex-direction: column; }
  .site-header > .button { align-self: stretch; }
  .game-toolbar-actions { width: 100%; }
  .game-toolbar .button { flex: 1 1 180px; }
  .round-view-actions { justify-content: stretch; }
  .round-view-actions .button { flex: 1 1 180px; }
  :root { --score-label-width: 145px; }
}

@media print {
  body { background: #ffffff; }
  .site-header, .game-toolbar .button, .bottom-actions, .round-view-actions, .save-status, .current-round-badge, .round-chevron { display: none !important; }
  main { width: 100%; padding: 0; }
  .panel { box-shadow: none; break-inside: avoid; }
  .round-card { margin-bottom: 0.6rem; }
  .collapsed-round-scroll { display: none !important; }
  .round-details { display: block !important; }
}

.round-heading {
	background-color: #89f562 !important ;
}