/* Phone-first. Everything tappable is at least 44px, nothing scrolls sideways. */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #12161c;
  --ink-dim: #5b6472;
  --line: #dde1e7;
  --accent: #1b64d8;
  --accent-ink: #ffffff;
  --ok: #0f7a44;
  --warn: #96620a;
  --danger: #b3261e;
  --clock: #0f7a44;
  --radius: 12px;
  /* The sticky search sits exactly below the sticky header, so this has to
     match the header's real height. The header is pinned to it with
     min-height, and its two lines are kept from wrapping, so it cannot grow. */
  --header-h: 70px;
}

/*
 * Dark tokens live in one place and are applied twice: once for people whose
 * phone is in dark mode and who have not chosen otherwise, and once for anyone
 * who picked Dark explicitly in Settings. Picking Light wins over the phone.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0b1220;
    --card: #151d2b;
    --ink: #eef1f6;
    --ink-dim: #9aa5b6;
    --line: #26314a;
    --accent: #4d8dfb;
    --accent-ink: #06101f;
    --ok: #4ad48b;
    --warn: #f0c35c;
    --danger: #ff8b80;
    --clock: #4ad48b;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #151d2b;
  --ink: #eef1f6;
  --ink-dim: #9aa5b6;
  --line: #26314a;
  --accent: #4d8dfb;
  --accent-ink: #06101f;
  --ok: #4ad48b;
  --warn: #f0c35c;
  --danger: #ff8b80;
  --clock: #4ad48b;
}

:root[data-theme='light'] {
  color-scheme: light;
}
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
    sans-serif;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

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

.app {
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: calc(var(--header-h) + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
}

.header-line {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px 10px;
  align-items: baseline;
  overflow: hidden;
}

.header-main {
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
}

.header-sub {
  color: var(--ink-dim);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-until {
  margin-top: 2px;
  /* Fixed line box: the on-the-clock state uses bigger text but must not make
     the header taller, or it would slide under the sticky search box. */
  min-height: 24px;
  line-height: 24px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
}

.header-clock {
  background: var(--clock);
}

.header-clock .header-main,
.header-clock .header-sub,
.header-clock .header-until {
  color: #06101f;
}

.header-clock .header-until {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* ---------- banner ---------- */
.banner {
  display: block;
  width: 100%;
  border: 0;
  background: var(--danger);
  color: #fff;
  padding: 10px 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
}

/* ---------- layout ---------- */
.main {
  padding: 10px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.card-count {
  color: var(--ink-dim);
  font-weight: 500;
}

.empty {
  color: var(--ink-dim);
  font-size: 14px;
  margin: 6px 0;
}

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

.loading {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-dim);
}

/* ---------- search ---------- */
.search-wrap {
  position: sticky;
  /* Below the header (z-index 20), not underneath it. */
  top: calc(var(--header-h) + env(safe-area-inset-top));
  z-index: 10;
  display: flex;
  align-items: center;
  background: var(--bg);
  padding: 4px 0;
}

.search {
  flex: 1;
  min-width: 0;
  height: 46px;
  font-size: 17px;
  padding: 0 40px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  -webkit-appearance: none;
  appearance: none;
}

.search-clear {
  margin-left: -38px;
  width: 34px;
  height: 44px;
  border: 0;
  background: transparent;
  font-size: 24px;
  color: var(--ink-dim);
}

/* ---------- chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  font-size: 14px;
  font-weight: 700;
}

.chip-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- lists ---------- */
.list,
.strip {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.list > .row:first-child {
  border-top: 0;
}

.row-rank {
  flex: 0 0 46px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.row-rank-no {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.row-rank-adp {
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Board rows show a team name here rather than "T8", so the column is wider.
   Height is unchanged: the name is a single clipped line. */
.row-board .row-rank {
  flex: 0 0 78px;
}

.row-body {
  flex: 1 1 auto;
  min-width: 0;
}

.row-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  font-size: 12.5px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-taken {
  opacity: 0.55;
}

.row-mine {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.strip-row {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.strip li:first-child .strip-row {
  border-top: 0;
}

.strip-pos {
  flex: 0 0 46px;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-dim);
}

.strip-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-adp {
  color: var(--ink-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ---------- buttons ---------- */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 15px;
  font-weight: 700;
}

.btn:disabled {
  opacity: 0.45;
}

.btn-wide {
  width: 100%;
}

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

.btn-take {
  flex: 0 0 auto;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-remove,
.btn-restore {
  font-size: 14px;
}

.btn-step {
  width: 52px;
  font-size: 22px;
  font-weight: 700;
}

/* ---------- steppers and facts ---------- */
.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.stepper:first-of-type {
  border-top: 0;
}

.stepper-label {
  display: flex;
  flex-direction: column;
}

.stepper-label small {
  color: var(--ink-dim);
  font-size: 12.5px;
}

.stepper-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stepper-value {
  min-width: 34px;
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0;
  font-size: 14px;
}

.facts dt {
  color: var(--ink-dim);
}

.facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- team names ---------- */
.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  min-width: 0;
}

.seat-no {
  flex: 0 0 62px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  /* 16px keeps iOS from zooming the page when the field is focused. */
  font-size: 16px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  -webkit-appearance: none;
  appearance: none;
}

.format-line {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: break-word;
}

/* ---------- next up strip ---------- */
.nextup {
  margin: 0;
  min-height: 32px;
  line-height: 32px;
  padding: 0 2px;
  font-size: 13.5px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nextup-tag {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.05em;
}

.nextup strong {
  color: var(--accent);
}

/* ---------- my roster ---------- */
.slot-row {
  align-items: center;
}

.slot-tag {
  flex: 0 0 46px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}

.slot-open {
  color: var(--ink-dim);
  font-weight: 500;
  font-style: italic;
}

.slot-sub {
  margin: 12px 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.copy-box {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}

/* ---------- appearance picker ---------- */
.segmented {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.segment {
  flex: 1 1 0;
  min-height: 44px;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-dim);
  font-size: 15px;
  font-weight: 700;
}

.segment:first-child {
  border-left: 0;
}

.segment-on {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- suggestion ---------- */
.btn-suggest {
  min-height: 48px;
  background: linear-gradient(135deg, #7b3fe4, #b03fd6);
  border-color: #7b3fe4;
  color: #fff;
  font-size: 16px;
}

.muted-note {
  margin: -4px 2px 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.sheet {
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.sheet-grip {
  width: 40px;
  height: 4px;
  margin: 8px auto 4px;
  border-radius: 2px;
  background: var(--line);
}

.sheet-body {
  padding: 8px 16px 4px;
  min-width: 0;
}

.sheet-for {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.sheet-player {
  margin: 2px 0 2px;
  font-size: 25px;
  line-height: 1.15;
  overflow-wrap: break-word;
}

.sheet-meta {
  font-size: 13.5px;
  color: var(--ink-dim);
}

.sheet-title {
  margin: 4px 0 8px;
  font-size: 19px;
}

.sheet-headline {
  margin: 12px 0 6px;
  font-size: 16.5px;
  font-weight: 700;
}

.sheet-reasoning {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--ink);
}

.sheet-error {
  font-size: 15px;
  color: var(--danger);
}

.sheet-block {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: 14px;
}

.sheet-block-tag {
  font-weight: 800;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.sheet-sub {
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.sheet-alts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sheet-alts li {
  padding: 6px 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.sheet-alts li:first-child {
  border-top: 0;
}

.sheet-alt-name {
  display: block;
  font-weight: 700;
  font-size: 15px;
  overflow-wrap: break-word;
}

.sheet-alt-pos {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--ink-dim);
}

.sheet-alt-why {
  display: block;
  font-size: 13.5px;
  color: var(--ink-dim);
  overflow-wrap: break-word;
}

.chip-confidence {
  display: inline-block;
  margin: 12px 0 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--line);
  color: var(--ink-dim);
}

.chip-high {
  background: var(--ok);
  color: #06101f;
}

.chip-medium {
  background: var(--warn);
  color: #fff;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.sheet-loading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 26px 2px;
}

.sheet-loading-main {
  font-size: 16.5px;
  font-weight: 700;
}

.sheet-loading-sub {
  font-size: 13.5px;
  color: var(--ink-dim);
}

.spinner {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 584px;
  margin: 0 auto;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #12161c;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.toast-ok {
  background: var(--ok);
  color: #06101f;
}

.toast-warn {
  background: var(--warn);
  color: #fff;
}

.toast-error {
  background: var(--danger);
  color: #fff;
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.toast-undo:disabled {
  opacity: 0.5;
}

.toast-undo,
.toast-close {
  flex: 0 0 auto;
  min-height: 44px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  font-weight: 800;
  padding: 0 12px;
}

.toast-close {
  border: 0;
  min-width: 44px;
  font-size: 22px;
  padding: 0 6px;
}

/* ---------- tabs ---------- */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1 1 0;
  min-height: 56px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-dim);
}

.tab-on {
  color: var(--accent);
  box-shadow: inset 0 3px 0 var(--accent);
}

/* ---------- key gate ---------- */
.gate {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(40px + env(safe-area-inset-top)) 20px 20px;
}

.gate h1 {
  font-size: 22px;
  margin: 0 0 8px;
}

.gate-help {
  color: var(--ink-dim);
  font-size: 15px;
}

.gate-input {
  width: 100%;
  height: 48px;
  font-size: 17px;
  padding: 0 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  -webkit-appearance: none;
  appearance: none;
}

@media (min-width: 700px) {
  .main {
    padding: 14px 0;
  }
}
