:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1a1a2e;
  --text2: #8892a4;
  --border: rgba(0,0,0,0.06);
  --shadow: 0 2px 16px rgba(0,0,0,0.07);
  --radius: 20px;
  --accent: #6c63ff;
  --nav-h: 68px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

/* ── Header ─────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 var(--border);
}

.header-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-date {
  font-size: 0.8rem;
  color: var(--text2);
  font-weight: 500;
}

/* ── Tab Panes ──────────────────────────────────────── */
.tab-panes {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--nav-h);
}

.tab-pane {
  display: none;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.tab-pane.active { display: block; }

#pane-stats.active { display: flex; flex-direction: column; gap: 14px; }

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

/* ── Week Strip (Today) ─────────────────────────────── */
.week-strip {
  display: flex;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 10px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.strip-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.strip-day {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.3px;
}

.strip-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f0f2f8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text2);
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.strip-item.today .strip-circle {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 800;
}

.strip-circle.done-full { background: #1dd1a1; color: #fff; }
.strip-circle.done-part { background: rgba(108,99,255,0.2); color: var(--accent); }

/* ── Today Progress ─────────────────────────────────── */
.today-progress {
  background: linear-gradient(135deg, #6c63ff, #a78fff);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(108,99,255,0.3);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.today-progress .prog-text { font-size: 0.85rem; font-weight: 600; opacity: 0.85; }
.today-progress .prog-count { font-size: 1.5rem; font-weight: 800; }
.today-progress .prog-bar-wrap {
  flex: 1;
  margin: 0 16px;
  height: 6px;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  overflow: hidden;
}
.today-progress .prog-bar {
  height: 100%;
  background: #fff;
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
}
.today-progress .prog-pct { font-size: 0.9rem; font-weight: 700; opacity: 0.9; }

/* ── Today List ─────────────────────────────────────── */
.today-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.today-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: opacity 0.25s, transform 0.15s;
  cursor: default;
}

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

.habit-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  color: #fff;
}

.habit-icon.sm {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1rem;
}

.habit-info { flex: 1; min-width: 0; }

.habit-title {
  font-size: 0.97rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.today-item.done .habit-title {
  text-decoration: line-through;
  color: var(--text2);
}

.habit-sub { font-size: 0.76rem; color: var(--text2); margin-top: 3px; }

.check-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #dde1ea;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
  transition: all 0.2s;
}

.check-btn.checked { border-color: transparent; }

/* ── Routines ───────────────────────────────────────── */
.routine-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 88px;
}

.routine-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.routine-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.routine-name { font-size: 0.97rem; font-weight: 700; color: var(--text); }
.routine-freq { font-size: 0.74rem; color: var(--text2); margin-top: 2px; }

.del-btn {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.3rem;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.del-btn:hover { background: #fff0f0; color: #ff6b6b; }

/* 7-day row */
.day-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 12px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.day-lbl {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--text2);
}

.day-circle {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f0f2f8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text2);
  border: 1.5px solid transparent;
  transition: all 0.2s;
}

.day-circle.done { color: #fff; }
.day-circle.today-ring { border-color: var(--accent); }

/* Routine progress bar */
.routine-prog-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.routine-pct {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text);
  min-width: 36px;
}

.routine-bar-track {
  flex: 1;
  height: 6px;
  background: #f0f2f8;
  border-radius: 999px;
  overflow: hidden;
}

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

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 18px);
  right: max(16px, calc(50vw - 240px + 16px));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6c63ff, #a78fff);
  color: #fff;
  border: none;
  font-size: 1.7rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(108,99,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 20;
  line-height: 1;
  padding-bottom: 2px;
}

.fab:hover { transform: scale(1.08); box-shadow: 0 6px 26px rgba(108,99,255,0.55); }
.fab:active { transform: scale(0.96); }

/* ── Calendar ───────────────────────────────────────── */
.cal-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.cal-month-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.2px;
}

.cal-nav-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background 0.2s;
}

.cal-nav-btn:hover { background: #eef0f8; }

.cal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 8px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text2);
  padding: 4px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.cal-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  position: relative;
}

.cal-cell:not(.empty)[style*="cursor"] { }
.cal-cell:not(.empty):hover { transform: scale(1.1); }

.cal-num {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  pointer-events: none;
}

.cal-cell.empty { background: transparent; }
.cal-cell.l0  { background: transparent; }
.cal-cell.l0 .cal-num { color: var(--text2); }
.cal-cell.l1  { background: rgba(255,159,67,0.18); }
.cal-cell.l2  { background: rgba(108,99,255,0.22); }
.cal-cell.l3  { background: rgba(84,160,255,0.28); }
.cal-cell.l4  { background: rgba(29,209,161,0.3); }
.cal-cell.l4 .cal-num { font-weight: 700; color: #0a8c6c; }

.cal-cell.today {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}

.cal-cell.today .cal-num { color: var(--accent); font-weight: 800; }

.cal-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text2);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.ld0 { background: #eef0f8; border: 1px solid #dde1ea; }
.ld1 { background: rgba(255,159,67,0.35); }
.ld2 { background: rgba(108,99,255,0.35); }
.ld3 { background: rgba(84,160,255,0.4); }
.ld4 { background: rgba(29,209,161,0.5); }

/* ── Stats ──────────────────────────────────────────── */
.card-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.stats-ring-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ring-wrap {
  position: relative;
  width: 150px;
  height: 150px;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg { fill: none; stroke: #eef0f8; stroke-width: 10; }

.ring-fg {
  fill: none;
  stroke: url(#ringGrad);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.4,0,0.2,1);
}

.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -1px;
}

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

.stats-mini-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px 12px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stats-num {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
}

.stats-desc { font-size: 0.74rem; color: var(--text2); margin-top: 5px; }

.stats-bar-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 110px;
  margin-top: 4px;
}

.bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
}

.bar-track {
  flex: 1;
  width: 100%;
  background: #f0f2f8;
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 8px;
  background: linear-gradient(180deg, #6c63ff 0%, #a78fff 100%);
  transition: height 0.7s cubic-bezier(0.4,0,0.2,1);
}

.bar-label {
  font-size: 0.68rem;
  color: var(--text2);
  font-weight: 600;
}

/* ── Bottom Nav ─────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.07);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
  background: none;
  border: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 8px 0;
  border-radius: 12px;
  transition: background 0.2s;
}

.nav-item:hover { background: #f5f6fa; }
.nav-icon { font-size: 1.3rem; filter: grayscale(1); transition: filter 0.2s; }
.nav-label { font-size: 0.68rem; font-weight: 600; color: var(--text2); transition: color 0.2s; }
.nav-item.active .nav-icon { filter: none; }
.nav-item.active .nav-label { color: var(--accent); }

/* ── Modals (bottom sheet) ──────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-backdrop.visible { opacity: 1; pointer-events: all; }

.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px 40px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34,1.2,0.64,1);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-backdrop.visible .modal-sheet { transform: translateY(0); }

.sheet-handle {
  width: 38px;
  height: 4px;
  background: #dde1ea;
  border-radius: 2px;
  margin: 0 auto 18px;
}

.sheet-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 18px;
}

.sheet-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid #dde1ea;
  border-radius: 14px;
  font-size: 0.97rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  margin-bottom: 18px;
  transition: border-color 0.2s;
}

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

.picker-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.color-picker, .icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  outline: none;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: #1a1a2e; transform: scale(1.15); }

.icon-swatch {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #f5f6fa;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.icon-swatch:hover { background: #eef0f8; }
.icon-swatch.selected { border-color: var(--accent); background: rgba(108,99,255,0.1); }

.sheet-footer {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.sheet-btn {
  flex: 1;
  padding: 14px;
  border-radius: 14px;
  border: none;
  font-size: 0.97rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.sheet-btn:hover { opacity: 0.86; }
.sheet-btn:active { transform: scale(0.98); }
.sheet-btn.cancel { background: #f0f2f8; color: var(--text2); }
.sheet-btn.confirm { background: linear-gradient(135deg, #6c63ff, #a78fff); color: #fff; box-shadow: 0 3px 14px rgba(108,99,255,0.35); }

/* Day modal content */
.day-summary {
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-pct {
  background: rgba(108,99,255,0.1);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.82rem;
  padding: 3px 10px;
  border-radius: 20px;
}

.day-habit-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.day-habit-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f8f9fc;
  border-radius: 12px;
  font-size: 0.9rem;
  color: var(--text2);
}

.day-habit-list li.done { color: var(--text); }
.day-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: #fff;
  flex-shrink: 0;
}

.day-check { margin-left: auto; font-weight: 700; }
.day-habit-list li.done .day-check { color: #1dd1a1; }

/* ── Storage Warning ────────────────────────────────── */
#storage-warn {
  background: #fff3cd;
  color: #856404;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 10px 16px;
  text-align: center;
  border-bottom: 1px solid #ffc107;
  line-height: 1.5;
}

/* ── Empty State ────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--text2);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 56px 24px;
}
