/* Money OS — calm, legible, mobile-first. One accent. Big numbers. 44px+ tap targets. */
:root {
  color-scheme: light dark;
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #efece5; --line: #e2ded4;
  --text: #1b1d1f; --muted: #5d6268; --accent: #1f6f54; --accent-ink: #ffffff; --accent-soft: #e3f0ea;
  --warn: #8a5a00; --warn-soft: #fbf0d9; --neg: #a3261d; --neg-soft: #fbe6e3; --biz: #3d4f8f; --biz-soft: #e6e9f6;
  --radius: 16px; --gap: 16px; --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(20, 22, 26, .05), 0 6px 20px rgba(20, 22, 26, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --surface: #1d2025; --surface-2: #262a30; --line: #30353c;
    --text: #f0f1f2; --muted: #a3a9b1; --accent: #5cc3a0; --accent-ink: #0c1f18; --accent-soft: #1b3229;
    --warn: #f0c060; --warn-soft: #33290f; --neg: #ff8d82; --neg-soft: #3a1b18; --biz: #a9b8f5; --biz-soft: #20264a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.75rem; line-height: 1.15; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 650; display: flex; align-items: center; gap: 6px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }

.app { min-height: 100dvh; }
main { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 104px); display: flex; flex-direction: column; gap: var(--gap); }
main:focus { outline: none; }
.boot { padding: 48px 8px; color: var(--muted); text-align: center; display: grid; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack-tight { display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lead { font-size: 1.05rem; color: var(--text); }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--neg); font-size: .9rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; overflow-wrap: anywhere; }
.plain { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; }
.screen-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sub-nav { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.sub-nav::-webkit-scrollbar { display: none; }
.chip { min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; display: inline-flex; align-items: center; text-decoration: none; color: var(--text); cursor: pointer; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-warn { border-color: var(--warn); background: var(--warn-soft); }
.card-accent { border-color: transparent; background: var(--accent-soft); }

/* numbers */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.neg { color: var(--neg); }
.money.pos { color: var(--accent); }
.bignum { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bignum-label { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.bignum-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.bignum.hero .bignum-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }
.bignum.hero .bignum-value { font-size: clamp(2.6rem, 13vw, 3.6rem); letter-spacing: -.035em; }
.bignum-sub { color: var(--muted); font-size: .9rem; }
.tone-accent .bignum-value, .tone-accent .money { color: var(--accent); }
.tone-accent .money.neg { color: var(--neg); } /* a negative number is never shown in the 'good' colour */
.tone-muted .bignum-value { color: var(--muted); }
.help { width: 24px; height: 24px; min-width: 24px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 700; cursor: pointer; padding: 0; position: relative; }
.help::after { content: ""; position: absolute; inset: -12px; } /* 48px hit area */

/* rows */
.row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 8px 0; border-top: 1px solid var(--line); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0; }
.row:first-of-type { border-top: 0; }
.card > .row:first-child, .card-head + .row { border-top: 0; }
.row-btn { cursor: pointer; }
.row-btn:active { background: var(--surface-2); }
.row-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: .88rem; }
.row-right { display: flex; flex-direction: column; align-items: flex-end; font-weight: 600; flex: none; }
.badge { font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-biz { background: var(--biz-soft); color: var(--biz); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-neg { background: var(--neg-soft); color: var(--neg); }

/* buttons */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { background: var(--neg); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #2a0c09; } }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.btn-small { min-height: 44px; padding: 0 14px; border-radius: 12px; font-size: .92rem; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick .btn { min-height: 64px; flex-direction: column; gap: 2px; font-size: .95rem; }

/* notices */
.notice { border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--surface-2); border: 1px solid var(--line); }
.notice p { color: var(--muted); font-size: .92rem; }
.notice-warn { background: var(--warn-soft); border-color: transparent; }
.notice-warn strong { color: var(--warn); }
.notice-ok { background: var(--accent-soft); border-color: transparent; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty h3 { color: var(--text); }

/* math block */
.waterfall { margin: 0; display: grid; gap: 0; }
.wf-line { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.wf-line:first-child { border-top: 0; }
.wf-line dt { color: var(--muted); }
.wf-line dd { margin: 0; font-weight: 600; }
.wf-total dt { color: var(--text); font-weight: 650; }
.wf-total dd { font-size: 1.15rem; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.bar-fill.tone-warn { background: var(--warn); }
.bar-fill.tone-neg { background: var(--neg); }
.bar-fill.tone-biz { background: var(--biz); }

/* verdict (purchase checker) */
.verdict { border-radius: var(--radius); padding: 18px; display: grid; gap: 6px; background: var(--surface-2); }
.verdict strong { font-size: 1.25rem; letter-spacing: -.01em; }
.verdict-comfortable { background: var(--accent-soft); } .verdict-comfortable strong { color: var(--accent); }
.verdict-possible, .verdict-wait { background: var(--warn-soft); } .verdict-possible strong, .verdict-wait strong { color: var(--warn); }
.verdict-reserved, .verdict-too_much { background: var(--neg-soft); } .verdict-reserved strong, .verdict-too_much strong { color: var(--neg); }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-weight: 600; font-size: .95rem; }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.input { min-height: var(--tap); width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; appearance: none; -webkit-appearance: none; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
textarea.input { min-height: 88px; resize: vertical; }
.input.invalid, .field-error .input { border-color: var(--neg); }
.money-wrap { position: relative; }
.money-prefix { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.3rem; font-weight: 600; pointer-events: none; }
.input-money { padding-left: 34px; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; min-height: 60px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { min-height: 40px; display: grid; place-items: center; border-radius: 9px; font-weight: 600; font-size: .92rem; cursor: pointer; color: var(--muted); text-align: center; padding: 0 6px; }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.toggle { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(20px); }
.counter { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; min-height: var(--tap); border-top: 1px solid var(--line); padding: 6px 0; }
.counter:first-of-type { border-top: 0; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.3rem; font-weight: 600; cursor: pointer; }
.stepper input { width: 56px; min-height: 44px; text-align: center; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; font-variant-numeric: tabular-nums; }
.choice { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }

/* sheet */
dialog.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92dvh; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--text); overflow: hidden; }
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: rgba(10, 12, 14, .5); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; gap: 12px; }
.sheet-head h2 { font-size: 1.2rem; }
.sheet-close { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.sheet-body { padding: 8px 20px calc(env(safe-area-inset-bottom) + 24px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 22px; } }

/* toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 92px); display: grid; gap: 8px; justify-items: center; padding: 0 16px; z-index: 40; pointer-events: none; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; display: flex; gap: 14px; align-items: center; max-width: 560px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); font-size: .95rem; }
.toast-action { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; min-height: 44px; padding: 0 6px; cursor: pointer; }

/* tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-left)) calc(env(safe-area-inset-bottom) + 6px) max(8px, env(safe-area-inset-right)); z-index: 30; }
.tab { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; border-radius: 12px; position: relative; }
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab.active { color: var(--accent); }
.tab-dot { position: absolute; top: 4px; right: calc(50% - 22px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--neg); color: #fff; font-size: .68rem; display: grid; place-items: center; padding: 0 5px; }

.firstrun { padding-top: 12px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
