/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --border: #30363d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  /* Theme color (overridden by data-theme on body) */
  --theme: #39d353;
  --theme-dim: #26a641;
  --theme-dark: #006d32;
  --theme-darker: #0e4429;
  --accent: #8b949e;
  --danger: #f85149;
  --warning: #d29922;
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 200ms ease;
}

/* ── Theme color palettes ─────────────────────────────────────────────────── */
[data-theme="green"]  { --theme: #39d353; --theme-dim: #26a641; --theme-dark: #006d32; --theme-darker: #0e4429; }
[data-theme="teal"]   { --theme: #2dd4bf; --theme-dim: #14b8a6; --theme-dark: #0d7a6a; --theme-darker: #083f38; }
[data-theme="cyan"]   { --theme: #22d3ee; --theme-dim: #06b6d4; --theme-dark: #0e7490; --theme-darker: #083344; }
[data-theme="blue"]   { --theme: #60a5fa; --theme-dim: #3b82f6; --theme-dark: #1d4ed8; --theme-darker: #1a2744; }
[data-theme="purple"] { --theme: #a78bfa; --theme-dim: #8b5cf6; --theme-dark: #6d28d9; --theme-darker: #2a1a4e; }
[data-theme="pink"]   { --theme: #f472b6; --theme-dim: #ec4899; --theme-dark: #be185d; --theme-darker: #4a0d2e; }
[data-theme="orange"] { --theme: #fb923c; --theme-dim: #f97316; --theme-dark: #c2410c; --theme-darker: #431a07; }
[data-theme="yellow"] { --theme: #facc15; --theme-dim: #eab308; --theme-dark: #a16207; --theme-darker: #3b2506; }

/* ── Heat level classes (theme-aware) ─────────────────────────────────────── */
.heat-1 { background: var(--theme-darker) !important; border-color: var(--theme-darker) !important; }
.heat-2 { background: var(--theme-dark) !important; border-color: var(--theme-dark) !important; }
.heat-3 { background: var(--theme-dim) !important; border-color: var(--theme-dim) !important; }
.heat-4 { background: var(--theme) !important; border-color: var(--theme) !important; }

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

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;
}

a { color: var(--theme); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

[x-cloak] { display: none !important; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  color: var(--theme);
  font-size: 14px;
}

.header-title h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.main-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: color-mix(in srgb, var(--theme) 15%, transparent);
  color: var(--theme);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-date {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.logout-link {
  font-size: 13px;
}

/* ── Main content ──────────────────────────────────────────────────────────── */
.main-content {
  max-width: 1060px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

/* ── Progress bar ──────────────────────────────────────────────────────────── */
.progress-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.progress-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.progress-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--theme);
  font-variant-numeric: tabular-nums;
}

.progress-text {
  font-size: 14px;
  color: var(--text-muted);
}

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

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--theme-dark), var(--theme));
  border-radius: 99px;
  transition: width 400ms ease;
}

/* ── Habit list ────────────────────────────────────────────────────────────── */
.habits-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Done section ──────────────────────────────────────────────────────────── */
.habits-done-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 20px;
  opacity: 0.5;
  transition: opacity 200ms ease;
}

.habits-done-section:hover {
  opacity: 0.7;
}

.habits-done-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ── Breathing pulse on incomplete habit rows ─────────────────────────────── */
@keyframes habit-breathe {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50%       { box-shadow: 0 0 8px 1px color-mix(in srgb, var(--theme) 12%, transparent); }
}

#habits-incomplete .habit-row:not(.on-fire) {
  animation: habit-breathe 4s ease-in-out infinite;
}

/* Stagger the animation so they don't all pulse in sync */
#habits-incomplete .habit-row:nth-child(2) { animation-delay: 0.8s; }
#habits-incomplete .habit-row:nth-child(3) { animation-delay: 1.6s; }
#habits-incomplete .habit-row:nth-child(4) { animation-delay: 2.4s; }
#habits-incomplete .habit-row:nth-child(5) { animation-delay: 3.2s; }
#habits-incomplete .habit-row:nth-child(6) { animation-delay: 0.4s; }
#habits-incomplete .habit-row:nth-child(7) { animation-delay: 1.2s; }
#habits-incomplete .habit-row:nth-child(8) { animation-delay: 2.0s; }
#habits-incomplete .habit-row:nth-child(9) { animation-delay: 2.8s; }
#habits-incomplete .habit-row:nth-child(10) { animation-delay: 3.6s; }

.habit-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: visible;
  transition: border-color 200ms ease, box-shadow 300ms ease;
  position: relative;
}

/* habit-detail-panel must also not clip */
.habit-detail-panel {
  overflow: visible;
}

.habit-row:hover {
  border-color: #444c56;
}

.habit-row.completed {
  border-color: var(--border);
}

.habit-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.habit-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: -3px;
  opacity: 0;
  transition: opacity 150ms ease;
  user-select: none;
  margin-right: -8px;
}

.habit-row:hover .habit-drag-handle {
  opacity: 0.5;
}

.habit-drag-handle:hover {
  opacity: 1 !important;
}

.habit-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  opacity: 0;
  transition: opacity 150ms ease;
  margin-left: auto;
}

.habit-row:hover .habit-edit-btn {
  opacity: 0.5;
}

.habit-edit-btn:hover {
  opacity: 1 !important;
  color: var(--text);
}

.habit-add-inline {
  padding: 4px 16px 8px;
}

.habit-add-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 150ms ease;
  padding: 0 4px;
}

.habit-add-btn:hover {
  opacity: 1;
}

.habit-add-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.habit-add-input {
  flex: 1;
  font-size: 14px;
  padding: 6px 10px;
}

.habit-add-submit {
  padding: 6px 12px;
  font-size: 13px;
}

/* ── Habit edit modal ──────────────────────────────────────────────────────── */

.habit-edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.habit-edit-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 94%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.habit-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 32px 0;
}

.habit-edit-header h3 {
  font-size: 22px;
  font-weight: 600;
}

.habit-edit-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.habit-edit-close:hover {
  color: var(--text);
}

.habit-edit-body {
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.habit-edit-body .form-label {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: -8px;
  font-weight: 500;
}

.habit-edit-body .form-input,
.habit-edit-body .form-select {
  font-size: 16px;
  padding: 10px 14px;
}

/* ── Toggle switch for metric tracking ──────────────────────────────────── */
.habit-edit-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  margin-top: 6px;
  font-size: 15px;
  color: var(--text);
  user-select: none;
}

.habit-edit-toggle input[type="checkbox"] {
  display: none;
}

.habit-edit-toggle-track {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  transition: background 200ms ease;
  flex-shrink: 0;
}

.habit-edit-toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 200ms ease, background 200ms ease;
}

.habit-edit-toggle input:checked + .habit-edit-toggle-track {
  background: var(--theme-dark);
}

.habit-edit-toggle input:checked + .habit-edit-toggle-track::after {
  transform: translateX(20px);
  background: var(--theme);
}

.habit-edit-metric-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-left: 12px;
  border-left: 2px solid var(--theme-dark);
  margin-top: 4px;
}

.habit-edit-metric-row {
  display: flex;
  gap: 16px;
}

.habit-edit-metric-row > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.habit-edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px 28px;
  border-top: 1px solid var(--border);
}

.habit-edit-footer-right {
  display: flex;
  gap: 10px;
}

/* ── Delete button (styled for the modal) ───────────────────────────────── */
.btn-danger {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: var(--danger);
}

/* ── Checkbox (solid fill box) ─────────────────────────────────────────────── */
.checkbox-box {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 2px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  transition: background 200ms ease, border-color 200ms ease, transform 100ms ease;
}

.checkbox-box:hover {
  border-color: var(--theme-dim);
  filter: brightness(1.2);
}

.checkbox-box:active {
  transform: scale(0.88);
}

/* ── Habit name ────────────────────────────────────────────────────────────── */
.habit-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  transition: color var(--transition);
}

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

/* ── Metric badge ──────────────────────────────────────────────────────────── */
.metric-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 10px;
  white-space: nowrap;
}

/* ── Expand button ─────────────────────────────────────────────────────────── */
.expand-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}

.expand-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.arrow-indicator {
  display: inline-block;
  transition: transform 200ms ease;
}

.arrow-down { transform: rotate(0deg); }
.arrow-up { transform: rotate(180deg); }

/* ── Detail panel ──────────────────────────────────────────────────────────── */
.habit-detail-panel {
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.detail-enter { transition: all 200ms ease; overflow: hidden; }
.detail-enter-start { opacity: 0; max-height: 0; }
.detail-enter-end { opacity: 1; max-height: 500px; }
.detail-leave { transition: all 150ms ease; overflow: hidden; }
.detail-leave-start { opacity: 1; max-height: 500px; }
.detail-leave-end { opacity: 0; max-height: 0; }

.detail-form {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: visible;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
}

.detail-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ── Star rating ───────────────────────────────────────────────────────────── */
.star-rating {
  display: flex;
  gap: 4px;
  align-items: center;
}

.star-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  padding: 0 2px;
  transition: transform 150ms ease, color 150ms ease;
  line-height: 1;
}

.star-btn:hover { transform: scale(1.2); }

.star-filled { color: var(--warning); }
.star-empty  { color: var(--border); }

/* ── Metric input ──────────────────────────────────────────────────────────── */
.metric-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metric-input {
  width: 100px;
}

.metric-unit-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Segmented slider ──────────────────────────────────────────────────────── */
.seg-slider-wrap {
  margin-top: 4px;
  user-select: none;
  -webkit-user-select: none;
  overflow: visible;
}

.seg-slider-track {
  position: relative;
  height: 28px;
  background: var(--border);
  border-radius: 6px;
  cursor: pointer;
  overflow: visible;
  touch-action: none;
}

.seg-slider-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(90deg, var(--theme-dark), var(--theme));
  transition: width 80ms ease;
  z-index: 1;
}

.seg-slider-fill[style*="width:100%"],
.seg-slider-fill[style*="width: 100%"] {
  border-radius: 6px;
}

/* Segment markers */
.seg-marker {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255,255,255,0.08);
  z-index: 2;
  pointer-events: none;
}

/* Goal line — no longer used, goal = end of track */

/* Labels */
.seg-slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.seg-current-label {
  font-weight: 700;
  color: var(--theme);
  transition: color 200ms;
}

/* ── Enchanted mode (over goal) ───────────────────────────────────────────── */

/* All ancestors already have overflow:visible set */

/* The fill bar extends past the track. No width cap. */
.seg-fill-enchanted {
  background:
    linear-gradient(90deg, var(--theme-dark), var(--theme), var(--theme), var(--theme-dim), var(--theme)) !important;
  background-size: 200% 100% !important;
  animation: enchant-gradient 3s ease infinite !important;
  border-radius: 6px !important;
  z-index: 5;
  /* Break past the track boundary */
  margin-right: -12px;
  padding-right: 12px;
}

/* Minecraft-style diagonal shimmer glint sweeping across */
.seg-fill-enchanted::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 6px,
    rgba(255, 255, 255, 0.12) 6px,
    rgba(255, 255, 255, 0.12) 12px
  );
  background-size: 200% 200%;
  animation: enchant-glint 1.5s linear infinite;
  pointer-events: none;
  z-index: 6;
}

/* Neon glow trailing the bar end */
.seg-enchant-glow {
  position: absolute;
  top: -6px;
  right: -10px;
  bottom: -6px;
  width: 32px;
  border-radius: 0 10px 10px 0;
  background: radial-gradient(ellipse at right, color-mix(in srgb, var(--theme) 70%, white), color-mix(in srgb, var(--theme) 30%, transparent) 40%, transparent 70%);
  animation: enchant-pulse 1s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 7;
}

/* Glow on the track itself */
.on-fire .seg-slider-track {
  box-shadow:
    0 0 16px color-mix(in srgb, var(--theme) 40%, transparent),
    0 0 6px color-mix(in srgb, var(--theme) 30%, transparent);
}

/* The bar "breaks out" — push past the parent container visually */
.on-fire .seg-slider-wrap {
  position: relative;
  z-index: 2;
}

/* Current value label goes neon */
.seg-current-enchanted {
  color: var(--theme) !important;
  text-shadow: 0 0 10px color-mix(in srgb, var(--theme) 60%, transparent), 0 0 20px color-mix(in srgb, var(--theme) 30%, transparent);
  font-size: 13px;
}

/* Particle container */
.seg-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 8;
}

.seg-particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform, opacity;
}

/* Ambient glow leaks out of the habit row */
.habit-row.on-fire {
  box-shadow:
    0 0 20px color-mix(in srgb, var(--theme) 25%, transparent),
    0 0 50px color-mix(in srgb, var(--theme) 15%, transparent),
    inset 0 0 20px color-mix(in srgb, var(--theme) 5%, transparent);
  border-color: color-mix(in srgb, var(--theme) 50%, transparent) !important;
  z-index: 10;
  position: relative;
}

/* Glow bleed past the right edge of the row */
.habit-row.on-fire::after {
  content: '';
  position: absolute;
  top: -8px;
  right: -16px;
  bottom: -8px;
  width: 40px;
  background: radial-gradient(ellipse at left, color-mix(in srgb, var(--theme) 30%, transparent), transparent 70%);
  border-radius: 0 12px 12px 0;
  pointer-events: none;
  animation: enchant-pulse 1.2s ease-in-out infinite alternate;
}

/* ── Enchant keyframes ───────────────────────────────────────────────────── */
@keyframes enchant-gradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes enchant-glint {
  0%   { background-position: 0% 0%; }
  100% { background-position: 200% 200%; }
}

@keyframes enchant-pulse {
  0%   { opacity: 0.5; transform: scaleX(0.8); }
  100% { opacity: 1; transform: scaleX(1.2); }
}

@keyframes particle-float {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--px), var(--py)) scale(0); }
}

/* ── Detail inputs ─────────────────────────────────────────────────────────── */
.detail-input, .detail-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  transition: border-color var(--transition);
  resize: none;
}

.detail-input:focus, .detail-textarea:focus {
  outline: none;
  border-color: var(--theme);
}

.detail-textarea {
  min-height: 72px;
  width: 100%;
}

.save-btn {
  align-self: flex-start;
  background: var(--theme-dark);
  border: 1px solid var(--theme-dim);
  color: #fff;
  padding: 7px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: background var(--transition), transform 100ms ease;
}

.save-btn:hover { background: var(--theme-dim); }
.save-btn:active { transform: scale(0.97); }

.save-inline {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.opacity-100 { opacity: 1; }
.opacity-0 { opacity: 0; }

/* ── Heatmap ───────────────────────────────────────────────────────────────── */
.heatmap-section {
  margin-top: 40px;
}

/* old heatmap-container styles moved to .chart-wrapper */

.heatmap-loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px;
  text-align: center;
}

.heatmap-svg {
  display: block;
}

.heatmap-cell {
  cursor: pointer;
  transition: opacity 150ms;
}

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

.heatmap-label {
  fill: #8b949e;
  font-size: 11px;
  font-family: -apple-system, sans-serif;
}

.heatmap-tooltip {
  position: absolute;
  background: #1c2128;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  justify-content: flex-end;
}

.legend-label {
  font-size: 12px;
  color: var(--text-muted);
}

.legend-cell {
  width: 13px;
  height: 13px;
  border-radius: 3px;
}

/* ── Stats ─────────────────────────────────────────────────────────────────── */
.stats-container {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 16px;
}

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.stats-header .section-title {
  margin: 0;
}

.stats-habit-select {
  margin-bottom: 12px;
}

.stats-habit-select .form-select {
  width: 100%;
}

.stats-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.stats-selectors {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.form-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  min-width: 200px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.form-select:focus {
  outline: none;
  border-color: var(--theme);
}

.window-btns {
  display: flex;
  gap: 4px;
}

.window-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.window-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.window-btn.active {
  background: color-mix(in srgb, var(--theme) 15%, transparent);
  color: var(--theme);
  border-color: var(--theme);
}

.chart-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  padding-bottom: 50px;
  margin-bottom: 20px;
  height: 350px;
  overflow: hidden !important;
}

.chart-wrapper canvas {
  height: 280px !important;
  max-height: 280px;
  width: 100%;
}

.chart-wrapper > div {
  width: 100%;
}

.chart-wrapper > div:has(canvas) {
  height: 280px;
}

/* Heatmap grid (GitHub-style contribution graph) */
.heatmap-container {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.heatmap-months {
  display: flex;
  gap: 3px;
  margin-bottom: 4px;
  width: 100%;
}

.heatmap-day-labels-spacer {
  width: 32px;
  flex-shrink: 0;
}

.heatmap-grid {
  display: flex;
  gap: 0;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none; /* Firefox */
}

.heatmap-grid::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Custom scroll slider below heatmap */
.heatmap-scroll-slider {
  -webkit-appearance: none;
  appearance: none;
  width: calc(100% - 40px);
  height: 28px;
  background: transparent;
  outline: none;
  cursor: pointer;
  position: absolute;
  bottom: 10px;
  left: 20px;
}

.heatmap-scroll-slider::-webkit-slider-runnable-track {
  height: 12px;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.heatmap-scroll-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 60px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  border: 2px solid var(--text-muted);
  margin-top: -7px;
  cursor: grab;
  transition: background 0.15s;
}

.heatmap-scroll-slider::-webkit-slider-thumb:hover {
  background: var(--text-muted);
}

.heatmap-scroll-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  background: var(--text);
}

/* Firefox */
.heatmap-scroll-slider::-moz-range-track {
  height: 12px;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.heatmap-scroll-slider::-moz-range-thumb {
  width: 60px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  border: 2px solid var(--text-muted);
  cursor: grab;
}

.heatmap-scroll-slider::-moz-range-thumb:hover {
  background: var(--text-muted);
}

.heatmap-day-labels {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
  width: 28px;
  padding-top: 18px; /* align with cells below month labels */
  margin-right: 4px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
}

.heatmap-day-label {
  width: 28px;
  height: 14px;
  font-size: 9px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  white-space: nowrap;
}

.heatmap-week {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.heatmap-grid .heatmap-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  transition: outline 0.1s;
}

.heatmap-day-labels .heatmap-day-label {
  height: 14px;
}

.heatmap-grid .heatmap-cell.empty {
  background: transparent;
}

.heatmap-grid .heatmap-cell.done {
  background: var(--theme);
}

.heatmap-grid .heatmap-cell.missed {
  background: var(--border);
}

.heatmap-grid .heatmap-cell.no-log {
  background: #1a1e24;
}

.heatmap-grid .heatmap-cell.future {
  background: #12151a;
}

.heatmap-grid .heatmap-cell:not(.empty):hover {
  outline: 2px solid var(--text-muted);
  outline-offset: -1px;
  cursor: default;
}

/* 7d strip layout — large day tiles */
.heatmap-strip {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
  width: 100%;
  height: 100%;
}

.heatmap-tile {
  flex: 1;
  border-radius: 10px;
  padding: 16px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: opacity 0.15s;
}

.heatmap-tile.done { background: var(--theme); color: #fff; }
.heatmap-tile.missed { background: var(--border); color: var(--text-muted); }
.heatmap-tile.no-log { background: #1a1e24; color: var(--text-muted); }
.heatmap-tile-day { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.heatmap-tile-num { font-size: 24px; font-weight: 700; line-height: 1; }
.heatmap-tile-status { font-size: 16px; line-height: 1; }

.heatmap-tile.streak-dim { opacity: 0.15; }
.heatmap-tile.streak-highlight { outline: 2px solid var(--theme); outline-offset: 2px; }

/* 30d flow layout — calendar month grid */
.heatmap-flow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.heatmap-month-title {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.heatmap-flow-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2px;
}

.heatmap-flow-cell {
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  transition: opacity 0.15s;
}

.heatmap-flow-cell.empty {
  background: transparent;
}

.heatmap-flow-cell.done { background: var(--theme); }
.heatmap-flow-cell.missed { background: var(--border); }
.heatmap-flow-cell.no-log { background: #1a1e24; }
.heatmap-flow-cell.future { background: #12151a; }

.heatmap-flow-num {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.heatmap-flow-cell.done .heatmap-flow-num { color: #fff; }

.heatmap-flow-cell:hover {
  outline: 2px solid var(--text-muted);
  outline-offset: -1px;
  cursor: default;
}

.heatmap-flow-cell.streak-dim { opacity: 0.15; }
.heatmap-flow-cell.streak-highlight { outline: 2px solid var(--theme); outline-offset: -1px; }

/* Month-grouped grid (quarter / year / all) */
.heatmap-month-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex-shrink: 0;
}

.heatmap-month-group + .heatmap-month-group {
  margin-left: 8px;
}

.heatmap-month-label {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 4px;
  white-space: nowrap;
}

.heatmap-month-weeks {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

/* Streak highlight on heatmap */
.heatmap-grid .heatmap-cell.streak-dim {
  opacity: 0.2;
}

.heatmap-grid .heatmap-cell.streak-highlight {
  outline: 2px solid var(--theme);
  outline-offset: -1px;
}

/* Clickable stat card */
.stat-card-clickable {
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stat-card-clickable:hover {
  border-color: var(--text-muted);
}

.stat-card-active {
  border-color: var(--theme) !important;
  box-shadow: 0 0 0 1px var(--theme);
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--surface);
  z-index: 5;
}

.stats-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 15px;
}

/* Summary cards row */
.stats-summary-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.stats-summary-row .stat-card {
  flex: 1 1 0;
  min-width: 90px;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-card-value.accent {
  color: var(--theme);
}

.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* Overview section */
.stats-overview-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

.stats-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-section-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Habit ranking bars */
.habit-rank-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.habit-rank-name {
  font-size: 13px;
  color: var(--text);
  width: 140px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-rank-bar-track {
  flex: 1;
  height: 20px;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.habit-rank-bar-fill {
  height: 100%;
  border-radius: 10px;
  background: var(--theme);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 2px;
}

.habit-rank-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  width: 40px;
  text-align: right;
  flex-shrink: 0;
}

/* Day-of-week chart */
.dow-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: 120px;
  gap: 8px;
  padding-top: 8px;
}

.dow-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.dow-bar-wrap {
  width: 100%;
  max-width: 48px;
  height: 80px;
  background: var(--bg);
  border-radius: 6px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.dow-bar {
  width: 100%;
  border-radius: 6px;
  background: var(--theme);
  transition: height 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 2px;
}

.dow-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.dow-pct {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Two-col layout for overview charts */
.stats-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .stats-two-col { grid-template-columns: 1fr; }
  .habit-rank-name { width: 100px; }
}

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-habits-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.settings-habit-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}

.settings-habit-row:hover {
  border-color: #444c56;
}

.settings-row-main {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
}

.settings-habit-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-habit-name {
  font-size: 15px;
  font-weight: 500;
}

.settings-metric-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 1px 10px;
}

.settings-habit-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.settings-row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 14px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.icon-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.edit-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

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

.danger-text { color: var(--danger); }
.danger-text:hover { border-color: var(--danger); }

.demo-data-actions {
  display: flex;
  gap: 10px;
}

/* ── Theme picker ─────────────────────────────────────────────────────────── */
.theme-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.theme-swatch:hover {
  transform: scale(1.15);
}

.theme-active {
  border-color: var(--text) !important;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text-muted);
}

.theme-swatch-green  { background: #39d353; }
.theme-swatch-teal   { background: #2dd4bf; }
.theme-swatch-cyan   { background: #22d3ee; }
.theme-swatch-blue   { background: #60a5fa; }
.theme-swatch-purple { background: #a78bfa; }
.theme-swatch-pink   { background: #f472b6; }
.theme-swatch-orange { background: #fb923c; }
.theme-swatch-yellow { background: #facc15; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.habit-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inline-edit-form {
  background: var(--surface2);
  border-top: 1px solid var(--border);
  padding: 16px 18px;
}

.form-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-label.sm { font-size: 11px; }

.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  width: 100%;
  transition: border-color var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--theme);
}

.form-input.sm {
  width: 120px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--theme);
}

.metric-fields {
  margin-top: 10px;
}

.metric-fields-inner {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-actions {
  display: flex;
  gap: 8px;
  padding-top: 4px;
}

.btn-primary {
  background: var(--theme-dark);
  border: 1px solid var(--theme-dim);
  color: #fff;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition), transform 100ms;
}

.btn-primary:hover { background: var(--theme-dim); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

/* ── Add habit section ─────────────────────────────────────────────────────── */
.add-habit-section {
  margin-top: 8px;
}

.add-habit-btn {
  margin-bottom: 12px;
}

.add-habit-form-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes flash-green {
  0%   { background: var(--surface); }
  30%  { background: rgba(57,211,83,0.15); }
  100% { background: var(--surface); }
}

.habit-flash {
  animation: flash-green 600ms ease forwards;
}

/* ── Habit row section transitions ────────────────────────────────────────── */
@keyframes row-enter {
  0%   { opacity: 0; transform: translateY(-16px) scale(0.97); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.habit-row-enter {
  animation: row-enter 600ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.habit-row-animating {
  z-index: 100;
  position: relative;
}

@keyframes pop-in {
  0%   { transform: scale(0.85); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.checkbox-box.checked {
  animation: pop-in 250ms ease forwards;
}

/* ── Checkbox particle burst ──────────────────────────────────────────────── */
@keyframes check-burst {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ── Confetti ─────────────────────────────────────────────────────────────── */
@keyframes confetti-fall {
  0%   { transform: translateY(0) translateX(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(100vh) translateX(var(--drift)) rotate(var(--spin)); opacity: 0; }
}

/* ── Progress bar complete state ──────────────────────────────────────────── */
.progress-bar-fill.progress-full {
  background: linear-gradient(90deg, var(--theme-dark), var(--theme), color-mix(in srgb, var(--theme) 80%, white));
  box-shadow: 0 0 12px color-mix(in srgb, var(--theme) 50%, transparent), 0 0 4px color-mix(in srgb, var(--theme) 30%, transparent);
  animation: progress-glow 2s ease-in-out infinite alternate;
}

.progress-header.progress-complete {
  border-color: color-mix(in srgb, var(--theme) 40%, transparent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--theme) 10%, transparent);
}

@keyframes progress-glow {
  0%   { box-shadow: 0 0 8px color-mix(in srgb, var(--theme) 30%, transparent), 0 0 2px color-mix(in srgb, var(--theme) 20%, transparent); }
  100% { box-shadow: 0 0 16px color-mix(in srgb, var(--theme) 60%, transparent), 0 0 6px color-mix(in srgb, var(--theme) 40%, transparent); }
}

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}

.login-icon {
  font-size: 32px;
  color: var(--theme);
  display: block;
  margin-bottom: 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--transition);
}

.google-btn {
  background: #fff;
  color: #3c4043;
}

.google-btn:hover {
  background: #f1f3f4;
  text-decoration: none;
}

.dev-btn {
  background: var(--theme-dark);
  border: 1px solid var(--theme-dim);
  color: #fff;
}

.dev-btn:hover {
  background: var(--theme-dim);
  text-decoration: none;
}

.login-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Week overview ─────────────────────────────────────────────────────────── */
.week-overview-section {
  margin-top: 32px;
  margin-bottom: 8px;
}

.week-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}

.week-nav-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 140px;
  text-align: center;
}

.week-grid {
  display: grid;
  grid-template-columns: minmax(100px, 160px) repeat(7, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.week-corner {
  /* empty top-left cell */
}

.week-day-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.week-day-label:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  text-decoration: none;
}

.week-day-active {
  color: var(--theme);
}

.week-day-num {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.week-day-active .week-day-num {
  color: var(--theme);
}

.week-habit-name {
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  padding-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.04);
  background: var(--surface2);
  transition: transform 100ms ease, filter 100ms ease;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.week-cell:hover {
  transform: scale(1.08);
  filter: brightness(1.2);
  text-decoration: none;
  z-index: 1;
}

.week-cell-na {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

.week-cell-val {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.week-cell-check {
  font-size: 16px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ── Date navigation ──────────────────────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}

.date-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition);
}

.date-nav-btn:hover {
  background: var(--surface2);
  border-color: #444c56;
  text-decoration: none;
}

.date-nav-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.date-nav-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  min-width: 180px;
  text-align: center;
}

/* ── Profile dropdown ─────────────────────────────────────────────────────── */
.profile-dropdown {
  position: relative;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.profile-btn:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--border);
}

.profile-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--theme-dark);
  color: var(--theme);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-name {
  font-size: 13px;
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-caret {
  font-size: 10px;
  color: var(--text-muted);
}

.profile-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
}

.profile-menu-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-menu-name {
  font-size: 14px;
  font-weight: 600;
}

.profile-menu-badge {
  font-size: 11px;
  background: var(--surface2);
  color: var(--text-muted);
  padding: 1px 8px;
  border-radius: 99px;
}

.profile-menu-divider {
  height: 1px;
  background: var(--border);
}

.profile-menu-item {
  display: block;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  transition: background var(--transition);
}

.profile-menu-item:hover {
  background: rgba(255,255,255,0.06);
  text-decoration: none;
}

/* ── Slider text input ────────────────────────────────────────────────────── */
.seg-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.seg-text-input {
  width: 64px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--theme);
  font-size: 13px;
  font-weight: 700;
  padding: 3px 8px;
  text-align: center;
  -moz-appearance: textfield;
}

.seg-text-input::-webkit-inner-spin-button,
.seg-text-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.seg-text-input:focus {
  outline: none;
  border-color: var(--theme);
}

.seg-input-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.seg-goal-label-end {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Landing page ─────────────────────────────────────────────────────────── */
.landing-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.landing-hero {
  max-width: 480px;
  width: 100%;
  text-align: center;
}

.landing-icon {
  font-size: 48px;
  color: var(--theme);
  display: block;
  margin-bottom: 12px;
}

.landing-title {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.landing-tagline {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 36px;
}

.landing-features {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 36px;
}

.landing-feature {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.feature-icon {
  color: var(--theme);
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.landing-feature strong {
  font-size: 14px;
  display: block;
  margin-bottom: 4px;
}

.landing-feature p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guest-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.guest-btn:hover {
  background: var(--surface2);
  text-decoration: none;
}

.landing-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-inner { gap: 12px; padding: 0 12px; }
  .header-date { display: none; }
  .main-content { padding: 16px 12px 40px; }
  .stats-selectors { flex-direction: column; align-items: flex-start; }
  .stats-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .metric-fields-inner { flex-direction: column; }
  .form-input.sm { width: 100%; }
  .settings-row-main { flex-direction: column; align-items: flex-start; }
  .week-grid { grid-template-columns: minmax(80px, 110px) repeat(7, 1fr); padding: 10px; gap: 3px; }
  .week-habit-name { font-size: 11px; }
  .week-cell { min-height: 32px; }
  .week-cell-val { font-size: 11px; }
  .week-day-num { font-size: 13px; }
}

/* ── Todo page ───────────────────────────────────────────────────────────── */
.todos-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px;
  overflow: visible;
}

.todos-container .carousel-view {
  overflow: visible;
  margin: 0 -50vw;
  padding: 0 50vw;
}

.todo-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin-top: 2px;
  margin-left: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.todo-add-btn:hover {
  opacity: 1;
  color: var(--theme);
  background: var(--surface2);
}

.todo-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.todo-completed-section {
  margin-top: 24px;
  opacity: 0.5;
}

.todo-completed-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px 4px;
}

.todo-item {
  border-radius: 8px;
  transition: opacity 0.2s ease;
}

.todo-item.todo-dragging {
  opacity: 0.3;
}

.todo-item.todo-drop-into > .todo-main {
  outline: 2px solid var(--theme);
  outline-offset: -2px;
  border-radius: 8px;
}

.todo-children {
  /* Children are indented via padding-left on the .todo-item */
}

.todo-main {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  transition: background 0.15s ease;
}

.todo-main:hover {
  background: var(--surface2);
}

.todo-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  opacity: 0;
  font-size: 10px;
  letter-spacing: -2px;
  user-select: none;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  transition: opacity 0.15s ease;
}

.todo-main:hover .todo-drag-handle {
  opacity: 0.6;
}

.todo-drag-handle:hover {
  opacity: 1 !important;
}

.todo-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  position: relative;
}

.todo-checkbox:hover {
  border-color: var(--theme);
}

.todo-checkbox.checked {
  background: var(--theme);
  border-color: var(--theme);
}

.todo-checkbox.checked::after {
  content: '\2713';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
}

.todo-title {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  cursor: text;
}

.todo-title.done {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-inline-edit {
  flex: 1;
  font-size: 14px;
  padding: 2px 6px;
  margin: -2px 0;
}

.todo-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.todo-main:hover .todo-actions {
  opacity: 1;
}

.todo-delete {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.todo-delete:hover {
  background: var(--surface2);
  color: #f85149;
}

.todo-drop-indicator {
  height: 2px;
  background: var(--theme);
  border-radius: 1px;
  pointer-events: none;
  margin: 1px 0;
}

.todo-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Category cards ──────────────────────────────────────────────────────── */

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  transition: background 600ms ease, border-color 600ms ease;
}

.category-card.category-all-done {
  background: transparent;
  border-color: transparent;
}

.category-card-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.category-card-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  opacity: 0;
  font-size: 10px;
  letter-spacing: -2px;
  user-select: none;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  transition: opacity 0.15s ease;
}

.category-card-drag-handle:active { cursor: grabbing; }
.category-card:hover .category-card-drag-handle { opacity: 0.5; }
.category-card-drag-handle:hover { opacity: 1 !important; }

.category-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-left: 0;
}

.category-card.category-card-dragging {
  opacity: 0.3;
}

.category-card-drop-indicator {
  height: 3px;
  background: var(--theme);
  border-radius: 2px;
  pointer-events: none;
  margin: 4px 0;
}

/* ── Todos header & view toggle ──────────────────────────────────────────── */

.todos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.todos-header .section-title {
  margin-bottom: 0;
}

.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.view-toggle-btn:hover {
  color: var(--text);
  background: var(--surface2);
}

.view-toggle-btn.active {
  color: var(--theme);
  background: var(--surface2);
}

/* ── Carousel view ──────────────────────────────────────────────────────── */

.carousel-view {
  perspective: 1200px;
  padding: 8px 0 24px;
}

.carousel-scene {
  overflow: visible;
  position: relative;
}

.carousel-track {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-card {
  position: absolute;
  top: 0;
  transform-origin: top center;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  transform-style: preserve-3d;
  will-change: transform, opacity, filter, left;
}

.carousel-category-card {
  min-height: 350px;
  border-radius: 20px;
  padding: 24px;
}

.carousel-category-card .category-card-title {
  font-size: 16px;
  margin-bottom: 4px;
}

.carousel-category-card .todo-section {
  gap: 4px;
}

.carousel-category-card .todo-add-btn {
  margin-left: 8px;
  margin-top: 8px;
}

/* Navigation */
.carousel-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}

.carousel-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.carousel-nav-btn:hover:not(:disabled) {
  background: var(--surface2);
  border-color: var(--theme);
  color: var(--theme);
}

.carousel-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.carousel-dots {
  display: flex;
  gap: 8px;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  cursor: pointer;
  padding: 0;
  transition: all 0.25s ease;
}

.carousel-dot.active {
  background: var(--theme);
  transform: scale(1.35);
}

.carousel-dot:hover:not(.active) {
  background: var(--text-muted);
}

/* ── Category management (settings) ──────────────────────────────────────── */

.category-manage-row {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

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

.category-manage-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.category-manage-name {
  font-size: 14px;
  font-weight: 500;
}

.category-manage-actions {
  display: flex;
  gap: 4px;
}

.category-manage-edit {
  display: flex;
  gap: 8px;
  align-items: center;
}

.category-manage-edit .form-input {
  flex: 1;
}

.category-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

.category-select {
  font-size: 11px;
  padding: 2px 6px;
  max-width: 100px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.category-add-form .form-input {
  font-size: 14px;
}

.todo-category-select {
  opacity: 0.4;
  transition: opacity 200ms ease;
}

.todo-item:hover .todo-category-select {
  opacity: 1;
}

/* ── Tracker page ────────────────────────────────────────────────────────── */

.tracker-sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tracker-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 200ms ease, background 200ms ease;
  font-size: 14px;
}

.tracker-pill:hover {
  border-color: #444c56;
}

.tracker-pill.active {
  border-color: var(--theme);
  background: var(--theme-darker);
}

.tracker-pill-unit {
  color: var(--text-muted);
  font-size: 12px;
}

.tracker-add-pill {
  border-style: dashed;
  color: var(--text-muted);
}

.tracker-add-form {
  margin-bottom: 16px;
}

.tracker-inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.tracker-unit-input {
  max-width: 100px;
}

.tracker-entry-section {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tracker-entry-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.tracker-entry-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tracker-entry-form .form-input[type="date"] {
  width: auto;
  max-width: 150px;
}

.tracker-entry-form .form-input[type="number"] {
  width: 100px;
}

.tracker-value-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tracker-value-unit {
  color: var(--text-muted);
  font-size: 13px;
  min-width: 24px;
}

.tracker-saved {
  color: var(--theme);
  font-size: 13px;
  margin-left: 8px;
}

.tracker-entries-list {
  margin-top: 20px;
}

.tracker-entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

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

.tracker-entry-date {
  color: var(--text-muted);
  min-width: 100px;
}

.tracker-entry-display,
.tracker-entry-edit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tracker-entry-value {
  color: var(--text);
  font-weight: 500;
  min-width: 60px;
}

.tracker-entry-display .icon-btn {
  opacity: 0;
  transition: opacity 150ms ease;
}

.tracker-entry-row:hover .tracker-entry-display .icon-btn {
  opacity: 1;
}

.tracker-edit-input {
  width: 90px;
}

/* ── Schedule ─────────────────────────────────────────────────────────────── */

.schedule-container {
  max-width: 700px;
  margin: 0 auto;
}

.schedule-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.schedule-add-btn-mobile {
  display: none; /* shown via @media (hover: none) */
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.schedule-timeline {
  position: relative;
  height: 1800px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
}

.schedule-hour {
  position: absolute;
  width: 100%;
  left: 0;
}

.schedule-hour-label {
  position: absolute;
  left: 8px;
  top: -8px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
  z-index: 1;
}

.schedule-hour-line {
  position: absolute;
  left: 56px;
  right: 0;
  top: 0;
  border-top: 1px solid var(--border);
}

.schedule-add-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

/* Block */
.schedule-block {
  position: absolute;
  left: 60px;
  right: 12px;
  background: var(--theme-darker);
  border-left: 3px solid var(--theme);
  border-radius: var(--radius-sm);
  cursor: grab;
  overflow: visible;
  z-index: 2;
  transition: box-shadow 0.18s, background 0.15s, transform 0.1s;
  min-height: 20px;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.schedule-block:focus-within {
  outline: none;
}

.schedule-block:hover {
  background: var(--theme-dark);
}

/* Selected: glowing ring, elevated */
.schedule-block.is-selected {
  box-shadow: 0 0 0 2px var(--theme), 0 6px 20px rgba(0,0,0,0.3);
  z-index: 8;
  background: var(--theme-dark);
}

/* Dragging */
.schedule-block.is-dragging {
  cursor: grabbing;
  box-shadow: 0 0 0 2px var(--theme), 0 12px 32px rgba(0,0,0,0.45);
  z-index: 100;
  opacity: 0.88;
  transform: scaleX(1.01);
}

.schedule-block-content {
  flex: 1;
  padding: 0 32px 0 10px; /* right padding leaves room for delete btn */
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

.schedule-block-display {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.schedule-block-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schedule-block-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Delete button (shown when selected) */
.schedule-block-del {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.25);
  color: rgba(255,255,255,0.75);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  z-index: 4;
  padding: 0;
}
.schedule-block-del:hover {
  background: var(--danger);
  color: #fff;
}

/* Resize handles */
.schedule-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 10px;
  cursor: ns-resize;
  z-index: 3;
  transition: background 0.15s, height 0.15s, opacity 0.15s;
  opacity: 0;
}
.schedule-block:hover .schedule-resize-handle,
.schedule-block.is-selected .schedule-resize-handle {
  opacity: 1;
}

.schedule-resize-top {
  top: -3px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(to bottom, var(--theme), transparent);
}

.schedule-resize-bottom {
  bottom: -3px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: linear-gradient(to top, var(--theme), transparent);
}

/* Larger hit targets on selected block */
.schedule-block.is-selected .schedule-resize-handle {
  height: 18px;
}
.schedule-block.is-selected .schedule-resize-top  { top: -5px; }
.schedule-block.is-selected .schedule-resize-bottom { bottom: -5px; }

/* Inline edit */
.schedule-block-edit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.schedule-edit-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  padding: 0 0 2px 0;
  font-size: 13px;
  font-weight: 600;
  width: 100%;
  outline: none;
  caret-color: #fff;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 0;
}

.schedule-edit-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.schedule-edit-btn {
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  flex-shrink: 0;
}
.schedule-edit-btn:hover {
  background: rgba(255, 255, 255, 0.32);
}

/* Long-press hold indicator */
.schedule-hold-indicator {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--theme);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  z-index: 50;
  animation: schedule-hold-grow 0.5s cubic-bezier(0.2, 0, 0.4, 1) forwards;
}

@keyframes schedule-hold-grow {
  0%   { transform: translate(-50%, -50%) scale(0);    opacity: 0.3; }
  60%  { transform: translate(-50%, -50%) scale(0.85); opacity: 0.2; }
  100% { transform: translate(-50%, -50%) scale(1);    opacity: 0; }
}

/* Hour hover zones with add button */
.schedule-hour-zone {
  position: absolute;
  left: 56px;
  right: 0;
  z-index: 20;
  pointer-events: none;
}

.schedule-hour-add {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, background 0.15s, color 0.15s;
  pointer-events: none;
}

.schedule-hour-zone:hover .schedule-hour-add,
.schedule-hour-add:focus {
  opacity: 1;
  pointer-events: auto;
}

.schedule-hour-add {
  pointer-events: auto;
}

.schedule-hour-add:hover {
  background: var(--theme);
  border-color: var(--theme);
  color: #fff;
}

/* Now indicator */
.schedule-now {
  position: absolute;
  left: 56px;
  right: 0;
  z-index: 4;
  pointer-events: none;
}

.schedule-now-line {
  border-top: 2px solid var(--danger);
  position: relative;
}

.schedule-now-line::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -5px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
}


/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE — two separate concerns handled with the right media queries:
   1. @media (hover: none)  → touch devices: fix hover-only UI
   2. @media (max-width: 680px) → narrow screens: fix layout
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Touch devices: reveal hover-hidden elements ─────────────────────── */
@media (hover: none) {
  /* Habit row controls */
  .habit-edit-btn       { opacity: 0.55; }
  .habit-drag-handle    { display: none; }

  /* Category drag handle */
  .category-card-drag-handle { display: none; }

  /* Todo drag handle */
  .todo-drag-handle { display: none; }

  /* Todo actions (delete, category) */
  .todo-actions { opacity: 1; }

  /* Tracker entry edit/delete buttons */
  .tracker-entry-display .icon-btn { opacity: 1; }

  /* Schedule: hide per-hour add buttons on touch — use long-press instead */
  .schedule-hour-add {
    opacity: 0 !important;
    pointer-events: none !important;
  }
  /* Resize handles always visible on touch when selected */
  .schedule-block.is-selected .schedule-resize-handle {
    opacity: 1;
  }
}

/* ── 2. Narrow screens: layout fixes ────────────────────────────────────── */
@media (max-width: 680px) {

  /* Global: remove tap flash on all interactive elements */
  * { -webkit-tap-highlight-color: transparent; }
  button, a, [role="button"], input, select, textarea {
    touch-action: manipulation; /* eliminate 300ms delay everywhere */
  }

  /* Safe area insets (iPhone notch / home bar) */
  .site-header {
    padding-top: env(safe-area-inset-top);
  }

  /* Compact header */
  .header-inner {
    padding: 0 12px;
    gap: 8px;
    height: 48px;
  }
  .header-date   { display: none; }
  .profile-name  { display: none; }
  .profile-caret { display: none; }

  /* Bottom tab bar nav */
  .main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-link {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 2px;
    font-size: 10px;
    border-radius: 0;
    min-height: 50px;
    white-space: nowrap;
    overflow: hidden;
  }

  /* Main content padding + space for bottom tab bar */
  .main-content {
    padding: 16px 12px calc(58px + env(safe-area-inset-bottom));
  }

  /* Prevent iOS auto-zoom on input focus */
  input, textarea, select { font-size: 16px !important; }

  /* Remove 300ms tap delay */
  button, a { touch-action: manipulation; }

  /* ── Today ── */
  .progress-header   { padding: 12px 14px; }
  .progress-count    { font-size: 20px; }
  .category-card     { padding: 12px; }
  .habit-main        { padding: 12px; gap: 10px; }
  .checkbox-box      { width: 28px; height: 28px; border-radius: 6px; }
  .section-title     { font-size: 16px; margin-bottom: 14px; }

  .date-nav-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Week grid: scroll horizontally */
  #week-grid-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .week-grid { min-width: 460px; }

  /* Heatmap: scroll horizontally */
  .heatmap-container {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    align-items: flex-start;
    justify-content: flex-start;
  }

  /* Habit edit modal slides up from bottom */
  .habit-edit-overlay { align-items: flex-end; }
  .habit-edit-panel {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 85vh;
  }
  .habit-edit-header { padding: 20px 20px 0; }
  .habit-edit-body   { padding: 16px 20px; }
  .habit-edit-footer { padding: 16px 20px 20px; }

  /* ── Todos ── */
  .todos-container {
    padding: 0;
  }
  /* Remove the -50vw trick that bleeds off screen */
  .todos-container .carousel-view {
    margin: 0;
    padding: 0;
  }
  /* On mobile, carousel JS puts front card as position:relative.
     Override ALL absolute-positioned card styles with !important
     so the inline styles from the ring calculation don't apply. */
  .carousel-scene {
    height: auto !important;
  }
  .carousel-track {
    position: relative;
    height: auto;
    min-height: 0;
  }
  .carousel-card {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
    transition: none !important;
  }

  .todo-checkbox      { width: 24px; height: 24px; }
  .todo-category-select { display: none; }
  .todo-item          { overflow: hidden; }

  /* ── Trackers ── */
  .tracker-entry-form {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .tracker-entry-form .form-input { max-width: 100%; width: 100%; }
  .tracker-value-input-wrap       { width: 100%; }
  .tracker-inline-form {
    flex-direction: column;
    align-items: stretch;
  }
  .tracker-unit-input { max-width: 100%; }

  /* ── Stats ── */
  .window-btns  { flex-wrap: wrap; gap: 6px; }
  .window-btn   { padding: 6px 12px; font-size: 12px; }
  .stats-two-col { grid-template-columns: 1fr; }
  .stats-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
  }
  .form-select  { min-width: 0; width: 100%; }

  /* Scale down stat cards to fit without clipping */
  .stat-card-value     { font-size: 20px; }
  .stat-card           { padding: 10px 8px; }
  .stats-summary-row   { gap: 8px; }
  .stats-summary-row .stat-card { min-width: 70px; }

  /* Chart: shorter on mobile */
  .chart-wrapper {
    height: 230px;
    padding: 12px;
    padding-bottom: 36px;
  }
  .chart-wrapper canvas        { height: 175px !important; max-height: 175px; }
  .chart-wrapper > div:has(canvas) { height: 175px; }

  /* Heatmap: allow horizontal scroll only for year/all (grid is wide),
     but don't let it bleed outside the card */
  .heatmap-container {
    overflow-x: hidden !important;
    width: 100%;
  }
  .heatmap-grid {
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
  }
  .heatmap-grid::-webkit-scrollbar { display: none; }

  /* Consistency bars: shrink name column so bars have room */
  .habit-rank-name  { width: 90px; font-size: 12px; }
  .habit-rank-pct   { width: 32px; font-size: 11px; }

  /* Overview panels: less padding */
  .stats-overview-section { padding: 14px; }

  /* ── Settings ── */
  .demo-data-actions          { flex-direction: column; gap: 8px; }
  .demo-data-actions form     { display: block !important; width: 100%; }
  .demo-data-actions button   { width: 100%; }
  .settings-row-main          { flex-direction: column; align-items: flex-start; }

  /* ── Schedule ── */
  .schedule-hour-label { font-size: 10px; }
  .schedule-hour-line  { left: 44px; }
  .schedule-hour-zone  { left: 44px; }
  .schedule-block      { left: 48px !important; }
  .schedule-now        { left: 44px; }
  /* Larger touch targets for resize handles on mobile */
  .schedule-block.is-selected .schedule-resize-handle { height: 26px; }
  .schedule-block.is-selected .schedule-resize-top    { top: -8px; }
  .schedule-block.is-selected .schedule-resize-bottom { bottom: -8px; }
  /* Delete button slightly bigger */
  .schedule-block-del  { width: 26px; height: 26px; font-size: 12px; }
  /* Content padding adjusted for bigger del button */
  .schedule-block-content { padding-right: 36px; }
}
