:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-card: #1e293b;
  --bg-card-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #22d3ee;
  --accent-2: #06b6d4;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --tab-h: 64px;
  --header-h: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

/* Header */
.app-header {
  padding: calc(var(--safe-top) + 14px) 16px 12px 16px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}
.header-row { display: flex; justify-content: space-between; align-items: center; }
.date { color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
.title { font-size: 24px; font-weight: 700; margin-top: 2px; }
.streak-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card-2);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
}
.streak-flame { font-size: 16px; }
.streak-num { font-size: 16px; }

/* Views */
.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px calc(var(--tab-h) + var(--safe-bottom) + 24px) 16px;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: block; }

.section { margin-top: 18px; }
.section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 10px 4px;
  font-weight: 600;
}

/* Slot (time-of-day) cards */
.slot {
  margin-bottom: 18px;
}
.slot-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px;
  margin-bottom: 8px;
}
.slot-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 600;
}
.slot-emoji { font-size: 20px; }
.slot-time { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.slot-progress {
  font-size: 12px; color: var(--text-muted);
  background: var(--bg-card); padding: 4px 10px; border-radius: 999px;
}

/* Exercise card */
.ex-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background .15s, border-color .15s;
}
.ex-card.done { background: var(--bg); border-color: var(--border); opacity: 0.55; }
.ex-card.done .ex-name { text-decoration: line-through; color: var(--text-muted); }

.ex-check {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.ex-check:active { transform: scale(0.9); }
.ex-card.done .ex-check {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.ex-check::after { content: ""; }
.ex-card.done .ex-check::after { content: "✓"; font-size: 16px; font-weight: 700; }

.ex-body { flex: 1; min-width: 0; }
.ex-name { font-weight: 600; font-size: 15px; }
.ex-details { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.ex-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 6px;
  background: var(--bg-card-2); color: var(--text-muted);
}
.tag.optional { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

.ex-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--bg-card-2); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 10px;
  border: 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--accent); color: #042f3a; }
.btn.primary:active { background: var(--accent-2); }
.btn.ghost { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:active { background: var(--bg-card-2); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.row-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

/* Cards & forms */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.form-row { display: flex; gap: 10px; margin: 10px 0; }
.form-row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
input[type="text"], input[type="url"], input[type="number"], input[type="time"], textarea, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; }

.hint { color: var(--text-muted); font-size: 13px; margin: 8px 0 0 0; }
.hint.center { text-align: center; }

/* Plan list */
.plan-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.plan-item .ex-body { flex: 1; }

/* Avoid list */
.avoid-card ul { margin: 0; padding-left: 20px; }
.avoid-card li { margin: 4px 0; color: var(--text-muted); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; }

/* Calendar */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 16px; }
.cal-day {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-dim);
  cursor: pointer;
  border: 1px solid transparent;
}
.cal-day.has-data { color: var(--text); }
.cal-day.full { background: var(--success); color: white; font-weight: 600; }
.cal-day.partial { background: rgba(34, 197, 94, 0.3); color: var(--text); }
.cal-day.today { border-color: var(--accent); }

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
}
.tab.active { color: var(--accent); }
.tab-icon { font-size: 22px; }
.tab-label { font-size: 11px; font-weight: 500; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--bg-elev);
  width: 100%; max-width: 600px;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(var(--safe-bottom) + 16px) 16px;
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp .2s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { margin: 0 0 12px 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { flex: 1; }

/* Timer modal */
.timer-display {
  font-size: 56px;
  font-weight: 700;
  text-align: center;
  margin: 24px 0;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.timer-controls { display: flex; gap: 8px; justify-content: center; }

/* Empty states */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-emoji { font-size: 48px; margin-bottom: 12px; }
