/* Halfly, "Night": a deep indigo ground, one periwinkle accent, large rupee figures.
   Green and peach only ever mean "you lent" and "you borrowed", and always sit beside those words. */
@font-face { font-family: Manrope; src: url(/fonts/manrope-latin-wght-normal.woff2) format('woff2'); font-weight: 200 800; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: Manrope; src: url(/fonts/manrope-latin-ext-wght-normal.woff2) format('woff2'); font-weight: 200 800; font-display: swap; unicode-range: U+0100-02BA, U+1E00-1E9F, U+1EF2-1EFF, U+20A0-20AB, U+20AD-20C0; }

:root {
  color-scheme: dark;
  --bg: #151b3d; --surf: #212955; --surf-hi: #2c356a; --line: #3b4580;
  --fg: #f2f4ff; --sub: #b3bbe6; --acc: #9dbdff; --pos: #84e3bc; --neg: #ffb491; --danger: #ff9d9d;
  --p2: #d3b6ff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 500 15px/1.4 Manrope, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent; }
#view { max-width: 520px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 20px calc(112px + env(safe-area-inset-bottom)); }
h1, h2, h3, p, ol { margin: 0; }
h1 { font-size: 1.65rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; font-weight: 800; }
h3 { font-size: .95rem; font-weight: 800; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--acc); color: var(--bg); }
:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }
.i { flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.muted { color: var(--sub); font-size: .875rem; }
.center { text-align: center; }
.stack { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 0; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
button, .button { min-height: 48px; padding: 8px 16px; border: 0; border-radius: 16px; background: var(--surf); color: var(--fg); font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; }
button:active, .button:active { background: var(--surf-hi); }
button.primary { background: var(--acc); color: var(--bg); font-weight: 800; }
button.light { background: var(--fg); color: var(--bg); font-weight: 800; }
button.primary:active, button.light:active { filter: brightness(.92); }
button.wide { width: 100%; min-height: 54px; }
button.quiet { background: none; color: var(--acc); min-height: 44px; padding: 6px 4px; }
button.link { background: none; min-height: 40px; padding: 4px; color: var(--acc); text-decoration: underline; text-underline-offset: 3px; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: progress; }
.iconbtn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 44px; padding: 0; flex: none; border: 0; border-radius: 14px; background: var(--surf); }
.iconbtn select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.iconbtn:focus-within { outline: 3px solid var(--acc); outline-offset: 2px; }
.iconbtn.plain { background: none; color: var(--sub); }

input, select, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surf); caret-color: var(--acc); }
input::placeholder, textarea::placeholder { color: var(--sub); opacity: 1; }
textarea { resize: vertical; }
select.compact { width: auto; min-height: 44px; padding: 6px 10px; font-size: .875rem; font-weight: 700; }
input[type="file"] { padding: 10px; }
label.field { display: grid; gap: 6px; font-size: .85rem; color: var(--sub); min-width: 0; }
label.field > * { color: var(--fg); font-size: 1rem; }
label.check { display: flex; gap: 12px; align-items: center; min-height: 44px; }
label.check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--acc); }

/* ---------- page furniture ---------- */
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 48px; }
.top > :first-child { margin-right: auto; }
.brand { font-weight: 800; font-size: 1.1rem; }
.section { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 28px 0 8px; }
.empty { text-align: center; color: var(--sub); padding: 36px 16px; }
.error { color: var(--danger); font-weight: 700; text-align: center; }
.error:empty { display: none; }

/* ---------- balance ---------- */
.balance { margin: 8px 0 8px; }
.balance h1 { font-size: 1.05rem; font-weight: 600; color: var(--sub); letter-spacing: 0; }
.balance .amount { font-size: clamp(2.75rem, 15vw, 3.9rem); font-weight: 800; letter-spacing: -0.035em; line-height: 1.15; margin: 2px 0 18px; overflow-wrap: anywhere; }
.balance .amount.long { font-size: clamp(2rem, 10vw, 3rem); }
.balance .two > * { min-width: 0; line-height: 1.2; }

.dayhead { font-size: .82rem; font-weight: 700; color: var(--sub); margin: 22px 0 2px; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); }
.list.spaced { margin-top: 18px; }
.item { display: flex; gap: 12px; align-items: center; width: 100%; min-height: 62px; padding: 9px 0; background: none; border-radius: 14px; text-align: left; font-weight: 500; justify-content: flex-start; }
.item:active { background: var(--surf); }
a.grow { display: block; }
.tile { width: 44px; height: 44px; flex: none; border-radius: 14px; background: var(--surf); color: var(--acc); display: grid; place-items: center; }
.title { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { display: block; color: var(--sub); font-size: .82rem; font-weight: 500; overflow-wrap: anywhere; }
.end { text-align: right; flex: none; }
.verb { display: block; font-size: .75rem; color: var(--sub); }
.money { display: block; font-weight: 800; font-size: 1rem; white-space: nowrap; }
.pos, .pos .verb { color: var(--pos); }
.neg, .neg .verb { color: var(--neg); }

.chip { min-height: 44px; padding: 6px 14px; border-radius: 14px; font-size: .875rem; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on, .chip[aria-pressed="true"] { background: var(--acc); color: var(--bg); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; padding: 4px; background: var(--surf); border-radius: 18px; }
.seg button { background: transparent; min-height: 44px; padding: 4px 2px; line-height: 1.15; font-size: .82rem; border-radius: 14px; }
.seg button[aria-pressed="true"] { background: var(--acc); color: var(--bg); }

.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surf); gap: 3px; margin-top: 6px; }
.bar > span { display: block; min-width: 0; transition: flex-grow .25s cubic-bezier(.16, 1, .3, 1); }
.bar > span:first-child { background: var(--acc); } .bar > span:last-child { background: var(--p2); }
.legend { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: .85rem; font-weight: 700; }
.legend .p1 { color: var(--acc); } .legend .p2 { color: var(--p2); }
.total { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 12px; }
.meter { height: 6px; border-radius: 3px; background: var(--acc); margin-top: 7px; }

/* ---------- trips ---------- */
.spent { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 14px 16px; border-radius: 18px; background: var(--surf); }
.spent b { display: block; font-size: 1.5rem; font-weight: 800; }
.pass { background: var(--surf); border-radius: 20px; }
.pass .route { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; align-items: center; padding: 16px 18px 14px; }
.pass .route b { display: block; font-size: 1.1rem; font-weight: 800; overflow-wrap: anywhere; line-height: 1.2; }
.pass .route span { display: block; }
.pass .route > [role="img"] { color: var(--acc); transform: rotate(45deg); }
.pass .route > :last-child { text-align: right; }
.pass .stub { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 14px 4px 18px; border-top: 2px dashed var(--line); font-size: .84rem; }
.day { margin-top: 20px; }
.day h3 { margin-bottom: 4px; }
.timeline { list-style: none; padding: 0; }
.timeline li { position: relative; }
/* The line joins one stop to the next; the last stop of a day ends it. */
.timeline li:not(:last-child)::after { content: ''; position: absolute; left: 63px; top: 34px; bottom: -14px; width: 2px; background: var(--line); }
.stop { display: grid; grid-template-columns: 42px 24px minmax(0, 1fr); gap: 10px; align-items: start; width: 100%; padding: 12px 0; min-height: 52px; background: none; border-radius: 12px; text-align: left; font-weight: 500; }
button.stop:active { background: var(--surf); }
.stop .time { font-size: .85rem; font-weight: 800; padding-top: 1px; }
.stop .dot { width: 12px; height: 12px; margin: 5px 6px 0; border-radius: 50%; border: 3px solid var(--acc); }
.stop .what { display: block; font-weight: 700; overflow-wrap: anywhere; }
.flight .stop .dot { width: 24px; height: 24px; margin: -1px 0 0; border: 0; background: var(--acc); color: var(--bg); display: grid; place-items: center; }

/* ---------- navigation ---------- */
#tabs { position: fixed; inset: auto 0 0 0; max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; justify-items: center; padding: 8px 8px calc(10px + env(safe-area-inset-bottom)); background: var(--surf); border-radius: 24px 24px 0 0; }
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; width: 100%; min-height: 52px; color: var(--sub); font-size: .72rem; font-weight: 700; border-radius: 14px; }
#tabs [aria-current="page"] { color: var(--fg); background: var(--surf-hi); }
#tabs .add { width: 56px; height: 56px; padding: 0; border-radius: 20px; background: var(--acc); color: var(--bg); }

/* ---------- sheets ---------- */
dialog { width: 100%; max-width: 520px; max-height: 94dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 26px 26px 0 0; background: var(--bg); color: var(--fg); overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; animation: rise .28s cubic-bezier(.16, 1, .3, 1); }
@keyframes rise { from { transform: translateY(32px); } }
dialog::backdrop { background: rgb(5 8 24 / .7); }
dialog > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
dialog.full { height: 100dvh; max-height: 100dvh; border-radius: 0; }
.sheet-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 16px 8px; text-align: center; }
.sheet-head h2 { font-size: 1rem; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 10px; }
.sheet-body > * { flex: none; }
.sheet-foot { display: grid; gap: 8px; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }

.hero { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.hero input.amount-input { border: 0; background: none; text-align: center; font-weight: 800; letter-spacing: -0.035em; line-height: 1.1; padding: 0; min-height: 0; border-radius: 12px; font-size: clamp(2.75rem, 9dvh, 4.25rem); }
.hero input.amount-input[data-size="m"] { font-size: 2.75rem; }
.hero input.amount-input[data-size="s"] { font-size: 2.1rem; }
.hero.small input.amount-input { font-size: 3rem; }
.hero input.amount-input:focus-visible { outline: 0; } /* the caret shows where you are */
dialog:focus-visible { outline: 0; }
.hero select.currency { width: auto; min-height: 38px; padding: 4px 12px; border: 0; border-radius: 12px; font-size: .82rem; font-weight: 800; color: var(--sub); text-align: center; }
.hero input.what { text-align: center; border: 0; border-bottom: 2px solid var(--surf-hi); border-radius: 0; background: none; font-size: 1.1rem; font-weight: 600; }
.hero input.what:focus-visible { outline: 0; border-bottom-color: var(--acc); }
.ratebox { display: grid; justify-items: center; gap: 2px; font-size: .75rem; color: var(--sub); }
.ratebox label { display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 700; color: var(--fg); }
.ratebox input.rate { width: 116px; min-height: 40px; padding: 4px 10px; }
.ratebox a { text-decoration: underline; }

/* Expense entry: the amount takes the spare height, the pad sits under your thumb. */
.full .sheet-body { gap: 8px; }
.full .hero { flex: 1 0 auto; }
.pickers { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pickers .chip { color: var(--fg); }
.pickers .chip .i { color: var(--acc); }
.pickers .chip[aria-expanded="true"] { background: var(--surf-hi); box-shadow: inset 0 0 0 2px var(--acc); }
.result { text-align: center; font-weight: 800; color: var(--sub); min-height: 1.4em; }
.result.pos { color: var(--pos); } .result.neg { color: var(--neg); }
/* The padding leaves room for focus rings, which a scrolling box would otherwise cut off. */
.panel { --key: clamp(44px, 6.4dvh, 54px); height: calc(var(--key) * 4 + 8px); margin: -4px; padding: 4px; overflow-y: auto; overscroll-behavior: contain; }
.keys { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.keys button { height: var(--key); min-height: 0; background: none; font-size: 1.5rem; font-weight: 700; touch-action: manipulation; user-select: none; }
.keys button:active { background: var(--surf); }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 5px; }
.choice { flex-direction: column; gap: 4px; min-height: 60px; padding: 6px 2px; font-size: .72rem; overflow-wrap: anywhere; line-height: 1.2; }
.choice .i { color: var(--acc); }
.choice[aria-pressed="true"] { background: var(--acc); color: var(--bg); }
.choice[aria-pressed="true"] .i { color: var(--bg); }
.shares { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.shares div { padding: 10px; border-radius: 14px; background: var(--surf); text-align: center; }
.shares span { display: block; font-size: .78rem; color: var(--sub); }
.shares b { font-size: 1.15rem; font-weight: 800; }
.panel textarea { height: 100%; resize: none; }

/* On short screens the pickers become one sideways-scrolling row so Save stays in view. */
@media (max-height: 760px) {
  .pickers { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; margin: 0 -16px; padding: 3px 16px; scrollbar-width: none; flex-shrink: 0; }
  .pickers .chip { flex: none; }
  .full .sheet-body { gap: 6px; }
  .hero { gap: 2px; }
}

/* ---------- toast ---------- */
#toast { position: fixed; inset: auto 12px calc(94px + env(safe-area-inset-bottom)) 12px; margin: 0 auto; width: auto; max-width: 496px; border: 0; padding: 10px 10px 10px 16px; border-radius: 18px; background: var(--fg); color: var(--bg); align-items: center; gap: 8px; font-weight: 700; }
#toast:popover-open { display: flex; }
#toast span { flex: 1; }
#toast button, #toast .button { min-height: 44px; padding: 6px 12px; background: var(--bg); color: var(--fg); font-size: .85rem; }

/* ---------- sign in ---------- */
.login { max-width: 340px; margin: 10vh auto 0; display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.login img { border-radius: 18px; }
.login h1 { font-size: 2.25rem; margin-bottom: 8px; }

@media (min-width: 600px) {
  dialog { margin: auto; border-radius: 26px; border: 1px solid var(--line); }
  dialog.full { height: min(860px, 94dvh); max-height: 94dvh; max-width: 420px; border-radius: 26px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
input[type="file"]::file-selector-button { font: inherit; font-weight: 700; margin-right: 10px; padding: 6px 12px; border: 0; border-radius: 10px; background: var(--surf-hi); color: var(--fg); cursor: pointer; }
