* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; font-family: var(--serif); font-weight: 560; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

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

header.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  border-bottom: 1px solid var(--line);
}
header.top .wrap { display: flex; align-items: center; gap: 10px; }
header.top .title { flex: 1; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}
.card.amber { background: var(--amber-bg); border-color: var(--amber-line); }
.card.amber h2 { color: var(--amber); }
.card.soft { background: var(--surface-2); box-shadow: none; }

.row { display: flex; gap: 12px; align-items: center; }
.row.wrapx { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }

.big { font-family: var(--serif); font-size: 2.7rem; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.mid { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.2rem; }
.stat span { font-size: 0.85rem; color: var(--muted); }

button, .btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-ink);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
}
button.secondary, .btn.secondary { background: var(--surface); color: var(--primary); border-color: var(--line); }
button.ghost { background: transparent; color: var(--primary); border-color: transparent; padding: 8px 10px; }
button.small, .btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
button.block, .btn.block { width: 100%; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}

.answers { display: grid; gap: 10px; }
.answers button { justify-content: flex-start; text-align: left; background: var(--surface); color: var(--text); border-color: var(--line); }
.answers button.chosen { border-color: var(--primary); background: var(--primary-soft); }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.88rem; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
.radio { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; background: var(--surface); }
.radio input { width: auto; min-height: 0; margin-top: 4px; }

.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--clean); border-radius: 99px; }

.chip { display: inline-block; font-size: 0.78rem; font-weight: 650; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.due { background: var(--amber-bg); color: var(--amber); }
.chip.paid { background: var(--clean-soft); color: var(--clean); }
.chip.hold { background: var(--recovery-soft); color: var(--recovery); }
.chip.use { background: var(--use-soft); color: var(--use); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

.vault { display: grid; grid-template-columns: 1fr; gap: 8px; }
.scene { position: relative; aspect-ratio: 3 / 2; max-height: 340px; margin: 4px auto; width: 100%; border-radius: 14px; overflow: hidden; background: var(--surface-2); }
.scene img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity 1.2s ease; }
.scene img.house { object-fit: cover; object-position: center 70%; }
.scene img.preview { opacity: 1; }
.scene .season { position: absolute; left: 10px; bottom: 8px; font-size: 0.75rem; font-weight: 650; color: #2b2622; background: rgba(251,248,242,.8); padding: 2px 8px; border-radius: 99px; }
.scene img:not(.house) { filter: var(--scene-dim); }
.house-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.house-pick button { flex-direction: column; background: var(--surface); color: var(--text); border-color: var(--line); padding: 10px; }
.house-pick button.chosen { border-color: var(--primary); background: var(--primary-soft); }
.house-pick img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 10px; }

.jar { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.jar i { width: 18px; height: 18px; border-radius: 50%; background: var(--gold); box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .wrap { display: grid; grid-template-columns: repeat(5, 1fr); padding: 0 4px; }
nav.tabs a {
  text-align: center; text-decoration: none; color: var(--muted);
  font-size: 0.72rem; font-weight: 600; padding: 8px 2px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; justify-content: center;
}
nav.tabs a svg { width: 22px; height: 22px; }
nav.tabs a.on { color: var(--primary); }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .h { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.cal .d { position: relative; }
.cal .d { aspect-ratio: 1; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; background: var(--surface-2); color: var(--muted); }
.cal .d.clean { background: var(--clean-soft); color: var(--clean); font-weight: 650; }
.cal .d.recovery { background: var(--recovery-soft); color: var(--recovery); font-weight: 650; }
.cal .d.use { background: var(--use-soft); color: var(--use); font-weight: 650; outline: 2px solid var(--use); outline-offset: -2px; }
.cal .d.pending { outline: 2px dashed var(--recovery); outline-offset: -2px; }
.cal .d.today { box-shadow: 0 0 0 2px var(--primary); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.85rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }

table.months { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.months td, table.months th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: left; }
table.months td.num, table.months th.num { text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: calc(100% - 32px);
  font-weight: 600; font-size: 0.95rem;
}
.toast.err { background: var(--danger); color: #fff; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; }

.steps { display: flex; gap: 6px; margin: 12px 0; }
.steps i { flex: 1; height: 5px; border-radius: 9px; background: var(--line); }
.steps i.on { background: var(--primary); }

.countdown { font-variant-numeric: tabular-nums; font-weight: 700; }
.note { font-size: 0.9rem; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
details > summary { cursor: pointer; font-weight: 600; color: var(--primary); min-height: 32px; }
.copybox { display: flex; gap: 8px; }
.copybox input { font-size: 0.85rem; }
.hero { text-align: center; padding: 48px 0 24px; }
.hero img { width: 96px; height: 96px; border-radius: 22px; }
@media (max-width: 380px) { .big { font-size: 2.2rem; } .grid2 { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.dot { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 6px; height: 6px; border-radius: 50%; background: var(--recovery); }
.legend .dot { transform: none; margin-right: 5px; }

/* ---- Card-first home ---------------------------------------------------- */
.hero-card { display: block; position: relative; margin: 14px 0; border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.hero-card .scene { max-height: none; margin: 0; border-radius: 0; aspect-ratio: 3 / 2; }
.hero-day { position: absolute; top: 14px; left: 16px; display: flex; flex-direction: column; }
.hero-big { font-family: var(--serif); font-size: 2.9rem; font-weight: 620; line-height: 1; letter-spacing: -0.02em; text-shadow: 0 1px 14px var(--bg), 0 0 2px var(--bg); }
.hero-small { font-weight: 650; font-size: 0.95rem; opacity: 0.85; margin-top: 4px; }
.hero-best { margin-top: 8px; align-self: flex-start; background: var(--gold); color: #2b2622; font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 99px; }
.hero-foot { background: var(--surface); color: var(--text); padding: 12px 16px 14px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.hero-foot b { font-family: var(--serif); font-size: 1.25rem; }
.hero-more { font-size: 0.85rem; font-weight: 650; color: var(--primary); }
.hero-card .scene .season { display: none; }
.progress.glow { margin-top: 6px; height: 8px; background: var(--surface-2); }
.progress.glow > i { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

.week { text-align: center; }
.week p { margin: 6px 0 0; }
.lanterns { display: flex; justify-content: center; align-items: flex-end; gap: 4px; padding-top: 4px; }
.lantern { width: 40px; height: 60px; overflow: visible; }
.lantern .glow { animation: breathe 2.6s ease-in-out infinite; animation-delay: var(--d); transform-origin: 16px 21.5px; }
.lantern:not(.lit) { opacity: 0.75; }
.lantern .flame { transform-origin: 16px 25px; animation: flicker 2.6s ease-in-out infinite; animation-delay: var(--d); }
.lantern .halo { animation: breathe 3.2s ease-in-out infinite; animation-delay: var(--d); transform-origin: 16px 27px; }
@keyframes flicker { 0%, 100% { transform: scale(1, 1) rotate(0); } 30% { transform: scale(0.94, 1.06) rotate(-2deg); } 60% { transform: scale(1.04, 0.95) rotate(1.5deg); } }
@keyframes breathe { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; transform: scale(1.04); } }
@media (max-width: 360px) { .lantern { width: 32px; height: 48px; } }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.tile { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); min-height: 112px; }
.tile b { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; }
.tile small { color: var(--muted); }
.tile.amber { background: var(--amber-bg); border-color: var(--amber-line); }
.tile.amber b { color: var(--amber); }
.tile-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.jar.mini { margin: 4px 0 0; gap: 3px; }
.jar.mini i { width: 12px; height: 12px; }
.quote { font-family: var(--serif); font-size: 1.2rem; }
.small-link { font-size: 0.9rem; font-weight: 650; text-decoration: none; }

.rcard h2 { margin-top: 6px; font-size: 1.3rem; }
.slides { display: flex; align-items: flex-start; overflow-x: auto; transition: height 0.25s ease; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 4px 0 0; overflow-y: hidden; overscroll-behavior-x: contain; }
.slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; padding: 8px 0 4px; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.slide.try { background: var(--primary-soft); border-radius: 14px; padding: 14px; }
.panel-text { font-family: var(--serif); font-size: 1.25rem; line-height: 1.4; margin: 0; }
.q { font-weight: 650; margin-bottom: 10px; }
.answers button.right { border-color: var(--clean); background: var(--clean-soft); opacity: 1; }
.answers button.wrong { opacity: 0.6; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background 0.3s, transform 0.3s; }
.dots i.on { background: var(--primary); transform: scale(1.25); }

/* ---- Months as bricks --------------------------------------------------- */
.bricks { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-top: 8px; }
.brick { border-radius: 6px; padding: 6px 2px 5px; text-align: center; background: var(--surface-2); border: 1px dashed var(--line); font-size: 0.68rem; line-height: 1.2; color: var(--muted); }
.brick b { display: block; font-size: 0.78rem; color: var(--text); }
.brick.clean { background: var(--brick); border: 0; color: #fbf3ea; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15); }
.brick.clean b { color: #fff; }
.brick.reset { background: transparent; border: 1px solid var(--line); }
.brick.now { border: 2px solid var(--gold); background: var(--amber-bg); }

.trio { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 14px 8px; }
.trio b { display: block; font-family: var(--serif); font-size: 1.7rem; font-weight: 600; }
.trio span { font-size: 0.8rem; color: var(--muted); }

.steps-bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin: 2px 0 6px; }
.steps-bar i { height: 4px; border-radius: 4px; background: var(--line); transition: background 0.3s; }
.steps-bar i.on { background: var(--primary); }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; min-height: 36px; }
.card-foot .note { margin: 0; }
.card-foot button { border-radius: 99px; padding: 6px 16px; margin-left: auto; white-space: nowrap; flex-shrink: 0; }
.card-foot button[hidden] { display: none; }

.hand { font-family: var(--hand); }
:root[data-look='clay'] .hand { font-size: 1.45em; line-height: 1; color: var(--primary); }
.look-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.look-pick button { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; }
.look-pick button.chosen { border: 2px solid var(--primary); }
.look-pick .mini { border-radius: 10px; padding: 8px 6px; text-align: left; font-size: 0.8rem; line-height: 1.2; }
.look-pick .mini b { display: block; font-size: 1.05rem; font-weight: 400; }
.look-pick .sw { display: flex; gap: 3px; margin-top: 6px; }
.look-pick .sw i { width: 12px; height: 12px; border-radius: 50%; }

.lantern-slot { position: relative; display: inline-block; width: 40px; height: 60px; }
.lantern-slot .lantern { position: absolute; inset: 0; }
.lantern-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; z-index: 1; }
.lantern-art + .lantern { visibility: hidden; }
.lantern-slot.lit .lantern-art { animation: lantern-glow 3s ease-in-out infinite; animation-delay: var(--d); }
.lantern-slot:not(.lit) .lantern-art { opacity: 0.85; }
@keyframes lantern-glow { 0%, 100% { filter: drop-shadow(0 0 6px var(--gold)); } 50% { filter: drop-shadow(0 0 11px var(--gold)); } }
@media (max-width: 360px) { .lantern-slot { width: 32px; height: 48px; } }

/* Keep the day count readable over any picture. */
.hero-card .scene::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 22, 28, 0.55) 0%, rgba(20, 22, 28, 0.18) 38%, rgba(20, 22, 28, 0) 60%); pointer-events: none; }
.hero-day { z-index: 1; color: #fffaf0; }
.hero-big { text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45); }
.hero-small { opacity: 0.95; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); }

/* Calendar: light, dawn and night */
.cal .d { flex-direction: column; gap: 1px; line-height: 1; }
.cal .d .sym { width: 13px; height: 13px; }
.cal .d.clean { background: var(--lit-day); color: var(--text); outline: 0; }
.cal .d.clean .sym { color: var(--flame); }
.cal .d.recovery { background: linear-gradient(180deg, var(--surface-2) 0%, color-mix(in srgb, var(--gold) 14%, var(--surface)) 100%); color: var(--muted); }
.cal .d.recovery .sym { color: color-mix(in srgb, var(--gold) 55%, var(--muted)); }
.cal .d.use { background: #262a36; color: #e9e4f2; outline: 0; box-shadow: inset 0 0 0 1px rgba(201, 196, 230, 0.35); }
.cal .d.use .sym { color: #c9c4e6; }
.cal .d.pending .sym { color: var(--muted); }
.legend .key { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 5px; margin-right: 6px; vertical-align: -4px; }
.legend .key .sym { width: 11px; height: 11px; }
.legend .key.clean { background: var(--lit-day); color: var(--flame); }
.legend .key.recovery { background: color-mix(in srgb, var(--gold) 14%, var(--surface)); color: color-mix(in srgb, var(--gold) 55%, var(--muted)); }
.legend .key.use { background: #262a36; color: #c9c4e6; }
.legend .key.pending { background: var(--surface-2); color: var(--muted); }
:root[data-look='hearth'] .cal .d.use, :root[data-look='hearth'] .legend .key.use { background: #12151d; }
