/* Sackville: an old account book. Dark: by candlelight in Bag End's study. Light: the ledger page by day.
   Layout: .topbar, then .page (front: hero + form; ledger: head + two columns), then .foot. */

* { box-sizing: border-box; margin: 0; }

@font-face { font-family: 'IM Fell English'; src: url('fonts/imfell-regular.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'IM Fell English'; font-style: italic; src: url('fonts/imfell-italic.woff2') format('woff2'); font-display: swap; }

:root, :root[data-theme="dark"] {
  --bg: #17130d;
  --bg-glow: #2a2216;
  --card: #221c13;
  --card-2: #2a2318;
  --border: #43382a;
  --rule: rgba(184, 134, 46, 0.14);
  --text: #eee4cd;
  --muted: #a69a80;
  --brass: #d1a04a;
  --brass-soft: rgba(209, 160, 74, 0.16);
  --plus: #8fbf73;
  --minus: #e08a6d;
  --ink-on-brass: #1d170e;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2ead6;
  --bg-glow: #fbf6e8;
  --card: #fbf7ea;
  --card-2: #f4ecd8;
  --border: #d9c9a3;
  --rule: rgba(80, 110, 160, 0.16);
  --text: #33291a;
  --muted: #7d7058;
  --brass: #9b6b1f;
  --brass-soft: rgba(155, 107, 31, 0.13);
  --plus: #3f7a2c;
  --minus: #b0472b;
  --ink-on-brass: #fbf6e8;
  --shadow: 0 6px 20px rgba(110, 85, 40, 0.15);
  color-scheme: light;
}

:root {
  --display: 'IM Fell English', 'Palatino Linotype', Palatino, Georgia, serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 14px;
}

html { background: var(--bg); }
body {
  min-height: 100vh;
  font: 16px/1.5 var(--body);
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), transparent 70%), var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brass); }
button, input, select { font: inherit; color: inherit; }
h1, h2 { font-family: var(--display); font-weight: 400; letter-spacing: 0.01em; }

/* ---------------------------------------------------------------- frame */

.topbar, .page, .foot { width: min(1120px, 100% - 32px); margin-inline: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 20px 0 8px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font: 1.45rem var(--display); color: var(--text); text-decoration: none; }
.spoon { width: 22px; height: 22px; fill: none; stroke: var(--brass); stroke-width: 2; stroke-linecap: round; }
.spoon.big { width: 54px; height: 54px; stroke-width: 1.4; }
.tools { display: flex; gap: 8px; }
.tools button {
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; letter-spacing: 0.06em;
}
.tools button:hover { color: var(--text); border-color: var(--muted); }
.theme { font-family: system-ui, sans-serif; font-size: 1.05rem !important; }

.foot { margin-top: 56px; padding: 22px 0 36px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }

/* ---------------------------------------------------------------- controls */

.field {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--border); outline: none;
}
.field:focus { border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-soft); }
.field.small { width: 7.5em; padding: 6px 10px; text-align: right; font-variant-numeric: tabular-nums; }
button {
  padding: 9px 16px; border-radius: 10px; cursor: pointer;
  background: var(--card-2); border: 1px solid var(--border);
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--brass); color: var(--ink-on-brass); border-color: var(--brass); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--minus); margin-left: auto; }
button.link { background: none; border: 0; padding: 4px 6px; color: var(--brass); }
button.link:hover { text-decoration: underline; }
button.link.small { font-size: 1rem; vertical-align: middle; color: var(--muted); }
.primary-link { display: inline-block; margin-top: 12px; padding: 10px 18px; border-radius: 10px; background: var(--brass); color: var(--ink-on-brass); text-decoration: none; font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.card h2 { font-size: 1.45rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 0.92rem;
  transition: opacity .2s, transform .2s; z-index: 10; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--minus); color: #fff; }

/* ---------------------------------------------------------------- front page */

.front { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: start; padding-top: 48px; }
.hero h1 { font-size: clamp(3rem, 8vw, 5.2rem); line-height: 1; }
.tagline { margin-top: 10px; font: italic 1.6rem var(--display); color: var(--brass); }
.intro { margin-top: 18px; max-width: 34em; color: var(--muted); font-size: 1.08rem; }
.start { display: flex; flex-direction: column; gap: 6px; }
.start h2 { margin-bottom: 8px; }
.start label { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.people-rows { display: flex; flex-direction: column; gap: 8px; }
.start .link { align-self: flex-start; margin-top: 4px; }
.start .primary { margin-top: 16px; padding: 12px; font-size: 1.02rem; }
.recent { grid-column: 2; }
.steps { margin-top: 28px; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 14px; max-width: 30em; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 2.2em 1fr; align-items: baseline; }
.steps li::before { content: counter(step); font: 1.6rem var(--display); color: var(--brass); }
.recent ul { list-style: none; padding: 0; margin-top: 8px; }
.recent li + li { border-top: 1px solid var(--rule); }
.recent a { display: block; padding: 8px 0; text-decoration: none; }

/* ---------------------------------------------------------------- ledger page */

.ledger-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; padding: 28px 0 22px; }
.ledger-head h1 { font-size: clamp(2rem, 5vw, 2.9rem); line-height: 1.1; }
.meta { margin-top: 6px; color: var(--muted); }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.iam { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.iam .field { width: auto; padding: 8px 10px; }

.layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

/* entries: the ruled lines of the ledger */
.entries { list-style: none; padding: 0; }
.entries > li { border-top: 1px solid var(--rule); }
.entries > li:last-child { border-bottom: 1px solid var(--rule); }
.entry-btn, .entry.payment {
  width: 100%; display: grid; grid-template-columns: 4.2em 1fr auto; gap: 12px; align-items: baseline;
  padding: 12px 4px; background: none; border: 0; border-radius: 0; text-align: left;
}
.entry.payment { grid-template-columns: 4.2em 1fr auto auto; color: var(--muted); font-style: italic; }
.entry-btn:hover { background: var(--brass-soft); }
.when { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.what b { font-weight: 600; }
.what small { display: block; color: var(--muted); font-size: 0.85rem; }
.sum { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.empty { color: var(--muted); padding: 18px 0 6px; }

/* the expense form */
.expense-form { display: flex; flex-direction: column; gap: 12px; padding: 16px; margin: 4px 0 16px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); }
.entries .expense-form { margin: 10px 0; }
.expense-form .field { background: var(--card); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.grid2 .field { color: var(--text); font-size: 1rem; }
.amount-in { font-variant-numeric: tabular-nums; }
.split-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.segs { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg { border: 0; border-radius: 0; padding: 6px 12px; background: transparent; font-size: 0.88rem; }
.seg[aria-pressed="true"] { background: var(--brass); color: var(--ink-on-brass); }
.split-rows { display: flex; flex-direction: column; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-top: 1px solid var(--rule); cursor: pointer; }
.split-row .who { flex: 1; }
.split-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brass); }
.split-row .share { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.split-rows.equal .field.small { display: none; }
.split-rows.exact input[type="checkbox"], .split-rows.exact .share { display: none; }
.status { color: var(--minus); font-size: 0.88rem; min-height: 1em; }
.status:empty { display: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* settle up */
.settle .note { margin: 4px 0 10px; color: var(--muted); }
.transfers { list-style: none; padding: 0; }
.transfers li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--rule); flex-wrap: wrap; }
.transfers .who { flex: 1; min-width: 9em; }
.transfers button { padding: 6px 12px; font-size: 0.88rem; }
.lobelia { margin-top: 12px; font: italic 1.05rem var(--display); color: var(--brass); }
.all-square { text-align: center; padding: 14px 0 4px; }
.quiet-title { font: 1.5rem var(--display); margin-top: 6px; }
.all-square p:last-child { color: var(--muted); }

/* balances */
.balances ul { list-style: none; padding: 0; margin-top: 10px; }
.balances li { display: grid; grid-template-columns: minmax(4em, 7em) 1fr auto; align-items: center; gap: 10px; padding: 7px 0; }
.balances .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--rule); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 4px; }
.plus .bar span { background: var(--plus); }
.minus .bar span { background: var(--minus); }
.balances .sum { font-weight: 500; font-size: 0.92rem; }
.plus .sum { color: var(--plus); }
.minus .sum { color: var(--minus); }
.zero .sum { color: var(--muted); }

/* people and history: folded by default */
details summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: '▸'; margin-left: auto; color: var(--muted); transition: transform .15s; }
details[open] summary::after { transform: rotate(90deg); }
.count { color: var(--muted); font-size: 0.9rem; }
.people ul, .history ul { list-style: none; padding: 0; margin-top: 10px; }
.people li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-top: 1px solid var(--rule); }
.row-actions { display: flex; gap: 2px; font-size: 0.88rem; }
.inline { display: flex; gap: 8px; margin-top: 12px; }
.history li { display: grid; grid-template-columns: 8.5em 1fr; gap: 10px; padding: 6px 0; border-top: 1px solid var(--rule); font-size: 0.9rem; }

/* ---------------------------------------------------------------- phones */

@media (max-width: 820px) {
  .front { grid-template-columns: 1fr; gap: 28px; padding-top: 28px; }
  .recent { grid-column: auto; }
  /* one column: settle up first (that is what people open the link for), then the expenses */
  .layout { display: flex; flex-direction: column; }
  .col { display: contents; }
  .settle { order: 1; } .expenses { order: 2; } .balances { order: 3; } .people { order: 4; } .history { order: 5; }
  .ledger-head { align-items: flex-start; }
}
@media (max-width: 520px) {
  .card { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .entry-btn { grid-template-columns: 3.6em 1fr auto; gap: 8px; }
  .entry.payment { grid-template-columns: 3.6em 1fr auto; }
  .entry.payment .link { grid-column: 2 / -1; justify-self: start; padding-left: 0; }
  .history li { grid-template-columns: 1fr; gap: 0; }
}
