/* Token VALUES for rink-tracker. Names come from the house theme contract;
   this file is the only place hex lives. Dark-first — the crew reads this in a
   cold building under fluorescents, and the GM reads it on a desktop. */

:root {
  color-scheme: dark;

  /* Surfaces */
  --bg: #070b10;
  --surface: #0e141c;
  --elevated: #141d28;

  /* Text tiers */
  --text: #e8f0f8;
  --text-2: #9fb2c6;
  /* #61748a read 3.54:1 on --elevated — under AA for the small-caps section
     titles and field labels that use this tier. Lifted to ~4.6:1 while staying
     clearly below --text-2 so the three tiers still separate. */
  --text-3: #74879c;

  /* Status */
  --green: #43d19e;
  --amber: #f5b544;
  --red: #f2544f;
  --blue: #4aa8ff;

  /* Accent — rink ice */
  --accent: #5cc8f5;
  --purple: #a78bfa;

  /* Borders */
  --border: rgba(150, 180, 210, 0.14);
  --border-strong: rgba(150, 180, 210, 0.28);

  /* Glass */
  --glass-bg: rgba(20, 29, 40, 0.62);
  --glass-border: rgba(160, 190, 220, 0.16);
  --blur: 14px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  /* Spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s7: 32px;
  --s8: 48px;

  /* Shadow + glow */
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  --glow-green: 0 0 0 1px rgba(67, 209, 158, 0.4), 0 0 18px rgba(67, 209, 158, 0.18);
  --glow-amber: 0 0 0 1px rgba(245, 181, 68, 0.45), 0 0 18px rgba(245, 181, 68, 0.2);
  --glow-red: 0 0 0 1px rgba(242, 84, 79, 0.5), 0 0 22px rgba(242, 84, 79, 0.26);

  /* Motion */
  --tx-fast: 110ms cubic-bezier(0.4, 0, 0.2, 1);
  --tx: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --tx-slow: 340ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Charts */
  --chart-1: #5cc8f5;
  --chart-2: #43d19e;
  --chart-3: #f5b544;
  --chart-4: #a78bfa;
  --chart-grid: rgba(150, 180, 210, 0.12);

  /* Domain extension — severity tiers (crew-side pad grammar). Tier 3 glows. */
  --sev-1: #7f93a8;
  --sev-2: #f5b544;
  --sev-3: #f2544f;

  --dock-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Metrics never jitter their neighbours. */
.num, .metric, [data-metric] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

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

/* This aesthetic leans on pulse and glow — gate all of it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── Shell ─────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  padding-top: calc(var(--s3) + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur)) saturate(1.3);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.3);
  flex: 0 0 auto;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.2px;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.topbar .spacer { flex: 1 1 auto; min-width: 0; }

/* The scrolling element is the view, never the window. */
.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--s4);
  padding-bottom: calc(var(--dock-h) + var(--s6) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

/* ── Dock ──────────────────────────────────────────────────────────── */
/* Floating, offset from the edges, labelled. Never icon-only. */

.dock {
  position: fixed;
  left: max(var(--s3), env(safe-area-inset-left));
  right: max(var(--s3), env(safe-area-inset-right));
  bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  height: var(--dock-h);
  display: flex;
  align-items: stretch;
  gap: var(--s1);
  padding: var(--s1);
  border-radius: var(--r-xl);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
  box-shadow: var(--shadow);
  z-index: 40;
  overflow-x: auto;
  scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
/* `display: flex` above outranks the UA stylesheet's `[hidden] { display: none }`,
   so setting el.hidden left the dock painting its background and border as a
   hairline at the bottom of the screen — with --dock-h at 0 it was a sliver, not
   an absence. Both callers rely on `hidden` meaning gone: the boot-failure
   screen, and renderDock when fewer than two surfaces have shipped. */
.dock[hidden] { display: none; }

.dock a {
  flex: 1 1 0;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-3);
  border-radius: var(--r-lg);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: color var(--tx-fast), background var(--tx-fast);
}
.dock a .ico { font-size: 17px; line-height: 1; }
.dock a[aria-current="page"] {
  color: var(--text);
  background: rgba(92, 200, 245, 0.14);
}

/* ── Cards + surfaces ──────────────────────────────────────────────── */

.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: var(--s4);
  backdrop-filter: blur(var(--blur)) saturate(1.25);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.25);
  /* Inset top light, flat and ≤0.05 — matte by default. */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045);
  min-width: 0;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0 0 var(--s2);
}

.muted { color: var(--text-2); }
.dim { color: var(--text-3); }

.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  /* The narrow floor is 206px (split-screen). Inside a card's padding that
     leaves ~142px, which a label + status chip + action button cannot share on
     one line — so the row wraps instead of pushing its tail past the edge. */
  flex-wrap: wrap;
}
/* A basis rather than 0 is what actually triggers the wrap: with min-width:0
   alone the grow child just shrinks to nothing and the fixed children stay put
   and overflow. */
.row > .grow { flex: 1 1 8rem; min-width: 0; }
.row > .fixed { flex: 0 0 auto; }

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Controls ──────────────────────────────────────────────────────── */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--elevated);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--tx-fast), border-color var(--tx-fast), opacity var(--tx-fast);
}
.btn:hover { border-color: var(--accent); }
.btn:active { background: var(--surface); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn.primary {
  background: rgba(92, 200, 245, 0.16);
  border-color: rgba(92, 200, 245, 0.5);
  color: #d8f2ff;
}
.btn.danger {
  background: rgba(242, 84, 79, 0.14);
  border-color: rgba(242, 84, 79, 0.45);
  color: #ffd9d8;
}
.btn.small { min-height: 36px; padding: 0 var(--s3); font-size: 13px; }
/* Anything visually under 44px carries its own hitbox instead of growing. */
.btn.small::before { content: ""; position: absolute; inset: -4px; }

.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-3);
}
.input {
  min-height: 44px;
  width: 100%;
  min-width: 0;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  outline: none;
}
.input:focus-visible { border-color: var(--accent); }
textarea.input { min-height: 88px; resize: vertical; }

/* ── Chips + pills ─────────────────────────────────────────────────── */

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: 4px var(--s2);
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  /* nowrap alone is what pushed a long due-pill ("before the CHL tournament")
     past the right edge on the 206px floor. The ellipsis quartet needs all
     four declarations — nowrap, overflow, text-overflow and a shrinkable
     min-width — plus a cap so the chip can never exceed its row. */
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.green { color: var(--green); border-color: rgba(67, 209, 158, 0.35); }
.chip.amber { color: var(--amber); border-color: rgba(245, 181, 68, 0.4); }
.chip.red { color: var(--red); border-color: rgba(242, 84, 79, 0.45); }

.empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--text-3);
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
}
.empty strong { display: block; color: var(--text-2); margin-bottom: var(--s1); font-weight: 600; }

/* ── Sheet ─────────────────────────────────────────────────────────── */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 11, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tx);
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--elevated);
  border-top: 1px solid var(--glass-border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow);
  z-index: 51;
  transform: translateY(101%);
  transition: transform var(--tx-slow);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: translateY(0); }
.sheet-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.sheet-head h2 { margin: 0; font-size: 16px; min-width: 0; flex: 1 1 auto; }
.sheet-body {
  padding: var(--s4);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  min-height: 0;
}
/* Grabber */
.sheet::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-strong);
}

/* ── Desktop reading layout ────────────────────────────────────────── */
/* Not a stretched phone: the GM reads this on a monitor, so the surfaces sit
   side by side and the measure is capped. */

@media (min-width: 900px) {
  .view {
    padding: var(--s6);
    padding-bottom: calc(var(--dock-h) + var(--s7));
  }
  .grid-read {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: var(--s5);
    align-items: start;
  }
  .grid-read > * { min-width: 0; }
  .dock {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(720px, calc(100% - var(--s7)));
  }
  .sheet {
    left: 50%;
    right: auto;
    transform: translate(-50%, 101%);
    width: min(720px, 92vw);
    border-radius: var(--r-xl);
    bottom: var(--s6);
    max-height: 82dvh;
  }
  .sheet.open { transform: translate(-50%, 0); }
  .prose { max-width: 68ch; }
  /* Art reads this on a monitor. Sub-labels inside cards were running to 99ch
     on the ultrawide profiles, which is well past comfortable measure — a
     ceiling costs nothing on phones (they never get near it). */
  .card p, .card .dim { max-width: 80ch; }
}

@media (min-width: 1500px) {
  .view { align-items: center; }
  .view > * { width: 100%; max-width: 1360px; }
}
