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

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #1a1a1a;
  --surface-3: #222222;
  --border: #222222;
  --border-2: #2e2e2e;
  --accent: #7c6af7;
  --accent-dim: rgba(124, 106, 247, 0.15);
  --accent-glow: rgba(124, 106, 247, 0.35);
  --text: #f0f0f0;
  --text-muted: #888888;
  --text-dim: #555555;
  --danger: #e05252;
  --success: #4caf82;
  --radius: 6px;
  --radius-lg: 10px;
  --nav-h: 52px;
  --grid-cell: 11px;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Nav ── */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
}

.nav-logo {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  text-decoration: none;
  color: var(--text);
}

.nav-logo em { font-style: normal; color: var(--accent); }

.nav-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-2);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

.btn-danger {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}
.btn-danger:hover { color: var(--danger); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-muted);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Layout ── */
.page {
  padding-top: calc(var(--nav-h) + 2.5rem);
  padding-bottom: 5rem;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── Section headers ── */
.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

/* ── Today header ── */
.today-header {
  margin-bottom: 2rem;
}

.today-date {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  margin-bottom: 0.3rem;
}

.today-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.today-sub .accent-text { color: var(--accent); }

/* ── Progress bar ── */
.progress-wrap {
  margin: 1.25rem 0 2rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(0.4,0,0.2,1);
  width: 0%;
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: right;
}

/* ── Habit list ── */
.habit-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1rem;
}

.habit-row {
  padding: 1rem 1.25rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  position: relative;
}

.habit-row:last-child { border-bottom: none; }

.habit-row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}

.habit-row.done::before { opacity: 1; }
.habit-row.done { background: var(--surface-2); }

/* ── Checkbox ── */
.habit-check {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-2);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-content: center;
  transition: all 0.15s;
  background: transparent;
}

.habit-check:hover { border-color: var(--accent); }

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

.habit-check:checked::after {
  content: '';
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
  display: block;
}

/* ── Habit info ── */
.habit-info {
  flex: 1;
  min-width: 0;
}

.habit-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  transition: color 0.15s;
}

.habit-row.done .habit-name {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
}

.habit-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--accent);
  font-weight: 700;
}

.streak-badge.cold { color: var(--text-dim); }

/* ── Note area ── */
.habit-row-main {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.note-area {
  display: none;
  padding: 0.4rem 1.25rem 0 calc(1.25rem + 18px + 0.9rem);
}

.note-area.open { display: block; }

.note-input {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  outline: none;
  resize: none;
  overflow: hidden;
  min-height: 36px;
  line-height: 1.55;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}

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

.note-input::placeholder { color: var(--text-dim); }

.note-preview {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.72rem;
}

/* ── History button ── */
.btn-history {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-dim);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-history:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Add habit ── */
.add-habit-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.add-habit-form.hidden { display: none; }

.habit-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.habit-input:focus { border-color: var(--accent); }
.habit-input::placeholder { color: var(--text-dim); }

/* ── FAB ── */
.habit-list-header {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 0.6rem;
}

.add-habit-fab {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(124,106,247,0.4);
  transition: background 0.15s, transform 0.15s;
}

.add-habit-fab:hover {
  background: #9080ff;
  transform: scale(1.1);
}

/* ── Section divider ── */
.section-gap { margin-top: 3rem; }

/* ── Grid section ── */
.grid-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.grid-habit-select {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  outline: none;
  cursor: pointer;
}

.grid-habit-select:focus { border-color: var(--accent); }
.grid-habit-select option { background: var(--surface-2); }

/* ── Contribution grid ── */
.contrib-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  overflow-x: auto;
}

.contrib-month-labels {
  display: flex;
  gap: 0;
  margin-bottom: 0.35rem;
  padding-left: 28px;
}

.contrib-month-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  flex-shrink: 0;
  user-select: none;
}

.contrib-body {
  display: flex;
  gap: 0.35rem;
}

.contrib-day-labels {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 0.35rem;
  flex-shrink: 0;
}

.contrib-day-label {
  font-size: 0.6rem;
  color: var(--text-dim);
  height: var(--grid-cell);
  display: flex;
  align-items: center;
  user-select: none;
  width: 22px;
}

.contrib-grid {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.contrib-week {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.contrib-cell {
  width: var(--grid-cell);
  height: var(--grid-cell);
  border-radius: 2px;
  background: var(--surface-3);
  cursor: pointer;
  transition: opacity 0.1s;
  position: relative;
  flex-shrink: 0;
}

.contrib-cell:hover { opacity: 0.8; }

.contrib-cell[data-level="0"] { background: var(--surface-3); }
.contrib-cell[data-level="1"] { background: rgba(124,106,247,0.25); }
.contrib-cell[data-level="2"] { background: rgba(124,106,247,0.55); }
.contrib-cell[data-level="3"] { background: rgba(124,106,247,0.8); }
.contrib-cell[data-level="4"] { background: var(--accent); }

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

.contrib-cell.future { background: transparent; cursor: default; }

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  color: var(--text);
  font-size: 0.7rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  display: none;
}

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 1rem;
}

.stat-box {
  padding: 1.25rem;
  text-align: center;
  background: var(--surface);
}

.stat-box + .stat-box { border-left: 1px solid var(--border); }

.stat-box-num {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--accent);
  line-height: 1;
}

.stat-box-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ── Principles callout ── */
.principles-strip {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 3rem;
}

.principles-header {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.principles-header-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.principles-header-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.principles-chevron {
  color: var(--text-dim);
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.principles-header.open .principles-chevron { transform: rotate(180deg); }

.principles-body {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
}

.principles-body.open { display: grid; }

.principle-card {
  background: var(--surface);
  padding: 1.25rem;
}

.principle-num {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.principle-title {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.principle-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ── Empty state ── */
.empty-state {
  padding: 2.5rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.empty-state strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

/* ── All-done state ── */
.all-done-banner {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: rgba(76,175,130,0.08);
  border: 1px solid rgba(76,175,130,0.25);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--success);
  font-weight: 600;
}

.all-done-banner.visible { display: flex; }

/* ── Legend ── */
.grid-legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  justify-content: flex-end;
}

.legend-label { font-size: 0.65rem; color: var(--text-dim); }

.legend-cell {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ── Manage habits panel ── */
.manage-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.manage-row:last-child { border-bottom: none; }

.manage-name {
  font-size: 0.85rem;
  font-weight: 600;
  flex: 1;
}

.manage-actions { display: flex; gap: 0.4rem; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 400px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.modal-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.modal-field { margin-bottom: 0.85rem; }

.modal-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.modal-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus { border-color: var(--accent); }
.modal-input::placeholder { color: var(--text-dim); }

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ── Day modal habit list ── */
.day-habit-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.day-habit-row {
  padding: 0.85rem 1.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  position: relative;
}

.day-habit-row:last-child { border-bottom: none; }

.day-habit-row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}

.day-habit-row.done::before { opacity: 1; }
.day-habit-row.done { background: var(--surface-2); }

.day-habit-row .note-area {
  padding-left: calc(18px + 0.9rem);
}

/* ── Manage meta ── */
.manage-meta {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: 0.6rem;
}

/* ── Wide modal (timeline) ── */
.modal-wide {
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.tl-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tl-stats {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tl-stat {
  flex: 1;
  padding: 0.85rem 1rem;
  text-align: center;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35rem;
}

.tl-stat + .tl-stat { border-left: 1px solid var(--border); }

.tl-stat-num {
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.tl-stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tl-list {
  overflow-y: auto;
  flex: 1;
  padding: 1rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tl-month {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 1rem 0 0.5rem;
}

.tl-month:first-child { padding-top: 0; }

.tl-entry {
  display: flex;
  gap: 0.85rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.tl-entry:last-child { border-bottom: none; }

.tl-entry-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-2);
  margin-top: 0.35rem;
  flex-shrink: 0;
  transition: background 0.15s;
}

.tl-entry.has-note .tl-entry-dot { background: var(--accent); }

.tl-entry-body { flex: 1; min-width: 0; }

.tl-entry-date {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tl-today-tag {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  letter-spacing: 0.04em;
}

.tl-entry-note {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.tl-entry-no-note {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
}

.tl-empty {
  padding: 2rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .stats-row { grid-template-columns: 1fr; }
  .stat-box + .stat-box { border-left: none; border-top: 1px solid var(--border); }
  .principles-body { grid-template-columns: 1fr; }
}
