:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: rgba(0, 0, 0, 0.06);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.1);
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.04);
  --nav-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

/* Hero */
.hero {
  padding: 28px 4px 20px;
  animation: fadeUp 0.6s ease both;
}

.hero-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  margin-bottom: 12px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 7vw, 36px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero-sub {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 16px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-pill {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-pill .val {
  display: block;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-pill .lbl {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.progress-ring-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 20px;
}

.ring-svg {
  flex-shrink: 0;
}

.ring-label {
  flex: 1;
}

.ring-label strong {
  display: block;
  font-size: 18px;
  margin-bottom: 4px;
}

.ring-label span {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Panels */
.panel {
  display: none;
  animation: fadeUp 0.4s ease both;
}

.panel.active {
  display: block;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin: 28px 0 12px;
}

.section-label:first-child {
  margin-top: 8px;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.card-value small {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.card-note {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 400px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Today card */
.today-hero-card {
  background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(0, 122, 255, 0.25);
}

.today-hero-card.rest-day {
  background: linear-gradient(135deg, #8e8e93 0%, #636366 100%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.today-hero-card.sleep-week {
  background: linear-gradient(135deg, #5e5ce6 0%, #bf5af2 100%);
  box-shadow: 0 8px 32px rgba(94, 92, 230, 0.25);
}

.today-date {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 8px;
}

.today-sport {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.today-meta {
  font-size: 14px;
  opacity: 0.9;
  line-height: 1.6;
}

.today-note {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 13px;
  opacity: 0.85;
}

/* Tracking inputs */
.track-section {
  margin-top: 16px;
}

.track-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.track-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.2s;
}

.track-row input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 12px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--bg);
  color: var(--accent);
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.checklist li:last-child {
  border-bottom: none;
}

.check-box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid #d1d1d6;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-top: 1px;
}

.check-box.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.check-box.checked::after {
  content: "✓";
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.recent-logs {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.recent-logs div {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

/* Phase timeline */
.phase-timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.phase-block {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--accent);
}

.phase-block.current {
  border-left-color: var(--green);
  background: linear-gradient(90deg, rgba(52, 199, 89, 0.06), var(--surface));
}

.phase-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.phase-theme {
  font-weight: 600;
  margin-bottom: 2px;
}

.phase-focus {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Charts & bars */
.chart-card {
  padding: 12px 8px 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-name {
  font-size: 13px;
  font-weight: 500;
}

.bar-track {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease;
}

.bar-val {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: right;
}

/* Calendar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 8px 0 12px;
  z-index: 10;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.calendar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cal-day {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.cal-day.today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cal-day.past {
  opacity: 0.65;
}

.cal-date-num {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.cal-date-sub {
  font-size: 11px;
  color: var(--text-tertiary);
}

.cal-sport-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sport-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.cal-duration {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-align: right;
}

/* Nutrition */
.macro-grid {
  display: flex;
  justify-content: space-around;
  gap: 8px;
}

.macro-item {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.macro-ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px;
  font-size: 12px;
  font-weight: 700;
}

.macro-ring span {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.meal-grid {
  display: grid;
  gap: 10px;
}

.meal-card h4 {
  margin: 4px 0 8px;
  font-size: 16px;
}

.meal-time {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.meal-options {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-secondary);
}

.meal-options li {
  margin-bottom: 4px;
}

.meal-kcal {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

.bullet-list {
  margin: 0;
  padding-left: 20px;
}

.bullet-list li {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.tag-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-list li {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.tag-list li.avoid {
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.2);
  background: rgba(255, 59, 48, 0.05);
}

/* Sleep */
.sleep-intro {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.bedtime-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.bedtime-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.bedtime-item.current {
  outline: 2px solid #5e5ce6;
}

.bedtime-item.done {
  opacity: 0.55;
}

.bedtime-time {
  font-weight: 700;
  color: #5e5ce6;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  padding: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.2s;
  min-width: 56px;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 18px;
  line-height: 1;
}

/* Loading & error */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}

.error {
  color: var(--red);
  background: rgba(255, 59, 48, 0.08);
  padding: 16px;
  border-radius: var(--radius-sm);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
