:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d8e0ea;
  --text: #17222f;
  --muted: #5c6b7d;
  --accent: #0b5cab;
  --accent-ink: #ffffff;
  --warn-bg: #fff4e0;
  --warn-border: #e8b563;
  --warn-ink: #7a4a06;
  --danger-bg: #fdeaea;
  --danger-border: #e08b8b;
  --danger-ink: #8c2020;
  --ok: #1a7a4c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 51, 0.06), 0 4px 14px rgba(16, 32, 51, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #18202a;
    --surface-2: #1f2935;
    --border: #2c3846;
    --text: #e6edf5;
    --muted: #9aa9bb;
    --accent: #4a9bf0;
    --accent-ink: #0a1420;
    --warn-bg: #372a12;
    --warn-border: #8a6a2c;
    --warn-ink: #f0d29a;
    --danger-bg: #3a1d1d;
    --danger-border: #8c4a4a;
    --danger-ink: #f4b9b9;
    --ok: #57c48d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__title h1 {
  font-size: 19px;
  font-weight: 650;
}

.topbar__sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.topbar__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.weekbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.weekbar select {
  flex: 1 1 auto;
  max-width: 380px;
}

.weekbar__count {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--accent);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn--icon {
  padding: 8px 12px;
  font-size: 17px;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- layout ---------- */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px;
}

.empty {
  padding: 48px 18px;
  text-align: center;
  color: var(--muted);
}

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid;
  font-size: 13.5px;
}

.banner--warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-ink);
}

.banner--danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-ink);
}

.banner h3 {
  font-size: 13.5px;
  margin-bottom: 6px;
}

.banner ul {
  margin: 0;
  padding-left: 18px;
}

.banner li + li {
  margin-top: 4px;
}

.daygroup {
  margin-bottom: 24px;
}

.daygroup__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.daygroup__head h2 {
  font-size: 16px;
  font-weight: 650;
}

.daygroup__head span {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- fixture card ---------- */

.fixture {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 12px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.fixture--clash {
  border-color: var(--danger-border);
}

.fixture__slot {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fixture__ko {
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.fixture__ends {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.fixture__teams {
  min-width: 0;
}

.fixture__match {
  font-weight: 600;
  word-break: break-word;
}

.fixture__match .vs {
  color: var(--muted);
  font-weight: 450;
  padding: 0 4px;
}

.fixture--away {
  border-style: dashed;
}

.fixture__readonly {
  align-self: center;
  font-size: 12.5px;
  color: var(--muted);
}

.fixture__venue {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.fixture__venue-text {
  word-break: break-word;
}

.side {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.side--home {
  color: var(--accent);
}

.side--away {
  color: var(--warn-ink);
}

.side--none {
  color: var(--danger-ink);
}

.fixture__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.tag {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.tag--moved {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-ink);
}

.tag--cup {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tag--postponed {
  background: var(--danger-ink);
  border-color: var(--danger-ink);
  color: #fff;
}

.fixture--postponed .fixture__controls,
.fixture--postponed .fixture__notes,
.fixture--postponed .fixture__slot {
  opacity: 0.45;
}

.grid__row--postponed .grid__opposition {
  color: var(--danger-ink);
  font-weight: 600;
}

.fixture__controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, auto));
  gap: 8px;
  align-items: end;
}

.ctl label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 3px;
}

.ctl input,
.ctl select {
  padding: 6px 8px;
  font-size: 14px;
}

.fixture__notes {
  grid-column: 1 / -1;
}

.fixture__notes input {
  font-size: 13px;
}

.saving {
  border-color: var(--accent) !important;
}

/* ---------- dialogs ---------- */

.dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: min(640px, 94vw);
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.dialog::backdrop {
  background: rgba(9, 14, 20, 0.5);
}

.dialog__inner {
  padding: 20px;
}

.dialog__inner--narrow {
  max-width: 360px;
}

.dialog h2 {
  font-size: 17px;
  margin-bottom: 6px;
}

.dialog__hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.dialog textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.dialog__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.field small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.field--row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.feedlist {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) minmax(100px, 1fr) auto;
  gap: 6px 8px;
  align-items: center;
}

.feedlist__head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.feedlist .linkbtn {
  margin-top: 0;
}

.venuelist {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(130px, 1.6fr) minmax(70px, 0.8fr) auto;
  gap: 6px 8px;
  align-items: center;
}

.venuelist .linkbtn {
  margin-top: 0;
}

.tag--venue {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

.grid__venue {
  white-space: nowrap;
}

.bookmarklet__steps {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.6;
}

.bookmarklet {
  display: inline-block;
  padding: 3px 10px;
  margin-left: 4px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
}

details.field summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.agegrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.agegrid label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.error {
  color: var(--danger-ink);
  font-size: 13px;
  margin: 0 0 8px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 4px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow);
  z-index: 50;
}

[hidden] {
  display: none !important;
}

/* ---------- small screens ---------- */

@media (max-width: 720px) {
  .fixture {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .fixture__slot {
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
  }

  .fixture__controls {
    grid-template-columns: repeat(3, 1fr);
  }

  .topbar__actions .btn {
    flex: 1 1 auto;
  }

  .field--row {
    grid-template-columns: 1fr;
  }
}

.linkbtn {
  margin-top: 6px;
  padding: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

.linkbtn:hover {
  color: var(--accent);
}

/* ---------- team sheet image + teams editor ---------- */

.dialog--wide {
  max-width: min(1100px, 96vw);
}

.sheetwrap {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

#sheetPreview canvas {
  display: block;
}

.teamtable {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(130px, 1.1fr);
  gap: 6px 10px;
  align-items: center;
  max-height: 58vh;
  overflow-y: auto;
  padding-right: 4px;
}

.teamtable__head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 4px 0;
  z-index: 1;
}

.teamtable__fa {
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-word;
}

.teamtable input {
  padding: 5px 8px;
  font-size: 13px;
}

/* ---------- view toggle ---------- */

.segmented {
  display: inline-flex;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.segmented__btn {
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  white-space: nowrap;
}

/* Sits beside the group before it rather than being pushed apart from it —
   unless that group is hidden, when it takes over the push to the right. */
.segmented--next {
  margin-left: 8px;
}

.segmented[hidden] + .segmented--next {
  margin-left: auto;
}

.segmented__btn + .segmented__btn {
  border-left: 1px solid var(--border);
}

.segmented__btn[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.segmented__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- grid (team sheet) view ---------- */

.gridwrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #101820;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  white-space: nowrap;
}

.grid td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: #17222f;
}

/* Home blue, away orange, no game red — the same coding as the image export,
   kept literal so the screen and the exported picture read the same way. */
.grid__row--home td {
  background: #bdd7ee;
}

.grid__row--away td {
  background: #f8cbad;
}

.grid__row--nogame td {
  background: #f8cbad;
  color: #c00000;
  font-style: italic;
}

.grid__row--clash td {
  box-shadow: inset 0 -2px 0 var(--danger-ink);
}

.grid__row--early .grid__edit input[type='time'] {
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.grid__split td {
  background: #101820;
  padding: 0;
  height: 8px;
  border: 0;
}

.grid__team {
  font-weight: 650;
}

.grid__opposition {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid__na {
  color: #6b7480;
}

.grid__edit {
  padding: 3px 6px;
}

.grid__edit input,
.grid__edit select {
  width: auto;
  min-width: 62px;
  padding: 3px 6px;
  font-size: 13px;
  color: #17222f;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 5px;
}

.grid__edit input[type='number'] {
  min-width: 58px;
}

.grid__actions {
  width: 1%;
}

.grid__actions .linkbtn {
  margin: 0;
  font-size: 11.5px;
  color: #4a5460;
}

.grid__legend {
  margin: 12px 2px 0;
  font-size: 12.5px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .segmented {
    margin-left: 0;
  }

  main:has(.gridwrap) {
    padding: 12px 8px;
  }
}
