/* Scribe design system: ledger paper, ink, tabular numbers. */
:root {
  --paper: #F6F1E6;
  --paper-2: #FFFDF8;
  --paper-3: #EFE8DA;
  --ink: #1B1813;
  --ink-2: #4B463D;
  --muted: #6B6357;
  --line: #DBD3C2;
  --line-2: #ECE5D6;
  --red: #B8322A;
  --red-bg: #F7E2DF;
  --green: #1E6B48;
  --green-bg: #DDEFE4;
  --gold: #C9962E;
  --gold-bg: #F8EBCB;
  --focus: #2F6BD8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(27, 24, 19, .05), 0 10px 28px -14px rgba(27, 24, 19, .22);
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15130F;
    --paper-2: #1E1B16;
    --paper-3: #26231D;
    --ink: #EFE9DC;
    --ink-2: #C9C2B3;
    --muted: #A59C8E;
    --line: #35312A;
    --line-2: #2A2721;
    --red: #E8766D;
    --red-bg: #3A211F;
    --green: #4FB381;
    --green-bg: #1C3328;
    --gold: #E2B354;
    --gold-bg: #3A2F17;
    --focus: #6E9BF0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --paper: #15130F;
  --paper-2: #1E1B16;
  --paper-3: #26231D;
  --ink: #EFE9DC;
  --ink-2: #C9C2B3;
  --muted: #A59C8E;
  --line: #35312A;
  --line-2: #2A2721;
  --red: #E8766D;
  --red-bg: #3A211F;
  --green: #4FB381;
  --green-bg: #1C3328;
  --gold: #E2B354;
  --gold-bg: #3A2F17;
  --focus: #6E9BF0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  background-image: radial-gradient(1200px 600px at 50% -200px, color-mix(in srgb, var(--paper-2) 70%, transparent), transparent);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em; margin: 0; line-height: 1.15; }
h1 { font-size: clamp(2rem, 7vw, 3.2rem); font-variation-settings: "opsz" 144; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }
.wrap { width: 100%; max-width: 720px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hidden { display: none !important; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-in { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; letter-spacing: -0.02em; }
.brand svg { width: 22px; height: 22px; }
.top-title { color: var(--muted); font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title::before { content: "/"; margin-right: 10px; color: var(--line); }
.top-actions { display: flex; gap: 6px; }

main { flex: 1; padding-top: 20px; padding-bottom: 40px; display: flex; flex-direction: column; gap: 16px; }
.foot { padding: 20px 16px 36px; color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; justify-content: space-between; border-top: 1px solid var(--line-2); }
.foot a { text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* Buttons */
.btn {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ink);
  background: var(--ink); color: var(--paper);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.sec { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.btn.sec:hover { border-color: var(--ink-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--paper-3); }
.btn.danger { color: var(--red); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.icon { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.btn.icon svg { width: 18px; height: 18px; }
.btn.wide { width: 100%; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1B1813; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.end { justify-content: flex-end; }
.btn-row.between { justify-content: space-between; }

/* Inputs */
.inp, select.inp, textarea.inp {
  appearance: none; -webkit-appearance: none;
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper-2); color: var(--ink);
  font: inherit; font-size: 16px;
  outline: none;
}
.inp:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.inp::placeholder { color: var(--muted); }
.inp.num { text-align: right; }
.inp.big { font-size: 22px; min-height: 52px; }
textarea.inp { resize: vertical; line-height: 1.5; }
label.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field { display: flex; flex-direction: column; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }
.row > .btn, .row > .fit { flex: none; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > .field { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prefix { position: relative; }
.prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: var(--font-mono); pointer-events: none; }
.prefix > .inp { padding-left: 28px; }
.suffix { position: relative; }
.suffix > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: var(--font-mono); pointer-events: none; }
.suffix > .inp { padding-right: 32px; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
  touch-action: manipulation;
}
.chip[aria-pressed="true"], .chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .x { opacity: .6; font-size: 18px; line-height: 1; margin-left: 2px; }
.chip.add { border-style: dashed; color: var(--muted); }

/* Segmented control */
.seg { display: inline-flex; background: var(--paper-3); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 999px; cursor: pointer; min-height: 38px;
}
.seg button[aria-pressed="true"] { background: var(--paper-2); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Cards */
.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card.tint-gold { background: var(--gold-bg); border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); }
.card.tint-green { background: var(--green-bg); border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.card h2 { margin-bottom: 10px; }
.card .lead { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.head h2 { margin: 0; }

/* Page heading with editable name */
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.title-inp {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  font-family: var(--font-display); font-weight: 700; font-size: clamp(1.6rem, 6vw, 2.2rem); letter-spacing: -0.01em;
  padding: 2px 4px; margin-left: -4px; border-radius: 8px; width: 100%; min-width: 0; outline: none;
}
.title-inp:focus { background: var(--paper-2); box-shadow: 0 0 0 2px var(--line); }
.title-inp::placeholder { color: var(--muted); opacity: .7; }
.subline { color: var(--muted); font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Lists */
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.list > .item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { color: var(--muted); font-size: 13px; }
.item .amt { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 17px; white-space: nowrap; }
.item.link { cursor: pointer; }
.item.link:hover .t { text-decoration: underline; }

/* Standings */
.standing { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--paper-2); }
.standing.lead { background: var(--gold-bg); border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.standing .rank { width: 26px; text-align: center; font-family: var(--font-mono); color: var(--muted); font-weight: 600; }
.standing .name { flex: 1; font-weight: 600; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing .gap { color: var(--muted); font-family: var(--font-mono); font-size: 13px; }
.standing .total { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 26px; min-width: 56px; text-align: right; }
.standing .tally { display: flex; gap: 6px; }
.standing .tally .btn { width: 44px; padding: 0; font-size: 22px; font-weight: 500; }

/* Table */
.tbl-wrap { overflow: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.tbl { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.tbl th, .tbl td { padding: 0; border-bottom: 1px solid var(--line-2); text-align: right; vertical-align: middle; }
.tbl th { font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 8px 6px; white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.tbl th:first-child, .tbl td:first-child { position: sticky; left: 0; background: var(--paper-2); text-align: left; color: var(--muted); font-family: var(--font-mono); font-size: 13px; padding: 8px 10px 8px 0; z-index: 1; }
.tbl td .cell {
  appearance: none; -webkit-appearance: none; width: 72px; min-height: 44px; border: 0; background: transparent; color: var(--ink);
  font-family: var(--font-mono); font-size: 16px; text-align: right; padding: 0 8px; outline: none; border-radius: 6px;
}
.tbl td .cell:focus { background: var(--paper-3); box-shadow: inset 0 0 0 2px var(--focus); }
.tbl tfoot td { border-top: 2px solid var(--ink); border-bottom: 0; font-family: var(--font-mono); font-weight: 600; font-size: 17px; padding: 10px 8px; }
.tbl tfoot td:first-child { font-family: var(--font-body); color: var(--ink); font-weight: 600; }
.tbl tr.open td { background: color-mix(in srgb, var(--gold-bg) 55%, transparent); }
.tbl td.del { width: 36px; }
.tbl td.del button { appearance: none; border: 0; background: transparent; color: var(--muted); width: 36px; height: 44px; cursor: pointer; font-size: 18px; }
.tbl td.del button:hover { color: var(--red); }

/* Big result */
.result { text-align: center; padding: 28px 16px; }
.result .big { font-family: var(--font-display); font-size: clamp(2.6rem, 14vw, 5rem); font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.result .sub { color: var(--muted); margin-top: 8px; }
.result .mono { font-family: var(--font-mono); }
.dice { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 6px 0 12px; }
.die { width: 64px; height: 64px; border-radius: 14px; background: var(--paper-2); border: 2px solid var(--ink); display: grid; place-items: center; font-family: var(--font-mono); font-size: 28px; font-weight: 600; box-shadow: var(--shadow); }
.die.d6 { font-size: 46px; font-family: "Apple Color Emoji", "Segoe UI Symbol", var(--font-mono); }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
.pop { animation: pop .35s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes flip { 0% { transform: rotateX(0); } 100% { transform: rotateX(1800deg); } }
.coin { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 14px; display: grid; place-items: center; background: var(--gold); color: #1B1813; font-family: var(--font-display); font-weight: 700; font-size: 44px; border: 4px solid color-mix(in srgb, var(--gold) 60%, var(--ink)); box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--gold) 85%, white), var(--shadow); }
.coin.spin { animation: flip .9s cubic-bezier(.3,.7,.3,1) both; }
.order { counter-reset: ord; display: flex; flex-direction: column; gap: 6px; }
.order .o { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-sm); font-weight: 600; font-size: 17px; }
.order .o::before { counter-increment: ord; content: counter(ord); font-family: var(--font-mono); color: var(--muted); font-weight: 600; width: 22px; }
.order .o:first-child { background: var(--gold-bg); border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }

/* Settlement lines */
.pay { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.pay:last-child { border-bottom: 0; }
.pay .who { flex: 1; font-size: 16px; min-width: 0; }
.pay .who b { font-weight: 600; }
.pay .arrow { color: var(--muted); margin: 0 6px; }
.pay .amt { font-family: var(--font-mono); font-weight: 600; font-size: 18px; white-space: nowrap; }
.bal { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.bal:last-child { border-bottom: 0; }
.bal .name { flex: 1; font-weight: 600; }
.bal .tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.bal .tag.pos { background: var(--green-bg); color: var(--green); }
.bal .tag.neg { background: var(--red-bg); color: var(--red); }
.bal .tag.zero { background: var(--paper-3); color: var(--muted); }
.bal .amt { font-family: var(--font-mono); font-weight: 600; min-width: 80px; text-align: right; }

/* Stat */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--paper-3); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-family: var(--font-mono); font-weight: 600; font-size: 22px; }
.stat.hi { background: var(--ink); color: var(--paper); }
.stat.hi .k { color: color-mix(in srgb, var(--paper) 70%, transparent); }

/* Banner */
.banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--gold-bg); border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--line)); }
.banner .big { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; }

/* Empty state */
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .glyph { font-size: 34px; margin-bottom: 6px; }

/* Dialog / sheet */
dialog.sheet { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100dvh; width: 100%; margin: 0; }
dialog.sheet::backdrop { background: rgba(10, 8, 5, .5); backdrop-filter: blur(2px); }
dialog.sheet[open] { position: fixed; inset: auto 0 0 0; }
.sheet-in { background: var(--paper); color: var(--ink); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow: auto; border: 1px solid var(--line); border-bottom: 0; display: flex; flex-direction: column; gap: 14px; }
.sheet-in::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: -6px auto 0; }
.sheet-in h2 { font-size: 1.3rem; }
@media (min-width: 640px) {
  dialog.sheet[open] { inset: 0; margin: auto; width: min(480px, 92vw); }
  .sheet-in { border-radius: 18px; border-bottom: 1px solid var(--line); max-height: 82vh; }
  .sheet-in::before { display: none; }
}

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; opacity: 0; transition: opacity .18s ease, transform .18s ease; z-index: 50; pointer-events: none; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Home */
.hero { padding: 28px 0 8px; }
.hero .quote { font-family: var(--font-display); font-style: italic; font-weight: 500; font-size: clamp(1.25rem, 4.5vw, 1.6rem); color: var(--ink-2); margin-top: 14px; line-height: 1.3; max-width: 34ch; }
.hero .quote b { font-style: normal; font-weight: 700; color: var(--ink); }
.tools { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .tools { grid-template-columns: 1fr 1fr; } }
.tool { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: var(--radius); background: var(--paper-2); border: 1px solid var(--line); text-decoration: none; box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease; }
.tool:hover { transform: translateY(-2px); border-color: var(--ink-2); }
.tool .ic { width: 44px; height: 44px; border-radius: 12px; background: var(--paper-3); display: grid; place-items: center; flex: none; }
.tool .ic svg { width: 24px; height: 24px; }
.tool h2 { font-size: 1.2rem; margin: 0 0 2px; }
.tool p { color: var(--muted); font-size: 14px; }
.tool .say { margin-top: 8px; font-size: 13px; color: var(--ink-2); font-style: italic; font-family: var(--font-display); }

/* Account */
.acct .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--paper); font-weight: 700; font-size: 13px; display: grid; place-items: center; font-family: var(--font-body); }
.acct.err .avatar { box-shadow: 0 0 0 2px var(--red); }
.note { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.note.ok { background: var(--green-bg); color: var(--green); }
.note.err { background: var(--red-bg); color: var(--red); }
.note.info { background: var(--paper-3); color: var(--ink-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.dot.idle { background: var(--green); }
.dot.syncing { background: var(--gold); }
.dot.error { background: var(--red); }

/* Notes */
.note-body { min-height: 50vh; font-size: 17px; }
.note-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }

@media (max-width: 400px) {
  .standing .total { font-size: 22px; }
  .btn { padding: 0 13px; }
}
