/* ============ Tokens ============ */

:root {
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --kb: 0px;
  --radius: 20px;

  /* Spring curves (linear() is supported in iOS 17.2+; older browsers fall back to ease). */
  --spring: linear(0, 0.08 3%, 0.32 8%, 0.72 16%, 1.02 24%, 1.12 30%, 1.13 34%, 1.09 40%, 1 50%, 0.97 58%, 0.985 68%, 1.005 80%, 1);
  --spring-soft: linear(0, 0.12 4%, 0.42 10%, 0.75 18%, 0.93 26%, 1.025 34%, 1.04 42%, 1.02 54%, 1.005 70%, 1);
  --out: cubic-bezier(.22, 1, .36, 1);
}

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000;
  --surface: #121214;
  --surface-2: #1c1c1f;
  --surface-3: #2c2c30;
  --field: #2a2a2e;
  --seg-on: #48484e;
  --toggle-off: #48484e;
  --text: #fff;
  --text-2: rgba(235, 235, 245, .62);
  --text-3: rgba(235, 235, 245, .34);
  --line: rgba(255, 255, 255, .08);
  --accent: #32d74b;
  --danger: #ff453a;
  --scrim: rgba(0, 0, 0, .6);
  --shadow: 0 18px 40px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fff;
  --surface: #f2f2f6;
  --surface-2: #fff;
  --surface-3: #e3e3e9;
  --field: #f0f0f4;
  --seg-on: #fff;
  --toggle-off: #d1d1d6;
  --text: #000;
  --text-2: rgba(60, 60, 67, .72);
  --text-3: rgba(60, 60, 67, .36);
  --line: rgba(0, 0, 0, .08);
  --accent: #28c142;
  --danger: #ff3b30;
  --scrim: rgba(0, 0, 0, .32);
  --shadow: 0 18px 40px rgba(0, 0, 0, .16), 0 2px 8px rgba(0, 0, 0, .08);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
    --bg: #fff;
    --surface: #f2f2f6;
    --surface-2: #fff;
    --surface-3: #e3e3e9;
    --field: #f0f0f4;
    --seg-on: #fff;
  --toggle-off: #d1d1d6;
    --text: #000;
    --text-2: rgba(60, 60, 67, .72);
    --text-3: rgba(60, 60, 67, .36);
    --line: rgba(0, 0, 0, .08);
    --accent: #28c142;
    --danger: #ff3b30;
    --scrim: rgba(0, 0, 0, .32);
    --shadow: 0 18px 40px rgba(0, 0, 0, .16), 0 2px 8px rgba(0, 0, 0, .08);
  }
}

/* ============ Base ============ */

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

input { -webkit-user-select: text; user-select: text; font: inherit; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

svg { display: block; }

#app { position: fixed; inset: 0; }

.status-scrim {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--sat);
  background: var(--bg);
  z-index: 20;
  pointer-events: none;
}

#scroller {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 18px) calc(var(--sab) + 140px) calc(var(--sal) + 18px);
}
#scroller.locked { overflow: hidden; }

.wrap { max-width: 640px; margin: 0 auto; }

/* ============ Header ============ */

.top-row { display: flex; justify-content: space-between; align-items: center; min-height: 52px; }

.streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px 0 12px;
  border-radius: 22px;
  background: var(--surface);
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: transform .45s var(--spring);
}
.streak:active { transform: scale(.92); }
.flame { font-size: 20px; display: inline-block; transform-origin: 50% 90%; animation: flicker 2.4s ease-in-out infinite; }
.streak.zero .flame { filter: grayscale(1); opacity: .45; animation: none; }

@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(0); }
  30% { transform: scale(1.08, .96) rotate(-3deg); }
  60% { transform: scale(.96, 1.06) rotate(2deg); }
}

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: var(--surface);
  transition: transform .45s var(--spring);
}
.icon-btn:active { transform: scale(.9) rotate(30deg); }
.icon-btn svg { width: 24px; height: 24px; }

.hero { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 14px 0 30px; }
.date { min-width: 0; }

#weekday {
  margin: 0;
  font-size: clamp(42px, 12.5vw, 72px);
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: .95;
}
#monthday {
  margin: 6px 0 0;
  font-size: clamp(22px, 6.4vw, 30px);
  font-weight: 800;
  letter-spacing: -.015em;
  color: var(--text-2);
}

.ring { position: relative; width: 116px; height: 116px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring .track { stroke: var(--surface-3); }
.ring .bar {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset .9s var(--spring-soft), opacity .3s;
}
.ring.full .bar { filter: drop-shadow(0 0 7px var(--accent)); }
.ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: 32px;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ring-label small { font-size: 16px; margin-left: 1px; letter-spacing: 0; }
.ring-label em { font-style: normal; font-size: 12px; font-weight: 750; letter-spacing: 0; color: var(--text-2); margin-top: 4px; }

/* ============ Carry-over card ============ */

.carry {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 6px 10px 18px;
  margin-bottom: 24px;
  animation: rise .55s var(--spring-soft) both;
}
.carry-text { flex: 1; font-size: 15px; font-weight: 700; color: var(--text-2); }
.carry-text b { display: block; font-size: 18px; font-weight: 850; color: var(--text); }
.carry-yes {
  height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: var(--text);
  color: var(--bg);
  font-weight: 850;
  font-size: 15px;
  white-space: nowrap;
  transition: transform .4s var(--spring);
}
.carry-yes:active { transform: scale(.93); }
.carry-no { width: 44px; height: 44px; font-size: 18px; color: var(--text-2); font-weight: 800; }

@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* ============ Groups ============ */

.group { margin-bottom: 20px; }

.group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 2px 4px 6px;
  text-align: left;
  transition: transform .4s var(--spring);
}
.group-head:active, .group-head.pressing { transform: scale(.97); }
.group-head.pressing { transition-duration: .48s; transform: scale(.94); }
.g-emoji { font-size: 22px; width: 28px; text-align: center; flex: none; }
.g-name {
  flex: 1;
  min-width: 0;
  font-size: 21px;
  font-weight: 850;
  letter-spacing: -.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.g-count {
  font-size: 15px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  padding: 5px 11px;
  border-radius: 999px;
  transition: background .3s, color .3s;
}
.g-count.complete { background: var(--c); color: #000; }
.chev { width: 20px; height: 20px; color: var(--text-3); transition: transform .45s var(--spring); flex: none; }
.group.collapsed .chev { transform: rotate(-90deg); }

.group-body {
  display: grid;
  grid-template-rows: 1fr;
  margin: 0 -10px;
  padding: 0 10px;
  overflow: hidden;
  transition: grid-template-rows .42s var(--out), opacity .3s;
}
.group.collapsed .group-body { grid-template-rows: 0fr; opacity: 0; }

.tasks {
  list-style: none;
  margin: 0;
  padding: 2px 0 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============ Task ============ */

.task { position: relative; border-radius: var(--radius); touch-action: pan-y; --p: 0; }

.swipe-bg {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  opacity: 0;
}
.task.swiping .swipe-bg { opacity: 1; }
.task[data-dir="right"] .swipe-bg { background: var(--c); color: #000; }
.task[data-dir="left"] .swipe-bg { background: var(--danger); color: #fff; }
.task[data-dir="right"] .sb-del, .task[data-dir="left"] .sb-done { visibility: hidden; }
.sb { width: 30px; height: 30px; opacity: var(--p); transform: scale(calc(.55 + var(--p) * .35)); transition: transform .3s var(--spring); }
.sb svg { width: 100%; height: 100%; }
.task[data-armed] .sb { transform: scale(1.25); }

.task-fg {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 68px;
  padding: 8px 16px 8px 8px;
  background: var(--surface);
  border-radius: inherit;
  will-change: transform;
  transition: background .2s;
}
.task-fg.springback { transition: transform .5s var(--spring); }
.task-fg.flyout { transition: transform .24s var(--out); }

.check {
  width: 52px; height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.check svg { width: 32px; height: 32px; overflow: visible; transition: transform .35s var(--spring); }
.check:active svg { transform: scale(.82); }
.check-ring { fill: none; stroke: var(--c); stroke-width: 2.6; }
.check-fill {
  fill: var(--c);
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0);
  transition: transform .5s var(--spring);
}
.tick {
  fill: none;
  stroke: #000;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset .3s var(--out) .1s;
}
.task.done .check-fill { transform: scale(1); }
.task.done .tick { stroke-dashoffset: 0; }
.task.pop .check svg { animation: pop .6s ease-out; }

@keyframes pop {
  0% { transform: scale(1); }
  22% { transform: scale(.7); }
  52% { transform: scale(1.22); }
  76% { transform: scale(.95); }
  100% { transform: scale(1); }
}

/* Block (not flex) so .task-text stays inline and the strike can follow wrapped lines. */
.task-body { flex: 1; min-width: 0; display: block; padding: 12px 0; cursor: pointer; }

.task-text {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.012em;
  line-height: 1.28;
  word-break: break-word;
  /* Animated strikethrough that works across wrapped lines */
  background: linear-gradient(currentColor, currentColor) 0 58% / 0% 2.5px no-repeat;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-size .38s var(--out) .06s, color .3s;
}
.task.done .task-text { color: var(--text-3); background-size: 100% 2.5px; }

.task-meta { display: block; margin-top: 3px; font-size: 13px; font-weight: 750; color: var(--text-3); }
.task-meta:empty { display: none; }

.task.lifted { z-index: 5; }
.task.lifted .task-fg { box-shadow: var(--shadow); background: var(--surface-2); }
.reordering .task:not(.lifted) { transition: transform .32s var(--spring-soft); }

.particle, .shock { position: fixed; pointer-events: none; z-index: 60; will-change: transform, opacity; }
.particle { border-radius: 50%; }
.shock { width: 40px; height: 40px; border: 3px solid; border-radius: 50%; }

/* ============ Empty state ============ */

.empty { text-align: center; padding: 36px 20px 0; animation: rise .6s var(--spring-soft) both; }
.empty-emoji { font-size: 68px; display: inline-block; animation: float 3.2s ease-in-out infinite; }
.empty h2 { font-size: 32px; font-weight: 900; letter-spacing: -.03em; margin: 14px 0 8px; }
.empty p { color: var(--text-2); font-size: 18px; font-weight: 650; line-height: 1.4; margin: 0; }
.empty b { color: var(--text); }

@keyframes float { 50% { transform: translateY(-8px) rotate(-4deg); } }

/* ============ FAB ============ */

#fab {
  position: fixed;
  right: calc(var(--sar) + 22px);
  bottom: calc(var(--sab) + 22px);
  width: 70px; height: 70px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transition: transform .5s var(--spring);
}
#fab:active { transform: scale(.86) rotate(90deg); }
#fab svg { width: 32px; height: 32px; }

/* ============ Toast ============ */

#toast-root {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--sab) + 108px);
  display: flex;
  justify-content: center;
  padding: 0 calc(var(--sar) + 16px) 0 calc(var(--sal) + 16px);
  pointer-events: none;
  z-index: 40;
}
.toast {
  position: absolute;
  bottom: 0;
  width: calc(100% - 32px);
  max-width: 480px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 7px 7px 7px 18px;
  border-radius: 18px;
  background: var(--text);
  color: var(--bg);
  font-weight: 750;
  font-size: 16px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(24px) scale(.95);
  transition: transform .5s var(--spring), opacity .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast-msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-btn { height: 44px; padding: 0 18px; border-radius: 13px; background: var(--bg); color: var(--text); font-weight: 850; }
.toast-btn:active { transform: scale(.94); }
.toast-bar {
  position: absolute; left: 0; bottom: 0;
  width: 100%; height: 3px;
  background: currentColor;
  opacity: .3;
  transform-origin: left;
  animation: drain linear forwards;
}
@keyframes drain { to { transform: scaleX(0); } }

/* ============ Sheets ============ */

.sheet-wrap { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .3s; }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }

.sheet {
  position: absolute;
  left: 0; right: 0;
  bottom: var(--kb);
  margin: 0 auto;
  max-width: 600px;
  max-height: calc(100% - var(--sat) - var(--kb) - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface-2);
  border-radius: 30px 30px 0 0;
  padding: 0 calc(var(--sar) + 20px) calc(var(--sab) + 20px) calc(var(--sal) + 20px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
  transform: translateY(105%);
  transition: transform .52s var(--spring-soft);
}
.kb-open .sheet { padding-bottom: 14px; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.closing .sheet { transition: transform .3s var(--out); }

.grab-zone { padding: 8px 0 2px; touch-action: none; position: sticky; top: 0; background: var(--surface-2); z-index: 2; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--text-3); margin: 0 auto 12px; }
.sheet h2 { font-size: 28px; font-weight: 900; letter-spacing: -.03em; margin: 2px 0 14px; }
.sheet h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  font-weight: 800;
  margin: 24px 4px 8px;
}
.hint { font-size: 14px; font-weight: 600; color: var(--text-2); margin: 8px 4px 0; line-height: 1.4; }
.hint.center { text-align: center; margin-top: 18px; }

.field {
  width: 100%;
  height: 58px;
  border: 0;
  outline: 0;
  border-radius: 16px;
  background: var(--field);
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  padding: 0 18px;
  -webkit-appearance: none;
  appearance: none;
}
.field::placeholder { color: var(--text-3); }

.add-form, .edit-form { display: flex; gap: 10px; }
.add-go {
  width: 58px; height: 58px;
  flex: none;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  transition: transform .4s var(--spring);
}
.add-go:active { transform: scale(.88); }
.add-go svg { width: 26px; height: 26px; }
.add-note { font-size: 14px; font-weight: 700; color: var(--text-3); text-align: center; margin: 14px 0 0; }
.add-note.bump { color: var(--accent); animation: bump .45s var(--spring); }
@keyframes bump { 0% { transform: scale(.9); } }

.seg { display: flex; gap: 4px; padding: 4px; border-radius: 15px; background: var(--field); margin-top: 14px; }
.seg button {
  flex: 1;
  height: 44px;
  border-radius: 11px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .25s, color .25s, box-shadow .25s, transform .4s var(--spring);
}
.seg button svg { width: 16px; height: 16px; }
.seg button:active { transform: scale(.95); }
.seg button[aria-pressed="true"] { background: var(--seg-on); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }

.days {
  display: none;
  justify-content: space-between;
  gap: 6px;
  margin-top: 12px;
}
.days.show { display: flex; animation: rise .4s var(--spring-soft); }
.days button {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--field);
  color: var(--text-2);
  font-weight: 850;
  font-size: 15px;
  transition: background .2s, color .2s, transform .4s var(--spring);
}
.days button:active { transform: scale(.88); }
.days button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px 0 12px;
  border-radius: 22px;
  background: var(--field);
  font-size: 16px;
  font-weight: 750;
  transition: background .2s, color .2s, transform .4s var(--spring);
}
.chip:active { transform: scale(.92); }
.chip[aria-pressed="true"] { background: var(--c); color: #000; }
.chip-new { background: transparent; border: 2px dashed var(--surface-3); color: var(--text-2); }
.chip-new svg { width: 16px; height: 16px; }

.btn {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 18px;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 18px;
  font-weight: 850;
  transition: transform .4s var(--spring), background .2s, color .2s;
}
.btn:active { transform: scale(.96); }
.btn.danger { background: transparent; color: var(--danger); margin-top: 8px; }
.btn.danger.armed { background: var(--danger); color: #fff; }

/* Category editor */
.cat-row { display: flex; gap: 10px; }
.emoji-field { width: 64px; flex: none; padding: 0; text-align: center; font-size: 30px; }
.emoji-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 14px; }
.emoji-pick button { height: 44px; border-radius: 12px; font-size: 24px; transition: background .2s, transform .35s var(--spring); }
.emoji-pick button:active { transform: scale(.85); }
.emoji-pick button[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 30%, transparent); }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; margin-top: 18px; }
.swatch {
  aspect-ratio: 1;
  min-height: 34px;
  border-radius: 50%;
  background: var(--c);
  transition: transform .4s var(--spring), box-shadow .2s;
}
.swatch[aria-pressed="true"] { transform: scale(1.08); box-shadow: 0 0 0 3px var(--surface-2), 0 0 0 6px var(--c); }

/* Settings */
.set-group { background: var(--field); border-radius: 16px; overflow: hidden; }
.set-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  text-align: left;
  font-size: 17px;
  font-weight: 700;
}
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .label { flex: 1; min-width: 0; }
.set-row > svg { width: 18px; height: 18px; color: var(--text-3); }
.set-row.add-row { color: var(--accent); }
.set-row.add-row svg { width: 20px; height: 20px; color: var(--accent); }
.set-row.muted { color: var(--text-3); }
.set-row input[type="time"] {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 850;
  text-align: right;
  -webkit-appearance: none;
  appearance: none;
  min-width: 90px;
}
.set-row .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.cat-emoji { font-size: 20px; }

.toggle {
  position: relative;
  width: 52px; height: 32px;
  flex: none;
  border-radius: 16px;
  background: var(--toggle-off);
  transition: background .25s;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .4s var(--spring);
}
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }

.htest { margin-top: 10px; background: var(--field); border-radius: 16px; padding: 0 4px 12px; }
.htest summary {
  list-style: none;
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.htest summary::-webkit-details-marker { display: none; }
.htest summary::after { content: "›"; margin-left: auto; font-size: 22px; color: var(--text-3); transition: transform .3s var(--spring); }
.htest[open] summary::after { transform: rotate(90deg); }
.htest:not([open]) { padding-bottom: 0; }
.hgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 8px; }
.hgrid button {
  height: 48px;
  border-radius: 12px;
  background: var(--seg-on);
  font-weight: 800;
  font-size: 15px;
  transition: transform .35s var(--spring);
}
.hgrid button:active { transform: scale(.9); }
.htest .hint { padding: 0 8px; }

/* History */
.hist-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.stat { background: var(--field); border-radius: 16px; padding: 14px 16px; }
.stat b { display: block; font-size: 30px; font-weight: 900; letter-spacing: -.03em; }
.stat span { font-size: 13px; font-weight: 750; color: var(--text-2); }

.hist-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.hist-dow { text-align: center; font-size: 12px; font-weight: 850; color: var(--text-3); padding-bottom: 2px; }
.cell {
  aspect-ratio: 1;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) var(--m, 0%), var(--field));
  transition: transform .35s var(--spring);
}
button.cell:active { transform: scale(.88); }
.cell.out { background: transparent; }
.cell.none { background: transparent; box-shadow: inset 0 0 0 2px var(--field); }
.cell.rest { background: var(--field); opacity: .5; }
.cell.perfect { background: var(--accent); }
.cell.today { box-shadow: 0 0 0 2.5px var(--surface-2), 0 0 0 5px var(--text); }
.cell.sel { transform: scale(1.12); }
.hist-detail { text-align: center; min-height: 22px; margin: 16px 0 6px; font-size: 16px; font-weight: 750; color: var(--text-2); }
.legend { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 750; color: var(--text-3); }
.legend .cell { width: 16px; border-radius: 4px; }

/* ============ Celebration ============ */

#celebrate {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}
#celebrate.show { opacity: 1; pointer-events: auto; }
.cel-word {
  font-size: clamp(100px, 33vw, 190px);
  font-weight: 900;
  letter-spacing: -.065em;
  line-height: .9;
  transform: scale(.55);
  transition: transform .8s var(--spring);
}
#celebrate.show .cel-word { transform: scale(1); }
.cel-sub {
  margin-top: 18px;
  font-size: 22px;
  font-weight: 800;
  color: var(--text-2);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .4s .25s, transform .6s var(--spring) .25s;
}
#celebrate.show .cel-sub { opacity: 1; transform: none; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; display: none; }

/* ============ Reduced motion ============ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }
}
