/* ============================================================
   Streak — lightweight design system.

   Same language as hanifedma.com/ponder: no framework, no web fonts
   (the system stack means nothing to download), and no GPU-heavy
   effects — no backdrop-filter, no large blurs, no transforms on
   long lists — so it stays smooth on a low-spec CPU with no GPU.

   Theming is a [data-theme] attribute on <html>, set before the first
   paint so there is never a flash of the wrong colours.
   ============================================================ */

:root {
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 11px;
  --maxw: 980px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  --cell-w: 34px;
  --cell-h: 42px;
  --name-w: 208px;
}

/* ---------- Dark (default) — palette matched to hanifedma.com ---------- */
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-2: #202021;
  --surface-3: #282829;
  --elevated: #232323;
  --border: #333333;
  --border-strong: #454545;
  --text: #f0f0f0;
  --muted: #a6a6a6;
  --faint: #6f6f6f;
  --accent: #22c55e;
  --accent-hover: #4ade80;
  --accent-soft: rgba(34, 197, 94, 0.16);
  --accent-contrast: #052e16;
  --danger: #f4566b;
  --danger-soft: rgba(244, 86, 107, 0.14);
  /* Amber, for the one action that is irreversible but destroys nothing you
     chose to keep. Red stays reserved for deletion, so the two never blur. */
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.13);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
  --cell-empty: #2a2a2b;
  --cell-off: #1f1f20;
  --track: #2a2a2b;

  /* Habit colours — pastel on black, like the reference app. */
  --h-green: #4ade80;
  --h-teal: #2dd4bf;
  --h-sky: #38bdf8;
  --h-blue: #60a5fa;
  --h-indigo: #a5b4fc;
  --h-purple: #c084fc;
  --h-pink: #f9a8d4;
  --h-red: #fb7185;
  --h-amber: #fbbf24;
  --h-lime: #a3e635;
}

/* ---------- Light ---------- */
:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e8eaed;
  --elevated: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1a1a1a;
  --muted: #565b64;
  --faint: #868e96;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-soft: rgba(22, 163, 74, 0.10);
  --accent-contrast: #ffffff;
  --danger: #e11d48;
  --danger-soft: rgba(225, 29, 72, 0.10);
  /* Darker than the dark theme's amber: #fbbf24 on white fails contrast. */
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.09);
  --shadow: 0 12px 34px rgba(20, 20, 30, 0.10);
  --shadow-sm: 0 2px 10px rgba(20, 20, 30, 0.06);
  --cell-empty: #e9ebee;
  --cell-off: #f5f6f8;
  --track: #e9ebee;

  /* Darker variants so they stay readable on white. */
  --h-green: #16a34a;
  --h-teal: #0d9488;
  --h-sky: #0284c7;
  --h-blue: #2563eb;
  --h-indigo: #4f46e5;
  --h-purple: #9333ea;
  --h-pink: #db2777;
  --h-red: #e11d48;
  --h-amber: #d97706;
  --h-lime: #65a30d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* The page background is set on <html> as well as <body>. Without it the
   canvas colour comes from body via background-propagation, and it is far
   clearer to have the root paint it directly — both fade together on a theme
   change, so there is no moment where the page and its contents disagree. */
html { background: var(--bg); }

/* [hidden] must always beat class-based display rules. */
[hidden] { display: none !important; }

/* No transitions until the first paint, so nothing animates on load. */
.preload *, .preload *::before, .preload *::after { transition: none !important; }

/* A deliberate theme toggle fades every colour slowly, like hanifedma.com.
   Grid and calendar cells are excluded on purpose: fading several hundred of
   them at once is exactly what makes a weak machine stutter. Normal hover and
   focus stay snappy because .theming is only present for the ~2s of the fade.

   The class is set on <html> (see app.js), so the leading `.theming` below
   covers the root and `.theming *` covers <body> and everything under it.
   With the class on <body> instead, body was NOT matched by `.theming *`, so
   the page background snapped while its contents faded. */
.theming,
.theming *:not(.cell):not(.cal-cell),
.theming *:not(.cell):not(.cal-cell)::before {
  /* `stroke` matters as much as `fill` here: the progress rings and the login
     mark are SVG strokes, so without it they snap while the page fades. */
  transition-property: background-color, border-color, color, box-shadow, fill, stroke;
  transition-duration: 2s;
  transition-timing-function: ease;
}

/* Elements that own a `transition` shorthand need it restating during the fade.
   The shorthand REPLACES transition-property, so whichever rule wins silently
   drops the other's properties — these put both halves back together. */

/* The sliding pill: same specificity as the rule above but declared later, so
   it was winning and losing the colour fade. */
.theming .view-tabs.anim .tab-pill {
  transition: transform .32s ease, width .32s ease,
              background-color 2s ease, box-shadow 2s ease !important;
}

/* The ring's sweep animation must survive the fade, and vice versa. */
.theming .ring-fg {
  transition: stroke 2s ease, stroke-dashoffset .35s ease !important;
}

/* Grid and calendar cells are kept out of the blanket rule above because there
   are hundreds of them. They still need to keep step with the page, so they get
   a narrow fade of their own: cells carry no background any more (the row does),
   so this is a paint-only colour change and stays cheap on a weak CPU. */
.theming .cell { transition: color 2s ease; }
.theming .cal-cell { transition: background-color 2s ease, color 2s ease; }

/* …but don't let the rule above strip the toggle's own sun/moon animation:
   it replaces transition-property, so the knob would snap across instead of
   sliding. These need !important to beat it. */
.theming .theme-switch .slider::before {
  transition: transform 2s ease, background-color 2s ease, border-color 2s ease !important;
}
.theming .theme-switch .ts-label {
  transition: opacity 1.5s ease, color 2s ease !important;
}

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }

button, input, select, textarea { font-family: inherit; }
::selection { background: var(--accent-soft); }

h1, h2, h3 { line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1 1 auto; }
.danger-text { color: var(--danger); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.input:focus-visible { outline: none; }

/* ---------------- Boot / noscript ---------------- */
.boot-loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 60;
}
.boot-mark {
  font-size: 40px; color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.noscript-note {
  max-width: 520px; margin: 80px auto; padding: 28px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.noscript-mark { font-size: 34px; color: var(--accent); }

/* ---------------- Header ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 11px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

/* View nav — sliding segmented control; JS sets the pill's position/width. */
.view-tabs {
  position: relative; display: inline-flex; padding: 3px; flex: 0 0 auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.tab-pill {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0;
  border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-sm);
}
.view-tabs.anim .tab-pill { transition: transform .32s ease, width .32s ease; }
.view-tab {
  position: relative; z-index: 1; flex: 0 0 auto;
  border: none; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 13px; padding: 7px 16px; border-radius: 8px;
  cursor: pointer; white-space: nowrap; transition: color .2s ease;
}
.view-tab:hover, .view-tab.active { color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 9px; }

/* All top-bar controls share one shape: 40px tall, same surface and radius. */
.user-chip {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.local-chip { padding: 0 12px; gap: 6px; }
.chip-icon { font-size: 14px; line-height: 1; }
.user-photo {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid var(--border); object-fit: cover; background: var(--surface-2);
}
.user-initial {
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
  font-size: 12px; font-weight: 700; line-height: 1;
}
.user-name {
  font-size: 13px; color: var(--muted); font-weight: 500;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.theme-switch {
  position: relative; display: inline-flex; flex: 0 0 auto;
  height: 40px; width: 92px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
/* Hidden but still keyboard-focusable — display:none would drop it from the
   tab order and make the toggle unreachable without a mouse. */
.theme-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.theme-switch .slider { position: absolute; inset: 0; border-radius: inherit; }
.theme-switch .slider::before {
  content: "☀️";
  position: absolute; top: 50%; left: 3px; width: 32px; height: 32px; z-index: 2;
  border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; box-shadow: var(--shadow-sm);
  transform: translateY(-50%); transition: transform .35s ease;
}
.theme-switch input:checked + .slider::before { content: "🌙"; transform: translate(50px, -50%); }
.theme-switch .ts-label {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 12px; font-weight: 600; color: var(--muted);
  pointer-events: none; transition: opacity .3s ease;
}
.theme-switch .ts-light { right: 12px; opacity: 1; }
.theme-switch .ts-dark { left: 12px; opacity: 0; }
.theme-switch input:checked + .slider .ts-light { opacity: 0; }
.theme-switch input:checked + .slider .ts-dark { opacity: 1; }
.theme-switch input:focus-visible + .slider {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: inherit;
}

.lang-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .12s ease;
}
.lang-btn:hover { background: var(--surface-3); }
.lang-glyph { font-size: 14px; line-height: 1; }
#langLabel { min-width: 18px; text-align: center; }

.menu-wrap { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 46px; z-index: 40; min-width: 160px;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 6px;
}
.menu-item {
  display: block; width: 100%; text-align: start;
  border: none; background: none; color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }

/* ---------------- Buttons ---------------- */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
/* Outlined rather than filled: it sits in the same modal as the green "Done"
   and the red "Delete all habits", and a third solid block of colour there
   reads as a row of equally weighted choices. */
.btn-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.btn-warn:hover:not(:disabled) { background: var(--warn-soft); border-color: var(--warn); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.text-btn {
  border: none; background: none; color: var(--accent); cursor: pointer;
  font-size: 13px; padding: 5px 8px; border-radius: 8px; font-weight: 500;
}
.text-btn:hover { background: var(--surface-2); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 16px; cursor: pointer; line-height: 1;
  transition: background .12s ease;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.menu-btn { font-size: 20px; }

.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 18px; margin-top: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .12s ease;
}
.google-btn:hover { background: var(--surface-3); }

/* Where Google renders its own button. It sizes itself, so this only has to
   centre it and reserve nothing — an empty holder must collapse, or a card
   with no button gets a hole in it. */
.gsi-holder { display: flex; justify-content: center; margin-top: 6px; }
.gsi-holder:empty { display: none; }
.gsi-wait { margin: 10px 0 0; }

/* The fallback route, demoted to sit under Google's button. Still a real
   button — it is the only way in when that one can't be drawn — but it stops
   competing with it: no logo, no border, no weight. */
.google-btn-alt {
  border-color: transparent; background: none;
  font-size: 13px; font-weight: 500; color: var(--muted);
  padding: 8px 12px; margin-top: 10px; width: auto;
}
.google-btn-alt:hover { background: var(--surface-3); color: var(--text); }
.google-btn-alt svg { display: none; }
/* The login card centres its own contents; the sign-in dialog does not. */
.modal-card .gsi-wait { text-align: center; }
.modal-card .google-btn-alt { display: flex; width: fit-content; margin-inline: auto; }

.sync-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; }
.g-badge { display: inline-flex; background: #fff; border-radius: 4px; padding: 2px; }

/* ---------------- Inputs ---------------- */
.input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  transition: border-color .12s ease;
}
.input:focus { outline: none; border-color: var(--accent); }
/* An avoid habit can only ever be a ceiling, so its goal direction is fixed
   and shown rather than offered. Dimmed, but still readable — it is telling
   you what the habit does, not hiding a control. */
.input:disabled { color: var(--muted); background: var(--surface-2); cursor: default; opacity: 1; }
.select { cursor: pointer; }
.input[type="date"], .input[type="number"] { min-width: 0; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block; font-size: 13px; font-weight: 600; color: var(--muted);
  margin-bottom: 6px;
}
.hint { display: block; font-size: 12px; margin-top: 5px; }
.row-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-inline .input { width: auto; flex: 1 1 90px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.error-text {
  color: var(--danger); font-size: 13px; margin: 8px 0 0;
  background: var(--danger-soft); padding: 8px 12px; border-radius: 8px;
}

/* Segmented radio group (type / frequency pickers). */
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: block; text-align: center; cursor: pointer;
  padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.seg input:checked + span {
  color: var(--accent-contrast); background: var(--accent); border-color: var(--accent);
}
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.dayboxes { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.daybox input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.daybox span {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600;
}
.daybox input:checked + span {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.daybox input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch > span[aria-hidden] {
  display: block; width: 28px; height: 28px; border-radius: 50%;
  background: var(--habit); cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border);
}
.swatch input:checked + span[aria-hidden] {
  border-color: var(--bg); box-shadow: 0 0 0 2px var(--habit);
}
.swatch input:focus-visible + span[aria-hidden] { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------------- Habit colours ----------------
   One variable per row/item; every coloured part reads --habit, so a row
   only has to set it once. */
.c-green  { --habit: var(--h-green); }
.c-teal   { --habit: var(--h-teal); }
.c-sky    { --habit: var(--h-sky); }
.c-blue   { --habit: var(--h-blue); }
.c-indigo { --habit: var(--h-indigo); }
.c-purple { --habit: var(--h-purple); }
.c-pink   { --habit: var(--h-pink); }
.c-red    { --habit: var(--h-red); }
.c-amber  { --habit: var(--h-amber); }
.c-lime   { --habit: var(--h-lime); }

/* ---------------- Layout ---------------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 20px 18px 96px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.center-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card { max-width: 420px; width: 100%; text-align: center; padding: 34px 28px; }
.login-card h1 { font-size: 24px; margin: 14px 0 8px; }
.login-mark { display: flex; justify-content: center; }
.mark-bg { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.mark-check { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.local-link { margin-top: 14px; display: inline-block; }
.login-privacy { font-size: 12px; margin: 14px 0 0; }

.empty-state { text-align: center; padding: 48px 18px; }
.empty-emoji { font-size: 40px; display: block; margin-bottom: 10px; }
.empty-state p { margin: 4px 0; }
.empty-add { margin-top: 20px; }

.list-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 14px 2px 8px; font-size: 13px;
}
.offline-badge {
  font-size: 12px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px;
}

/* ---------------- Today ---------------- */
.today-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.today-date { font-size: 19px; margin: 0 0 4px; }
.today-sub { margin: 0; font-size: 14px; }

.big-ring { position: relative; flex: 0 0 auto; width: 64px; height: 64px; }
.big-ring svg { transform: rotate(-90deg); }
.big-ring-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.ring-bg { fill: none; stroke: var(--track); stroke-width: 5; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round;
  transition: stroke-dashoffset .35s ease;
}

.today-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.today-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
}
.today-item.is-done { border-color: var(--habit); background: var(--surface-2); }
.today-item.is-skip { opacity: .6; }
.ti-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 11px;
  border: none; background: none; color: inherit; cursor: pointer;
  padding: 4px; text-align: start; border-radius: 8px;
}
.ti-dot {
  flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--habit);
}
.ti-text { min-width: 0; display: flex; flex-direction: column; }
.ti-name {
  font-size: 15px; font-weight: 600; color: var(--habit);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.today-item.is-done .ti-name { text-decoration: line-through; text-decoration-thickness: 1px; }
.ti-sub { font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.streak-badge { color: var(--muted); }
.ti-actions { flex: 0 0 auto; }

.ti-progress {
  display: block; height: 3px; margin-top: 6px; max-width: 220px;
  background: var(--track); border-radius: 999px; overflow: hidden;
}
.ti-progress-fill { display: block; height: 100%; background: var(--habit); border-radius: 999px; }

.check-btn {
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--border-strong); background: var(--surface-2);
  color: transparent; font-size: 20px; line-height: 1;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.check-btn:hover { border-color: var(--habit); color: var(--faint); }
.check-btn.on { background: var(--habit); border-color: var(--habit); color: var(--bg); }
.check-btn.skipped { color: var(--muted); border-style: dashed; }

/* ---- Avoid habits ("don't eat sweets"): kept by default ----
   The tick is already on when you arrive, so it is drawn as an outline
   rather than a filled block — a solid badge would read as something you
   just achieved, when in fact you have only not broken it yet. The button
   still says what it does: press it to record a slip. */
.check-btn.is-avoid.on {
  background: transparent; border-color: var(--habit); color: var(--habit);
}
.check-btn.is-avoid.on:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.check-btn.is-avoid.broke {
  background: var(--danger); border-color: var(--danger); color: #fff;
}
.check-btn.is-avoid.broke:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
/* Nothing was crossed off — the day was simply not spoiled. */
.today-item.is-avoid .ti-name { text-decoration: none; }
.today-item.is-avoid.is-done { background: var(--surface); }
.today-item.is-broke { border-color: var(--danger); }
.today-item.is-broke .ti-name { color: var(--danger); }

.stepper { display: flex; align-items: center; gap: 4px; }
.step-btn {
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-size: 17px; line-height: 1;
}
.step-btn:hover { background: var(--surface-3); }
.step-val {
  min-width: 58px; height: 36px; padding: 0 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--habit);
  font-size: 14px; font-weight: 700;
}

/* Once there are habits, the add button sits full-width under the list so it
   reads as the end of the list rather than a stray control. */
.today-foot { margin-top: 10px; }
.today-foot .btn { width: 100%; }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.search-wrap { position: relative; flex: 1 1 180px; min-width: 150px; }
.search-icon {
  position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .65; pointer-events: none;
}
.search-wrap .input { padding-inline-start: 34px; }

/* ---------------- Grid ----------------
   Both axes scroll inside this one box, which is what lets the header row
   and the habit-name column stay pinned with plain position:sticky. */
.grid-wrap {
  overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  max-height: calc(100vh - 250px);
  /* On a very short window that calc can reach zero and hide the grid
     entirely, leaving only the sticky header row visible. */
  min-height: 180px;
  -webkit-overflow-scrolling: touch;
}
.grid { border-collapse: separate; border-spacing: 0; width: max-content; }

.grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface); border-bottom: 1px solid var(--border);
  font-weight: 600; padding: 7px 0; width: var(--cell-w); min-width: var(--cell-w);
}
.grid thead th.corner {
  inset-inline-start: 0; z-index: 3;
  width: var(--name-w); min-width: var(--name-w);
  border-inline-end: 1px solid var(--border);
}
.day { color: var(--muted); font-size: 11px; line-height: 1.25; }
.day-dow { display: block; text-transform: uppercase; letter-spacing: .3px; font-size: 10px; }
.day-num { display: block; font-size: 12px; color: var(--text); }
.day.weekend .day-dow { color: var(--faint); }
.day.is-today { color: var(--accent); }
.day.is-today .day-num { color: var(--accent); font-weight: 800; }
.month-edge { border-inline-start: 1px solid var(--border-strong); }

.habit-cell {
  position: sticky; inset-inline-start: 0; z-index: 1;
  background: var(--surface); border-inline-end: 1px solid var(--border);
  width: var(--name-w); min-width: var(--name-w);
  padding: 0; text-align: start; font-weight: 400;
}
.habit-btn {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: none; background: none; cursor: pointer;
  padding: 6px 12px; height: var(--cell-h); color: inherit; text-align: start;
}
.habit-btn:hover { background: var(--surface-2); }
.habit-name {
  flex: 1 1 auto; min-width: 0; font-size: 14px; font-weight: 600; color: var(--habit);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.habit-streak {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 1px 7px;
}
.ring { flex: 0 0 auto; transform: rotate(-90deg); }
.habit-btn .ring-bg { stroke-width: 3; }
.habit-btn .ring-fg { stroke: var(--habit); stroke-width: 3; }

.grid tbody tr { border-bottom: 1px solid var(--border); }
/* Row striping is painted on the ROW, not on each of its cells. Visually
   identical (cells are transparent and let the row show through), but during a
   theme fade it means a dozen animating surfaces instead of several hundred.
   The sticky name column keeps its own background — it scrolls over the cells
   and has to stay opaque. */
.grid tbody tr:nth-child(odd),
.grid tbody tr:nth-child(odd) .habit-cell { background: var(--surface-2); }
.grid tbody tr:hover,
.grid tbody tr:hover .habit-cell { background: var(--surface-3); }

.cell {
  width: var(--cell-w); min-width: var(--cell-w); height: var(--cell-h);
  text-align: center; vertical-align: middle;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  font-size: 15px; line-height: 1; color: var(--cell-empty);
  border-bottom: 1px solid var(--border);
  /* No transition here on purpose — this element exists hundreds of times. */
}
.cell.is-done { color: var(--habit); font-weight: 700; font-size: 17px; }
.cell.is-partial { color: var(--habit); font-size: 11px; font-weight: 700; opacity: .8; }
.cell.is-skip { color: var(--faint); }
.cell.is-miss { color: var(--danger); font-weight: 700; }
/* Off-schedule days stay clickable on purpose — you can still back-fill a
   day you did anyway, or one from before you started tracking. */
.cell.is-unscheduled, .cell.is-prestart { color: var(--cell-off); }
.cell:hover { color: var(--faint); }
.cell.is-done:hover { color: var(--habit); }

/* An avoid habit's row is a wall of kept days with the occasional slip in it.
   Drawing those keeps as loudly as a completed chore buries the one cell that
   actually carries information, so they are quieter — and the slip, which is
   already .is-miss in red, is what the eye lands on. */
.grid tbody tr.is-avoid .cell.is-done { font-weight: 400; font-size: 14px; opacity: .72; }
.grid tbody tr.is-avoid .cell.is-done:hover { opacity: 1; }
/* Only reachable for a day that hasn't happened yet: nothing to show. */
.grid tbody tr.is-avoid .cell.is-none { color: var(--cell-off); }

.grid-hint { font-size: 12px; margin: 8px 2px 0; text-align: center; }

/* ---------------- Reorder ---------------- */
/* Reorder is a mode, so the button has to look switched on while it is —
   otherwise there is nothing telling you how to get back to the grid. */
.reorder-btn { display: inline-flex; align-items: center; gap: 7px; }
.reorder-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.reorder-btn[aria-pressed="true"]:hover { background: var(--accent-hover); }

.reorder-panel { margin-top: 14px; }
.reorder-hint { margin: 0 2px 10px; }
.reorder-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.reorder-item {
  position: relative; /* so .dragging can lift above its neighbours */
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  transition: transform .14s ease;
}
/* The row under the finger follows it directly — no easing, or it lags behind. */
.reorder-item.dragging {
  transition: none; z-index: 5;
  border-color: var(--habit); box-shadow: var(--shadow);
}
.reorder-list.is-dragging { user-select: none; -webkit-user-select: none; }

.drag-handle {
  flex: 0 0 auto; cursor: grab;
  padding: 4px 2px; margin-inline-start: -2px;
  color: var(--faint); font-size: 15px; line-height: 1;
  /* Only the handle opts out of touch scrolling, so a touch anywhere else on
     the row still scrolls the page. */
  touch-action: none;
}
.drag-handle:hover { color: var(--text); }
.reorder-item.dragging .drag-handle { cursor: grabbing; }
.reorder-name {
  flex: 1 1 auto; min-width: 0; font-weight: 600; color: var(--habit);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reorder-item .icon-btn { width: 34px; height: 34px; }

/* ---------------- Popover ---------------- */
.popover {
  position: fixed; z-index: 70; width: 244px; padding: 12px;
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.pop-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.pop-name {
  font-size: 13px; font-weight: 700; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.pop-date { font-size: 12px; flex: 0 0 auto; }
.pop-row { display: flex; gap: 6px; align-items: center; margin-bottom: 9px; }
.pop-input { flex: 1 1 auto; }
.pop-unit { font-size: 12px; flex: 0 0 auto; }
.pop-actions { display: grid; gap: 4px; }
.pop-btn {
  text-align: start; border: none; background: none; color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.pop-btn:hover { background: var(--surface-2); }
.pop-btn.danger { color: var(--danger); }

/* ---------------- Modal ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 80; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.modal-card {
  position: relative; margin: 5vh auto; max-width: 480px; width: calc(100% - 32px);
  max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow);
}
.modal-card h2 { font-size: 19px; margin: 0 0 16px; }
.modal-section { margin-bottom: 20px; }
.modal-section h3 { font-size: 14px; margin: 0 0 10px; color: var(--muted); }
.modal-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}
.danger-zone { border-top: 1px solid var(--border); padding-top: 16px; }

/* "Start over": its own bordered block, so it is plainly not part of the data
   tools above it and plainly not the delete below it. */
.reset-zone { border-top: 1px solid var(--border); padding-top: 16px; }
.reset-zone .small { margin: 0 0 10px; }
/* Full width and free to wrap. The label is a sentence, and in Korean it is a
   longer one — .btn's nowrap would push it straight out of a 320px modal. */
.reset-zone .btn {
  display: block; width: 100%; margin-bottom: 8px;
  white-space: normal; text-align: center; line-height: 1.35;
}

/* The consequences, under the question rather than inside it. */
.confirm-detail { margin: -8px 0 0; font-size: 14px; line-height: 1.5; }

.archived-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.archived-item {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
}
.archived-name {
  flex: 1 1 auto; min-width: 0; font-weight: 600; color: var(--habit);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------- Stats ---------------- */
.stats-panel { position: fixed; inset: 0; z-index: 75; }
.stats-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.stats-sheet {
  position: absolute; inset-block: 0; inset-inline-end: 0;
  width: min(520px, 100%); overflow-y: auto;
  background: var(--bg); border-inline-start: 1px solid var(--border);
  padding: 20px 20px 60px;
}
.stats-close { position: absolute; top: 14px; inset-inline-end: 16px; }
.stats-body { padding-top: 6px; }
.stats-title-row { display: flex; align-items: center; gap: 10px; padding-inline-end: 48px; }
.stats-title-row h2 { font-size: 20px; margin: 0; color: var(--habit); }
/* Says which way round to read the panel: on an avoid habit a full green
   month means nothing went wrong, not that something was done 31 times. */
.kind-chip {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; letter-spacing: .2px;
  color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}
.stats-meta { font-size: 13px; margin: 6px 0 0; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 18px 0; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.tile-icon { font-size: 15px; }
.tile-value { font-size: 24px; font-weight: 800; line-height: 1.2; }
.tile-unit { font-size: 12px; font-weight: 600; color: var(--muted); margin-inline-start: 4px; }
.tile-label { font-size: 12px; }

.stats-section { margin: 22px 0; }
.stats-section h3 { font-size: 14px; margin: 0 0 12px; color: var(--muted); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-title { font-size: 15px; margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border-radius: 7px; font-size: 12px;
  background: var(--surface-2); color: var(--muted);
}
/* aspect-ratio is recent-ish; keep a sane height on browsers without it. */
@supports not (aspect-ratio: 1 / 1) { .cal-cell { height: 34px; } }
.cal-cell.empty { background: none; }
.cal-cell.is-done { background: var(--habit); color: var(--bg); font-weight: 700; }
.cal-cell.is-partial { background: var(--habit); color: var(--bg); opacity: .5; }
.cal-cell.is-skip { background: var(--surface-3); color: var(--faint); }
.cal-cell.is-miss { background: var(--danger-soft); color: var(--danger); }
.cal-cell.is-unscheduled, .cal-cell.is-prestart, .cal-cell.is-future {
  background: none; color: var(--faint); opacity: .5;
}
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--accent); }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.bar-track {
  width: 100%; height: 78px; display: flex; align-items: flex-end;
  background: var(--track); border-radius: 6px; overflow: hidden;
}
.bar-fill { width: 100%; background: var(--habit); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-label { font-size: 11px; color: var(--muted); }
.bar-pct { font-size: 10px; }

/* ---------------- Toasts ---------------- */
.toasts {
  position: fixed; z-index: 90; inset-block-end: 18px; inset-inline: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px;
  max-width: 420px;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 11px 15px; font-size: 14px; box-shadow: var(--shadow);
  animation: toast-in .18s ease;
}
.toast.out { opacity: 0; transition: opacity .2s ease; }
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-action {
  border: none; background: none; color: var(--accent);
  font-weight: 700; font-size: 13px; cursor: pointer; padding: 2px 4px; flex: 0 0 auto;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---------------- Responsive ---------------- */
@media (max-width: 720px) {
  :root { --name-w: 148px; --cell-w: 32px; --cell-h: 40px; }
  /* The top bar stays ONE row and never wraps — a wrapped header reads as
     broken. Instead the controls shrink, and the least useful labels drop out
     first at the narrower breakpoints below. */
  .topbar-inner { padding: 8px 10px; gap: 7px; flex-wrap: nowrap; }
  .view-tabs { flex: 0 1 auto; min-width: 0; }
  .view-tab { padding: 7px 12px; }
  .topbar-actions { flex: 0 0 auto; gap: 7px; }
  .page { padding: 16px 12px 90px; }
  .user-name { max-width: 84px; }
  .sync-long { display: none; }
  .theme-switch { width: 52px; }
  .theme-switch .ts-label { display: none; }
  .theme-switch input:checked + .slider::before { transform: translate(10px, -50%); }
  /* Keep the buttons together on one row and give search its own, instead of
     letting a single button wrap awkwardly onto a third line. The reorder
     button falls back to its icon here; its tooltip and aria-label remain. */
  .toolbar .search-wrap { order: 3; flex: 1 0 100%; }
  .reorder-btn-label { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .stats-sheet { inset-block-start: 8vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .grid-wrap { max-height: calc(100vh - 280px); }
  .today-date { font-size: 17px; }
  .modal-card { margin: 3vh auto; padding: 18px; }
}

/* Below this the header collapses towards icons. Each thing removed here is
   either redundant or available elsewhere — nothing becomes unreachable. */
@media (max-width: 560px) {
  /* The "This device" chip only restates what the Sign in button next to it
     already implies; Settings still shows where data is stored. */
  #localChip { display: none; }
  /* Account: avatar only. Sign out moves into the ⋮ menu (see #menuSignOut). */
  #userName, #signOutBtn { display: none; }
  .user-chip { padding: 0 6px; }
  /* A square toggle: the sun/moon glyph carries the state on its own. */
  .theme-switch { width: 40px; }
  .theme-switch input:checked + .slider::before { transform: translate(0, -50%); }
  .view-tab { padding: 7px 10px; font-size: 12.5px; }
}

@media (max-width: 460px) {
  .lang-btn { padding: 0 10px; }
  .lang-glyph { display: none; }
  /* Google's mark is recognisable enough without the word next to it.
     The button keeps an aria-label so it is still announced properly. */
  .sync-btn { width: 40px; padding: 0; justify-content: center; }
  .sync-btn > span:not(.g-badge) { display: none; }
}

/* Print: a clean paper copy of the grid. */
@media print {
  .topbar, .toolbar, .today-foot, .toasts, .grid-hint, .modal-root, .stats-panel { display: none !important; }
  .grid-wrap { max-height: none; overflow: visible; border: none; }
  body { background: #fff; color: #000; }
}
