:root {
  color-scheme: dark;
  --ink: #f2f1e9;
  --muted: #a8b0aa;
  --faint: #748078;
  --night: #0b0f0d;
  --night-soft: #111714;
  --panel: #171d19;
  --panel-solid: #171d19;
  --line: #2b342e;
  --moss: #a6cf83;
  --moss-deep: #78aa5f;
  --gold: #e8c66c;
  --coral: #e48770;
  --shadow: 0 12px 30px rgba(0, 0, 0, .2);
  --radius: 22px;
  --small-radius: 14px;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 280px; background: var(--night); scroll-behavior: smooth; }

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: #0b0f0d;
  line-height: 1.5;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

button, a, input { -webkit-tap-highlight-color: transparent; }

button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(240, 199, 110, .9);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: .7rem 1rem;
  border-radius: 10px;
  background: var(--ink);
  color: var(--night);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.atmosphere { display: none; }

.site-header {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .75rem max(1rem, env(safe-area-inset-left));
  display: flex;
  align-items: center;
}

.brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 800; letter-spacing: -.02em; text-decoration: none; }
.brand-mark { display: block; width: 2rem; height: 2rem; }
.version-badge { margin-inline-start: .7rem; padding: .2rem .55rem; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: var(--panel); font-size: .75rem; font-weight: 750; white-space: nowrap; }

main { width: min(1120px, 100%); margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-right)) max(5rem, calc(2rem + env(safe-area-inset-bottom))) max(1rem, env(safe-area-inset-left)); }

.view-enter { animation: reveal .5s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }

.eyebrow { margin: 0 0 .45rem; color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .9rem; font-size: clamp(2.2rem, 11vw, 4.7rem); line-height: .96; letter-spacing: -.055em; }
h2 { margin-bottom: .35rem; font-size: clamp(1.35rem, 6vw, 2rem); line-height: 1.1; letter-spacing: -.03em; }
h3 { margin-bottom: .25rem; font-size: 1rem; }
.lede { max-width: 44rem; margin-bottom: 0; color: var(--muted); font-size: clamp(1rem, 4vw, 1.16rem); }

.onboarding { max-width: 920px; margin: 4vh auto 0; }
.hero { position: relative; margin-bottom: 2rem; padding: 1.25rem 0; }
.hero::before { content: ""; position: absolute; top: -.5rem; right: 2%; width: 4rem; height: .3rem; border-radius: 99px; background: var(--moss); }

.setup-card, .panel, .state-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.setup-card { padding: clamp(1rem, 5vw, 2rem); }
.step-row { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.3rem; }
.step-number { display: grid; place-items: center; flex: 0 0 auto; width: 2.2rem; height: 2.2rem; border-radius: 50%; color: var(--night); background: var(--gold); font-weight: 900; }
.step-row p { margin: 0; color: var(--muted); font-size: .86rem; }

.form-grid { display: grid; gap: 1rem; }
.field { display: grid; gap: .45rem; min-width: 0; }
.field label, .field-label { color: #dce5d8; font-size: .84rem; font-weight: 750; }
.field-hint { color: var(--faint); font-size: .74rem; }
input {
  width: 100%;
  min-height: 3.25rem;
  padding: .75rem .9rem;
  border: 1px solid rgba(197, 221, 193, .18);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(7, 13, 10, .45);
}
input:hover { border-color: rgba(197, 221, 193, .35); }
input:focus { border-color: var(--gold); }
input::placeholder { color: #68756c; }
input[type="date"] { color-scheme: dark; }

.choice-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: grid; min-height: 3.25rem; place-items: center; padding: .4rem; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: rgba(7, 13, 10, .35); font-size: .84rem; font-weight: 750; text-align: center; cursor: pointer; }
.choice input:checked + span { border-color: var(--moss); color: #10160e; background: var(--moss); }
.choice input:focus-visible + span { outline: 3px solid rgba(240, 199, 110, .9); outline-offset: 3px; }

.form-error { margin: .8rem 0 0; padding: .75rem .9rem; border: 1px solid rgba(229, 139, 113, .32); border-radius: 12px; color: #ffc2af; background: rgba(124, 51, 35, .18); font-size: .84rem; }
.actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.3rem; }

.btn { display: inline-flex; min-height: 3rem; align-items: center; justify-content: center; gap: .5rem; padding: .7rem 1rem; border: 1px solid transparent; border-radius: 12px; font-weight: 850; text-decoration: none; cursor: pointer; transition: transform .16s ease, background .16s ease, border-color .16s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { color: #10160e; background: var(--moss); box-shadow: none; }
.btn-secondary { border-color: var(--line); color: var(--ink); background: rgba(255,255,255,.035); }
.btn-danger { border-color: rgba(229, 139, 113, .23); color: #f4ae98; background: rgba(229, 139, 113, .07); }
.btn-small { min-height: 2.25rem; padding: .4rem .7rem; font-size: .78rem; }

.promise { display: grid; gap: .85rem; margin: 1.4rem 0 0; padding: 0; list-style: none; color: var(--muted); font-size: .82rem; }
.promise li { display: flex; gap: .6rem; }
.promise li::before { content: "✦"; color: var(--gold); }

.quest-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin: 1.2rem 0 1.5rem; }
.quest-header h1 { margin: 0; font-size: clamp(2rem, 9vw, 3.4rem); }
.day-pill { flex: 0 0 auto; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: rgba(255,255,255,.03); font-size: .75rem; font-weight: 800; }

.dashboard-grid, .dashboard-column { display: grid; gap: 1rem; }
.dashboard-column { min-width: 0; }
.panel { min-width: 0; padding: 1rem; box-shadow: 0 8px 20px rgba(0,0,0,.16); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.panel-heading p { margin: .25rem 0 0; color: var(--muted); font-size: .79rem; }

.budget-panel { overflow: hidden; border-color: #3d5845; background: #19221c; }
.budget-panel.over-budget, .history-item.over-budget { border-color: var(--coral); background: #321f1b; }
.budget-panel.over-budget { box-shadow: 0 8px 24px rgba(106,35,24,.24); }
.budget-panel.over-budget .eyebrow, .budget-panel.over-budget .day-pill { color: #ffc2af; }
.budget-panel.over-budget .day-pill { border-color: rgba(229,139,113,.4); background: rgba(229,139,113,.12); }
.budget-number { margin: .2rem 0 .1rem; font-size: clamp(3.2rem, 20vw, 6.5rem); font-weight: 900; line-height: .9; letter-spacing: -.07em; }
.budget-number span { color: var(--muted); font-size: 1rem; font-weight: 700; letter-spacing: 0; }
.budget-caption { color: var(--muted); font-size: .82rem; }
.progress-track { height: .7rem; margin: 1.2rem 0 .65rem; border-radius: 99px; background: rgba(3,8,5,.65); overflow: hidden; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--moss); transition: width .45s ease; }
.progress-fill.over { background: var(--coral); }
.budget-meta { display: flex; justify-content: space-between; gap: .8rem; color: var(--muted); font-size: .75rem; }
.budget-warning { display: grid; gap: .2rem; margin-top: 1rem; padding: .85rem; border: 1px solid rgba(229,139,113,.42); border-radius: 12px; color: #ffd2c4; background: rgba(86,31,23,.38); }
.budget-warning strong { font-size: .86rem; }
.budget-warning span { color: #eeb4a3; font-size: .76rem; }

.log-zone { display: grid; gap: .8rem; }
.log-button { width: 100%; min-height: 4.2rem; font-size: 1rem; }
.log-button::before { content: "+"; display: grid; flex: 0 0 auto; width: 1.6rem; height: 1.6rem; aspect-ratio: 1 / 1; place-items: center; padding: 0; border-radius: 50%; color: var(--night); background: rgba(16, 32, 15, .16); font-family: Arial, sans-serif; font-size: 1.2rem; line-height: 1.6rem; }
.reassure { margin: 0; color: var(--faint); font-size: .75rem; text-align: center; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.stat { min-width: 0; padding: .85rem; border: 1px solid var(--line); border-radius: var(--small-radius); background: rgba(2,8,5,.18); }
.stat strong { display: block; font-size: 1.5rem; letter-spacing: -.04em; }
.stat span { color: var(--muted); font-size: .72rem; }
.status-rule { margin: .85rem 0 0; padding-top: .75rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }

.joker-panel { border-color: rgba(240,199,110,.2); }
.joker-count { color: var(--gold); font-size: 1.6rem; font-weight: 900; }
.joker-copy { margin-bottom: 1rem; color: var(--muted); font-size: .83rem; }

.secret-panel { border-color: #554b2f; background: #242218; }
.secret-icon { display: grid; place-items: center; flex: 0 0 2.3rem; width: 2.3rem; height: 2.3rem; aspect-ratio: 1; border-radius: 50%; color: #2a2514; background: var(--gold); }
.secret-url { display: block; margin: .75rem 0; padding: .75rem; border: 1px dashed rgba(240,199,110,.3); border-radius: 10px; color: #f7dfa3; background: rgba(0,0,0,.16); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .73rem; overflow-wrap: anywhere; user-select: all; }
.secret-warning { color: #e5cf99; font-size: .78rem; }
.secret-actions { justify-content: space-between; }
.delete-confirm { margin-top: 1rem; padding: .8rem; border: 1px solid rgba(229,139,113,.35); border-radius: 12px; background: #321f1b; }
.delete-confirm[hidden], .secret-actions[hidden] { display: none; }
.delete-confirm p { margin: 0; color: #eeb4a3; font-size: .78rem; }
.delete-confirm .actions { margin-top: .75rem; }

.record-list, .history-list, .history-logs { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.record-item, .history-item { display: grid; min-width: 0; gap: .65rem; padding: .75rem; border: 1px solid var(--line); border-radius: 12px; background: rgba(3,9,5,.2); }
.record-item { container-type: inline-size; }
.history-item { padding: 0; }
.history-summary { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: .65rem; }
.record-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .45rem .65rem; }
.record-actions { display: flex; grid-column: -2; grid-row: 1; gap: .4rem; }
.history-main { min-width: 0; }
.record-title strong, .history-main strong, .history-log strong { font-size: .86rem; }
.history-main span { display: block; color: var(--faint); font-size: .72rem; }
.record-title, .history-log-summary { display: flex; min-width: 0; align-items: center; gap: .45rem; }
.record-title { flex-wrap: wrap; row-gap: 0; }
.record-title > span, .history-log-summary > span { flex: 0 0 auto; color: var(--faint); font-size: .72rem; }
.inline-note { min-width: 0; color: var(--muted); font-size: .76rem; }
.history-log-summary .inline-note { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-log-summary .inline-note::before { content: "· "; color: var(--gold); }
.record-summary > .inline-note { overflow-wrap: anywhere; }
.record-summary > :is(.inline-note, .note-form) { grid-column: 1 / -1; }
.note-form { min-width: 0; }
.note-form[hidden], .btn[hidden], .inline-note[hidden] { display: none; }
.note-form input { display: block; min-height: 2.25rem; padding: .4rem .6rem; font-size: .78rem; }
.note-save { min-width: 3.65rem; }

@container (min-width: 27rem) {
  .record-summary { grid-template-columns: max-content minmax(0, 1fr) auto; }
  .record-summary > :is(.inline-note, .note-form) { grid-column: 2; grid-row: 1; }
  .record-summary > .inline-note::before { content: "· "; color: var(--gold); }
}
.history-logs, .history-empty { margin: 0 .75rem; padding: .2rem 0 .75rem; border-top: 1px solid var(--line); }
.history-empty { padding-top: .55rem; color: var(--muted); font-size: .76rem; }
.history-log { display: grid; min-width: 0; gap: .45rem; padding-top: .55rem; }
.history-log-summary { width: 100%; }
.history-log .note-form { min-width: 0; }
.history-value { flex: 0 0 auto; text-align: right; }
.history-value strong { display: block; font-size: .9rem; }
.history-value span { color: var(--faint); font-size: .68rem; }
.empty { padding: 1rem; border: 1px dashed var(--line); border-radius: 12px; color: var(--faint); font-size: .8rem; text-align: center; }

.history-summary { padding: .75rem; border-radius: 11px; cursor: pointer; list-style: none; }
.history-summary::-webkit-details-marker { display: none; }
.history-summary::after { content: ""; flex: 0 0 .45rem; width: .45rem; height: .45rem; margin: 0 .15rem 0 .25rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; color: var(--gold); transform: rotate(45deg); }
.history-item details[open] > .history-summary::after { transform: rotate(225deg); }
.history-main { flex: 1 1 auto; }
.history-item.over-budget :is(.history-main span, .history-value, .history-value span), .history-item.over-budget .history-summary::after { color: #ffc2af; }

.state-wrap { display: grid; min-height: 65vh; place-items: center; }
.state-card { width: min(31rem, 100%); padding: 2rem 1rem; text-align: center; }
.state-card p { color: var(--muted); }
.loader { width: 2.5rem; height: 2.5rem; margin: 0 auto 1rem; border: 3px solid var(--line); border-top-color: var(--moss); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-region { position: fixed; z-index: 20; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); left: max(1rem, env(safe-area-inset-left)); display: grid; justify-items: center; pointer-events: none; }
.toast { max-width: 30rem; padding: .75rem 1rem; border: 1px solid rgba(197,221,193,.22); border-radius: 99px; color: var(--ink); background: #24352b; box-shadow: 0 10px 30px rgba(0,0,0,.35); font-size: .82rem; animation: toast-in .25s ease both; }
.toast.error { border-color: rgba(229,139,113,.4); background: #4a2b23; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.noscript { margin: 1rem; padding: 1rem; border-radius: 12px; background: #4a2b23; text-align: center; }

@media (min-width: 700px) {
  .site-header { padding-top: 1.5rem; }
  main { padding-inline: 1.5rem; }
  .onboarding { display: grid; grid-template-columns: minmax(0, .85fr) minmax(21rem, 1fr); align-items: center; gap: 3rem; min-height: 76vh; }
  .hero { margin: 0; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
  .promise { grid-template-columns: repeat(3, 1fr); }
  .panel { padding: 1.25rem; }
}

@media (min-width: 960px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1.5fr) minmax(15rem, .7fr); align-items: start; }
  .budget-panel { padding: 1.6rem; }
  .budget-number { margin-top: 1rem; }
}

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