:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-muted: #efede7;
  --ink: #171914;
  --muted: #73766d;
  --line: rgba(23, 25, 20, 0.09);
  --accent: #f4d35e;
  --accent-strong: #ddbb35;
  --success: #82b389;
  --danger: #d57c6c;
  --shadow: 0 18px 50px rgba(39, 39, 32, 0.08);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% -10%, rgba(244, 211, 94, 0.24), transparent 30rem),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; overscroll-behavior: none; background: #10130f; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(221, 187, 53, 0.34);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(22px, var(--safe-top)) 18px calc(100px + var(--safe-bottom));
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 0.78rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.85rem, 8vw, 3.15rem); line-height: 0.98; letter-spacing: -0.055em; }
h2 { margin: 0; font-size: 1.12rem; letter-spacing: -0.025em; }
p { line-height: 1.5; }

.icon-button, .primary-button, .secondary-button, .chip, .check-button, .nav-item, .segmented button, .habit-card {
  border: 0;
  cursor: pointer;
}
.icon-button {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 16px; background: var(--surface-solid);
  box-shadow: 0 8px 24px rgba(36, 37, 31, 0.08); display: grid; place-items: center;
}
.icon-button svg, .nav-item svg, .inline-icon svg { width: 21px; height: 21px; stroke-width: 1.9; }

.hero-card {
  position: relative; overflow: hidden; padding: 22px; border-radius: var(--radius-xl); background: #171914;
  color: white; box-shadow: var(--shadow); margin-bottom: 28px;
}
.hero-card::after {
  content: ""; position: absolute; width: 170px; height: 170px; border-radius: 50%; right: -58px; top: -74px;
  border: 34px solid rgba(244, 211, 94, 0.9); opacity: 0.95;
}
.hero-grid { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; }
.hero-card .muted { color: rgba(255,255,255,.64); }
.hero-value { font-size: 2.7rem; line-height: 1; font-weight: 800; letter-spacing: -0.06em; margin: 10px 0 6px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.hero-pill { padding: 8px 11px; border-radius: 999px; background: rgba(255,255,255,.09); font-size: .78rem; color: rgba(255,255,255,.8); }
.progress-ring { width: 96px; height: 96px; transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 8; }
.progress-ring .track { stroke: rgba(255,255,255,.12); }
.progress-ring .value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .35s ease; }
.ring-wrap { position: relative; width: 96px; height: 96px; }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; }

.section { margin: 0 0 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.section-count { color: var(--muted); font-size: .82rem; font-weight: 700; }
.habit-list { display: grid; gap: 11px; }
.habit-card {
  position: relative;
  width: 100%;
  min-height: 74px;
  text-align: left;
  padding: 14px 15px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  border-radius: 20px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(32, 33, 28, .055);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease, background .15s ease;
  overflow: hidden;
}
.habit-card:hover {
  border-color: rgba(23,25,20,.14);
  box-shadow: 0 14px 34px rgba(32, 33, 28, .085);
}
.habit-card:active { transform: scale(.99); }
.habit-card:focus-visible, .weekly-habit-card:focus-visible { outline: 3px solid rgba(221, 187, 53, 0.34); outline-offset: 3px; }
.habit-card.done { opacity: 1; background: color-mix(in srgb, var(--success) 7%, var(--surface-solid)); }
.habit-card.done .habit-title { color: color-mix(in srgb, var(--ink) 62%, var(--muted)); }
.habit-emoji {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-size: 1.2rem;
  background: var(--surface-muted);
}
.habit-main { min-width: 0; }
.habit-title { font-size: .96rem; font-weight: 780; letter-spacing: -0.015em; line-height: 1.22; }
.habit-description {
  display: -webkit-box;
  margin-top: 4px;
  overflow: hidden;
  color: color-mix(in srgb, var(--ink) 76%, var(--muted));
  font-size: .78rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.habit-subtitle { margin-top: 5px; color: var(--muted); font-size: .76rem; line-height: 1.3; }
.habit-meta { font-size: .7rem; }
.habit-controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.details-progress { height: 7px; border-radius: 99px; background: var(--surface-muted); overflow: hidden; }
.details-progress span { display: block; height: 100%; min-width: 0; border-radius: inherit; background: var(--accent-strong); }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.details-grid div { min-width: 0; }
.details-grid span { display: block; color: var(--muted); font-size: .68rem; font-weight: 760; }
.details-grid strong { display: block; margin-top: 3px; font-size: .82rem; font-weight: 780; overflow-wrap: anywhere; }
.check-button {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: transparent;
  border: 1.7px solid rgba(23,25,20,.18); transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.check-button.checked { background: var(--ink); color: white; border-color: var(--ink); }
.check-button:active { transform: scale(.88); }
.check-button svg { width: 18px; height: 18px; }
.counter { display: flex; gap: 7px; align-items: center; }
.counter button { border: 0; width: 34px; height: 34px; border-radius: 12px; background: var(--surface-muted); cursor: pointer; font-weight: 800; }
.counter strong { min-width: 28px; text-align: center; font-size: .84rem; }
.empty-card { padding: 25px; border: 1px dashed rgba(23,25,20,.16); border-radius: var(--radius-lg); color: var(--muted); text-align: center; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(8px, var(--safe-bottom));
  transform: translate3d(-50%, 0, 0);
  width: min(calc(100% - 24px), 720px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px;
  background: rgba(255,255,255,.97);
  border: 1px solid rgba(23,25,20,.08);
  border-radius: 24px;
  box-shadow: 0 18px 48px rgba(24,26,20,.16);
  /*
   * iOS Chrome/Safari can leave a stale compositing layer while the dynamic
   * browser toolbar collapses if backdrop-filter is used on a fixed element.
   * A nearly opaque surface is visually equivalent here and repaints cleanly.
   */
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  isolation: isolate;
  contain: layout paint style;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.nav-item {
  min-height: 54px;
  display: grid;
  gap: 4px;
  place-items: center;
  padding: 7px 3px;
  border-radius: 17px;
  background: transparent;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 730;
}
.nav-item.active { background: var(--ink); color: white; }

/* Both browser and standalone modes keep the safe area outside the panel. */
html[data-display-mode="standalone"] .bottom-nav {
  bottom: max(8px, var(--safe-bottom));
}

.fab {
  position: fixed; z-index: 21; right: max(22px, calc((100vw - 720px) / 2 + 22px)); bottom: calc(max(8px, var(--safe-bottom)) + 82px);
  width: 58px; height: 58px; border-radius: 20px; border: 0; background: var(--accent); box-shadow: 0 14px 34px rgba(126,101,9,.25);
  cursor: pointer; display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

.calendar-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; margin-bottom: 22px; }
.day-cell { border: 0; padding: 10px 3px; border-radius: 17px; background: transparent; text-align: center; cursor: pointer; }
.day-cell span { display: block; }
.day-name { color: var(--muted); font-size: .68rem; font-weight: 740; text-transform: uppercase; }
.day-number { margin-top: 7px; font-weight: 780; }
.day-dot { width: 4px; height: 4px; margin: 7px auto 0; border-radius: 50%; background: transparent; }
.day-cell.has-data .day-dot { background: var(--accent-strong); }
.day-cell.active { background: var(--ink); color: white; }
.day-cell.active .day-name { color: rgba(255,255,255,.55); }

.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; margin-bottom: 24px; }
.metric-card { background: var(--surface-solid); border-radius: var(--radius-lg); padding: 17px; box-shadow: 0 8px 24px rgba(31,32,27,.05); }
.metric-label { color: var(--muted); font-size: .75rem; font-weight: 720; }
.metric-value { margin-top: 8px; font-size: 1.65rem; font-weight: 820; letter-spacing: -0.05em; }
.chart-card, .settings-card { background: var(--surface-solid); border-radius: var(--radius-xl); padding: 18px; box-shadow: 0 8px 26px rgba(31,32,27,.05); margin-bottom: 14px; }
.week-chart { height: 170px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; margin-top: 18px; }
.bar-wrap { height: 100%; display: grid; grid-template-rows: 1fr auto; gap: 7px; align-items: end; }
.bar-track { height: 100%; display: flex; align-items: flex-end; border-radius: 12px; background: var(--surface-muted); overflow: hidden; }
.bar { width: 100%; min-height: 7px; background: var(--ink); border-radius: 12px; transition: height .3s ease; }
.bar-label { text-align: center; font-size: .68rem; color: var(--muted); font-weight: 720; }
.streak-list { display: grid; gap: 10px; margin-top: 14px; }
.streak-row { display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center; }
.streak-row .habit-emoji { width: 38px; height: 38px; border-radius: 13px; }
.streak-days { font-weight: 800; }

.settings-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-title { font-weight: 760; }
.settings-copy { color: var(--muted); font-size: .78rem; margin-top: 3px; }
.switch { width: 48px; height: 29px; border: 0; border-radius: 999px; background: #d8d7d1; padding: 3px; cursor: pointer; }
.switch::after { content: ""; display: block; width: 23px; height: 23px; border-radius: 50%; background: white; box-shadow: 0 2px 7px rgba(0,0,0,.16); transition: transform .2s ease; }
.switch.on { background: var(--ink); }
.switch.on::after { transform: translateX(19px); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: end; justify-content: center; background: rgba(8,10,8,.58); backdrop-filter: blur(8px); padding: 10px; }
.sheet {
  width: min(100%, 660px);
  max-height: 93vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 30px 30px 22px 22px;
  padding: 20px;
  box-shadow: 0 -20px 80px rgba(0,0,0,.24);
  animation: sheet-in .22s ease both;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 999px; margin: 0 auto 19px; background: #d5d2ca; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 19px; }
.habit-preview-sheet { background: var(--bg); }
.habit-detail-title { min-width: 0; display: flex; align-items: center; gap: 13px; }
.habit-detail-title h2 { margin-top: 2px; font-size: 1.34rem; overflow-wrap: anywhere; }
.habit-detail-description {
  margin: -4px 0 16px;
  max-width: 68ch;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.habit-detail-meter {
  display: grid;
  gap: 14px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface-solid);
  margin-bottom: 14px;
}
.detail-meter-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.detail-meter-head strong { display: block; margin-top: 4px; font-size: 2rem; line-height: 1; letter-spacing: -0.05em; }
.detail-meter-label { display: block; color: var(--muted); font-size: .72rem; font-weight: 760; letter-spacing: .04em; text-transform: uppercase; }
.detail-percent-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: .82rem;
  font-weight: 780;
}
.detail-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.detail-fact {
  min-width: 0;
  padding: 14px;
  border-radius: 18px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
}
.detail-fact span { display: block; color: var(--muted); font-size: .68rem; font-weight: 760; }
.detail-fact strong { display: block; margin-top: 4px; font-size: .92rem; font-weight: 780; line-height: 1.35; overflow-wrap: anywhere; }
.detail-sheet-grid { margin-bottom: 14px; }
.detail-checkin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface-solid);
}
.detail-week-grid { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 6px; margin: 0 0 14px; }
.detail-actions { grid-template-columns: .95fr 1.25fr; margin-top: 16px; }
.detail-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
}
.detail-actions .detail-edit-button { box-shadow: none; }
.detail-actions .detail-delete-button {
  background: var(--surface-solid);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--line));
}
.detail-actions svg { width: 18px; height: 18px; stroke-width: 1.9; }
.form-grid { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field label { font-size: .76rem; font-weight: 760; color: var(--muted); }
.field-optional { margin-left: 4px; font-weight: 600; opacity: .72; }
.field-hint { color: var(--muted); font-size: .68rem; line-height: 1.4; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 16px; padding: 13px 14px; background: var(--surface-solid); color: var(--ink);
}
.field textarea { min-height: 104px; resize: vertical; line-height: 1.45; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 5px; border-radius: 17px; background: var(--surface-muted); }
.segmented button { padding: 10px 5px; border-radius: 13px; background: transparent; font-size: .76rem; font-weight: 740; }
.segmented button.active { background: white; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.primary-button, .secondary-button { min-height: 47px; border-radius: 16px; padding: 12px 17px; font-weight: 790; }
.primary-button { background: var(--ink); color: white; }
.secondary-button { background: var(--surface-muted); }
.danger-button { color: var(--danger); }
.button-row { display: grid; grid-template-columns: 1fr 1.5fr; gap: 9px; margin-top: 7px; }
.days-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.day-chip { border: 0; border-radius: 12px; padding: 9px 2px; background: var(--surface-muted); cursor: pointer; font-size: .7rem; font-weight: 780; }
.day-chip.active { background: var(--ink); color: white; }

.toast { position: fixed; z-index: 90; left: 50%; bottom: calc(105px + var(--safe-bottom)); transform: translateX(-50%); width: min(calc(100% - 36px), 520px); padding: 13px 16px; border-radius: 16px; background: var(--ink); color: white; box-shadow: var(--shadow); animation: toast-in .2s ease; font-size: .84rem; }
@keyframes toast-in { from { transform: translate(-50%, 10px); opacity: 0; } }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }

@media (min-width: 700px) {
  .app-shell { padding-top: 34px; }
  .habit-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-card { padding: 29px; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-backdrop { align-items: center; }
  .sheet { border-radius: 30px; }
}

@media (max-width: 430px) {
  .detail-facts { grid-template-columns: 1fr; }
  .detail-actions { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Weekly habits */
.weekly-list { display: grid; gap: 12px; }
.weekly-habit-card {
  position: relative;
  padding: 17px; border-radius: var(--radius-lg); background: var(--surface-solid); border: 1px solid var(--line);
  box-shadow: 0 8px 26px rgba(31,32,27,.055); cursor: pointer; transition: opacity .2s ease, transform .15s ease, box-shadow .15s ease;
}
.weekly-habit-card:hover { box-shadow: 0 11px 30px rgba(31,32,27,.075); }
.weekly-habit-card:active { transform: scale(.992); }
.weekly-habit-card.done { border-color: rgba(130,179,137,.48); }
.weekly-card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.weekly-title-wrap { min-width: 0; display: flex; align-items: center; gap: 12px; }
.weekly-title-wrap > div:last-child { min-width: 0; }
.weekly-side { flex: 0 0 auto; display: flex; align-items: center; gap: 9px; }
.weekly-score { flex: 0 0 auto; text-align: right; }
.weekly-score strong { display: block; font-size: 1.18rem; letter-spacing: -.04em; }
.weekly-score span { display: block; margin-top: 2px; color: var(--muted); font-size: .7rem; font-weight: 730; }
.weekly-progress { height: 8px; margin: 15px 0 13px; border-radius: 99px; background: var(--surface-muted); overflow: hidden; }
.weekly-progress span { display: block; height: 100%; min-width: 0; border-radius: inherit; background: var(--accent-strong); transition: width .3s ease; }
.weekly-habit-card.done .weekly-progress span { background: var(--success); }
.weekly-days { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 6px; }
.weekly-day {
  min-height: 42px; display: grid; place-items: center; align-content: center; gap: 2px; border-radius: 12px;
  background: var(--surface-muted); color: var(--muted); font-size: .67rem; font-weight: 780;
}
.weekly-day b { min-height: .8rem; color: var(--ink); font-size: .68rem; }
.weekly-day.filled { background: color-mix(in srgb, var(--accent) 38%, var(--surface-muted)); color: var(--ink); }
.weekly-day.active { box-shadow: inset 0 0 0 2px var(--ink); }
.weekly-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.schedule-segmented { grid-template-columns: repeat(2, 1fr); }
.full-width { width: 100%; }
.token-list { display: grid; gap: 9px; margin-top: 12px; }
.token-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.token-row:first-child { border-top: 0; }
.token-reveal {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  margin: 13px 0; padding: 12px; border-radius: 16px; background: var(--surface-muted);
}
.token-reveal span { display: block; color: var(--muted); font-size: .68rem; font-weight: 760; }
.token-reveal code { display: block; margin-top: 5px; font-size: .76rem; overflow-wrap: anywhere; }

/* Authentication */
.auth-shell {
  width: min(100%, 510px); min-height: 100vh; margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) 18px 32px;
  display: flex; flex-direction: column; justify-content: center; position: relative;
}
.auth-theme { position: absolute; top: max(18px, env(safe-area-inset-top)); right: 18px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin: 50px 3px 25px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 18px; background: var(--accent); color: #171914; font-size: 1.55rem; font-weight: 900; box-shadow: 0 12px 28px rgba(126,101,9,.17); }
.auth-brand h1 { font-size: 2.55rem; }
.auth-card { padding: 23px; border-radius: 30px; background: var(--surface-solid); border: 1px solid var(--line); box-shadow: var(--shadow); }
.auth-heading { margin-bottom: 20px; }
.auth-heading h2 { font-size: 1.55rem; }
.auth-heading p:not(.eyebrow) { margin: 8px 0 0; color: var(--muted); font-size: .88rem; }
.auth-submit { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 3px; }
.inline-icon { display: inline-grid; place-items: center; }
.inline-icon svg { width: 18px; height: 18px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: .72rem; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: .82rem; }
.auth-switch button { border: 0; padding: 0; background: transparent; color: var(--ink); font-weight: 800; cursor: pointer; }
.auth-security { margin: 20px 0 0; padding-top: 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: .68rem; line-height: 1.5; }
.profile-row { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; }
.profile-avatar { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: var(--accent); color: #171914; font-weight: 850; font-size: 1.08rem; }

/* Dark theme */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11130f;
  --surface: rgba(30, 33, 27, .88);
  --surface-solid: #1c1f19;
  --surface-muted: #272b23;
  --ink: #f3f2ec;
  --muted: #a5a99d;
  --line: rgba(255,255,255,.09);
  --accent: #f4d35e;
  --accent-strong: #e1bd37;
  --success: #8fc398;
  --danger: #df8a79;
  --shadow: 0 18px 50px rgba(0,0,0,.28);
}
html[data-theme="dark"] body {
  background: radial-gradient(circle at 15% -10%, rgba(244,211,94,.12), transparent 30rem), var(--bg);
}
html[data-theme="dark"] .icon-button { box-shadow: 0 8px 24px rgba(0,0,0,.22); }
html[data-theme="dark"] .habit-card { border-color: var(--line); box-shadow: 0 5px 18px rgba(0,0,0,.16); }
html[data-theme="dark"] .habit-card:hover { border-color: rgba(255,255,255,.14); box-shadow: 0 9px 24px rgba(0,0,0,.22); }
html[data-theme="dark"] .weekly-habit-card:hover { box-shadow: 0 11px 30px rgba(0,0,0,.22); }
html[data-theme="dark"] .detail-percent-pill { background: #272b23; color: #f3f2ec; }
html[data-theme="dark"] .detail-actions .detail-delete-button { background: #1c1f19; }
html[data-theme="dark"] .detail-fact,
html[data-theme="dark"] .detail-checkin-row,
html[data-theme="dark"] .habit-detail-meter { box-shadow: 0 10px 28px rgba(0,0,0,.12); }
html[data-theme="dark"] .check-button { border-color: rgba(255,255,255,.22); }
html[data-theme="dark"] .check-button.checked,
html[data-theme="dark"] .nav-item.active,
html[data-theme="dark"] .day-cell.active,
html[data-theme="dark"] .day-chip.active,
html[data-theme="dark"] .primary-button { background: #f1f0e9; color: #151712; }
html[data-theme="dark"] .bottom-nav { background: rgba(27,30,24,.98); border-color: rgba(255,255,255,.08); box-shadow: 0 18px 48px rgba(0,0,0,.38); }
html[data-theme="dark"] .segmented button.active { background: #373c31; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
html[data-theme="dark"] .sheet-handle { background: #44483e; }
html[data-theme="dark"] .switch { background: #40443b; }
html[data-theme="dark"] .switch.on { background: var(--accent-strong); }
html[data-theme="dark"] .switch.on::after { background: #171914; }
html[data-theme="dark"] .empty-card { border-color: rgba(255,255,255,.13); }
html[data-theme="dark"] .hero-card { background: #20231c; }
html[data-theme="dark"] .weekly-day.active { box-shadow: inset 0 0 0 2px var(--accent); }
html[data-theme="dark"] .weekly-day.filled { background: rgba(244,211,94,.25); }
html[data-theme="dark"] .toast { background: #f1f0e9; color: #151712; }

@media (min-width: 700px) {
  .weekly-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-shell { padding-left: 0; padding-right: 0; }
}

/* Expanded habit card — mobile sheet + desktop dialog */
.habit-preview-backdrop {
  --sheet-drag-progress: 0;
  background: rgba(7, 9, 7, .62);
  backdrop-filter: blur(10px) saturate(.9);
  -webkit-backdrop-filter: blur(10px) saturate(.9);
}

.habit-preview-sheet {
  --detail-accent: #e7c456;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-solid) 96%, transparent), color-mix(in srgb, var(--bg) 96%, transparent));
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  box-shadow: 0 28px 90px rgba(0, 0, 0, .34);
  transition: transform .22s cubic-bezier(.22,.8,.26,1);
  transform: translate3d(0, 0, 0);
}

.habit-preview-sheet.is-dragging { transition: none; user-select: none; }
.habit-preview-sheet.is-closing { transition: transform .17s ease-in; }

.habit-preview-sheet .sheet-handle {
  width: 46px;
  height: 5px;
  margin: 0 auto 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 48%, transparent);
  cursor: grab;
  touch-action: none;
}
.habit-preview-sheet .sheet-handle:active { cursor: grabbing; }

.habit-preview-head { align-items: center; margin-bottom: 22px; }
.habit-detail-title { min-width: 0; align-items: center; gap: 15px; }
.habit-detail-emoji {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  display: grid;
  place-items: center;
  border-radius: 19px;
  background: color-mix(in srgb, var(--detail-accent) 10%, var(--surface-muted));
  border: 1px solid color-mix(in srgb, var(--detail-accent) 32%, var(--line));
  font-size: 1.55rem;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.habit-detail-heading { min-width: 0; }
.habit-detail-heading .eyebrow {
  margin-bottom: 7px;
  color: color-mix(in srgb, var(--detail-accent) 76%, var(--muted));
  letter-spacing: .11em;
}
.habit-detail-heading h2 {
  font-size: clamp(1.42rem, 5vw, 1.82rem);
  line-height: 1.08;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}
.habit-preview-close {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 17px;
  background: color-mix(in srgb, var(--surface-muted) 82%, transparent);
  border: 1px solid var(--line);
  box-shadow: none;
}
.habit-preview-close svg {
  display: block;
  width: 22px !important;
  height: 22px !important;
}

.habit-preview-layout { min-width: 0; }
.habit-preview-primary,
.habit-preview-secondary { min-width: 0; }

.habit-detail-meter {
  display: grid;
  gap: 17px;
  padding: 20px;
  margin: 0;
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface-solid) 92%, var(--surface-muted));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
}
.detail-meter-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.detail-meter-label {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 680;
  letter-spacing: 0;
  text-transform: none;
}
.detail-meter-head strong {
  display: block;
  margin-top: 7px;
  font-size: 2.25rem;
  line-height: 1;
  font-weight: 820;
  letter-spacing: -.05em;
}
.detail-percent-pill {
  flex: 0 0 auto;
  min-width: 60px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--detail-accent) 34%, var(--line));
  background: color-mix(in srgb, var(--detail-accent) 8%, var(--surface-muted));
  color: color-mix(in srgb, var(--detail-accent) 82%, var(--ink));
  font-size: 1rem;
  font-weight: 830;
}
.detail-progress-track {
  height: 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 24%, var(--surface-muted));
  overflow: hidden;
}
.detail-progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--detail-accent); }

.detail-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}
.detail-fact {
  min-width: 0;
  min-height: 86px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface-solid) 92%, var(--surface-muted));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
}
/* The direct-child selectors intentionally override the older generic .detail-fact span rule. */
.detail-fact > .detail-fact-icon {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px;
  display: grid !important;
  place-items: center;
  border-radius: 14px;
  background: color-mix(in srgb, var(--detail-accent) 11%, var(--surface-muted));
  color: var(--detail-accent) !important;
  font-size: 0 !important;
  line-height: 0 !important;
}
.detail-fact > .detail-fact-icon svg {
  display: block !important;
  width: 22px !important;
  height: 22px !important;
  min-width: 22px !important;
  max-width: 22px !important;
  stroke: currentColor;
  stroke-width: 1.85;
}
.detail-fact > .detail-fact-copy {
  min-width: 0;
  display: block !important;
  color: inherit !important;
  font-size: inherit !important;
  line-height: normal !important;
}
.detail-fact-copy > span {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
  line-height: 1.25;
}
.detail-fact-copy strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: .98rem;
  font-weight: 790;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.detail-checkin-row {
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  margin: 0;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface-solid) 92%, var(--surface-muted));
  border: 1px solid var(--line);
}
.detail-checkin-row .settings-title { font-size: 1rem; font-weight: 790; }
.detail-checkin-row .settings-copy { margin-top: 5px; font-size: .82rem; }
.detail-check-button { width: 44px; height: 44px; border-width: 1.6px; }
.detail-check-button svg { width: 19px !important; height: 19px !important; }
.detail-counter { flex-wrap: nowrap; }
.detail-counter button { width: 38px; height: 38px; }

.detail-week-grid { margin: 0; }

.detail-actions {
  display: grid;
  grid-template-columns: .9fr 1.25fr;
  gap: 10px;
  margin-top: 14px;
}
.detail-actions button {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 18px;
  font-size: .96rem;
  font-weight: 820;
}
.detail-actions button svg { width: 20px !important; height: 20px !important; }
.detail-actions .detail-delete-button {
  background: color-mix(in srgb, var(--danger) 6%, var(--surface-solid));
  border: 1px solid color-mix(in srgb, var(--danger) 48%, var(--line));
  color: color-mix(in srgb, var(--danger) 90%, var(--ink));
}
.detail-actions .detail-edit-button {
  background: linear-gradient(180deg, #f2d36d, #e7c456);
  border: 1px solid rgba(255,255,255,.18);
  color: #1a1b16;
  box-shadow: 0 10px 24px rgba(167,132,28,.20);
}

/* Mobile: a real draggable bottom sheet. */
@media (max-width: 759px) {
  .habit-preview-backdrop {
    align-items: end;
    padding: max(6px, var(--safe-top)) 6px 0;
  }
  .habit-preview-sheet {
    width: 100%;
    max-height: calc(100dvh - var(--safe-top) - 6px);
    padding: 18px 18px calc(18px + var(--safe-bottom));
    border-radius: 32px 32px 0 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .habit-preview-layout { display: flex; flex-direction: column; gap: 12px; }
  .habit-preview-primary,
  .habit-preview-secondary { display: contents; }
  .habit-detail-meter { order: 1; }
  .detail-facts { order: 2; }
  .detail-week-grid { order: 3; }
  .detail-checkin-row { order: 4; }
  .habit-detail-emoji { width: 54px; height: 54px; flex-basis: 54px; }
  .detail-fact {
    min-height: 82px;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }
  .detail-fact > .detail-fact-icon {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px;
    border-radius: 13px;
  }
  .detail-fact > .detail-fact-icon svg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
  }
  .detail-fact-copy strong { font-size: .9rem; }
}

@media (max-width: 370px) {
  .habit-preview-sheet { padding-left: 14px; padding-right: 14px; }
  .habit-detail-title { gap: 11px; }
  .habit-detail-emoji { width: 48px; height: 48px; flex-basis: 48px; border-radius: 16px; }
  .habit-preview-close { width: 44px; height: 44px; flex-basis: 44px; }
  .detail-facts { grid-template-columns: 1fr; }
  .detail-actions { grid-template-columns: 1fr; }
  .detail-actions .detail-edit-button { order: -1; }
}

/* Desktop: centered, wide and compact instead of a stretched phone sheet. */
@media (min-width: 760px) {
  .habit-preview-backdrop { align-items: center; padding: 32px; }
  .habit-preview-sheet {
    width: min(860px, calc(100vw - 64px));
    max-height: min(780px, calc(100dvh - 64px));
    padding: 28px;
    border-radius: 30px;
    overflow-y: auto;
  }
  .habit-preview-sheet .sheet-handle { display: none; }
  .habit-preview-head { margin-bottom: 20px; }
  .habit-preview-layout {
    display: grid;
    grid-template-columns: minmax(0, .92fr) minmax(0, 1.18fr);
    align-items: start;
    gap: 16px;
  }
  .habit-preview-primary,
  .habit-preview-secondary {
    display: grid;
    align-content: start;
    gap: 12px;
  }
  .detail-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-fact { min-height: 94px; }
  .detail-fact:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .detail-actions {
    width: min(430px, 100%);
    margin: 18px 0 0 auto;
  }
  .sheet:not(.habit-preview-sheet) .sheet-handle { display: none; }
}

html[data-theme="dark"] .habit-preview-sheet {
  --detail-accent: #e7c456;
  background:
    radial-gradient(circle at 18% 0%, rgba(231,196,86,.045), transparent 24rem),
    #10130f;
  border-color: rgba(255,255,255,.075);
}
html[data-theme="dark"] .habit-preview-close,
html[data-theme="dark"] .habit-detail-meter,
html[data-theme="dark"] .detail-fact,
html[data-theme="dark"] .detail-checkin-row {
  background: #1d211b;
  border-color: rgba(255,255,255,.085);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
}
html[data-theme="dark"] .habit-detail-emoji,
html[data-theme="dark"] .detail-fact > .detail-fact-icon {
  background: rgba(231,196,86,.10);
  border-color: rgba(231,196,86,.22);
}
html[data-theme="dark"] .detail-percent-pill {
  background: rgba(231,196,86,.07);
  border-color: rgba(231,196,86,.27);
  color: #f0cd66;
}
html[data-theme="dark"] .detail-progress-track { background: #41463c; }
html[data-theme="dark"] .detail-actions .detail-delete-button {
  background: rgba(190,75,67,.065);
  border-color: rgba(223,98,88,.42);
  color: #f07c73;
}

/* Journal timeline, timezone controls, and future-date safety */
button:disabled,
select:disabled {
  cursor: not-allowed;
}

.journal-week-nav {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 13px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-solid);
  box-shadow: 0 8px 24px rgba(31,32,27,.045);
}

.journal-week-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface-muted);
  box-shadow: none;
}

.journal-week-button:disabled {
  opacity: .32;
}

.journal-week-copy {
  min-width: 0;
  text-align: center;
}

.journal-week-copy strong {
  display: block;
  overflow: hidden;
  font-size: .9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.journal-week-copy span,
.journal-week-copy button {
  display: inline-block;
  margin-top: 3px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 720;
}

.journal-week-copy button {
  color: color-mix(in srgb, var(--accent-strong) 72%, var(--ink));
  cursor: pointer;
}

.day-cell.future,
.weekly-day.future {
  opacity: .3;
  filter: saturate(.35);
}

.day-cell.future {
  pointer-events: none;
}

.habit-card.is-future,
.weekly-habit-card.is-future {
  border-style: dashed;
  background: color-mix(in srgb, var(--surface-solid) 86%, var(--surface-muted));
}

.habit-card.is-future .habit-controls,
.weekly-habit-card.is-future .weekly-actions .counter {
  opacity: .38;
}

.counter button:disabled,
.check-button:disabled {
  opacity: .42;
  transform: none;
}

.settings-row-timezone {
  align-items: start;
}

.settings-select {
  width: min(280px, 42vw);
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 38px 0 12px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: .78rem;
  font-weight: 710;
}

.progress-metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

html[data-theme="dark"] .journal-week-nav {
  box-shadow: 0 10px 28px rgba(0,0,0,.13);
}

@media (max-width: 520px) {
  .journal-week-nav {
    gap: 8px;
    padding: 8px;
  }

  .journal-week-button {
    width: 38px;
    height: 38px;
  }

  .journal-week-copy strong {
    font-size: .78rem;
  }

  .settings-row-timezone {
    grid-template-columns: 1fr;
  }

  .settings-select {
    width: 100%;
  }

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

  .progress-metric-grid .metric-card:last-child {
    grid-column: 1 / -1;
  }
}
