:root {
  --bg: #f6f1e9; --card: #fffdf9; --ink: #1f2a37; --sub: #857d71; --line: #e9e1d4;
  --brand: #ef6a4c; --brand-soft: #fde7df; --brand-ink: #b8432a;
  --get: #0e8a78; --get-soft: #dcf3ee; --give: #c4432f; --give-soft: #fbe3dd;
  --av-l: 88%; --av-t: 30%;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 6px 20px rgba(60, 40, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f; --card: #211e18; --ink: #f1ece3; --sub: #a1988a; --line: #36312a;
    --brand: #ff7f60; --brand-soft: #3d241c; --brand-ink: #ffb09c;
    --get: #4fd1b8; --get-soft: #163530; --give: #ff8a74; --give-soft: #3d221c;
    --av-l: 28%; --av-t: 85%;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "Pretendard Variable", Pretendard, system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased; word-break: keep-all;
}
main { max-width: 560px; margin: 0 auto; padding: 20px 16px 40px; }
b { font-weight: 700; }
.num, .amt, .total { font-variant-numeric: tabular-nums; }
.sub { color: var(--sub); font-size: 13px; }
.label { font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--sub); text-transform: uppercase; }

/* 헤더 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.logo img { display: block; border-radius: 9px; }
.wordmark { font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
em { font-style: normal; color: var(--brand); }
.tagline { margin: 6px 0 20px; color: var(--sub); font-size: 14px; }
select {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
  max-width: 55%; padding: 7px 32px 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card) no-repeat right 12px center / 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23857d71' stroke-width='1.6'/%3E%3C/svg%3E");
  appearance: none; cursor: pointer;
}
.loading { color: var(--sub); text-align: center; padding: 48px 0; }
.top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-actions select { max-width: 180px; }
.icon-btn {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--sub); cursor: pointer;
}
.icon-btn:hover { color: var(--brand); border-color: var(--brand); }

/* 가이드 */
dialog {
  width: min(560px, 100%); max-height: 88vh; padding: 0; border: 0; border-radius: 20px;
  background: var(--bg); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 16, 10, .45); }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; max-width: 100%; border-radius: 20px 20px 0 0; max-height: 90vh; }
}
dialog[open] { display: flex; flex-direction: column; }
.g-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.g-body { overflow-y: auto; padding: 4px 20px 28px; }
.g-lead { margin: 16px 0 4px; }
.g-body h3 { font-size: 16px; font-weight: 800; margin: 24px 0 8px; display: flex; align-items: center; gap: 8px; }
.g-body h3 .step {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 12px;
}
.g-body .sub { margin: 0 0 8px; }
code { font: inherit; font-size: .92em; font-weight: 600; background: var(--brand-soft); color: var(--brand-ink); padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.g-table { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.g-table table { border-collapse: collapse; font-size: 13px; white-space: nowrap; width: 100%; }
.g-table th { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; text-align: left; }
.g-table th, .g-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.g-table tr:last-child td { border-bottom: 0; }
.g-cols { margin: 12px 0 0; display: grid; gap: 8px; }
.g-cols div { display: grid; grid-template-columns: 72px 1fr; gap: 10px; font-size: 14px; }
.g-cols dt { font-weight: 700; }
.g-cols dd { margin: 0; color: var(--sub); }
.g-rules { display: grid; gap: 8px; }
.g-rules li {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
.g-out { font-weight: 600; }
.g-out .sub { display: block; font-weight: 400; margin: 0; }
.g-empty { display: inline-block; font-size: 12px; font-weight: 600; color: var(--sub); border: 1px dashed var(--sub); border-radius: 6px; padding: 0 6px; }
.g-tips { display: grid; gap: 6px; font-size: 14px; }
.g-tips li { position: relative; padding-left: 16px; }
.g-tips li::before { content: ""; position: absolute; left: 2px; top: .6em; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }

/* 보딩패스 */
.pass { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.pass-main { padding: 18px 20px 16px; }
.trip-name { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 16px; }
.route { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.route .end { text-align: right; }
.route .big { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.route .line { position: relative; height: 20px; }
.route .line::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px dashed var(--line); }
.route .line svg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--card); padding: 0 6px; box-sizing: content-box; color: var(--brand); }
.meta { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.meta span { font-size: 13px; font-weight: 600; background: var(--bg); border-radius: 999px; padding: 3px 10px; }
.pass-stub { position: relative; padding: 16px 20px 18px; background: var(--brand-soft); border-top: 2px dashed var(--line); display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.pass-stub::before, .pass-stub::after { content: ""; position: absolute; top: -11px; width: 20px; height: 20px; border-radius: 50%; background: var(--bg); }
.pass-stub::before { left: -11px; } .pass-stub::after { right: -11px; }
.total { font-size: 32px; font-weight: 800; letter-spacing: -.03em; color: var(--brand-ink); line-height: 1.1; }
.total small { font-size: 18px; margin-left: 2px; }
.stub-side { text-align: right; }

/* 섹션 */
section { margin-top: 28px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
h2 .step { color: var(--brand); margin-right: 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
ul, ol { list-style: none; margin: 0; padding: 0; }
.btn {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--brand-ink); background: var(--brand-soft);
  border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.btn:active { transform: scale(.97); }

.av {
  display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%;
  font-size: 14px; font-weight: 700;
  background: hsl(var(--h) 70% var(--av-l)); color: hsl(var(--h) 50% var(--av-t));
}

/* 송금 */
.tr { display: flex; align-items: center; gap: 8px; padding: 14px 16px; }
.tr + .tr, .person + .person { border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.tr .arrow { color: var(--sub); flex: none; }
.tr .amt { margin-left: auto; font-size: 17px; white-space: nowrap; }
.empty { padding: 20px 16px; text-align: center; color: var(--sub); }

/* 사람별 */
.person { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; }
.pname { font-weight: 700; }
.nw { white-space: nowrap; }
.bar { height: 4px; border-radius: 4px; background: var(--bg); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--brand); opacity: .7; }
.chip { text-align: right; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 5px 9px; white-space: nowrap; }
.chip b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.chip.get { background: var(--get-soft); color: var(--get); }
.chip.give { background: var(--give-soft); color: var(--give); }
.chip.even { background: var(--bg); color: var(--sub); }

/* 여정 타임라인 */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 14px; bottom: 14px; border-left: 2px dashed var(--line); }
.day { position: relative; margin-bottom: 10px; }
.day::before {
  content: ""; position: absolute; left: -22px; top: 17px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--brand); box-sizing: border-box;
}
.day details { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.day summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; padding: 13px 16px; }
.day summary::-webkit-details-marker { display: none; }
.day-no { font-weight: 800; color: var(--brand); letter-spacing: .02em; }
.day summary .amt { margin-left: auto; font-weight: 700; }
.day summary::after { content: ""; width: 8px; height: 8px; border: solid var(--sub); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); transition: transform .15s; align-self: center; }
.day details[open] summary::after { transform: translateY(2px) rotate(-135deg); }
.items { padding: 0 16px 6px; border-top: 1px solid var(--line); }
.it { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; }
.it + .it { border-top: 1px dashed var(--line); }
.iname { font-weight: 600; }
.it .amt { white-space: nowrap; font-weight: 600; }
.it .orig { display: block; text-align: right; font-weight: 400; }

.warn { background: #fff4d6; color: #5c4400; border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a3117; color: #f0dca0; } }

footer { margin-top: 40px; text-align: center; color: var(--sub); font-size: 12px; }
footer p { margin: 2px 0; }
