* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  color-scheme: var(--color-scheme);
  background: var(--page-bg);
  font-family: var(--font-body);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1800px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.top-controls {
  display: grid;
  grid-template-columns: repeat(2, auto);
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.control-group {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 6px 8px;
}

.control-group h1, .control-group h2 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
}

.range-controls { flex-wrap: wrap; }

.control-group label, .swing-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input[type="number"] {
  width: 68px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  padding: 4px 8px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented button, .tabs button {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.segmented button:hover, .tabs button:hover { background: var(--surface-hover); color: var(--text); }
.segmented button[aria-pressed="true"] { border-color: var(--line-strong); background: var(--surface-hover); color: var(--heading); }

.apply-button {
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--selected-text);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 6px;
  margin: 0 auto;
}

.tabs button {
  height: auto;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  padding: 10px 16px;
  font-weight: 700;
}
.tabs button[aria-selected="true"] { border-bottom-color: transparent; background: var(--table-head); color: var(--heading); }

.content-panel {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.ticker-settings > h2 {
  margin: 0 0 16px;
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: 14px;
  text-align: center;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 30px;
}

.setting-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  min-width: 240px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--row-alt-bg);
  padding: 26px 12px 12px;
  position: relative;
}

.setting-group legend {
  position: absolute;
  top: 8px;
  left: 0;
  width: 100%;
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  text-align: center;
}

.setting-group label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.compact-setting { min-width: auto; }
.fixtures-setting {
  width: fit-content;
  max-width: 100%;
  flex-direction: column;
}
.fixture-control-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
}

.swing-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 16px;
}

.status { margin: 0 0 8px; color: var(--muted); font-size: 11px; text-align: right; }
.status.error { color: var(--danger); }
.view-note { margin: 0 0 8px; color: var(--muted); font-size: 11px; text-align: center; }

.table-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
  min-width: 0;
  max-width: 100%;
}

table {
  width: max-content;
  min-width: min(100%, 650px);
  margin: 0 auto;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 12px;
}

th, td {
  height: 36px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 3px 6px;
  text-align: center;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--table-head);
  color: var(--table-head-text);
  font-size: 11px;
}

tbody tr { background: var(--row-bg); }
tbody tr:nth-child(even) { background: var(--row-alt-bg); }
tbody tr:hover { background: var(--row-hover-bg); }

.sticky-team {
  position: sticky;
  left: 0;
  z-index: 7;
  width: 140px;
  min-width: 140px;
  max-width: 140px;
  background: var(--table-head);
  color: var(--heading);
  text-align: left;
}
tbody .sticky-team { z-index: 5; background: inherit; }
.team-identity {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
}
.team-crest {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  object-fit: contain;
}
.team-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sticky-average { position: sticky; right: 0; z-index: 7; min-width: 76px; background: var(--table-head); }
tbody .sticky-average { z-index: 5; color: var(--heading); font-weight: 700; }

.sort-button {
  display: inline-flex;
  width: 100%;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.sticky-team .sort-button { justify-content: flex-start; }
.rotation-pair .sort-button { justify-content: flex-start; }
.sort-indicator { color: var(--accent); font-size: 9px; }

.fixture-cell { min-width: 52px; }
.difficulty {
  display: inline-grid;
  min-width: 36px;
  min-height: 26px;
  place-items: center;
  border: 1px solid var(--difficulty-border);
  border-radius: var(--cell-radius);
  padding: 3px 5px;
  font-weight: 700;
  letter-spacing: .2px;
}
.d1 { background: var(--d1); color: var(--d1-text); }
.d2 { background: var(--d2); color: var(--d2-text); }
.d3 { background: var(--d3); color: var(--d3-text); }
.d4 { background: var(--d4); color: var(--d4-text); }
.d5 { background: var(--d5); color: var(--d5-text); }

.cell-stack { display: flex; min-width: 42px; flex-direction: column; align-items: center; gap: 2px; }
.competition-tags { display: flex; max-width: 52px; flex-wrap: wrap; justify-content: center; gap: 2px; }
.competition-tag {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--muted);
  padding: 1px 4px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .2px;
}
.competition-tag.provisional { border-style: dashed; opacity: .7; }
.competition-column { width: 52px; min-width: 52px; padding: 0 4px; }
.competition-cell { width: 52px; min-width: 52px; padding: 4px; }
.conflict-cell { box-shadow: inset 0 0 0 2px var(--danger); }

.ib-gap {
  width: 38px;
  min-width: 38px;
  background: var(--break-bg);
  color: var(--break);
  font-size: 9px;
  font-weight: 700;
}
.ib-gap span { display: inline-block; }
.gw-marker { display: block; margin-top: 2px; color: var(--break); font-size: 8px; }
.potential-dgw { background: var(--dgw-bg); }
.potential-bgw { background: var(--bgw-bg); }
.gw-status { display: block; color: var(--accent); font-size: 8px; }
.potential-bgw .gw-status { color: var(--negative); }

.expanded-table { min-width: max-content; }
.expanded-table th, .expanded-table td { width: 48px; min-width: 48px; padding: 2px 3px; }
.expanded-table .sticky-team { width: 125px; min-width: 125px; max-width: 125px; }
.expanded-date { font-size: 9px; line-height: 1.15; text-transform: uppercase; }
.expanded-date strong { display: block; margin-top: 2px; color: var(--heading); font-size: 10px; }
.expanded-gw { height: 24px; font-size: 9px; }
.expanded-gap { background: var(--row-alt-bg); }
.expanded-table .break-day { background: var(--break-bg); }
.expanded-table .afcon-day { box-shadow: inset 2px 0 0 var(--afcon); }

.rotation-rank { width: 38px; min-width: 38px; }
.rotation-pair {
  width: 270px;
  min-width: 270px;
  max-width: 270px;
  overflow: hidden;
  color: var(--heading);
  text-align: left;
  text-overflow: ellipsis;
}
.rotation-pair-content {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
}
.rotation-pair-content .team-identity { flex: 0 1 auto; }
.pair-plus { flex: 0 0 auto; }

.swing-table .fixture-cell { width: 52px; }
.swing-arrow {
  width: 42px;
  min-width: 42px;
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}
.swing { font-weight: 700; }
.swing.better { color: var(--positive); }
.swing.worse { color: var(--negative); }
.empty { color: var(--muted); }

@media (max-width: 980px) {
  .top-controls { grid-template-columns: auto; }
  .control-group { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .app-shell { padding: 8px; }
  .settings-row { margin-bottom: 18px; }
  .setting-group { width: 100%; min-width: 0; }
  .sticky-team { width: 125px; min-width: 125px; max-width: 125px; }
  .rotation-pair { width: 230px; min-width: 230px; max-width: 230px; }
}
