/* Packers Play Predictor — iPad/iOS PWA styles.
   Dark-first; light mode via prefers-color-scheme.
   Data colors validated (dataviz six checks):
     dark  surface #141917: green #45a678, gold #c9820a
     light surface #faf9f6: green #1d6f43, gold #a06d0a */

:root {
  --bg: #141917;
  --surface: #1d2420;
  --surface-2: #242c27;
  --ink: #eef2ef;
  --ink-2: #a8b3ac;
  --ink-3: #6f7a73;
  --accent: #45a678;         /* pass / primary data hue */
  --accent-2: #c9820a;       /* run / secondary data hue */
  --accent-ink: #0c110e;
  --good: #45a678;
  --bad: #c96a5a;
  --ring: rgba(255, 255, 255, 0.07);
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 4px 16px rgba(0,0,0,.25);
  --radius: 16px;
  --radius-inner: 10px;      /* 16 - 6 padding */
  --tap: 44px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf9f6;
    --surface: #ffffff;
    --surface-2: #f0efe9;
    --ink: #1b211d;
    --ink-2: #55605a;
    --ink-3: #8b948e;
    --accent: #1d6f43;
    --accent-2: #a06d0a;
    --accent-ink: #ffffff;
    --good: #1d6f43;
    --bad: #a4432f;
    --ring: rgba(0, 0, 0, 0.08);
    --shadow: 0 1px 2px rgba(20,30,20,.08), 0 4px 16px rgba(20,30,20,.08);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* Kill iOS double-tap-to-zoom (and the 300ms tap delay) on every element,
     while leaving pan and pinch-zoom intact. (#1) */
  touch-action: manipulation;
}

/* NOTE: do NOT put overflow on html/body — on iOS Safari any non-visible
   overflow on the root breaks `position: fixed`, so the bottom tab bar
   scrolls with the page. (#5) The sideways-scroll guard from #3 lives on
   the content region (.view) instead, which isn't an ancestor of the
   fixed tab bar. Root causes of overflow were already fixed in #3. */
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: none;
  border-radius: var(--radius-inner);
  box-shadow: inset 0 0 0 1px var(--ring);
  padding: 10px 12px;
  min-height: var(--tap);
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Chrome ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 var(--ring);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.topbar-title:active { scale: 0.96; }
.topbar-title { transition: scale .15s cubic-bezier(0.2, 0, 0, 1); }
.topbar h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.logo-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.session-chips { display: flex; gap: 6px; align-items: center; min-height: var(--tap); }
.chip {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  color: var(--ink-2);
}
.chip-opp { color: var(--accent); }

.view {
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 92px);
  max-width: 760px;
  margin: 0 auto;
  /* Sideways-scroll guard lives here (not on body) so it can't break the
     fixed tab bar on iOS. clip keeps overflow-y visible (no scroll trap).
     .view is a sibling of .tabbar, so this never affects it. (#3, #5) */
  overflow-x: clip;
}

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 -1px 0 var(--ring);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  /* Share the bar evenly and shrink on narrow phones so all five tabs fit
     within 320px instead of overflowing/clipping the last one. (#3) */
  flex: 1 1 0;
  min-width: 0;
  max-width: 96px;
  min-height: var(--tap);
  padding: 6px 6px;
  border-radius: 12px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  transition-property: color, scale, background-color;
  transition-duration: .18s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.tab svg { width: 22px; height: 22px; fill: currentColor; }
.tab:active { scale: 0.96; }
.tab[aria-selected="true"] { color: var(--accent); }

/* ---------- Cards & sections ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 0 1px var(--ring);
  padding: 16px;
  margin-bottom: 14px;
}
.card + .card { margin-top: 0; }
.card h2 {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin-bottom: 12px;
}

.enter { animation: rise .35s cubic-bezier(0.2, 0, 0, 1) both; }
.enter:nth-child(2) { animation-delay: .05s; }
.enter:nth-child(3) { animation-delay: .1s; }
.enter:nth-child(4) { animation-delay: .15s; }
.enter:nth-child(5) { animation-delay: .2s; }
.enter:nth-child(6) { animation-delay: .25s; }
@keyframes rise {
  from { opacity: 0; translate: 0 10px; }
  to   { opacity: 1; translate: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .enter { animation: none; }
}

/* ---------- Forms ---------- */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field .hint { font-weight: 400; color: var(--ink-3); }

.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-inner);
  box-shadow: inset 0 0 0 1px var(--ring);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  min-height: calc(var(--tap) - 6px);
  border-radius: 7px; /* inner: 10 - 3 padding */
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  transition-property: background-color, color, scale, box-shadow;
  transition-duration: .18s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.seg button:active { scale: 0.96; }
.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.seg.seg-wrap { flex-wrap: wrap; }
.seg.seg-wrap button { flex: 1 1 30%; }

.stepper {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.stepper input {
  flex: 1;
  min-width: 0; /* let the number field shrink instead of overflowing (#3) */
  text-align: center;
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.stepper button {
  width: 56px;
  border-radius: var(--radius-inner);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-2);
  transition-property: scale, background-color;
  transition-duration: .15s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.stepper button:active { scale: 0.96; background: var(--surface); }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
@media (min-width: 640px) {
  .grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 650;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
  transition-property: scale, opacity, filter;
  transition-duration: .18s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.btn:active { scale: 0.96; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ring);
}
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

/* ---------- Prediction report ---------- */

.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.badge {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 5px 10px;
  border-radius: 999px;
}
.badge-high   { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge-medium { background: color-mix(in srgb, var(--accent-2) 18%, transparent); color: var(--accent-2); }
.badge-low    { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }

.callout {
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
}
.callout strong { color: var(--ink); }

.split-bar {
  display: flex;
  height: 34px;
  border-radius: 8px;
  overflow: hidden;
  gap: 2px; /* spacer between fills */
  margin: 10px 0 4px;
}
.split-bar .part {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-ink);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}
.split-bar .part-pass { background: var(--accent); }
.split-bar .part-run  { background: var(--accent-2); }
.split-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 600;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface-2);
  border-radius: var(--radius-inner);
  box-shadow: inset 0 0 0 1px var(--ring);
  padding: 10px 12px;
}
.tile .k { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.tile .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .s { font-size: 11px; color: var(--ink-3); margin-top: 1px; }
.tile .s.s-good { color: var(--good); font-weight: 600; }

.hbar-list { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 52px; align-items: center; gap: 10px; min-height: 28px; }
.hbar .name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 14px; border-radius: 4px 4px 4px 4px; background: var(--surface-2); overflow: hidden; }
.hbar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0 4px 4px 0; /* rounded data-end, flat baseline */
  transition: width .4s cubic-bezier(0.2, 0, 0, 1);
}
.hbar .val { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); }
.hbar .sub { grid-column: 1 / -1; font-size: 11px; color: var(--ink-3); margin-top: -4px; }

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  color: var(--accent-2);
  margin-left: 6px;
  vertical-align: 1px;
}

.match-list { display: flex; flex-direction: column; }
.match {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  box-shadow: 0 1px 0 var(--ring);
  font-size: 14px;
}
.match:last-child { box-shadow: none; }
.match .who { font-weight: 600; }
.match .meta { color: var(--ink-3); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.note {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.5;
  margin-top: 10px;
}

/* ---------- History ---------- */

.log-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  box-shadow: 0 1px 0 var(--ring);
  overflow: hidden;
  transition-property: height, opacity, padding;
  transition-duration: .18s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.log-row:last-child { box-shadow: none; }
.log-row.removing { height: 0 !important; opacity: 0; padding-top: 0; padding-bottom: 0; }

.row-action {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 15px;
  color: var(--ink-3);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  transition-property: scale, color, background-color;
  transition-duration: .15s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.row-action:active { scale: 0.9; }
.row-action[disabled] { opacity: .5; }

.btn-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 4px;
  min-height: 40px;
}
.btn-link:active { opacity: .6; }

.pers-label { margin: 0 0 10px; font-weight: 600; color: var(--accent); }

.warn-banner {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
  border-radius: var(--radius-inner);
  padding: 10px 12px;
  margin-bottom: 14px;
}
.pof-group { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.pof-pos {
  flex: 0 0 30px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  padding-top: 11px;
}
.pof-group .seg { flex: 1; min-width: 0; }
.pof-group .seg button { flex: 0 1 auto; padding: 0 12px; }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s cubic-bezier(0.2, 0, 0, 1);
}
.log-main { flex: 1; min-width: 0; }
.log-main .t { font-size: 14px; font-weight: 600; }
.log-main .d { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.hit-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.hit-yes { background: var(--good); }
.hit-no  { background: var(--bad); }
.hit-half{ background: var(--accent-2); }

/* ---------- Tables ---------- */

.table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 8px 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
tbody tr { box-shadow: 0 1px 0 var(--ring); }
tbody tr:last-child { box-shadow: none; }

/* ---------- Roster ---------- */

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  box-shadow: 0 1px 0 var(--ring);
  min-height: var(--tap);
}
.player-row:last-child { box-shadow: none; }
.pos-pill {
  width: 38px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 0;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  color: var(--ink-2);
  flex-shrink: 0;
}
.player-info { flex: 1; min-width: 0; }
.player-info .n { font-size: 15px; font-weight: 600; }
.player-info .a { font-size: 12px; color: var(--ink-3); }
.player-row.inactive .n { color: var(--ink-3); text-decoration: line-through; }
.switch {
  position: relative;
  width: 50px; height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--ring);
  transition: background-color .2s cubic-bezier(0.2, 0, 0, 1);
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: translate .2s cubic-bezier(0.2, 0, 0, 1);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { translate: 20px 0; }

/* ---------- Sheet (modal) ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.45);
  opacity: 0;
  transition: opacity .25s cubic-bezier(0.2, 0, 0, 1);
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  max-width: 760px;
  margin: 0 auto;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.35);
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  translate: 0 100%;
  transition: translate .3s cubic-bezier(0.2, 0, 0, 1);
}
.sheet.show { translate: 0 0; }
.sheet-grab {
  width: 40px; height: 5px;
  border-radius: 999px;
  background: var(--ink-3);
  opacity: .4;
  margin: 6px auto 14px;
}
.sheet h2 { font-size: 19px; font-weight: 700; margin-bottom: 14px; }

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  left: 50%;
  z-index: 30;
  translate: -50% 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow), inset 0 0 0 1px var(--ring);
  opacity: 0;
  transition-property: opacity, translate;
  transition-duration: .25s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
  pointer-events: none;
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.show { opacity: 1; translate: -50% 0; }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 40px 20px;
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Login overlay ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
  background: var(--bg);
  animation: rise .3s cubic-bezier(0.2, 0, 0, 1) both;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 0 1px var(--ring);
  padding: 28px 22px;
}
.login-card img { border-radius: 16px; outline: 1px solid var(--ring); }
.login-card h2 { font-size: 19px; font-weight: 700; }
.login-card .note { margin: -4px 0 4px; }
.login-card input { width: 100%; text-align: center; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-error { color: var(--bad); font-size: 13px; font-weight: 600; margin-top: 2px; }

.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { rotate: 360deg; } }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14px; box-shadow: 0 1px 0 var(--ring); }
.kv:last-child { box-shadow: none; }
.kv .k { color: var(--ink-2); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
