@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #1d2a22;
  --muted: #6b7268;
  --line: #e6dfd0;
  --pine: #1f4a35;
  --pine-soft: #e3ece5;
  --berry: #a32638;
  --berry-soft: #f6e1e3;
  --gold: #c39a3e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 42, 34, .06), 0 4px 16px rgba(29, 42, 34, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
button, a, .person, .item, .toggle { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
body {
  font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; margin: 0; letter-spacing: -.01em; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 0 8px;
  position: sticky; top: 0; z-index: 4; background: var(--bg);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 26px; color: var(--pine); }
.year-select {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 28px 6px 12px; font-size: 16px; font-weight: 600; color: var(--pine); min-height: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--pine) 50%), linear-gradient(135deg, var(--pine) 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 8px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.me a { color: var(--muted); padding: 10px 4px; white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pine); color: #fff; font-weight: 600; font-size: 13px;
}

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.summary { margin: 12px 0 20px; }
.summary .big { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.summary .spent { font-family: Fraunces, serif; font-size: 40px; font-weight: 700; color: var(--pine); line-height: 1; }
.summary .of { color: var(--muted); }
.summary .remaining { margin-left: auto; font-weight: 600; }
.remaining.over { color: var(--berry); }
.split { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.split b { color: var(--ink); font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.footnote { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

.bar { height: 8px; border-radius: 999px; background: var(--pine-soft); overflow: hidden; margin-top: 14px; }
.bar > span { display: block; height: 100%; background: var(--pine); border-radius: inherit; transition: width .3s; }
.bar.over > span { background: var(--berry); }
.bar.thin { height: 5px; margin-top: 8px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 10px; }
.section-head h2 { font-size: 18px; }

/* people list */
.people { display: grid; gap: 8px; }
.person {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  transition: border-color .15s, transform .1s;
}
.person:hover { border-color: #cfc6b2; }
.person:active { transform: scale(.995); }
.person .row { display: flex; align-items: baseline; gap: 4px 8px; flex-wrap: wrap; }
.person .name { font-weight: 600; }
.person .meta { margin-left: auto; font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.person .meta b { color: var(--ink); font-weight: 600; }
.person .meta b.over { color: var(--berry); }
.person.surprise { background: repeating-linear-gradient(135deg, #fbf6ec 0 10px, #f7efdf 10px 20px); cursor: default; }
.person.surprise .meta { color: var(--gold); font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--pine-soft); color: var(--pine);
}
.badge.berry { background: var(--berry-soft); color: var(--berry); }
.badge.gold { background: #f5ecd6; color: #8a6a1f; }
.badge.ghost { background: #efe9dc; color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 16px; min-height: 44px; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: #cfc6b2; }
.btn.primary { background: var(--pine); border-color: var(--pine); color: #fff; }
.btn.primary:hover { background: #183d2b; }
.btn.danger { color: var(--berry); }
.btn.link { border: 0; background: none; padding: 10px 6px; min-height: 44px; color: var(--muted); font-weight: 500; }
.btn.block { width: 100%; padding: 12px; }
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 5;
  padding: 14px 20px; font-size: 15px; box-shadow: 0 6px 20px rgba(31, 74, 53, .35);
}

/* person page */
.back { margin: 14px 0 4px; }
.p-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.p-head h1 { font-size: 30px; color: var(--pine); }
.notice {
  margin: 12px 0; padding: 10px 14px; border-radius: 12px; font-size: 13.5px;
  background: #f5ecd6; color: #6e5418;
}
.items { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-top: 12px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); padding: 12px 14px; cursor: pointer; }
.item:hover { background: #fffaf0; }
.item .desc { font-weight: 500; }
.item .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.item .cost { margin-left: auto; font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty h2 { color: var(--pine); margin-bottom: 6px; }

/* dialog */
dialog {
  border: 0; padding: 0; width: min(520px, 100%); max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 20px; background: var(--card); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(20, 30, 24, .45); backdrop-filter: blur(2px); }
@media (max-width: 560px) {
  dialog { margin: auto 0 0; border-radius: 20px 20px 0 0; max-width: 100%; }
}
.sheet { padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 22px; margin-bottom: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 11px 12px;
  font-size: 16px; /* prevents iOS zoom */
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--pine); outline-offset: -1px; border-color: transparent; }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 26px; }
.toggles { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; min-height: 44px; font-weight: 500;
}
.toggle input { accent-color: var(--pine); width: 16px; height: 16px; margin: 0; }
.sheet-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.sheet-actions .spacer { flex: 1; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: -6px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e3ece5, transparent), var(--bg);
}
.login .card { max-width: 380px; width: 100%; text-align: center; padding: 34px 26px; }
.login h1 { font-size: 30px; color: var(--pine); margin: 10px 0 6px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.gbtn {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 11px 20px; font-weight: 600;
}
.gbtn:hover { border-color: #cfc6b2; }
.error { color: var(--berry); font-size: 13.5px; margin-top: 16px; }
.ornament { font-size: 40px; }

/* small phones */
@media (max-width: 380px) {
  .brand h1 { font-size: 22px; }
  .summary .spent { font-size: 34px; }
  .person .meta { margin-left: 0; width: 100%; }
}
.item { min-height: 56px; }
.sheet-actions .btn { flex: 0 0 auto; }
@media (max-width: 560px) {
  .sheet-actions { position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
}
