:root {
  --red: #9E1B1F;
  --red-dark: #7A1418;
  --gold: #C8962E;
  --gold-text: #8A5A0B;
  --ink: #2A1F1B;
  --muted: #5C504A;
  --placeholder: #6E625C;
  --soft: #F7F1EE;
  --tint: #FBF0EC;
  --page: #FCF8F6;
  --line: #EFE3DD;
  --line-2: #E6D6CF;
  --field: #D9C6BE;
  --stepper: #D9BFB4;
  --off: #B8A9A2;
  --ok: #2E6B3F;
  --ok-bg: #E9F2EC;
  --danger: #A32A1F;
  --danger-line: #E3B5B1;
  --out-bg: #F6E7C4;
  --out-text: #6B4A08;
  --display: 'Playfair Display', Georgia, serif;
  --body: 'Hind Siliguri', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.4;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
a { color: var(--red); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { display: inline-flex; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: #FFFFFF; display: flex; flex-direction: column; }

/* ---------- top bars ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: #FFFFFF;
  border-bottom: 6px solid var(--red);
  box-shadow: 0 2px 0 var(--gold);
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.titlebar { display: flex; align-items: center; gap: 6px; }
.titlebar h1 { margin: 0 auto 0 0; font-family: var(--display); font-size: 28px; font-weight: 700; color: var(--red); line-height: 1.15; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 12px; border: none; background: transparent; color: var(--red);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.iconbtn .icon { width: 24px; height: 24px; }
.iconbtn.spin .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.backbar {
  position: sticky; top: 0; z-index: 5;
  background: #FFFFFF; border-bottom: 6px solid var(--red); box-shadow: 0 2px 0 var(--gold);
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.backbtn {
  height: 44px; padding: 0 12px 0 4px; border: none; background: transparent; color: var(--red);
  display: inline-flex; align-items: center; gap: 2px; font-size: 17px; font-weight: 700;
}
.backbtn .icon { width: 24px; height: 24px; }

.status {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 14px; padding: 5px 12px; border-radius: 999px;
}
.status .icon { width: 16px; height: 16px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.status[data-state="saved"] { color: var(--ok); background: var(--ok-bg); }
.status[data-state="saving"] { color: var(--muted); background: var(--soft); }
.status[data-state="retrying"], .status[data-state="error"] { color: var(--danger); background: var(--tint); }
.status[data-state="retrying"] .dot, .status[data-state="error"] .dot { background: var(--danger); }

.demo { background: var(--out-bg); color: var(--out-text); font-size: 14px; font-weight: 600; text-align: center; padding: 6px 12px; }

/* ---------- list screen ---------- */
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--soft); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; }
.tile span:first-child { font-size: 14px; color: var(--muted); }
.tile strong { font-size: 24px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile.hi { background: var(--tint); }
.tile.hi span:first-child, .tile.hi strong { color: var(--red); }
.filters { background: #FFFFFF; padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.caption-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; margin-top: -4px; }
.totals-caption { margin: 0; font-size: 14px; color: var(--muted); }
.fgroup { display: flex; flex-direction: column; gap: 4px; }
.fhead { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.flabel { font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-text); }
.clearbtn {
  min-height: 36px; padding: 0 12px; margin-right: -8px; border: none; border-radius: 999px; background: transparent;
  color: var(--red); font-size: 15px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
  animation: fade-in 0.15s ease-out;
}
.clearbtn:active { background: var(--tint); }

.search {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 6px 0 16px;
  border: 1.5px solid var(--field); border-radius: 999px; background: #FFFFFF;
}
.search:focus-within { border-color: var(--red); }
.search .icon { width: 22px; height: 22px; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 18px; }
.search input::placeholder { color: var(--placeholder); }
.search input::-webkit-search-cancel-button { display: none; }
.search .iconbtn { color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1.5px solid var(--line-2); background: #FFFFFF; font-size: 15px;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.chip[aria-pressed="true"] { border-color: var(--red); background: var(--red); color: #FFFFFF; font-weight: 600; }
.chip:active, .choice:active { transform: scale(0.95); }

.list { flex: 1; background: var(--page); padding: 14px 16px calc(110px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.empty { padding: 40px 12px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty p { margin: 0; font-size: 17px; }
.linkbtn { border: none; background: transparent; color: var(--red); font-weight: 700; font-size: 17px; text-decoration: underline; min-height: 44px; padding: 0 8px; }

.card { background: #FFFFFF; border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: flex-start; gap: 4px; }
.card-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.card-title h2 { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 15px; color: var(--muted); }
.tag { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.tag.wed { background: var(--red); color: #FFFFFF; }
.tag.out { background: var(--out-bg); color: var(--out-text); }
.notebtn {
  height: 44px; padding: 0 10px; border: none; border-radius: 12px; background: transparent; color: var(--gold-text);
  display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.notebtn .icon { width: 20px; height: 20px; }
.notebtn[hidden] { display: none; }

.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stepbox { background: var(--soft); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.stepbox.hi { background: var(--tint); }
.stepbox > span { font-size: 14px; color: var(--muted); padding-left: 4px; }
.stepbox.hi > span, .stepbox.hi .num { color: var(--red); }
.num.unknown, .stepbox.hi .num.unknown { color: var(--off); }
.stepper { display: flex; align-items: center; gap: 4px; }
.num { flex: 1; text-align: center; font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; }
.step {
  width: 44px; height: 44px; border-radius: 50%; padding: 0; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--stepper); background: #FFFFFF; color: var(--red);
}
.step.plus { border: none; background: var(--red); color: #FFFFFF; }
.step .icon { width: 20px; height: 20px; }
.step { transition: transform 0.1s, background-color 0.15s; }
.step:active { transform: scale(0.9); }
.step.plus:active { background: var(--red-dark); }
.num.bump { animation: bump 0.22s ease-out; }

.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50vw - 280px + 16px)); bottom: calc(24px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 22px 0 18px; border-radius: 999px; border: none;
  background: var(--red); color: #FFFFFF; font-size: 17px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 6px 18px rgba(110, 20, 24, 0.3);
}
.fab .icon { width: 22px; height: 22px; }

/* ---------- forms (edit, categories, lock) ---------- */
.page { flex: 1; background: var(--page); padding: 20px 16px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 22px; }
.page-head { display: flex; flex-direction: column; gap: 2px; }
.page-head h1 { margin: 0; font-family: var(--display); font-size: 28px; font-weight: 700; color: var(--red); line-height: 1.2; }
.page-head p { margin: 0; font-size: 16px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 16px; font-weight: 700; }
.input {
  height: 54px; padding: 0 16px; border: 1.5px solid var(--field); border-radius: 14px;
  font-size: 18px; background: #FFFFFF; outline: none; width: 100%;
}
.input:focus, .textarea:focus { border-color: var(--red); }
.hint { margin: 0; font-size: 14px; color: var(--muted); }
.hint.error { color: var(--danger); }
fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--line-2);
  background: #FFFFFF; font-size: 16px;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.choice[aria-pressed="true"] { border-color: var(--red); background: var(--red); color: #FFFFFF; font-weight: 600; }
.choice.add { border-style: dashed; border-color: #A8968E; background: transparent; }
.newcat { display: flex; gap: 8px; }
.newcat .input { height: 48px; }
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: none; font-size: 17px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn .icon { width: 20px; height: 20px; }
.btn.primary { background: var(--red); color: #FFFFFF; }
.btn.quiet { background: var(--soft); color: var(--ink); }
.btn.danger { background: var(--danger); color: #FFFFFF; }
.btn.outline-danger { background: #FFFFFF; color: var(--danger); border: 1.5px solid var(--danger-line); }
.btn.big { min-height: 58px; font-size: 19px; border-radius: 16px; width: 100%; }

.section { display: flex; flex-direction: column; gap: 10px; }
.section h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel { background: #FFFFFF; border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; }
.panel > .row + .row { border-top: 1px solid #F1E7E2; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; min-height: 64px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-text strong { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.row-text span { font-size: 14px; color: var(--muted); }
.row .num { flex: 0 0 40px; font-size: 26px; }
.row .step { width: 48px; height: 48px; }
.row .step .icon { width: 22px; height: 22px; }

.switch {
  position: relative; width: 60px; height: 36px; border-radius: 999px; border: none; padding: 0; flex-shrink: 0;
  background: var(--off); transition: background-color 0.18s;
}
.switch::after {
  content: ''; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(42, 20, 16, 0.25); transition: transform 0.18s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.switch[aria-checked="true"] { background: var(--red); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }

.notes .label { font-size: 15px; font-weight: 600; color: var(--muted); }
.textarea {
  min-height: 96px; padding: 12px 14px; border: 1.5px solid var(--line-2); border-radius: 14px;
  font-size: 16px; background: #FFFFFF; outline: none; width: 100%; resize: vertical;
}

.savebar {
  position: sticky; bottom: 0; background: #FFFFFF; border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

/* ---------- lock ---------- */
.lock { flex: 1; display: flex; flex-direction: column; }
.lock-band { height: calc(14px + env(safe-area-inset-top)); background: var(--red); box-shadow: 0 3px 0 var(--gold); }
.lock form { flex: 1; padding: 64px 24px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 28px; }
.eyebrow { font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-text); font-weight: 600; }
.lock h1 { margin: 0; font-family: var(--display); font-size: 38px; font-weight: 700; color: var(--red); line-height: 1.1; }
.lock .intro { margin: 6px 0 0; font-size: 18px; color: var(--muted); }
.pwbox { display: flex; align-items: center; height: 58px; border: 2px solid var(--field); border-radius: 14px; padding: 0 4px 0 16px; background: #FFFFFF; }
.pwbox:focus-within { border-color: var(--red); }
.pwbox input { flex: 1; min-width: 0; border: none; outline: none; font-size: 20px; background: transparent; }
.pwbox button { height: 48px; padding: 0 12px; border: none; background: transparent; color: var(--red); font-size: 16px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { width: 26px; height: 26px; accent-color: var(--red); margin: 0; flex-shrink: 0; }
.check span { display: flex; flex-direction: column; }
.check strong { font-size: 17px; font-weight: 600; }
.check small { font-size: 14px; color: var(--muted); }
.lock .btn.big { margin-top: auto; }

.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; text-align: center; color: var(--muted); }

/* ---------- modal + toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(42, 20, 16, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.dialog {
  width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto; background: #FFFFFF;
  border-radius: 24px 24px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .dialog { border-radius: 24px; max-width: 440px; }
}
.dialog h2 { margin: 0; font-family: var(--display); font-size: 24px; color: var(--red); line-height: 1.2; overflow-wrap: anywhere; }
.dialog p { margin: 0; font-size: 17px; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--soft); border-radius: 14px; padding: 14px; font-size: 18px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

.toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px); background: var(--ink); color: #FFFFFF; padding: 12px 18px; border-radius: 14px;
  font-size: 16px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast { transition: opacity 0.2s, transform 0.2s ease-out; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- motion ---------- */
.screen-in { animation: fade-in 0.18s ease-out; }
.screen-in .page { animation: slide-in 0.22s cubic-bezier(0.2, 0.7, 0.3, 1); }
.card.enter { animation: rise-in 0.2s ease-out both; }
.card.flash { animation: rise-in 0.2s ease-out both, flash 1.4s ease-out 0.2s; }
.overlay { animation: fade-in 0.18s ease-out; }
.overlay .dialog { animation: sheet-up 0.22s cubic-bezier(0.2, 0.7, 0.3, 1); }
.overlay.closing { animation: fade-out 0.18s ease-in forwards; }
.overlay.closing .dialog { animation: sheet-down 0.18s ease-in forwards; }
.status[data-state="saved"] .icon { animation: pop 0.3s ease-out; }
.status[data-state="saving"] .dot { animation: pulse 1s ease-in-out infinite; }
.fab, .btn, .iconbtn, .notebtn { transition: transform 0.1s, background-color 0.15s; }
.fab:active, .btn:active, .iconbtn:active, .notebtn:active { transform: scale(0.96); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheet-down { to { transform: translateY(40px); opacity: 0; } }
@keyframes bump { 40% { transform: scale(1.3); } }
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.2); } }
@keyframes pulse { 50% { opacity: 0.3; } }
@keyframes flash { 0%, 40% { background: var(--out-bg); border-color: var(--gold); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
