/* Track & Throw — design tokens & global styles */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --ink: #0a0a0a;
  --ink-2: #3a3a36;
  --ink-3: #7a7a72;
  --ink-4: #b5b5ad;
  --line: #e6e4dc;
  --line-2: #d6d4ca;
  --accent: #ff6b1a;
  --accent-soft: #ffe1cc;
  --accent-ink: #b3470b;
  --foul: #b8b6ac;
  --green: #1f8a5b;
  --shadow-sm: 0 1px 0 rgba(20,18,10,0.04), 0 1px 2px rgba(20,18,10,0.04);
  --shadow-md: 0 4px 14px rgba(20,18,10,0.06), 0 1px 2px rgba(20,18,10,0.04);
  --shadow-lg: 0 10px 30px rgba(20,18,10,0.10);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --font: "Helvetica Neue", Helvetica, "Inter", -apple-system, system-ui, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ink); }

/* ---------- App shell ---------- */
#root { min-height: 100dvh; }
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}
@media (min-width: 520px) {
  .app { box-shadow: 0 0 0 1px var(--line), 0 30px 80px -20px rgba(20,18,10,0.18); }
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  padding: calc(var(--safe-top) + 14px) 18px 10px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); background: rgba(246,245,241,0.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.topbar .logo { width: 30px; height: 30px; border-radius: 7px; background: #fff; box-shadow: var(--shadow-sm); display: grid; place-items: center; overflow: hidden; }
.topbar .logo img { width: 100%; height: 100%; object-fit: cover; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; flex: 1; }
.topbar .topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(0.96); }

/* Main scroll area */
.main { flex: 1; padding: 6px 16px calc(100px + var(--safe-bottom)); }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 40;
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-3);
  padding: 4px 6px;
  font-size: 10.5px; letter-spacing: 0.02em;
  font-weight: 500;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--ink); }
.tab.active svg { color: var(--accent); }

/* ---------- Cards & rows ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 10px; }

.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 18px 4px 8px;
}

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  width: 100%; text-align: left;
}
.row + .row { margin-top: 8px; }
.row:active { background: var(--surface-2); }
.row .row-main { flex: 1; min-width: 0; }
.row .row-title { font-weight: 600; font-size: 15.5px; letter-spacing: -0.005em; }
.row .row-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.row .row-end { text-align: right; }
.row .row-end .pb-val { font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.row .row-end .pb-unit { font-size: 11px; color: var(--ink-3); }

/* Badges & chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 11px; font-weight: 500;
  border: 1px solid var(--line);
}
.chip.rank { background: var(--ink); color: #fff; border-color: var(--ink); font-family: var(--mono); }
.chip.rank-1 { background: #f4c542; color: #4a3000; border-color: #e6b328; }
.chip.rank-2 { background: #d8d6cf; color: #2a2a26; border-color: #c4c2bb; }
.chip.rank-3 { background: #d6a07a; color: #4a2510; border-color: #c08a64; }
.chip.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent-soft); }
.chip.foul { background: #f0eee8; color: var(--foul); border-color: #e6e4dc; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600; font-size: 14px;
  background: var(--ink); color: #fff;
  transition: transform 0.06s, opacity 0.12s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.accent { background: var(--accent); }
.btn.danger { background: #c0392b; }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 18px; font-size: 15px; border-radius: 14px; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

.btn-fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-bottom));
  width: 54px; height: 54px;
  background: var(--ink); color: #fff;
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(20,18,10,0.25);
  display: grid; place-items: center; z-index: 35;
}
.btn-fab svg { width: 22px; height: 22px; }
.btn-fab:active { transform: scale(0.94); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
.field label { font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: 0.02em; }
.input, .select, .textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 11px;
  font-size: 15px;
  color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); }
.input.mono, .input-mono { font-family: var(--mono); font-weight: 600; letter-spacing: -0.01em; }
.textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%237a7a72' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 3px;
}
.segmented button {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  display: inline-flex; align-items: center; gap: 6px;
}
.segmented button svg { width: 14px; height: 14px; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.segmented.block { display: flex; }
.segmented.block button { flex: 1; justify-content: center; }

/* ---------- Modal / Sheet ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(15,12,5,0.36);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity 0.18s;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  z-index: 100;
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 92dvh;
  display: flex; flex-direction: column;
  box-shadow: 0 -10px 40px rgba(20,18,10,0.16);
}
.sheet.open { transform: translateX(-50%) translateY(0); }
.sheet-grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 8px auto 6px; }
.sheet-head {
  padding: 6px 18px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; flex: 1; }
.sheet-body { padding: 16px 18px calc(24px + var(--safe-bottom)); overflow-y: auto; }

/* Full screen modal style (for competition detail) */
.modal-full {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex; flex-direction: column;
  max-width: 480px; margin: 0 auto;
  left: 50%; transform: translateX(50%) translateX(-100%);
}
@media (min-width: 480px) { .modal-full { transform: translateX(-50%) translateX(100%); left: 50%; } }
.modal-full.open { transform: translateX(-50%); }
@media (max-width: 479px) { .modal-full { transform: translateX(100%); left: 0; } .modal-full.open { transform: translateX(0); } }

.modal-head {
  padding: calc(var(--safe-top) + 12px) 14px 10px;
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  position: sticky; top: 0; z-index: 5;
}
.modal-head.scrolled { border-bottom-color: var(--line); background: rgba(246,245,241,0.9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.modal-head .back {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 8px 8px 4px;
  font-size: 14.5px;
  color: var(--ink); font-weight: 500;
}
.modal-head .back svg { width: 20px; height: 20px; }
.modal-head .title { flex: 1; font-size: 16px; font-weight: 600; text-align: center; padding-right: 60px; }
.modal-head .actions { display: flex; gap: 4px; }
.modal-body { flex: 1; overflow-y: auto; padding: 12px 16px calc(40px + var(--safe-bottom)); }

/* ---------- Empty state ---------- */
.empty {
  padding: 36px 24px 28px;
  text-align: center;
}
.empty .emoji-icon {
  width: 64px; height: 64px; border-radius: 18px;
  margin: 0 auto 14px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--ink-3);
}
.empty .emoji-icon svg { width: 32px; height: 32px; }
.empty h3 { font-size: 17px; margin: 0 0 6px; }
.empty p { font-size: 13.5px; color: var(--ink-3); margin: 0 0 18px; max-width: 280px; margin-inline: auto; }

/* ---------- Stats hero ---------- */
.hero {
  background: var(--ink); color: #fff;
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.hero .hero-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }
.hero .hero-value { font-family: var(--mono); font-size: 44px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.05; margin-top: 6px; }
.hero .hero-value .unit { font-size: 18px; opacity: 0.55; margin-left: 6px; font-weight: 500; }
.hero .hero-sub { font-size: 12.5px; opacity: 0.7; margin-top: 4px; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.hero-stat { padding: 10px 12px; background: rgba(255,255,255,0.08); border-radius: 12px; }
.hero-stat .k { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.6; }
.hero-stat .v { font-family: var(--mono); font-size: 18px; font-weight: 600; margin-top: 2px; }
.hero-stat .v .pos { color: #5fd498; }
.hero-stat .v .neg { color: #ff9b7a; }

/* ---------- Visualization ---------- */
.vis {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}
.vis-frame { position: relative; width: 100%; aspect-ratio: 5/6; }
.vis-frame svg { width: 100%; height: 100%; display: block; touch-action: manipulation; }

.legend { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 4px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; gap: 8px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); display: inline-block; margin-right: 5px; vertical-align: -1px; }
.legend .dot.accent { background: var(--accent); }
.legend .dot.foul { background: transparent; border: 1.5px solid var(--foul); }

/* Throw popover (inside vis) */
.throw-pop {
  position: absolute;
  background: var(--ink); color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  box-shadow: 0 10px 26px rgba(0,0,0,0.25);
  z-index: 4;
  min-width: 180px;
  pointer-events: auto;
}
.throw-pop .pop-distance { font-family: var(--mono); font-size: 20px; font-weight: 600; margin-bottom: 2px; }
.throw-pop .pop-comp { opacity: 0.78; font-size: 12px; }
.throw-pop .pop-meta { opacity: 0.6; font-size: 11px; margin-top: 6px; }
.throw-pop .pop-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--accent); font-weight: 600; font-size: 12px; }
.throw-pop .pop-close { position: absolute; top: 6px; right: 6px; color: rgba(255,255,255,0.5); width: 22px; height: 22px; display: grid; place-items: center; }

/* ---------- Throw list ---------- */
.throws-list { display: flex; flex-direction: column; gap: 6px; }
.throw-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 8px 0 6px;
  height: 52px;
  position: relative;
  overflow: hidden;
}
.throw-row.foul .dist-val { color: var(--foul); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.throw-row.best { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.throw-row .num { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); font-family: var(--mono); font-size: 13px; color: var(--ink-3); font-weight: 600; }
.throw-row.best .num { background: var(--ink); color: #fff; }
.throw-row .dist-input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  font-family: var(--mono); font-weight: 600; font-size: 18px;
  padding: 0; letter-spacing: -0.01em;
  width: 100%;
  min-width: 0;
}
.throw-row .dist-input:focus { outline: none; }
.throw-row .dist-input::placeholder { color: var(--ink-4); font-weight: 500; }
.throw-row .dist-val { font-family: var(--mono); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.throw-row .right-controls { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.throw-row .video-mark { color: var(--accent); width: 26px; height: 26px; display: grid; place-items: center; flex-shrink: 0; }
.throw-row .foul-toggle {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center;
  color: var(--ink-4);
  font-size: 11px;
  font-weight: 700; letter-spacing: 0.04em;
  flex-shrink: 0;
}
.throw-row .foul-toggle.on { background: var(--ink); color: #fff; }
.throw-row .menu-btn { color: var(--ink-3); width: 26px; height: 26px; display: grid; place-items: center; flex-shrink: 0; }

.throws-summary { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.throws-summary .big { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.throws-summary .small { font-size: 12.5px; color: var(--ink-3); }

/* Comp detail field grid */
.detail-grid { display: grid; gap: 12px; }
.detail-grid .field-row { gap: 10px; }
.dot-divider { color: var(--ink-4); }

.divider { height: 1px; background: var(--line); margin: 18px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + var(--safe-bottom));
  background: var(--ink); color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* Misc */
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.spacer-12 { height: 12px; } .spacer-16 { height: 16px; } .spacer-24 { height: 24px; }
.text-center { text-align: center; }
.flex { display: flex; } .flex-col { flex-direction: column; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* Comp picker chips */
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-pick {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 500;
  color: var(--ink-2);
}
.chip-pick.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip-pick.on .chip-dot { background: var(--accent); }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); }

/* Season switcher */
.season-switch {
  display: flex; align-items: center; gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  width: max-content;
  margin: 4px 0 14px;
}
.season-switch button { padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink-3); border-radius: 999px; }
.season-switch button.active { background: var(--ink); color: #fff; }
.season-switch .nav { width: 30px; height: 30px; display: grid; place-items: center; color: var(--ink-3); }

/* Animations */
@keyframes pop-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.fade-in { animation: fade-in 0.2s; }
.pop-in { animation: pop-in 0.2s; }

/* SVG ring used for "best in comp" */
.best-ring { stroke: var(--ink); fill: none; stroke-width: 1.5; }

/* tiny x for foul */
.foul-mark { stroke: var(--foul); stroke-width: 1.5; }
