:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --done: #a3e635;
  --done-text: #1a2e05;
  --dot-bg: #eceef1;
  --dot-icon: #9aa3ae;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --panel: #1c1f24;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --border: #2d3138;
    --accent: #60a5fa;
    --warn-bg: #451a03;
    --warn-text: #fbbf24;
    --done: #84cc16;
    --done-text: #0b1503;
    --dot-bg: #24282e;
    --dot-icon: #626b77;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar-left { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { font-size: 1.05rem; font-weight: 700; }
.topnav { display: flex; gap: 6px; }
.topnav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 8px;
}
.topnav a:hover { color: var(--text); background: var(--bg); }
.topnav a.is-active { color: var(--accent); background: var(--bg); font-weight: 600; }

.link-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.link-btn:hover { color: var(--text); border-color: var(--accent); }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.sync-banner {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.sync-banner--warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}

.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-value .unit { font-size: 1rem; font-weight: 400; color: var(--text-muted); }
.stat-sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.panel { margin-bottom: 24px; }
.panel h2 { font-size: 1rem; margin: 0 0 14px; }

.empty { color: var(--text-muted); font-size: 0.9rem; }

.pr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.pr-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.pr-label { color: var(--text-muted); font-size: 0.8rem; }
.pr-value { font-size: 1.3rem; font-weight: 700; margin: 4px 0; }
.pr-date { color: var(--text-muted); font-size: 0.75rem; }

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.activity-table th, .activity-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.activity-table th { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; }

@media (max-width: 640px) {
  .activity-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ── 月曆 ───────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 18px;
}
.month-title { font-size: 1.1rem; margin: 0; min-width: 9em; text-align: center; }

.month-picker { display: flex; gap: 8px; align-items: center; }
.month-select {
  appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 30px 8px 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  /* 自繪箭頭：各瀏覽器原生樣式差異大，統一外觀 */
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.month-select:hover { border-color: var(--accent); }
.month-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.month-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 1.3rem;
  line-height: 1;
}
.month-arrow:hover { border-color: var(--accent); color: var(--accent); }
.month-arrow.is-disabled { opacity: 0.3; cursor: default; }

.month-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.month-stat { text-align: center; }
.month-stat-value { font-size: 1.6rem; font-weight: 700; }
.month-stat-value .unit { font-size: 0.85rem; font-weight: 400; color: var(--text-muted); margin-left: 3px; }
.month-stat-label { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }

.cal-head, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-head { margin-bottom: 8px; }
.cal-head-cell {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.cal-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0 8px;
  border-radius: 10px;
}
.cal-cell.is-empty { visibility: hidden; }
.cal-cell.is-today { background: var(--bg); }
.cal-dot {
  width: 42px;
  height: 42px;
  max-width: 100%;
  border-radius: 50%;
  background: var(--dot-bg);
  color: var(--dot-icon);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-dot.is-done { background: var(--done); color: var(--done-text); }
.cal-dot.is-future { opacity: 0.4; }
.cal-icon { width: 22px; height: 22px; }
.cal-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-height: 1em;
  text-align: center;
  white-space: nowrap;
}

@media (max-width: 560px) {
  .cal-dot { width: 34px; height: 34px; }
  .cal-icon { width: 18px; height: 18px; }
  .cal-label { font-size: 0.62rem; }
  .month-stat-value { font-size: 1.3rem; }
}

/* ── 月報 ───────────────────────── */
.report-title { font-size: 1.3rem; margin: 0 0 10px; }
.report-header .coach-headline { margin-bottom: 0; }

/* ── 教練分析 ───────────────────────── */
.coach-headline {
  font-size: 0.95rem;
  margin: 0 0 16px;
  line-height: 1.6;
}

.coach-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.coach-metrics > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.cm-label { color: var(--text-muted); font-size: 0.75rem; }
.cm-value { font-size: 1.05rem; font-weight: 600; }

.zone-block { margin-bottom: 18px; }
.zone-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.zone-legend { font-size: 0.78rem; }
.zone-bar {
  display: flex;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
}
.zone-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: #fff;
  min-width: 2px;
}
.zone-1 { background: #6b7fd7; }
.zone-2 { background: #3fa796; }
.zone-3 { background: #d9a441; }
.zone-4 { background: #d97036; }
.zone-5 { background: #c9453d; }

.narrative {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: var(--bg);
}
.narrative-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.narrative-title { font-weight: 600; font-size: 0.92rem; }
.narrative-badge {
  font-size: 0.68rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}
.narrative-body { font-size: 0.9rem; line-height: 1.8; }
.narrative-body p { margin: 0 0 10px; }
.narrative-body p:last-child { margin-bottom: 0; }
.narrative-loading, .narrative-error { color: var(--text-muted); font-size: 0.87rem; }

.findings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.finding {
  border-left: 3px solid var(--border);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  background: var(--bg);
}
.finding.is-action { border-left-color: #dc2626; }
.finding.is-watch { border-left-color: #d97706; }
.finding.is-good { border-left-color: #16a34a; }
.finding-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 3px; }
.finding-detail { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 5px; }
.finding-suggestion { font-size: 0.87rem; line-height: 1.6; }

.coach-note {
  margin: 18px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.coach-note code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.95em;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.2rem; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }
.login-card input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.login-card button {
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
.login-error { color: #dc2626; font-size: 0.85rem; margin: 0; }

.error-page { max-width: 480px; margin: 80px auto; text-align: center; }
