/* Fonts are self-hosted so pages load fully even on restricted school Wi-Fi. */
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url('/fonts/barlow-condensed-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 800; font-display: swap; src: url('/fonts/barlow-condensed-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('/fonts/inter-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap; src: url('/fonts/inter-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('/fonts/inter-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 700; font-display: swap; src: url('/fonts/inter-latin-700-normal.woff2') format('woff2'); }

/* PISD colors, taken from the school seal: laurel maroon, bronze, gold, cream.
   (Variable names kept from v1: --navy is now the deep maroon.) */
:root {
  --navy: #5a1209;
  --navy-2: #8f1a10;
  --gold: #d4ae79;
  --gold-soft: #f6ead6;
  --bronze: #905b33;
  --bg: #f7f2eb;
  --card: #ffffff;
  --ink: #2b170c;
  --muted: #6e5d50;
  --line: #ebe0d2;
  --ok: #138a4c;
  --ok-soft: #e3f6ec;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --warn: #9a6200;
  --warn-soft: #fff3d6;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3, .display {
  font-family: 'Barlow Condensed', Inter, sans-serif;
  letter-spacing: .02em;
  margin: 0;
}
a { color: var(--navy-2); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar {
  background: linear-gradient(180deg, #6b160b, var(--navy));
  border-bottom: 3px solid var(--gold);
}
.topbar .logo { width: 40px; height: 40px; flex: none; display: block; }
.topbar h1 { font-size: 23px; text-transform: uppercase; font-weight: 800; }
.topbar h1 span { color: var(--gold); }
.topbar .spacer { flex: 1; }
.topbar button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); }

/* ---------- layout ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 440px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px;
  margin-bottom: 16px;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; color: var(--muted); }
input, select {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.field { margin-bottom: 14px; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button.gold, .btn.gold { background: var(--gold); color: var(--navy); }
button.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--bad); border: 1px solid #f3c4c4; }
button.sm, .btn.sm { padding: 6px 10px; font-size: 13px; }
button.block { width: 100%; padding: 14px; font-size: 16px; }
button:disabled { opacity: .55; cursor: default; }

.msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-top: 10px; }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px 16px 0; max-width: 1040px; margin: 0 auto; }
.tabs button {
  background: transparent; color: var(--muted); border-radius: 999px; padding: 8px 14px; white-space: nowrap;
}
.tabs button.active { background: var(--navy); color: #fff; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .n { font-family: 'Barlow Condensed', sans-serif; font-size: 34px; line-height: 1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.on .n { color: var(--ok); }
.stat.away .n { color: var(--bad); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.done { background: #e8edf6; color: var(--navy-2); }
.pill.away { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 24px; flex: 1; }

/* ---------- scan page ---------- */
.scan-hero { text-align: center; padding: 28px 20px; }
.scan-hero .icon {
  width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 14px;
  display: grid; place-items: center; font-size: 42px;
}
.scan-hero h2 { font-size: 30px; margin-bottom: 6px; }
.result-ok .icon { background: var(--ok-soft); color: var(--ok); }
.result-bad .icon { background: var(--bad-soft); color: var(--bad); }
.result-ok { border-top: 6px solid var(--ok); }
.result-bad { border-top: 6px solid var(--bad); }
.spinner {
  width: 46px; height: 46px; margin: 10px auto 16px; border-radius: 50%;
  border: 5px solid var(--line); border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- QR display ---------- */
.display-page { background: var(--navy); color: #fff; min-height: 100vh; display: flex; flex-direction: column; }
.display-main { flex: 1; display: grid; place-items: center; padding: 20px; text-align: center; }
.qr-box { background: #fff; padding: 18px; border-radius: 20px; display: inline-block; }
.qr-box img { display: block; width: min(72vmin, 520px); height: auto; image-rendering: pixelated; }
.display-title { font-size: clamp(30px, 6vw, 56px); text-transform: uppercase; margin-bottom: 6px; }
.display-sub { color: rgba(255,255,255,.75); margin-bottom: 20px; font-size: 17px; }
.countdown { margin-top: 16px; color: var(--gold); font-weight: 600; }
.bar { height: 6px; background: rgba(255,255,255,.15); border-radius: 99px; overflow: hidden; width: min(72vmin, 520px); margin: 10px auto 0; }
.bar > div { height: 100%; background: var(--gold); transition: width 1s linear; }
.oncourt { font-family: 'Barlow Condensed', sans-serif; font-size: 22px; margin-top: 14px; }

/* ---------- parent portal ---------- */
.card-title { font-size: 20px; margin-bottom: 10px; }
.kids { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.kids button { background: var(--card); color: var(--navy); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }
.kids button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.player-card { display: flex; gap: 16px; align-items: center; }
.player-card h2 { font-size: 30px; line-height: 1.05; }
.jersey {
  width: 64px; height: 64px; border-radius: 16px; flex: none; display: grid; place-items: center;
  background: var(--navy); color: var(--gold); font-family: 'Barlow Condensed', sans-serif; font-size: 30px; font-weight: 700;
}
.status-line { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c3cad6; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.rate { display: flex; align-items: baseline; gap: 10px; }
.rate-n { font-family: 'Barlow Condensed', sans-serif; font-size: 40px; line-height: 1; }
.meter { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.meter > div { height: 100%; background: var(--ok); }
.event { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.event:last-child { border-bottom: 0; }
.event-date { width: 54px; flex: none; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.2; }
.event-date strong { display: block; color: var(--ink); font-size: 14px; }
.event.cancelled .event-body > div:first-child strong { text-decoration: line-through; color: var(--muted); }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin-bottom: 6px; }
.kbd { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; font-size: 13px; }

/* ---------- coach extras ---------- */
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; margin: 0; }
.check input { width: auto; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { margin: 0; }
.days input { display: none; }
.days span { display: inline-block; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); cursor: pointer; font-weight: 600; }
.days input:checked + span { background: var(--navy); color: #fff; border-color: var(--navy); }
.today-events { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.today-event { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--gold); border-radius: 12px; padding: 10px 14px; }
.today-event.cancelled { border-left-color: var(--bad); opacity: .7; }
.date-group { font-family: 'Barlow Condensed', sans-serif; font-size: 18px; margin: 14px 0 4px; color: var(--navy-2); }
.date-group:first-child { margin-top: 0; }
details summary { cursor: pointer; font-weight: 600; color: var(--navy-2); }

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat .n { font-size: 28px; }
  .hide-sm { display: none; }
  th, td { padding: 9px 6px; }
  td.actions { white-space: normal; }
  td.actions button { margin: 2px 0 2px 4px; }
  .display-page .topbar h1 { font-size: 18px; white-space: nowrap; }
}

/* ---------- roles & lineups ---------- */
body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .admin-hide { display: none !important; }
.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; }
.roster-grid .check { font-size: 14px; }
details.small summary { font-weight: 500; color: var(--muted); }

/* ---------- installable app ---------- */
/* Installed on iPhone the page runs under the status bar, so pad the top bar past the notch. */
.topbar { padding-top: calc(14px + env(safe-area-inset-top)); padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
.btn.block { width: 100%; padding: 14px; font-size: 16px; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.hero-logo { width: 132px; height: 132px; margin: 0 auto 12px; display: block; }
.scan-btn { margin-bottom: 16px; font-size: 18px; padding: 18px; }
.install { text-align: center; }
.install p { margin: 4px 0 16px; }

/* in-app QR scanner */
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.scanner-frame {
  position: absolute; top: 42%; left: 50%; width: min(68vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border: 3px solid var(--gold); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none;
}
.scanner-bar { background: var(--navy); color: #fff; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); text-align: center; }
.scanner-msg { margin: 0 0 12px; font-weight: 500; }
.scanner-msg.bad { color: #ffd2cc; }
