/* splitzy (bill splitter) — 더치페이 정산 / 디자인 시스템
 * Mood: 밝고 사교적 (여행/모임 감성), 뉴트럴 페이퍼 + 프렌들리 코랄 액센트, 큰 금액 숫자.
 */

:root {
  /* base — native LIGHT */
  --bg: #f7f4f1;
  --surface: #ffffff;
  --surface-2: #f1ece6;
  --ink: #221a16;
  --muted: #7c6f66;
  --line: #e6ded5;
  --accent: #ef5b4c;          /* coral / tangerine — friendly */
  --accent-strong: #c93f31;
  --accent-soft: #fde4e0;
  --pos: #2f9e5e;             /* 받을 (gets) — green */
  --neg: #d05a3a;             /* 보낼 (owes) — warm red */
  --gold: #e0a52a;
  --shadow-ink: 30, 22, 18;

  --r-chip: 9px;
  --r-card: 18px;
  --r-modal: 22px;

  --sh-card: 0 1px 2px rgba(var(--shadow-ink),.05), 0 6px 20px rgba(var(--shadow-ink),.06);
  --sh-modal: 0 14px 44px rgba(var(--shadow-ink),.24);

  --font-display: 'Fraunces', 'Pretendard', Georgia, serif;
  --font-body: 'Pretendard', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --maxw: 760px;
}

/* ===== 3-way theme (Light/Dark/System) — base :root above = native LIGHT. ===== */
:root[data-theme="dark"] {
  --bg: #171210;
  --surface: #241d19;
  --surface-2: #15110e;
  --ink: #f1e8e0;
  --muted: #a99e94;
  --line: rgba(255, 240, 230, 0.12);
  --accent: #ff6f5e;
  --accent-strong: #ff8a7c;
  --accent-soft: #3a201b;
  --pos: #4cc77f;
  --neg: #ff8a66;
  --gold: #f0b53f;
  --shadow-ink: 0, 0, 0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1100px 460px at 100% -12%, var(--accent-soft) 0%, transparent 58%),
    radial-gradient(820px 400px at -12% 0%, #fbf1e4 0%, transparent 55%),
    var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(1100px 460px at 100% -12%, rgba(255,111,94,.10) 0%, transparent 58%),
    radial-gradient(820px 400px at -12% 0%, rgba(240,181,63,.06) 0%, transparent 55%),
    var(--bg);
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px 72px;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 24px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-chip); padding: 8px 10px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 14px; min-height: 40px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn .icon-label { font-size: 13px; }
.icon-btn.close { padding: 6px 9px; }

/* ---------- summary ---------- */
.summary {
  display: grid; grid-template-columns: 1.1fr 1.2fr 1fr; gap: 10px;
  margin: 18px 0;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 14px 12px; text-align: center; box-shadow: var(--sh-card);
  display: flex; flex-direction: column; justify-content: center;
}
.stat.cur-stat { text-align: left; padding: 10px 12px; }
.stat-num { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1.05; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.cur-select {
  font: inherit; font-weight: 700; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
  padding: 7px 8px; margin-top: 3px; width: 100%; cursor: pointer;
}
.cur-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- panel ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--sh-card);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-title { font-family: var(--font-display); font-weight: 600; font-size: 19px; margin: 0; }
.hint { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--r-chip); padding: 10px 16px; min-height: 44px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.xs { min-height: 34px; padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.btn.danger:hover { background: var(--accent-soft); }

/* ---------- member list ---------- */
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.member-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 8px 6px 14px; font-weight: 600; font-size: 14px;
}
.member-chip .avatar {
  width: 24px; height: 24px; border-radius: 999px; flex: none;
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700;
}
.member-chip .rm {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 999px;
}
.member-chip .rm:hover { color: var(--neg); background: var(--accent-soft); }

/* inline add row */
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row .input { flex: 1; }

/* ---------- expense form ---------- */
.expense-form {
  display: grid; grid-template-columns: 1fr 130px; gap: 10px;
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: var(--r-card); padding: 14px; margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field.grow { grid-column: 1; }
.field.amt { grid-column: 2; }
.field-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.input {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select.input { cursor: pointer; }
.part-tools { display: flex; gap: 6px; }
.part-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.part-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; user-select: none; transition: all .12s ease;
}
.part-chip .dot { width: 8px; height: 8px; border-radius: 999px; background: currentColor; opacity: .7; }
.part-chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.form-actions { display: flex; justify-content: flex-end; }

/* ---------- expense list ---------- */
.expense-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.expense-row {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.expense-row .ex-head { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.expense-row .ex-memo { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-row .ex-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.expense-row .ex-amount { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.expense-row .ex-rm {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 5px 9px; color: var(--muted);
}
.expense-row .ex-rm:hover { color: var(--neg); background: var(--accent-soft); }
.tag { background: var(--surface-2); border-radius: 999px; padding: 1px 8px; font-weight: 600; font-size: 11px; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 26px 12px; }
.empty-emoji { font-size: 40px; }
.empty-title { font-weight: 700; font-size: 16px; margin: 8px 0 2px; font-family: var(--font-display); }
.empty-sub { color: var(--muted); margin: 0; font-size: 13px; }

/* ---------- settlement ---------- */
.settle-panel { background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%); }
.settle-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.settle-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px;
}
.settle-card .who { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.settle-card .avatar { width: 30px; height: 30px; border-radius: 999px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.settle-card .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settle-card .arrow { color: var(--accent); font-weight: 700; }
.settle-card .amount { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--accent-strong); white-space: nowrap; }
.settle-approx { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* balance table */
.balance-wrap { margin-top: 18px; overflow-x: auto; }
.balance-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; margin: 0 0 8px; }
.balance-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 420px; }
.balance-table th, .balance-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.balance-table th { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: none; }
.balance-table td.num, .balance-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.balance-table tbody td { font-weight: 600; }
.balance-table .net-pos { color: var(--pos); }
.balance-table .net-neg { color: var(--neg); }
.balance-table .net-zero { color: var(--muted); }
.balance-table .mname { display: inline-flex; align-items: center; gap: 7px; }
.balance-table .mname .avatar { width: 20px; height: 20px; font-size: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; z-index: 80; box-shadow: var(--sh-modal);
  opacity: 0; transition: opacity .2s ease, transform .2s ease; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- foot ---------- */
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 14, 10, .46);
  display: grid; place-items: end center;
  padding: 0; animation: fade .2s ease;
}
@media (min-width: 560px) { .modal-backdrop { place-items: center; padding: 24px; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 460px; background: var(--surface);
  border-radius: var(--r-modal) var(--r-modal) 0 0; box-shadow: var(--sh-modal);
  max-height: 92vh; overflow: auto; animation: slideup .24s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 560px) { .modal { border-radius: var(--r-modal); } }
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 19px; }
.modal-body { padding: 18px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }

.share-note, .data-note { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.6; }
.share-warn { color: var(--gold); font-size: 12px; margin: 8px 0 0; }
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.data-actions .btn { flex: 1; min-width: 130px; }
.rule { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.help-list { margin: 0 0 14px; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.help-list li { font-size: 14px; line-height: 1.6; }
.help-foot { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- responsive ---------- */
@media (min-width: 720px) {
  .icon-btn .icon-label { display: inline; }
}
@media (max-width: 420px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .stat.cur-stat { grid-column: 1 / -1; }
  .stat-num { font-size: 22px; }
  .expense-form { grid-template-columns: 1fr; }
  .field.grow, .field.amt { grid-column: 1; }
  .icon-btn .icon-label { display: none; }
  .expense-row { grid-template-columns: 1fr auto; }
  .expense-row .ex-rm { grid-column: 2; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* i18n language switcher theming */
.topbar .i18n-switch {
  --i18n-switch-bg: var(--surface);
  --i18n-switch-border: var(--line);
  --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: var(--accent-soft);
  --i18n-switch-active-fg: var(--accent-strong);
  --i18n-switch-menu-bg: var(--surface);
  --i18n-switch-menu-border: var(--line);
  --i18n-switch-shadow: var(--sh-modal);
}
