/* Track & Train — design tokens & global styles (inherited from Track & Throw) */
: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;
  --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);

  /* Training-type palette — muted, warm-paper friendly */
  --t-orange: #ff6b1a;
  --t-blue:   #2f74c0;
  --t-green:  #1f8a5b;
  --t-violet: #7a5af0;
  --t-pink:   #d6457e;
  --t-amber:  #d99a16;
  --t-teal:   #128a82;
  --t-slate:  #5a6472;
}

* { 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; transform: scale(1.42); }
.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); }
.icon-btn svg { width: 20px; height: 20px; }

/* 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;
  display: flex; align-items: center; justify-content: space-between;
}

.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; display: flex; flex-direction: column; }
.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; }

/* 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.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent-soft); }

/* ---------- 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 svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn.lg svg { width: 19px; height: 19px; }

.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); }
.textarea { min-height: 96px; 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;
}

/* ---------- 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; }

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 3px;
}
.segmented button {
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.segmented.block { display: flex; }
.segmented.block button { flex: 1; }

/* ---------- Empty state ---------- */
.empty { padding: 40px 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; }

/* ---------- 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; }
.text-center { text-align: center; }
.flex { display: flex; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .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; }

/* ============================================================
   CALENDAR
   ============================================================ */
.cal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 2px 12px;
}
.cal-head .cal-month {
  flex: 1; font-size: 20px; font-weight: 600; letter-spacing: -0.015em;
  text-transform: capitalize;
}
.cal-head .cal-month .yr { color: var(--ink-3); font-weight: 500; margin-left: 6px; }
.cal-nav {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; color: var(--ink-2);
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.cal-nav:active { transform: scale(0.94); }
.cal-nav svg { width: 19px; height: 19px; }
.cal-today-btn {
  padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

.cal-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--line);
}
.cal-dow span {
  text-align: center; font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
}
.cal-weeks { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1.08;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  padding: 7px 2px 4px;
  gap: 4px;
  background: var(--surface);
}
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-weeks .cal-cell:nth-last-child(-n+7) { border-bottom: 0; }
.cal-cell.muted-day { background: var(--surface-2); }
.cal-cell.muted-day .cal-num { color: var(--ink-4); }
.cal-cell:active:not(.muted-day) { background: var(--surface-2); }
.cal-num {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  color: var(--ink-2); width: 26px; height: 22px;
  display: grid; place-items: center; letter-spacing: -0.01em;
}
.cal-cell.today .cal-num {
  color: var(--accent-ink);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.6px var(--accent);
  border-radius: 7px;
  width: 24px; height: 22px;
}
.cal-cell.has .cal-num { color: var(--ink); }
.cal-dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; align-content: flex-start; min-height: 8px; max-width: 100%; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.cal-more { font-family: var(--mono); font-size: 9px; color: var(--ink-3); line-height: 6px; }

/* Day sheet (sessions of a selected day) */
.day-date { font-size: 13px; color: var(--ink-3); font-weight: 500; }
.session-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  width: 100%; text-align: left;
}
.session-card + .session-card { margin-top: 8px; }
.session-card:active { background: var(--surface-2); }
.sc-bar { width: 4px; align-self: stretch; border-radius: 3px; flex-shrink: 0; }
.sc-main { flex: 1; min-width: 0; }
.sc-top { display: flex; align-items: center; gap: 8px; }
.sc-type { font-weight: 600; font-size: 15px; letter-spacing: -0.005em; }
.sc-feel { font-size: 17px; line-height: 1; }
.sc-notes {
  font-size: 13px; color: var(--ink-2); margin-top: 4px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sc-empty-notes { font-size: 13px; color: var(--ink-4); margin-top: 4px; font-style: italic; }

/* Type dot + swatch */
.type-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.type-swatch { width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0; }

/* ---------- Type picker (chips) ---------- */
.type-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 13px 9px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  transition: transform 0.06s;
}
.type-chip:active { transform: scale(0.96); }
.type-chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.type-chip.add { color: var(--ink-3); font-weight: 600; border-style: dashed; }
.type-chip.add svg { width: 15px; height: 15px; }

/* ---------- Emoji feeling rating ---------- */
.feel-row { display: flex; gap: 8px; }
.feel-btn {
  flex: 1; aspect-ratio: 1 / 1; max-width: 60px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 26px; line-height: 1;
  transition: transform 0.08s, background 0.12s, border-color 0.12s;
  filter: grayscale(0.45); opacity: 0.7;
}
.feel-btn:active { transform: scale(0.92); }
.feel-btn.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  filter: none; opacity: 1;
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(255,107,26,0.18);
}
.feel-label { text-align: center; font-size: 12px; color: var(--ink-3); font-weight: 600; min-height: 16px; margin-top: 8px; }

/* ---------- Color picker ---------- */
.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch {
  width: 34px; height: 34px; border-radius: 10px;
  border: 2px solid transparent;
  display: grid; place-items: center;
  transition: transform 0.06s;
}
.color-swatch:active { transform: scale(0.92); }
.color-swatch.on { border-color: var(--ink); }
.color-swatch.on svg { width: 16px; height: 16px; color: #fff; }

/* ---------- By-type tab ---------- */
.bt-hero {
  background: var(--ink); color: #fff;
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.bt-hero .bt-eyebrow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; display: flex; align-items: center; gap: 7px; }
.bt-hero .bt-eyebrow .type-dot { width: 9px; height: 9px; }
.bt-hero .bt-name { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 8px; }
.bt-hero .bt-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 16px; }
.bt-hero .bt-stat { padding: 10px 12px; background: rgba(255,255,255,0.08); border-radius: 12px; }
.bt-hero .bt-stat .k { font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.6; }
.bt-hero .bt-stat .v { font-family: var(--mono); font-size: 20px; font-weight: 600; margin-top: 3px; letter-spacing: -0.01em; }

/* horizontal type selector */
.type-scroller {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 2px 2px 12px;
  margin: 0 -2px;
  scrollbar-width: none;
}
.type-scroller::-webkit-scrollbar { display: none; }
.type-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13.5px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.type-pill.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* mini month strip for by-type history */
.bt-day-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  width: 100%; text-align: left;
}
.bt-day-row + .bt-day-row { margin-top: 8px; }
.bt-day-row:active { background: var(--surface-2); }
.bt-datebox {
  width: 46px; flex-shrink: 0; text-align: center;
  border-right: 1px solid var(--line); padding-right: 12px;
}
.bt-datebox .d { display: block; font-family: var(--mono); font-size: 20px; font-weight: 600; letter-spacing: -0.01em; line-height: 1; }
.bt-datebox .m { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; margin-top: 4px; }
.bt-day-main { flex: 1; min-width: 0; }

/* compact year dropdown (by-type history) */
.year-select {
  -webkit-appearance: none; appearance: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 28px 6px 12px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  letter-spacing: 0; text-transform: none;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  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 10px center;
}
.year-select:focus { outline: none; border-color: var(--ink); }

/* Animations — transform-only so content is never stranded invisible */
@keyframes pop-in { from { transform: scale(0.92); } to { transform: none; } }
@keyframes fade-in { from { transform: translateY(5px); } to { transform: none; } }
.fade-in { animation: fade-in 0.22s ease both; }
.pop-in { animation: pop-in 0.2s ease both; }
