:root {
  --ground: #E6ECDF;
  --ground-2: #DCE4D3;
  --card: #FFFDF8;
  --ink: #2B2420;
  --muted: #6B625A;
  --line: #D9DECF;
  --track: #DCE3D3;
  --clay: #5A3A2E;
  --clay-dark: #3A261F;
  --glaze: #EFE6D6;
  --broth: #E8A33D;
  --broth-light: #F6CD7A;
  --gold-ink: #8A5A12;
  --good: #3F6B22;
  --warn-bg: #F7EAD2;
  --warn-ink: #4A3410;
  --bad: #A8321B;
  --shadow: 0 1px 2px rgba(43, 36, 32, .05), 0 6px 18px -8px rgba(43, 36, 32, .18);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Zen Kaku Gothic New", system-ui, sans-serif;
  --tabs-h: 72px;
  --gutter: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ground); color: var(--ink); }
body { font: 16px/1.5 var(--body); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
a { color: #1F5C5A; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
.app { max-width: 520px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
.num { font-family: var(--display); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.xs { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- noren header ---------- */
.noren { position: relative; height: calc(108px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); background: #2B2420; color: #F4EDE1; overflow: hidden; }
.noren .waves { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 100px; }
.noren .slit { position: absolute; bottom: 0; width: 3px; height: 44px; background: var(--ground); }
.noren .slit-1 { left: 33.3%; } .noren .slit-2 { left: 66.6%; }
.noren-row { position: relative; display: flex; align-items: flex-start; justify-content: space-between; padding: 16px var(--gutter) 0; gap: 12px; }
.noren-left, .noren-right { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.noren-right { align-items: flex-end; text-align: right; }
.noren h1, .noren .wordmark { margin: 0; font: 700 30px/1.15 var(--display); letter-spacing: -0.03em; }
.noren .sub { font-size: 13px; color: #CFC4B8; }
.noren .big { font: 700 21px/1.2 var(--display); }
.emblem { flex: none; width: 46px; height: 46px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--broth); color: var(--broth); font: 700 22px/1 var(--body); display: grid; place-items: center; text-decoration: none; transition: transform .2s var(--ease); }
.emblem:active { transform: scale(.92) rotate(-8deg); }

/* ---------- layout ---------- */
.view { padding: 16px var(--gutter) 0; display: flex; flex-direction: column; gap: 14px; outline: none; }
.view.enter { animation: enter .28s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card { background: var(--card); border-radius: 22px; padding: 16px 18px; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
h2 { margin: 0; font-size: 16px; font-weight: 700; }
.section-head { display: flex; align-items: center; justify-content: space-between; min-height: 40px; margin-top: 4px; }
.section-head a, .section-head button.link { font-size: 14px; font-weight: 700; text-decoration: none; min-height: 44px; display: flex; align-items: center; }
.empty { text-align: center; padding: 26px 18px; color: var(--muted); }
.press { transition: transform .15s var(--ease); }
.press:active { transform: scale(.975); }

/* skeleton */
.skel { border-radius: 22px; background: linear-gradient(100deg, #F2F1EA 30%, #FBFAF5 50%, #F2F1EA 70%) 0 0 / 300% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -300% 0; } }

/* ---------- pots ---------- */
.pot { background: var(--card); border-radius: 24px; padding: 16px 14px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.pot .who { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }
.avatar { width: 28px; height: 28px; border-radius: 50%; color: #FFFDF8; font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }
.pot svg { align-self: center; width: 100%; max-width: 168px; height: auto; margin: 2px 0 0; overflow: visible; }
.pot .amount { font-size: 32px; line-height: 1.05; }
.pot .amount.over { color: var(--bad); }
.pot .meta { font-size: 13px; color: var(--muted); line-height: 1.35; }
.steam path { animation: steam 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: bottom; }
.steam path:nth-child(2) { animation-delay: .7s; }
.steam path:nth-child(3) { animation-delay: 1.4s; }
@keyframes steam { 0% { opacity: 0; transform: translateY(6px) scaleY(.8); } 35% { opacity: .9; } 100% { opacity: 0; transform: translateY(-10px) scaleY(1.1); } }
.broth { animation: fill .9s var(--ease) both; transform-box: fill-box; transform-origin: bottom; }
@keyframes fill { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bob { animation: bob 3.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(1.5px); } }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--track); gap: 2px; }
.bar > div { height: 100%; transition: width .6s var(--ease); }

.banner { display: flex; gap: 12px; align-items: center; background: var(--warn-bg); color: var(--warn-ink); border-radius: 18px; padding: 14px 16px; text-decoration: none; font-size: 15px; }
.banner svg { flex: none; width: 20px; height: 20px; stroke: #8A5A12; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.banner .go { margin-left: auto; font-weight: 700; }

.list { background: var(--card); border-radius: 22px; padding: 2px 16px; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; gap: 12px; min-height: 64px; border-bottom: 1px solid var(--ground); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; padding: 10px 0; text-align: left; cursor: pointer; color: inherit; }
.item:last-child { border-bottom: 0; }
.item:active { background: linear-gradient(90deg, transparent, #F4F1E8 15%, #F4F1E8 85%, transparent); }
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { width: 42px; flex: none; text-align: center; font-size: 13px; color: var(--muted); line-height: 1.2; }
.item .amt { font-size: 17px; flex: none; }
.whoicons { display: flex; flex: none; width: 38px; }
.whoicons .dot { width: 24px; height: 24px; }
.whoicons .dot + .dot { margin-left: -9px; border: 2px solid var(--card); }

/* ---------- controls ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--ground-2); border-radius: 14px; padding: 4px; }
.seg button { height: 42px; border: 0; border-radius: 11px; background: transparent; color: #4F473F; font-size: 15px; font-weight: 500; cursor: pointer; transition: background .2s, box-shadow .2s; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(43,36,32,.12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { white-space: nowrap; min-height: 44px; padding: 0 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); font-size: 15px; cursor: pointer; transition: transform .12s var(--ease), background .15s; }
.chip:active { transform: scale(.96); }
.chip[aria-pressed="true"] { background: var(--clay); border-color: var(--clay); color: #FFFDF8; font-weight: 700; }
.btn { min-height: 52px; padding: 0 20px; border-radius: 16px; border: 0; background: var(--clay); color: #FFFDF8; font-weight: 700; font-size: 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; transition: transform .12s var(--ease), opacity .2s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px dashed #A49B90; font-weight: 500; }
.btn.light { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1.5px solid #E2C2B8; }
.btn.full { width: 100%; }
.link { background: none; border: 0; color: #1F5C5A; font-weight: 700; font-size: 15px; cursor: pointer; min-height: 40px; padding: 0 6px; }
label.field, .field { display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--muted); }
.input { width: 100%; min-height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); padding: 0 14px; font-size: 16px; color: var(--ink); transition: border-color .15s; }
.input:focus { outline: none; border-color: var(--clay); }
.input.amount { font: 700 40px/1 var(--display); height: 72px; letter-spacing: -0.02em; }
.input.pin { font: 700 28px/1 var(--display); letter-spacing: 0.4em; height: 62px; text-align: center; }
select.input { appearance: none; 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% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; border-radius: 16px; border: 0; background: #C9CFC0; cursor: pointer; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s var(--ease); }
.switch[aria-checked="true"] { background: #1F5C5A; }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.swatch[aria-pressed="true"] { border-color: var(--ink); }

/* ---------- spends to sort ---------- */
.sortcard { background: var(--card); border-radius: 22px; padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.sortcard.leaving { animation: leave .3s var(--ease) forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(40px); } }
.sortcard .head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sortcard .head .grow { min-width: 0; display: flex; flex-direction: column; }
.sortcard .head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sortcard .amount { font-size: 24px; flex: none; }
.who3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.who3 .chip { padding: 0 8px; }
.matchnote, .warnnote { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 12px; border-radius: 14px; font-size: 14px; }
.matchnote { background: #E3EEE9; }
.warnnote { background: var(--warn-bg); color: var(--warn-ink); }
.matchnote span, .warnnote span { flex: 1; line-height: 1.35; }

/* ---------- bills ---------- */
.elec { background: var(--warn-bg); border-radius: 24px; padding: 18px; display: flex; gap: 12px; box-shadow: var(--shadow); }
.elec .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.elec .muted { color: #6B5A3E; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 40px; }
.spark div { flex: 1; border-radius: 3px; background: #E2C98F; min-height: 3px; transform-origin: bottom; animation: grow .6s var(--ease) both; }
.spark div:last-child { background: var(--gold-ink); }
@keyframes grow { from { transform: scaleY(0); } }
.progress { height: 10px; border-radius: 5px; background: #EAD7B4; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold-ink); border-radius: 5px; }
.lantern { animation: sway 4s ease-in-out infinite; transform-origin: 50% 0; }
@keyframes sway { 50% { transform: rotate(3deg); } }

/* ---------- week ---------- */
.catgrid { display: grid; grid-template-columns: 100px minmax(0, 1fr) 80px; gap: 10px 10px; align-items: center; font-size: 15px; }
.catgrid .b { height: 12px; border-radius: 6px; background: var(--broth); transform-origin: left; animation: growx .7s var(--ease) both; }
@keyframes growx { from { transform: scaleX(0); } }
.trend { display: flex; align-items: flex-end; gap: 8px; height: 56px; }
.trend div { flex: 1; border-radius: 6px 6px 0 0; background: var(--track); transform-origin: bottom; animation: grow .6s var(--ease) both; }
.trend div.now { background: var(--clay); }
.weeknav { display: flex; align-items: center; justify-content: space-between; }
.iconbtn { width: 46px; height: 46px; border-radius: 23px; border: 0; background: var(--card); display: grid; place-items: center; cursor: pointer; color: var(--ink); box-shadow: var(--shadow); }
.iconbtn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:disabled { opacity: .35; cursor: default; }

/* ---------- settings ---------- */
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--ground); }
.setrow:last-child { border-bottom: 0; }
.setrow .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.setrow .label { font-weight: 500; }
code { font-size: 12px; word-break: break-all; background: var(--ground); padding: 2px 6px; border-radius: 6px; }

/* ---------- tabs ---------- */
.tabs { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 520px; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding: 4px 6px env(safe-area-inset-bottom); background: rgba(255, 253, 248, .94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; z-index: 5; }
.tabs a { position: relative; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; border-radius: 16px; transition: color .2s; }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 6px; width: 44px; height: 30px; border-radius: 15px; background: var(--ground); z-index: -1; animation: pill .25s var(--ease); }
@keyframes pill { from { transform: scaleX(.5); opacity: 0; } }
.tabs svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs .add { display: flex; justify-content: center; background: none; border: 0; cursor: pointer; padding: 0; }
.tabs .add span { width: 56px; height: 56px; border-radius: 28px; background: var(--clay); color: var(--broth-light); display: grid; place-items: center; box-shadow: 0 6px 16px -4px rgba(58, 38, 31, .45); transition: transform .15s var(--ease); }
.tabs .add:active span { transform: scale(.9) rotate(90deg); }
.tabs .add svg { width: 26px; height: 26px; stroke-width: 2.6; }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* ---------- sheet ---------- */
.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 520px; max-height: 92dvh; border-radius: 26px 26px 0 0; background: var(--ground); color: var(--ink); }
.sheet[open] { animation: up .32s var(--ease); }
@keyframes up { from { transform: translateY(100%); } }
.sheet::backdrop { background: rgba(43, 36, 32, .45); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.sheet form { padding: 14px var(--gutter) calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.sheet .grab { width: 42px; height: 5px; border-radius: 3px; background: #B9B0A4; margin: 0 auto 2px; }
.sheet h2 { font: 700 24px/1.2 var(--display); letter-spacing: -0.02em; }
.sheet .actions { display: flex; gap: 10px; position: sticky; bottom: 0; }
.sheet .actions .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%); background: var(--ink); color: #F4EDE1; padding: 12px 18px; border-radius: 14px; font-size: 15px; z-index: 20; max-width: calc(100% - 32px); box-shadow: 0 8px 24px -8px rgba(0,0,0,.4); animation: toast .3s var(--ease); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- login ---------- */
.signed-out .tabs { display: none; }
.login { display: flex; flex-direction: column; gap: 18px; padding-top: 14px; }
.login-title { margin: 0; text-align: center; font: 700 28px/1.2 var(--display); letter-spacing: -0.02em; }
.person-pick { min-height: 164px; border: 0; border-radius: 24px; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 18px; font-weight: 700; cursor: pointer; color: var(--ink); box-shadow: var(--shadow); }
.avatar.big { width: 68px; height: 68px; font-size: 28px; }

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