:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #22302b;
  --muted: #68736d;
  --line: #e4dccb;
  --deep: #23493b;
  --on-deep: #f6f1e7;
  --accent: #cf5a34;
  --on-accent: #fff9f3;
  --plus: #2c7a58;
  --minus: #b3522c;
  --chip: #efe7d6;
  --radius: 18px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --card: #1d2521;
    --ink: #ece7da;
    --muted: #9aa59f;
    --line: #2d3832;
    --deep: #2a5a48;
    --on-deep: #f3eee2;
    --accent: #e0714b;
    --on-accent: #1a1210;
    --plus: #6cc79d;
    --minus: #eb9670;
    --chip: #28322d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .wordmark, .balance-figure {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.75rem; line-height: 1.15; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.loading { padding: 80px 16px; text-align: center; color: var(--muted); }

#app { max-width: 520px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

/* ---------- header + nav ---------- */
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 18px 2px 14px; }
.wordmark { font-weight: 700; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar { align-items: center; }
.topbar-side { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 60%; }
.whoami { color: var(--muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.btn.help { min-height: 34px; padding: 0 12px; flex: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs-inner { display: flex; width: 100%; max-width: 520px; }
.tab {
  flex: 1; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 0.8rem; font-weight: 600;
  padding: 10px 4px; border-radius: 12px; cursor: pointer; position: relative;
}
.tab[aria-current="page"] { color: var(--ink); background: var(--chip); }
.tab .dot { position: absolute; top: 6px; right: calc(50% - 26px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.hero { background: var(--deep); color: var(--on-deep); border: 0; padding: 20px; }
.hero .label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; }
.balance-figure { font-size: 3rem; font-weight: 700; line-height: 1.1; margin: 4px 0 6px; }
.balance-figure small { font-size: 1rem; font-weight: 600; opacity: 0.8; margin-left: 6px; }
.hero p { margin: 0; opacity: 0.88; font-size: 0.925rem; }
#board { scroll-margin-top: 12px; }
.hero .warn { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.14); opacity: 1; }

.actions { display: flex; gap: 10px; margin: 12px 0 4px; }
.actions > * { flex: 1; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-title { font-weight: 650; }
.when { font-size: 1.05rem; font-weight: 650; margin: 2px 0; }
.note { margin: 8px 0 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); font-size: 0.925rem; overflow-wrap: anywhere; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { display: inline-block; white-space: nowrap; font-size: 0.75rem; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.chip.booked { background: var(--deep); color: var(--on-deep); }
.chip.alert { background: var(--accent); color: var(--on-accent); }
.card.mine { border-color: color-mix(in srgb, var(--deep) 45%, var(--line)); }
.card.attention { border-color: var(--accent); }
.offer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 0; margin-top: 10px; border-top: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- buttons + forms ---------- */
button { font: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent;
  font-weight: 650; cursor: pointer; background: var(--chip); color: var(--ink); text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.deep { background: var(--deep); color: var(--on-deep); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 0.9rem; border-radius: 12px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 0.875rem; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { color: var(--muted); font-size: 0.875rem; margin: 8px 0 0; }
.estimate { margin: 14px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--chip); font-weight: 600; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--chip); border-radius: 14px; }
.segmented label { margin: 0; text-align: center; padding: 10px 6px; border-radius: 10px; cursor: pointer; font-size: 0.9rem; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.segmented label:has(input:checked) { background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.segmented label:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); }
.copybox { display: block; padding: 10px 12px; border-radius: 12px; background: var(--chip); font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; overflow-wrap: anywhere; user-select: all; }

/* ---------- balances + history ---------- */
.member { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.member .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--chip); position: relative; overflow: hidden; }
.bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.bar i.plus { left: 50%; background: var(--plus); }
.bar i.minus { right: 50%; background: var(--minus); }

.entry { padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry.dead .entry-line { text-decoration: line-through; color: var(--muted); }
.entry-line { font-weight: 600; }
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--muted); font-size: 0.875rem; margin-top: 2px; }

/* ---------- welcome ---------- */
.welcome { padding-top: 48px; }
.welcome .wordmark { display: block; margin-bottom: 28px; color: var(--deep); }
@media (prefers-color-scheme: dark) { .welcome .wordmark { color: var(--plus); } }
.steps { list-style: none; padding: 0; margin: 20px 0 24px; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0 0 12px 40px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -2px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--deep); color: var(--on-deep); font-weight: 700; font-size: 0.85rem; display: grid; place-items: center;
}

/* ---------- sheet + toast ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 520px; max-height: 92dvh;
  background: var(--bg); color: var(--ink); border-radius: 24px 24px 0 0; overflow: auto;
}
dialog.sheet::backdrop { background: rgba(10, 16, 13, 0.5); }
.sheet-body { padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet .btn.block { margin-top: 18px; }
@media (min-width: 560px) { dialog.sheet { margin: auto; border-radius: 24px; } }

#toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  max-width: min(92vw, 480px); padding: 12px 16px; border-radius: 14px; z-index: 2147483647;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.925rem; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.local-banner { background: var(--accent); color: var(--on-accent); font-size: 0.85rem; font-weight: 600; text-align: center; padding: 8px 16px; }

/* ---------- guide ---------- */
.guide h3 { font-size: 1.1rem; margin: 26px 0 10px; }
.guide-lead { font-size: 1.1rem; }
.guide .steps { margin: 0 0 4px; }
.guide .steps li { padding-bottom: 10px; }
.guide .hint { margin: 0; }
.guide-list { margin: 0; padding-left: 20px; }
.guide-list li { margin-bottom: 6px; }
.newhere { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.newhere .row-actions { margin-top: 0; }
