/* Lantern — night palette, one warm light.
   The lantern is the loud thing; everything else stays quiet. */

@property --glow { syntax: '<number>'; inherits: true; initial-value: 0.14; }

:root {
  --night: #0e1325;
  --dusk: #161e37;
  --dusk-2: #1f2947;
  --line: #2a355a;
  --text: #eaedf8;
  --mist: #98a3c7;
  --soft: #7f8bb0;

  --lantern: #ffbf5a;
  --lantern-2: #ff9440;
  --danger: #ff7a70;

  --body: #ff8075;
  --mind: #62b6ff;
  --craft: #b99bff;
  --social: #5ed9a6;

  --r-sm: 10px;
  --r-md: 16px;
  --r-pill: 999px;

  --font-display: 'Bricolage Grotesque', ui-rounded, 'Avenir Next', system-ui, sans-serif;
  --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --glow: 0.14;
  transition: --glow 900ms ease;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--night);
  color: var(--text);
  font: 400 1rem/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* The room brightens as the day's quests get done. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(70% 42% at 50% 6%, rgba(var(--halo-rgb), calc(var(--glow) * 0.26)), transparent 72%);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }

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

.muted { color: var(--mist); }
.small { font-size: 0.85rem; }

/* ---------- Layout ---------- */

.app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 20px calc(104px + env(safe-area-inset-bottom));
}

/* ---------- HUD ---------- */

.hud {
  display: grid;
  justify-items: center;
  text-align: center;
  padding: 22px 0 6px;
}

.lantern {
  width: 124px;
  height: auto;
  overflow: visible;
}

.lantern .halo {
  opacity: calc(0.08 + var(--glow) * 0.92);
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(calc(0.8 + var(--glow) * 0.3));
}
.lantern .glass { opacity: calc(0.1 + var(--glow) * 0.6); }
.lantern .flame-wrap {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(calc(0.45 + var(--glow) * 0.6));
}
.lantern .flame {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: flicker 2.8s ease-in-out infinite;
}
.lantern.flare { animation: flare 1.3s ease-out; }

@keyframes flicker {
  0%, 100% { transform: scale(1, 1) rotate(0deg); }
  30% { transform: scale(0.95, 1.07) rotate(-1.6deg); }
  62% { transform: scale(1.04, 0.97) rotate(1.3deg); }
}
@keyframes flare {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255, 191, 90, 0)); }
  25% { transform: scale(1.14); filter: drop-shadow(0 0 26px rgba(255, 191, 90, 0.95)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255, 191, 90, 0)); }
}

.level {
  margin-top: 2px;
  font: 800 2.1rem/1.05 var(--font-display);
  letter-spacing: -0.01em;
}
.rank { margin-top: 2px; color: var(--mist); font-weight: 600; }

.xp { width: 100%; margin-top: 16px; }
.bar {
  height: 10px;
  border-radius: var(--r-pill);
  background: var(--dusk-2);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--lantern-2), var(--lantern));
  transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.xp-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-size: 0.85rem;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}

/* ---------- Views ---------- */

.view { padding-top: 26px; }
.view[hidden] { display: none; }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
h2 { font: 700 1.5rem/1.15 var(--font-display); letter-spacing: -0.01em; }
.subhead {
  margin: 34px 0 12px;
  font: 700 1.1rem/1.2 var(--font-display);
}

.progress-pill {
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: var(--dusk-2);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- Add bar ---------- */

.add { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }

input[type='text'] {
  width: 100%;
  min-width: 0;
  padding: 13px 16px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--line);
  background: var(--dusk);
  color: var(--text);
  transition: border-color 0.15s;
}
input[type='text']::placeholder { color: var(--soft); }
input[type='text']:focus { outline: none; border-color: var(--lantern); }
input[type='text']:focus-visible { outline: none; border-color: var(--lantern); box-shadow: 0 0 0 3px rgba(255, 191, 90, 0.2); }

.btn {
  padding: 12px 20px;
  border: 0;
  border-radius: var(--r-md);
  font-weight: 700;
  background: var(--dusk-2);
  color: var(--text);
  transition: transform 0.12s, background 0.15s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, var(--lantern), var(--lantern-2)); color: #2a1604; }
.btn.ghost { background: transparent; color: var(--mist); }
.btn.danger-ghost { background: transparent; color: var(--danger); }
@media (hover: hover) {
  .btn.primary:hover { filter: brightness(1.07); }
  .btn.ghost:hover { color: var(--text); }
}

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--mist);
}
.icon-btn svg, .tab svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
@media (hover: hover) { .icon-btn:hover { background: var(--dusk-2); color: var(--text); } }

/* ---------- Quests ---------- */

.quests { margin-top: 4px; }

.quest {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 0 14px 2px;
  border-bottom: 1px solid var(--line);
}

.check {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2.5px solid var(--c);
  background: transparent;
  transition: background 0.18s, transform 0.18s;
}
.check::after { content: ''; position: absolute; inset: -8px; }
.check svg {
  width: 20px; height: 20px;
  fill: none; stroke: var(--night); stroke-width: 3.2;
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24;
  transition: stroke-dashoffset 0.28s ease 0.04s;
}
.check[aria-checked='true'] { background: var(--c); }
.check[aria-checked='true'] svg { stroke-dashoffset: 0; }
.check:active { transform: scale(0.9); }
@media (hover: hover) {
  .check[aria-checked='false']:hover { background: color-mix(in srgb, var(--c) 22%, transparent); }
}

.is-boss .check {
  width: 40px; height: 40px;
  border-width: 3px;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 16%, transparent);
}
.is-boss .q-title { font-weight: 700; }

.quest.pop .check { animation: bump 0.45s ease; }
@keyframes bump { 0% { transform: scale(0.85); } 45% { transform: scale(1.22); } 100% { transform: scale(1); } }

.q-main { min-width: 0; }
.q-title {
  font-weight: 600;
  overflow-wrap: anywhere;
  line-height: 1.3;
}
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--dusk-2);
  color: var(--mist);
  font-size: 0.78rem;
  font-weight: 600;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip.chip-xp { color: var(--lantern); }
.chip.boss { background: color-mix(in srgb, var(--lantern-2) 20%, transparent); color: var(--lantern); }

.quest.is-done .q-title { color: var(--soft); text-decoration: line-through; text-decoration-color: var(--line); }
.quest.is-done .chip { opacity: 0.6; }

.empty {
  padding: 30px 8px;
  text-align: center;
  color: var(--mist);
}

/* ---------- Hero tab ---------- */

.name-field { margin-bottom: 4px; }

.field { display: grid; gap: 8px; margin: 0 0 18px; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { padding: 0; font-size: 0.88rem; font-weight: 600; color: var(--mist); }

.stats { display: grid; gap: 18px; }
.stat-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.stat-name { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; }
.stat-name .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.stat-lvl { color: var(--mist); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.stats .bar { height: 8px; }
.stats .bar > i { background: var(--c); }

.streak { display: flex; align-items: center; gap: 18px; }
.streak-num { font: 800 3.4rem/1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.streak-num.lit { color: var(--lantern); }
.streak-info { display: grid; gap: 6px; }
.streak-label { font-weight: 700; }
.pips { display: flex; align-items: center; gap: 6px; color: var(--mist); font-size: 0.85rem; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--mist); }
.pip.on { background: var(--mind); border-color: var(--mind); }
.streak-note { margin-top: 10px; color: var(--mist); font-size: 0.9rem; }

.heat {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.heat i {
  aspect-ratio: 1;
  border-radius: 7px;
  background: var(--dusk-2);
}
.heat i[data-l='1'] { background: rgba(255, 191, 90, 0.28); }
.heat i[data-l='2'] { background: rgba(255, 191, 90, 0.5); }
.heat i[data-l='3'] { background: rgba(255, 175, 80, 0.75); }
.heat i[data-l='4'] { background: var(--lantern); }
.heat i.today { outline: 2px solid var(--text); outline-offset: 1px; }

.charms { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; }
.charm { display: grid; grid-template-columns: auto 1fr; gap: 11px; align-items: start; }
.charm-glyph {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: var(--soft);
  font-size: 1.05rem;
}
.charm.got .charm-glyph {
  border-color: var(--lantern);
  color: var(--lantern);
  background: rgba(255, 191, 90, 0.12);
}
.charm-name { font-weight: 700; font-size: 0.94rem; line-height: 1.2; }
.charm-desc { color: var(--mist); font-size: 0.82rem; line-height: 1.3; margin-top: 2px; }
.charm:not(.got) .charm-name { color: var(--mist); }

.settings { border-top: 1px solid var(--line); }
.row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 15px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  font-weight: 600;
}
.row.link { color: var(--text); }
.row.danger { color: var(--danger); }
.settings > p { padding: 10px 2px 0; }
.foot { margin-top: 18px; }

input[role='switch'] {
  appearance: none;
  position: relative;
  width: 48px; height: 28px;
  border-radius: var(--r-pill);
  background: var(--dusk-2);
  border: 1.5px solid var(--line);
  cursor: pointer;
  transition: background 0.2s;
  flex: none;
}
input[role='switch']::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--mist);
  transition: transform 0.2s, background 0.2s;
}
input[role='switch']:checked { background: rgba(255, 191, 90, 0.25); border-color: var(--lantern); }
input[role='switch']:checked::after { transform: translateX(20px); background: var(--lantern); }

/* ---------- Dock ---------- */

.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 0 20px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.dock-inner {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: min(340px, 100%);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--dusk) 90%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 32px rgba(3, 5, 14, 0.55);
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--mist);
  font-weight: 700;
  transition: background 0.2s, color 0.2s;
}
.tab[aria-current='page'] { background: var(--dusk-2); color: var(--lantern); }

/* ---------- Sheet + dialogs ---------- */

dialog {
  border: 0;
  padding: 0;
  color: var(--text);
  background: var(--dusk);
}
dialog::backdrop { background: rgba(5, 8, 18, 0.7); }

.sheet {
  width: min(520px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  margin: auto auto 0;
  border-radius: 26px 26px 0 0;
  overflow: auto;
}
.sheet[open] { animation: sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet form { padding: 10px 22px calc(22px + env(safe-area-inset-bottom)); }
.grab { width: 40px; height: 4px; margin: 0 auto 18px; border-radius: 4px; background: var(--line); }
.sheet h2 { margin-bottom: 18px; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; inset: 0; pointer-events: none; }
.opt label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--line);
  color: var(--mist);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.opt label .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.opt label small { color: var(--lantern); font-weight: 700; font-size: 0.8rem; }
.opt input:checked + label {
  color: var(--text);
  border-color: var(--c, var(--lantern));
  background: color-mix(in srgb, var(--c, var(--lantern)) 16%, transparent);
}
.opt input:focus-visible + label { outline: 2px solid var(--lantern); outline-offset: 2px; }

.form-error { margin: -4px 0 14px; color: var(--danger); font-size: 0.9rem; font-weight: 600; }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.sheet-actions .spacer { flex: 1; }

.levelup {
  width: min(320px, calc(100% - 40px));
  margin: auto;
  padding: 30px 24px 26px;
  border-radius: 26px;
  text-align: center;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 170, 70, 0.28), transparent 70%),
    var(--dusk);
  border: 1px solid var(--line);
}
.levelup[open] { animation: lu-in 0.4s cubic-bezier(0.2, 1.2, 0.3, 1); }
@keyframes lu-in { from { transform: scale(0.88); opacity: 0; } }
.lu-kicker { color: var(--mist); font-weight: 600; }
.levelup h2 { margin: 4px 0 2px; font-size: 3rem; font-weight: 800; color: var(--lantern); }
.lu-rank { margin-bottom: 22px; font-weight: 700; font-size: 1.1rem; }

/* ---------- Toast + effects ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: calc(100% - 40px);
  padding: 11px 18px;
  border-radius: var(--r-pill);
  background: var(--dusk-2);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.92rem;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#fx { position: fixed; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; }
.float-xp {
  position: absolute;
  font: 800 1.1rem/1 var(--font-display);
  color: var(--lantern);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
  animation: rise 0.95s ease-out forwards;
}
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -210%) scale(1.05); }
}
.spark {
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c);
  animation: spark 0.7s cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}
@keyframes spark {
  from { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}

/* ---------- Small screens + motion ---------- */

@media (max-width: 380px) {
  .charms { grid-template-columns: 1fr; }
  .level { font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  :root { transition: none; }
}

/* =====================================================================
   v2: themes, categories, schedules, charms, treasure
   ===================================================================== */

:root { --halo-rgb: 255, 170, 70; --glass-top: #ffd58a; --flame-core: #fff7d6; }

/* HUD coins */
.hud { position: relative; }
.coins {
  position: absolute; top: 22px; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px 7px 9px;
  border: 0; border-radius: var(--r-pill);
  background: var(--dusk-2); color: var(--text);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.coin {
  display: inline-block; flex: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffeab0, #ffc23d 55%, #e09a1a);
  box-shadow: inset 0 0 0 2px rgba(120, 70, 0, 0.35);
}

/* Buttons + inputs */
.btn.small { padding: 8px 14px; font-size: 0.88rem; border-radius: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small svg { width: 20px; height: 20px; }

input[type='date'], input[type='time'], input[type='number'], select {
  min-width: 0;
  padding: 11px 14px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--line);
  background: var(--dusk-2);
  color: var(--text);
}
select { width: 100%; margin-top: 4px; appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none' stroke='%2398a3c7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
select[hidden] { display: none; }
input[type='number'].narrow { width: 86px; }
input[type='date']:focus, input[type='time']:focus, input[type='number']:focus, select:focus { outline: none; border-color: var(--lantern); }
.inline-field { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; color: var(--mist); font-weight: 600; font-size: 0.92rem; }
.sched-detail { display: grid; gap: 10px; margin-top: 14px; }
.sched-detail[hidden] { display: none; }
#sched-summary { margin-top: 12px; min-height: 1.3em; }
.check-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; color: var(--mist); font-size: 0.92rem; font-weight: 500; }
.check-row input { width: 20px; height: 20px; accent-color: var(--lantern); }

.opt-add { padding: 9px 15px; border-radius: var(--r-pill); border: 1.5px dashed var(--line); background: none; color: var(--mist); font-weight: 600; font-size: 0.92rem; }
@media (hover: hover) { .opt-add:hover { color: var(--text); border-color: var(--mist); } }
#f-days .opt label, #rest-days .opt label { padding: 8px 12px; font-size: 0.86rem; }
.seg.emoji { gap: 6px; }
.seg.emoji .opt label { padding: 6px 10px; font-size: 1.3rem; line-height: 1.2; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 38px; height: 38px; padding: 0; border-radius: 50%; border: 3px solid transparent; background: var(--sw); }
.swatch[aria-pressed='true'] { border-color: var(--text); box-shadow: inset 0 0 0 3px var(--dusk); }
.custom-color { display: flex; align-items: center; gap: 12px; margin-top: 14px; color: var(--mist); font-weight: 600; font-size: 0.92rem; }
input[type='color'] { width: 46px; height: 38px; padding: 0; border: 1.5px solid var(--line); border-radius: 10px; background: none; cursor: pointer; }

.sub-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 34px 0 12px; }
.sub-row .subhead { margin: 0; }
.subhead.first { margin-top: 6px; }

/* Quest rows: the circle grows with the quest */
.quest { grid-template-columns: 44px 1fr auto; gap: 10px; }
.check, .later-dot { justify-self: center; }
.size-tiny .check { width: 26px; height: 26px; }
.size-small .check { width: 30px; height: 30px; }
.size-moderate .check { width: 34px; height: 34px; }
.size-large .check { width: 38px; height: 38px; border-width: 3px; }
.size-huge .check { width: 42px; height: 42px; border-width: 3px; box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 16%, transparent); }
.size-tiny .check svg { width: 15px; height: 15px; }
.size-huge .q-title, .size-large .q-title { font-weight: 700; }
.later-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px dashed var(--line); }
.chip b { font-weight: 700; }
.chip.chip-xp { color: var(--mist); }
.chip-xp b { color: var(--lantern); }
.chip.spot { background: color-mix(in srgb, var(--lantern) 22%, transparent); color: var(--lantern); }
.chip.next { color: var(--text); }
.chip .mini { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.later { margin-top: 30px; }
.later summary { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; list-style: none; font: 700 1.1rem/1.2 var(--font-display); }
.later summary::-webkit-details-marker { display: none; }
.later summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--mist); border-bottom: 2px solid var(--mist); transform: rotate(-45deg); transition: transform 0.2s; }
.later[open] summary::before { transform: rotate(45deg); }
.later summary span { color: var(--mist); font-weight: 600; font-size: 0.95rem; }
.later .quest { opacity: 0.88; }

/* Charms */
.filters { display: flex; gap: 8px; }
.filter { padding: 8px 18px; border-radius: var(--r-pill); border: 1.5px solid var(--line); background: none; color: var(--mist); font-weight: 600; }
.filter[aria-pressed='true'] { background: var(--dusk-2); color: var(--text); border-color: var(--lantern); }
.charm-list { display: grid; gap: 20px; }
.charm { --ring: var(--lantern); display: grid; grid-template-columns: auto 1fr auto; gap: 15px; align-items: center; }
.charm-glyph {
  width: 54px; height: 54px; display: grid; place-items: center;
  border-radius: 50%; border: 2px solid var(--line); background: var(--dusk);
  font-size: 1.65rem; line-height: 1; filter: grayscale(1); opacity: 0.5;
}
.charm.got .charm-glyph {
  filter: none; opacity: 1; border-color: var(--ring);
  background: color-mix(in srgb, var(--ring) 14%, var(--dusk));
  box-shadow: 0 0 20px color-mix(in srgb, var(--ring) 32%, transparent);
}
.charm-name { font-weight: 700; line-height: 1.2; }
.charm:not(.got) .charm-name { color: var(--mist); }
.charm-desc { color: var(--mist); font-size: 0.88rem; line-height: 1.3; margin-top: 2px; }
.charm-meta { margin-top: 4px; color: var(--soft); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.bar.thin { height: 6px; margin-top: 9px; }
.charm .bar.thin > i { background: var(--ring); }

/* Hero tab */
.themes { display: flex; flex-wrap: wrap; gap: 10px; }
.theme {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  min-width: 82px; padding: 12px 12px 10px;
  border-radius: var(--r-md); border: 1.5px solid var(--line);
  background: none; color: var(--text); font-weight: 600; font-size: 0.85rem;
}
.theme .sw { width: 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.7), var(--sw) 60%); box-shadow: 0 0 14px var(--sw); }
.theme.on { border-color: var(--sw); background: color-mix(in srgb, var(--sw) 10%, transparent); }
.theme:disabled { opacity: 0.55; cursor: not-allowed; }
.theme:disabled .sw { box-shadow: none; filter: grayscale(0.85); }
.theme small { color: var(--mist); font-weight: 500; font-size: 0.75rem; margin-top: -3px; }
.stat-top { align-items: center; gap: 8px; }
.stat-lvl { margin-left: auto; }
.stats .icon-btn.small { margin: -4px -8px -4px 0; }

.heat i[data-l='1'] { background: color-mix(in srgb, var(--lantern) 28%, transparent); }
.heat i[data-l='2'] { background: color-mix(in srgb, var(--lantern) 50%, transparent); }
.heat i[data-l='3'] { background: color-mix(in srgb, var(--lantern) 75%, transparent); }
.heat i[data-l='4'] { background: var(--lantern); }
input[role='switch']:checked { background: color-mix(in srgb, var(--lantern) 25%, transparent); }
input[type='text']:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--lantern) 22%, transparent); }

/* Dock with four tabs */
.dock-inner { grid-template-columns: repeat(4, 1fr); width: min(420px, 100%); border-radius: 26px; gap: 2px; }
.tab { flex-direction: column; gap: 3px; padding: 8px 0 7px; border-radius: 20px; font-size: 0.72rem; }
.tab svg { width: 22px; height: 22px; }

/* Celebrations */
.levelup h2 { font-size: 2.3rem; line-height: 1.1; }
.cel-glyph { margin: 0 0 6px; font-size: 3.6rem; line-height: 1.1; animation: cel-pop 0.7s cubic-bezier(0.2, 1.4, 0.3, 1); }
.cel-glyph[hidden] { display: none; }
@keyframes cel-pop { from { transform: scale(0.3) rotate(-20deg); opacity: 0; } }
.lu-note { margin: -12px 0 20px; color: var(--lantern); font-size: 0.9rem; font-weight: 600; }
.lu-note[hidden] { display: none; }
.lu-rank { margin-bottom: 22px; }

#fx { border: 0; padding: 0; margin: 0; background: transparent; width: 100vw; height: 100dvh; max-width: none; max-height: none; overflow: hidden; color: inherit; inset: 0; }
.confetti { position: absolute; top: -16px; width: 8px; height: 13px; border-radius: 2px; background: var(--c); animation: fall 2s ease-in forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); } }

@media (max-width: 380px) {
  .tab { font-size: 0.68rem; }
  .coins { top: 14px; }
}

/* =====================================================================
   v3: compact header, day browsing, center add button, manager
   ===================================================================== */

/* Compact header: lantern | level + xp | coins */
.hud {
  position: sticky; top: 0; z-index: 15;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; justify-items: stretch;
  gap: 14px; text-align: left;
  margin: 0 -20px; padding: calc(10px + env(safe-area-inset-top)) 20px 12px;
  background: linear-gradient(var(--night) 78%, transparent);
}
.lantern { width: 50px; margin-top: -4px; }
.lantern .halo { transform: scale(calc(0.55 + var(--glow) * 0.3)); }
.hud-main { min-width: 0; }
.hud-line { display: flex; align-items: baseline; gap: 9px; }
.level { margin: 0; font: 800 1.3rem/1.1 var(--font-display); letter-spacing: -0.01em; }
.rank { margin: 0; font-size: 0.86rem; font-weight: 600; color: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp { margin-top: 7px; }
.hud .bar { height: 8px; }
.xp-meta { margin-top: 5px; font-size: 0.76rem; }
.coins { position: static; flex: none; }
.app { padding-top: 0; }
.view { padding-top: 16px; }

/* Day header actions */
.head-actions { display: flex; align-items: center; gap: 2px; margin-bottom: -4px; }
.btn.ghost.small { padding: 7px 12px; background: var(--dusk-2); color: var(--text); margin-right: 6px; }
.icon-btn.pick { position: relative; cursor: pointer; }
.icon-btn.pick input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; border: 0; padding: 0;
}
.icon-btn.pick input::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.icon-btn.pick:focus-within { outline: 2px solid var(--lantern); outline-offset: 2px; }
.icon-btn svg, .wk-nav svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Week strip */
.weekbar { display: grid; grid-template-columns: 30px 1fr 30px; align-items: center; gap: 2px; margin: 0 -6px 4px; }
.wk-nav { width: 30px; height: 56px; padding: 0; border: 0; border-radius: 10px; background: none; color: var(--mist); display: grid; place-items: center; }
.wk-nav svg { width: 20px; height: 20px; }
@media (hover: hover) { .wk-nav:hover { color: var(--text); background: var(--dusk); } }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  position: relative; display: grid; justify-items: center; gap: 1px;
  padding: 7px 0 11px; border: 0; border-radius: 14px;
  background: none; color: var(--mist);
  transition: background 0.15s, color 0.15s;
}
.day .dow { font-size: 0.72rem; font-weight: 600; }
.day .num { font: 700 1.1rem/1.2 var(--font-display); color: var(--text); font-variant-numeric: tabular-nums; }
.day .ind { position: absolute; bottom: 5px; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; border: 1.5px solid transparent; }
.day[data-st='open'] .ind { border-color: var(--soft); }
.day[data-st='some'] .ind { border-color: var(--lantern); background: linear-gradient(90deg, var(--lantern) 50%, transparent 50%); }
.day[data-st='all'] .ind { border-color: var(--lantern); background: var(--lantern); box-shadow: 0 0 8px var(--lantern); }
.day.today .num { color: var(--lantern); }
.day[aria-pressed='true'] { background: var(--dusk-2); color: var(--text); }
.day.today[aria-pressed='false'] { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--lantern) 55%, transparent); }
@media (hover: hover) { .day[aria-pressed='false']:hover { background: var(--dusk); } }

.day-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 6px; }
.day-meta .muted { margin: 0; }
.day-meta [hidden] { display: none; }

/* Quest rows */
.q-icon { margin-right: 7px; }
.q-note { margin-top: 2px; color: var(--mist); font-size: 0.86rem; line-height: 1.3; overflow-wrap: anywhere; }
.chip.missed { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.quest .later-dot { justify-self: center; }

/* Dock: five slots with a raised + in the middle */
.dock-inner { grid-template-columns: 1fr 1fr 64px 1fr 1fr; width: min(440px, 100%); align-items: end; overflow: visible; }
.dock-add {
  justify-self: center; align-self: center;
  width: 54px; height: 54px; margin-top: -22px; padding: 0;
  display: grid; place-items: center;
  border: 4px solid var(--night); border-radius: 50%;
  background: linear-gradient(180deg, var(--lantern), var(--lantern-2));
  color: #2a1604;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--lantern-2) 45%, transparent);
  transition: transform 0.12s;
}
.dock-add svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; }
.dock-add:active { transform: scale(0.92); }
@media (hover: hover) { .dock-add:hover { filter: brightness(1.08); } }
@media (max-width: 380px) { .dock-inner { grid-template-columns: 1fr 1fr 58px 1fr 1fr; } }

/* Sheets: sticky buttons so Save is always reachable */
.sheet .sheet-actions {
  position: sticky; bottom: 0; z-index: 2;
  margin: 8px -22px calc(-22px - env(safe-area-inset-bottom));
  padding: 14px 22px calc(18px + env(safe-area-inset-bottom));
  background: var(--dusk); border-top: 1px solid var(--line);
}
.sheet-actions .btn { padding: 11px 16px; }
.sheet-actions .btn.small { padding: 8px 12px; }

/* Presets, notes, icon picker */
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { padding: 6px 12px; border-radius: var(--r-pill); border: 1.5px solid var(--line); background: none; color: var(--mist); font-size: 0.84rem; font-weight: 600; }
@media (hover: hover) { .chip-btn:hover { color: var(--text); border-color: var(--mist); } }
.more { margin: 2px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.more summary { padding: 13px 0; cursor: pointer; list-style: none; font-weight: 600; color: var(--mist); display: flex; align-items: center; gap: 10px; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--mist); border-bottom: 2px solid var(--mist); transform: rotate(-45deg); transition: transform 0.2s; }
.more[open] summary::before { transform: rotate(45deg); }
.more .field:last-child { margin-bottom: 18px; }
#f-icons .opt label { padding: 6px 10px; font-size: 1.25rem; line-height: 1.2; min-width: 44px; justify-content: center; }
#f-icons .opt:first-child label { font-size: 0.88rem; line-height: 1.7; }
input[type='date']:disabled { opacity: 0.45; }
#sd-range { gap: 12px; }
#sd-range .check-row { margin-top: 0; flex-wrap: wrap; }
input[type='text'], input[type='search'] { font-size: 1rem; }
input[type='search'] {
  width: 100%; padding: 12px 16px; border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--dusk-2); color: var(--text);
}
input[type='search']:focus { outline: none; border-color: var(--lantern); }
input[type='search']::placeholder { color: var(--soft); }

/* Manage dialog */
.manage-wrap { padding: 10px 22px calc(22px + env(safe-area-inset-bottom)); }
.manage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.manage-head h2 { margin: 0; }
#manage-list { min-height: 120px; margin-top: 6px; }
.m-cat { display: flex; align-items: center; gap: 9px; margin: 22px 0 4px; font: 700 1rem/1.2 var(--font-display); }
.m-cat .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.m-cat span { color: var(--mist); font-weight: 600; font-size: 0.88rem; }
.m-list { border-top: 1px solid var(--line); margin-top: 8px; }
.m-row { border-bottom: 1px solid var(--line); }
.m-btn { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 13px 2px; border: 0; background: none; text-align: left; }
.m-main { display: grid; gap: 2px; min-width: 0; }
.m-title { font-weight: 600; overflow-wrap: anywhere; }
.m-sub { color: var(--mist); font-size: 0.85rem; }
.m-btn svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--soft); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.m-row.fin .m-title { color: var(--soft); text-decoration: line-through; text-decoration-color: var(--line); }
@media (hover: hover) { .m-btn:hover .m-title { color: var(--lantern); } }
.sheet-actions .btn:disabled { visibility: hidden; }

/* Hero: XP settings */
.xp-settings { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.xp-settings summary { padding: 15px 2px; cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.xp-settings summary::-webkit-details-marker { display: none; }
.xp-settings summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--mist); border-bottom: 2px solid var(--mist); transform: rotate(45deg); transition: transform 0.2s; margin-right: 4px; }
.xp-settings[open] summary::after { transform: rotate(-135deg); }
.xp-settings > p { margin: -4px 2px 14px; }
.xp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); gap: 10px; margin: 0 2px 14px; }
.xp-field { display: grid; gap: 6px; font-size: 0.84rem; font-weight: 600; color: var(--mist); }
.xp-field input { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--dusk-2); color: var(--text); font-size: 1rem; }
.xp-field input:focus { outline: none; border-color: var(--lantern); }
.xp-settings > .btn { margin: 0 2px 16px; }
.settings { border-top: 0; }

/* Fixes */
[hidden] { display: none !important; }
.check-row input[type='date'] { width: auto; height: auto; accent-color: auto; }
.check-row input[type='checkbox'] { flex: none; }

/* =====================================================================
   v4: checklist quests, counting quests, skipping
   ===================================================================== */

/* Progress ring on the round button */
.check.has-prog {
  width: 38px; height: 38px; border: 0;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), color-mix(in srgb, var(--c) 24%, transparent) 0);
}
.check.has-prog::before { content: ''; position: absolute; inset: 3.5px; border-radius: 50%; background: var(--night); }
.check.has-prog > * { position: relative; }
.check.has-prog .frac { font: 700 0.64rem/1 var(--font-body); color: var(--text); font-variant-numeric: tabular-nums; }
.check.has-prog svg { position: absolute; }
.check.has-prog[data-done='true'] { background: var(--c); }
.check.has-prog[data-done='true']::before, .check.has-prog[data-done='true'] .frac { display: none; }
.check.has-prog[data-done='true'] svg { stroke-dashoffset: 0; }
.check.has-prog:not([data-done='true']) svg { stroke-dashoffset: 24; }
.size-huge .check.has-prog, .size-large .check.has-prog, .size-moderate .check.has-prog, .size-small .check.has-prog, .size-tiny .check.has-prog { width: 38px; height: 38px; border-width: 0; }

/* Checklist steps */
.steps { display: grid; gap: 0; margin-top: 10px; }
.step { display: flex; align-items: center; gap: 12px; padding: 5px 0; }
.step span { font-size: 0.95rem; line-height: 1.3; overflow-wrap: anywhere; }
.step.on span { color: var(--soft); text-decoration: line-through; text-decoration-color: var(--line); }
.step-check {
  position: relative; flex: none; width: 22px; height: 22px; padding: 0;
  display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--c); background: transparent; transition: background 0.15s;
}
.step-check::after { content: ''; position: absolute; inset: -10px; }
.step-check svg { width: 14px; height: 14px; fill: none; stroke: var(--night); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset 0.2s ease; }
.step-check[aria-checked='true'] { background: var(--c); }
.step-check[aria-checked='true'] svg { stroke-dashoffset: 0; }
@media (hover: hover) { .step-check[aria-checked='false']:hover { background: color-mix(in srgb, var(--c) 22%, transparent); } }

/* Counting */
.counter { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.cnt-btn {
  min-width: 44px; height: 38px; padding: 0 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--dusk-2); color: var(--text);
  font: 700 1rem/1 var(--font-body);
}
.cnt-btn.plus { border-color: var(--c); color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.cnt-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.cnt-btn:active:not(:disabled) { transform: scale(0.94); }
.cnt-val { color: var(--mist); font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.cnt-val b { color: var(--text); font-size: 1.15rem; font-family: var(--font-display); }

/* Skip */
.skip-btn { border: 1.5px dashed var(--line); background: none; color: var(--soft); cursor: pointer; padding: 1px 9px; font-family: inherit; }
@media (hover: hover) { .skip-btn:hover { color: var(--text); border-color: var(--mist); } }
.quest.is-skipped .q-title { color: var(--soft); }
.quest.is-skipped .chip { opacity: 0.8; }

/* Toast with an action button */
#toast.has-action { display: flex; align-items: center; gap: 14px; pointer-events: auto; padding-right: 8px; }
.toast-btn { padding: 6px 14px; border: 0; border-radius: var(--r-pill); background: var(--lantern); color: #2a1604; font-weight: 700; }

/* Quest sheet: steps editor and goal fields */
.step-edit { display: grid; gap: 8px; }
.step-row { display: flex; align-items: center; gap: 4px; }
.step-row input { flex: 1; }
.step-row .icon-btn.small svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.btn.ghost.small:disabled { visibility: visible; opacity: 0.4; }
#sd-list .btn { justify-self: start; background: var(--dusk-2); color: var(--text); }
input[type='text'].unit { width: 130px; }
#kind-hint { margin-top: 12px; min-height: 1.3em; }


/* =====================================================================
   v5: app shell, flames, reminders, emoji picker, charm library, phones
   ===================================================================== */

/* App shell: the page itself never scrolls. Only the content area does, and it
   keeps a steady gutter so every tab lines up exactly the same. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { height: 100vh; height: 100dvh; min-height: 0; }
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding-bottom: 0; }
.hud { position: static; flex: none; background: none; }
.app > main {
  flex: 1; min-height: 0;
  margin: 0 -20px;
  padding: 0 20px calc(112px + env(safe-area-inset-bottom));
  overflow-x: hidden; overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
.app > main::-webkit-scrollbar { width: 8px; }
.app > main::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.view { padding-bottom: 8px; }

/* Dock: three tabs and the + at the end */
.dock-inner { grid-template-columns: 1fr 1fr 1fr 64px; width: min(440px, 100%); align-items: center; }
@media (max-width: 380px) { .dock-inner { grid-template-columns: 1fr 1fr 1fr 58px; } }

/* Flames */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; }
.theme { width: 100%; min-width: 0; padding: 9px 4px 7px; gap: 5px; }
.theme .sw { width: 26px; height: 26px; }
.theme span { text-align: center; line-height: 1.15; }
html[data-theme='prism'] .lantern { animation: prism 9s linear infinite; }
@keyframes prism { to { filter: hue-rotate(360deg); } }

/* Reminders */
.reminders { display: grid; gap: 8px; margin-bottom: 14px; }
.reminder {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 10px 6px 10px 12px;
  border-radius: 16px;
  border: 1.5px dashed color-mix(in srgb, var(--c) 50%, transparent);
  background: color-mix(in srgb, var(--c) 9%, var(--night));
}
.rem-icon {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 50%; font-size: 1.3rem; line-height: 1;
  background: color-mix(in srgb, var(--c) 20%, transparent); color: var(--c);
}
.rem-icon .bell { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.reminder .q-title { font-weight: 700; }
#remind-wrap { margin-top: 16px; }
#remind-wrap .subhead { margin-top: 0; }

/* Emoji picker */
.emoji-pick { display: grid; gap: 8px; }
.ep-bar { display: flex; align-items: center; gap: 8px; }
.ep-current {
  flex: none; width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 14px; border: 1.5px solid var(--lantern);
  background: var(--dusk-2); font-size: 1.6rem; line-height: 1; color: var(--mist);
}
.ep-search { flex: 1; min-width: 0; width: auto; }
.ep-label { margin: 0; }
.ep-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 2px;
  max-height: 184px; overflow-y: auto; padding: 4px;
  border-radius: 14px; background: var(--dusk);
  overscroll-behavior: contain;
}
.ep-cell { aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; background: none; font-size: 1.5rem; line-height: 1; }
.ep-cell.on { background: color-mix(in srgb, var(--lantern) 22%, transparent); box-shadow: inset 0 0 0 2px var(--lantern); }
@media (hover: hover) { .ep-cell:hover { background: var(--dusk-2); } }

/* Charms: rarity and the compact library */
.filters { flex-wrap: wrap; }
.filter { padding: 8px 16px; }
.rarity {
  display: inline-block; margin-left: 8px; padding: 2px 8px; vertical-align: 2px;
  border-radius: var(--r-pill); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--r); background: color-mix(in srgb, var(--r) 16%, transparent);
}
.charm[data-tier='5'].got .charm-glyph { box-shadow: 0 0 26px color-mix(in srgb, var(--ring) 55%, transparent), 0 0 0 3px color-mix(in srgb, var(--ring) 22%, transparent); }
.subhead.rar { display: flex; align-items: center; gap: 8px; }
.subhead.rar .rdot { width: 10px; height: 10px; border-radius: 50%; background: var(--r); box-shadow: 0 0 10px var(--r); }
.subhead.rar span { margin-left: auto; color: var(--mist); font-weight: 500; font-size: 0.82rem; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-bottom: 6px; }
.lib-tile {
  width: 100%; height: 100%; display: grid; justify-items: center; align-content: start; gap: 5px;
  padding: 10px 4px 9px; border-radius: 14px;
  border: 1.5px solid color-mix(in srgb, var(--r) 30%, transparent);
  background: var(--dusk); color: var(--mist);
}
.lib-tile .lg { font-size: 1.7rem; line-height: 1.1; filter: grayscale(1); opacity: 0.5; }
.lib-tile .ln { font-size: 0.72rem; font-weight: 600; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.lib-tile.got { color: var(--text); border-color: var(--r); background: color-mix(in srgb, var(--r) 10%, var(--dusk)); box-shadow: 0 0 14px color-mix(in srgb, var(--r) 22%, transparent); }
.lib-tile.got .lg { filter: none; opacity: 1; }
@media (hover: hover) { .lib-tile:hover { border-color: var(--r); } }
.info-wrap { padding: 10px 22px calc(22px + env(safe-area-inset-bottom)); text-align: center; }
.info-wrap .sheet-actions { margin-top: 16px; }
.ci-glyph { font-size: 3.2rem; line-height: 1.1; margin-bottom: 6px; }
.info-wrap h2 { margin-bottom: 4px; }
.ci-rarity { margin-bottom: 10px; color: var(--r); font-weight: 700; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; }
.info-wrap .bar { margin: 14px auto 8px; max-width: 260px; }
.info-wrap .bar > i { background: var(--r, var(--lantern)); }

/* ---------------------------------------------------------------------
   Phones and tablets (the page adds .mobile when it detects a touch device)
   --------------------------------------------------------------------- */
html.mobile { -webkit-touch-callout: none; touch-action: manipulation; }
html.mobile body { -webkit-user-select: none; user-select: none; }
html.mobile input, html.mobile textarea, html.mobile select { -webkit-user-select: text; user-select: text; font-size: 16px; }
html.mobile .app { max-width: 560px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
html.mobile .hud { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
html.mobile .app > main { margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-gutter: auto; }

/* Bigger things to tap */
html.mobile .icon-btn, html.mobile .wk-nav { min-width: 44px; min-height: 44px; }
html.mobile .btn { min-height: 44px; }
html.mobile .btn.small { min-height: 40px; }
html.mobile .chip-btn, html.mobile .filter, html.mobile .opt label { min-height: 42px; }
html.mobile .filter { display: inline-flex; align-items: center; }
html.mobile .skip-btn { min-height: 34px; padding-left: 14px; padding-right: 14px; }
html.mobile .cnt-btn { min-height: 46px; min-width: 52px; }
html.mobile .step-check { position: relative; }
html.mobile .step-check::after, html.mobile .check::after { content: ''; position: absolute; inset: -8px; }
html.mobile .check { position: relative; }
html.mobile .day { min-height: 62px; }
html.mobile .theme { min-height: 74px; }
html.mobile .m-btn { min-height: 56px; }
html.mobile .quest, html.mobile .reminder { padding-top: 14px; padding-bottom: 14px; }

/* Dock: a full-width bar that sits on the bottom edge */
html.mobile .dock { padding: 0; }
html.mobile .dock-inner {
  width: 100%; max-width: 560px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-width: 1px 0 0; border-radius: 22px 22px 0 0; gap: 2px;
  background: color-mix(in srgb, var(--dusk) 94%, transparent);
  box-shadow: 0 -10px 30px rgba(3, 5, 14, 0.5);
  grid-template-columns: 1fr 1fr 1fr 70px;
}
html.mobile .tab { min-height: 52px; }
html.mobile .dock-add { width: 56px; height: 56px; margin-top: -26px; }
html.mobile .app > main { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
html.mobile #toast { bottom: calc(92px + env(safe-area-inset-bottom)); }

/* Sheets fill the width like native phone sheets */
html.mobile .sheet { width: 100%; max-height: 94dvh; border-radius: 22px 22px 0 0; overscroll-behavior: contain; }
html.mobile .sheet form, html.mobile .manage-wrap, html.mobile .info-wrap { padding-left: 18px; padding-right: 18px; }
html.mobile .sheet .sheet-actions { margin-left: -18px; margin-right: -18px; padding-left: 18px; padding-right: 18px; }
html.mobile .ep-grid { max-height: 168px; }
html.mobile .ep-cell { min-height: 44px; }

/* Short screens (a phone on its side): tighter header */
@media (max-height: 460px) {
  .hud { padding-top: 6px; padding-bottom: 6px; }
  .lantern { width: 38px; }
}

.theme:disabled .sw { filter: saturate(0.55); opacity: 0.75; box-shadow: none; }


/* =====================================================================
   v6: refrainment quests, charm builder
   ===================================================================== */

/* Refrainment: a filled circle until you slip, then a circle with an X */
#refrain-wrap { margin-top: 16px; }
#refrain-wrap .subhead { margin-top: 0; }
.refrain-note { margin: 2px 0 6px; }
.check.refrain svg { stroke-dashoffset: 0; }
.check.refrain.pending { border-style: dashed; background: color-mix(in srgb, var(--c) 82%, transparent); }
.check.refrain.paid { background: var(--c); }
.check.refrain.slip {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.check.refrain.slip svg { stroke: var(--danger); stroke-width: 3; }
@media (hover: hover) { .check.refrain.slip:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); } }
.quest.is-slip .q-title { color: var(--soft); }
.quest.is-slip .chip-xp { opacity: 0.5; text-decoration: line-through; }
.chip.refrain-chip { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.chip.pend-chip { color: var(--mist); border: 1px dashed var(--line); background: none; }
.chip.kept { color: #5ed9a6; background: color-mix(in srgb, #5ed9a6 14%, transparent); }
#sd-refrain .inline-field input[type='time'] { width: auto; }

/* Charm builder */
.charm-preview {
  --ring: var(--lantern);
  margin: 0 0 16px; padding: 14px 16px;
  border-radius: 18px; border: 1.5px solid color-mix(in srgb, var(--ring) 45%, transparent);
  background: color-mix(in srgb, var(--ring) 8%, var(--dusk));
  grid-template-columns: auto 1fr;
}
.ideas-label { margin: 0 0 8px; }
#h-ideas-wrap { margin-bottom: 18px; }
#h-ideas-wrap .presets { display: flex; flex-wrap: wrap; gap: 8px; }
#charm-sheet select { margin-top: 8px; }
#charm-sheet select:first-of-type { margin-top: 0; }
#charm-sheet .inline-field { margin-top: 12px; }
html.mobile #h-ideas-wrap .chip-btn { min-height: 40px; }

/* ---------- v7: account ---------- */
.account { margin: 18px 0; padding: 14px; border-radius: 14px; background: var(--card, rgba(255,255,255,.05)); border: 1px solid rgba(255,255,255,.08); display: grid; gap: 10px; }
.account h3 { margin: 0; font-size: 1rem; }
.account form { display: grid; gap: 10px; }
.account p { margin: 0; }
.acc-input { width: 100%; box-sizing: border-box; padding: 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15); background: rgba(0,0,0,.25); color: inherit; font: inherit; font-size: 16px; }
.acc-error { color: var(--danger); font-size: .88rem; }
.acc-actions { display: flex; gap: 10px; margin-top: 8px; }
#acc-status[data-status="offline"], #acc-status[data-status="error"] { color: var(--danger); }
.account [hidden] { display: none !important; }
