
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 15px; line-height: 1.7; color: #1f2328; background: #f6f8fa;
}
a { color: #0969da; text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
aside {
  background: #0d1117; color: #c9d1d9;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
aside h1 { font-size: 15px; margin: 0 0 2px; padding-left: 32px; color: #fff; }
aside .subtitle { font-size: 11px; color: #8b949e; padding-left: 32px; margin-bottom: 20px; }
details.nav-group { margin-bottom: 8px; }
details.nav-group > summary.nav-group-title {
  font-size: 12px; font-weight: 700; color: #c9d1d9;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 8px 10px; margin: 0 -4px;
  cursor: pointer; user-select: none; list-style: none; outline: none;
  border-radius: 4px;
  background: #161b22;
  border-left: 3px solid #30363d;
  display: flex; align-items: center;
}
details.nav-group > summary.nav-group-title:hover { background: #1c2128; border-left-color: #58a6ff; }
details.nav-group[open] > summary.nav-group-title { border-left-color: #58a6ff; }
details.nav-group > summary.nav-group-title::-webkit-details-marker { display: none; }
details.nav-group > summary.nav-group-title::before {
  content: '\25BE'; display: inline-block; width: 12px; margin-right: 6px;
  font-size: 10px; transition: transform 0.15s; color: #8b949e;
}
details.nav-group:not([open]) > summary.nav-group-title::before { transform: rotate(-90deg); }
details.nav-group[open] > a { padding-left: 18px; }
.nav-sep { border-top: 1px solid #21262d; margin: 12px 0; }

/* Sidebar collapse toggle */
.sidebar-toggle {
  position: fixed; top: 10px; left: 10px; z-index: 100;
  background: #21262d; color: #c9d1d9; border: 1px solid #30363d;
  width: 34px; height: 34px; border-radius: 6px; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-toggle:hover { background: #30363d; color: #fff; }
body.sidebar-collapsed .layout { display: block; }
body.sidebar-collapsed aside { display: none; }
body.sidebar-collapsed main { max-width: none; padding-top: 0; }
aside nav a {
  display: block; padding: 6px 10px; margin-bottom: 2px;
  border-radius: 4px; color: #c9d1d9; font-size: 12.5px; line-height: 1.4;
}
aside nav a:hover { background: #21262d; text-decoration: none; }
aside nav a.nav-home { font-weight: 600; color: #79c0ff; }
aside nav a.nav-nutrition { font-weight: 600; color: #4ade80; }
aside nav a.nav-raceday { font-weight: 600; color: #fb923c; margin-bottom: 4px; }
aside nav a.active,
aside nav a.active:hover { background: #1f6feb; color: #fff; }
aside nav a.nav-home.active,
aside nav a.nav-nutrition.active,
aside nav a.nav-raceday.active { color: #fff; }
.nav-dot { color: #484f58; margin-right: 6px; }
aside nav a.active .nav-dot { color: #fff; }

main { padding: 0; max-width: 980px; min-width: 0; }

/* Sticky top bar */
.sticky-bar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.96); backdrop-filter: blur(8px);
  border-bottom: 1px solid #d0d7de;
  padding: 10px 48px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
}
.sb-back { color: #1f6feb; font-weight: 600; white-space: nowrap; }
.sb-sep { color: #d0d7de; }
.sb-current { flex: 1; color: #656d76; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-current strong { color: #1f2328; }
.sb-nav { display: flex; gap: 10px; white-space: nowrap; }
.sb-nav a { color: #656d76; font-size: 12px; }
.sb-nav a.disabled { opacity: 0.3; pointer-events: none; }

/* Hero */
#top { padding: 40px 48px; }
.hero {
  background: linear-gradient(135deg, #1f6feb 0%, #0d1117 100%);
  color: #fff; padding: 32px 36px; border-radius: 12px; margin-bottom: 16px;
}

/* TCM medication-period strip — shown only during an active TCM window */
.tcm-strip {
  background: linear-gradient(90deg, #2d7a4e 0%, #1a4d33 100%);
  color: #d4f0dc; padding: 14px 20px; border-radius: 10px; margin: 0 0 24px;
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
  font-size: 13px; border-left: 4px solid #4ade80;
}
.tcm-strip .tcm-badge { font-weight: 700; color: #fff; font-size: 14px; }
.tcm-strip .tcm-day { background: rgba(255,255,255,0.15); padding: 3px 10px; border-radius: 12px; color: #fff; font-variant-numeric: tabular-nums; }
.tcm-strip .tcm-prescription { color: #a8e6c0; font-size: 12px; flex-basis: 100%; margin-top: 2px; }
.tcm-strip .tcm-doctor { color: #7dd3a3; font-size: 11px; }
.tcm-doc { margin: 0 48px 16px; }
@media (max-width: 768px) {
  .tcm-doc { margin: 0 16px 12px; }
}
.hero-label { font-size: 12px; color: #79c0ff; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; font-weight: 600; }
.hero-title { font-size: 28px; font-weight: 700; margin: 0 0 8px; }
.hero-count { font-size: 56px; font-weight: 800; line-height: 1; margin: 12px 0; }
.hero-sub { font-size: 14px; color: #c9d1d9; }
.hero-stats { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 18px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,0.15); }
.hero-stat { font-size: 12px; color: #79c0ff; }
.hero-stat strong { display: block; font-size: 18px; color: #fff; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hero-cta {
  display: inline-block; margin-top: 20px; margin-right: 12px; padding: 12px 22px;
  background: #fff; color: #0d1117; border-radius: 6px; font-weight: 600;
  transition: transform 0.15s;
}
.hero-cta:hover { transform: translateY(-2px); text-decoration: none; }
.hero-cta.green { background: #4ade80; color: #0d1117; }

/* Nutrition dashboard & Race day sections */
.nutrition-section, .race-day-section { padding: 0 48px; margin-bottom: 40px; scroll-margin-top: 64px; }
.nd-title { font-size: 22px; font-weight: 700; margin: 0 0 8px; color: #1f2328; }
.nd-sub { font-size: 13px; color: #656d76; margin-bottom: 20px; }
.nd-card { background: #fff; border: 1px solid #d0d7de; border-radius: 8px; padding: 20px 24px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.02); }
.nd-card h3 { margin: 0 0 14px; font-size: 16px; border: none; padding: 0; }
.nd-table { width: 100%; border-collapse: collapse; font-size: 13.5px; display: table; }
.nd-table thead { background: #f6f8fa; }
.nd-table th { font-weight: 600; padding: 10px 12px; text-align: left; border-bottom: 2px solid #d0d7de; }
.nd-table td { padding: 10px 12px; border-bottom: 1px solid #eaeef2; vertical-align: top; }
.nd-table tbody tr:hover { background: #f6f8fa; }
.nd-table tfoot td { border-bottom: none; padding-top: 12px; border-top: 2px solid #d0d7de; background: #f6f8fa; }
.nd-table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }
.nd-table .meal-tag { display: inline-block; background: #1f6feb; color: #fff; padding: 3px 10px; border-radius: 12px; font-weight: 700; text-align: center; min-width: 32px; }
.nd-table .meal-time { color: #656d76; font-family: ui-monospace, monospace; white-space: nowrap; }
.nd-table .date-cell { font-weight: 600; white-space: nowrap; }
.nd-table .note-cell { color: #424a53; font-size: 12.5px; }
.nd-table .qty-cell { font-weight: 700; color: #1f6feb; white-space: nowrap; }
.intensity-badge { display: inline-block; padding: 3px 10px; border-radius: 12px; color: #fff; font-weight: 700; font-size: 11.5px; white-space: nowrap; }
.nd-table tr.completed td { text-decoration: line-through; color: #9ca3af; opacity: 0.6; }
.nd-table tr.completed .intensity-badge { opacity: 0.5; text-decoration: none; }
body.dark .nd-table tr.completed td { color: #6e7681; }
.nd-note { margin-top: 14px; padding: 10px 14px; background: #f6f8fa; border-left: 3px solid #1f6feb; font-size: 12.5px; color: #424a53; border-radius: 4px; }
.nd-loading ul { margin: 0; padding-left: 22px; }
.nd-loading li { margin-bottom: 8px; font-size: 13.5px; }
.shopping-table .item-spec { font-size: 11.5px; color: #656d76; font-family: ui-monospace, monospace; margin-top: 2px; }

/* Race timeline */
.race-timeline { display: flex; flex-direction: column; gap: 6px; }
.tl-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-radius: 6px; background: #f6f8fa; border-left: 4px solid transparent; }
.tl-pre  { border-left-color: #6b7280; }
.tl-swim { border-left-color: #06b6d4; background: rgba(6,182,212,0.06); }
.tl-bike { border-left-color: #f97316; background: rgba(249,115,22,0.06); }
.tl-run  { border-left-color: #ef4444; background: rgba(239,68,68,0.06); }
.tl-emoji { font-size: 22px; line-height: 1.3; width: 28px; text-align: center; flex-shrink: 0; }
.tl-content { flex: 1; min-width: 0; }
.tl-time { font-size: 11.5px; color: #656d76; margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.tl-phase { display: inline-block; padding: 1px 8px; border-radius: 10px; color: #fff; font-weight: 700; font-size: 10px; margin-right: 8px; letter-spacing: 0.5px; }
.tl-action { font-size: 13.5px; font-weight: 600; color: #1f2328; margin-bottom: 4px; line-height: 1.4; }
.tl-nums { font-size: 11px; color: #656d76; display: flex; gap: 14px; flex-wrap: wrap; font-family: ui-monospace, monospace; }

/* Totals */
.nd-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 16px; }
.nd-total-item { background: linear-gradient(135deg, #1f6feb 0%, #0d1117 100%); color: #fff; padding: 16px; border-radius: 8px; text-align: center; }
.nd-total-label { display: block; font-size: 10px; opacity: 0.8; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.nd-total-value { display: block; font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Doc page */
.doc {
  background: #fff; padding: 32px 40px; border-radius: 8px;
  margin: 24px 48px 32px; border: 1px solid #d0d7de;
}
.meta-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px dashed #d0d7de; font-size: 12px; }
.file-tag {
  font-family: ui-monospace, monospace; font-size: 11px;
  color: #656d76; background: #eaeef2; padding: 3px 8px; border-radius: 4px;
}
.doc h1, .doc h2, .doc h3, .doc h4 { margin-top: 24px; margin-bottom: 12px; font-weight: 600; line-height: 1.3; }
.doc h1 { font-size: 26px; border-bottom: 2px solid #d0d7de; padding-bottom: 10px; margin-top: 0; }
.doc h2 { font-size: 20px; border-bottom: 1px solid #d0d7de; padding-bottom: 6px; }
.doc h3 { font-size: 17px; }
.doc h4 { font-size: 14px; color: #424a53; }
.doc p { margin: 0 0 12px; }
.doc ul, .doc ol { padding-left: 26px; margin: 0 0 12px; }
.doc li { margin-bottom: 3px; }
.doc blockquote { border-left: 4px solid #d0d7de; color: #656d76; margin: 0 0 12px; padding: 4px 14px; background: #f6f8fa; }
.doc code { font-family: ui-monospace, monospace; font-size: 13px; background: rgba(175,184,193,0.2); padding: 2px 6px; border-radius: 4px; }
.doc pre { background: #f6f8fa; padding: 14px; border-radius: 6px; overflow-x: auto; border: 1px solid #d0d7de; margin: 0 0 12px; }
.doc pre code { background: none; padding: 0; }
.doc table { border-collapse: collapse; margin: 0 0 14px; font-size: 13.5px; width: 100%; display: block; overflow-x: auto; }
.doc table thead { background: #f6f8fa; }
.doc th, .doc td { border: 1px solid #d0d7de; padding: 7px 11px; text-align: left; vertical-align: top; }
.doc th { font-weight: 600; }
.doc tr:nth-child(even) { background: #fafbfc; }
.doc hr { border: none; border-top: 1px solid #d0d7de; margin: 20px 0; }
.doc strong { color: #1f2328; }

/* Footer */
.footer { text-align: center; color: #656d76; font-size: 12px; padding: 20px 0 40px; }

/* Category cards (used on index only, below nutrition/raceday) */
.cat-section { margin-bottom: 40px; padding: 0 48px; }
.cat-title { font-size: 18px; margin: 0 0 4px; }
.cat-subtitle { font-size: 13px; color: #656d76; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card {
  background: #fff; padding: 16px 20px; border-radius: 8px;
  border: 1px solid #d0d7de; display: block; transition: all 0.15s;
  position: relative;
}
.card:hover { border-color: #0969da; text-decoration: none; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.card-title { font-size: 15px; font-weight: 700; color: #1f2328; margin-bottom: 6px; }
.card-desc { font-size: 13px; color: #424a53; line-height: 1.5; margin-bottom: 10px; }
.card-meta { font-size: 11px; color: #656d76; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card-file { font-family: ui-monospace, monospace; font-size: 10.5px; opacity: 0.7; }
.badge-star {
  position: absolute; top: -10px; right: 12px;
  background: #f85149; color: #fff; font-size: 11px; font-weight: 700;
  padding: 4px 10px; border-radius: 12px;
}

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  aside { position: static; height: auto; }
  #top { padding: 20px 16px; }
  .doc { margin: 12px; padding: 20px 18px; }
  .hero-count { font-size: 42px; }
  .cards { grid-template-columns: 1fr; }
  .sticky-bar { padding: 8px 12px; gap: 8px; font-size: 12px; flex-wrap: wrap; }
  .sb-current { order: 3; flex-basis: 100%; font-size: 11px; }
  .nutrition-section, .race-day-section, .cat-section { padding: 0 12px; }
  .nd-card { padding: 14px; }
  .nd-table { font-size: 12px; }
  .nd-table td, .nd-table th { padding: 7px 6px; }
  .nd-table .note-cell { font-size: 11.5px; }
  .tl-item { padding: 8px 10px; }
  .tl-action { font-size: 13px; }
  .tl-nums { font-size: 10.5px; gap: 10px; }
  .nd-total-value { font-size: 20px; }
}

@media print {
  aside, .sticky-bar, .theme-toggle, .sidebar-toggle { display: none; }
  .layout { grid-template-columns: 1fr; }
  .doc, .nd-card { page-break-inside: avoid; border: none; box-shadow: none; }
  body { background: #fff; }
}

/* Theme toggle button */
.theme-toggle {
  position: fixed; bottom: 20px; right: 20px;
  background: #24292f; color: #fff; border: none;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  font-size: 18px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 100;
}

/* Dark mode */
body.dark { background: #0d1117; color: #c9d1d9; }
body.dark .card { background: #161b22; border-color: #30363d; }
body.dark .card:hover { border-color: #1f6feb; }
body.dark .card-title { color: #f0f6fc; }
body.dark .card-desc { color: #8b949e; }
body.dark .doc { background: #161b22; border-color: #30363d; }
body.dark .doc h1, body.dark .doc h2 { border-color: #30363d; }
body.dark .doc blockquote { background: #0d1117; border-color: #30363d; color: #8b949e; }
body.dark .doc code, body.dark .doc pre { background: #0d1117; border-color: #30363d; }
body.dark .doc th { background: #0d1117; }
body.dark .doc th, body.dark .doc td { border-color: #30363d; }
body.dark .doc tr:nth-child(even) { background: #161b22; }
body.dark .file-tag { background: #21262d; color: #8b949e; }
body.dark .cat-subtitle { color: #8b949e; }
body.dark .doc strong { color: #f0f6fc; }
body.dark a { color: #58a6ff; }
body.dark .sticky-bar { background: rgba(22,27,34,0.96); border-color: #30363d; }
body.dark .sb-current strong { color: #f0f6fc; }
body.dark .sb-sep { color: #30363d; }
body.dark .nd-card { background: #161b22; border-color: #30363d; }
body.dark .nd-title { color: #f0f6fc; }
body.dark .nd-sub { color: #8b949e; }
body.dark .nd-table thead { background: #0d1117; }
body.dark .nd-table th { border-color: #30363d; color: #f0f6fc; }
body.dark .nd-table td { border-color: #21262d; color: #c9d1d9; }
body.dark .nd-table tbody tr:hover { background: #0d1117; }
body.dark .nd-table tfoot td { background: #0d1117; border-color: #30363d; }
body.dark .nd-table .note-cell { color: #8b949e; }
body.dark .nd-note { background: #0d1117; color: #8b949e; }
body.dark .tl-item { background: #0d1117; }
body.dark .tl-action { color: #f0f6fc; }
body.dark .tl-nums { color: #8b949e; }
body.dark .theme-toggle { background: #f6f8fa; color: #24292f; }
