/* レイアウト: 1カラムのモバイル優先。精算結果だけを「レシート」として目立たせ、他は静かに。 */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #18202e;
  --muted: #5b6577;
  --line: #d9dee6;
  --accent: #2747d8;
  --accent-ink: #ffffff;
  --marker: #ffe066;
  --ok: #1d8a5a;
  --ok-bg: #e3f4ec;
  --danger: #c73a2e;
  --danger-bg: #fbe9e7;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-logo: "Dela Gothic One", "Hiragino Sans", system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --surface: #1a202a; --ink: #e7ebf2; --muted: #9aa4b5; --line: #2b3340;
    --accent: #7f97ff; --accent-ink: #0d1220; --marker: #5e4f0c; --ok: #47c48a; --ok-bg: #143326;
    --danger: #ff7b6e; --danger-bg: #3a1a17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 var(--font-body);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
}
.brand { font-family: var(--font-logo); font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: .02em; }
.topbar-note { font-size: 12px; color: var(--muted); }

.wrap {
  max-width: 640px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 8px 48px;
  display: grid; gap: 18px;
}

h1, h2, h3 { margin: 0; line-height: 1.35; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stack { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.section-label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .08em; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-block { width: 100%; min-height: 52px; font-size: 16px; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[disabled] { opacity: .5; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; }
.back { font-size: 14px; text-decoration: none; font-weight: 700; }

/* 入力 */
.field { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.yen-input { position: relative; }
.yen-input span { position: absolute; left: 14px; top: 50%; translate: 0 -50%; color: var(--muted); font-family: var(--font-num); }
.yen-input .input { padding-left: 32px; font-family: var(--font-num); font-size: 18px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 14px;
}
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; font-size: 14px;
}
.check:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* 数字のタイル */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 22px; font-weight: 600; }
.marker { background: linear-gradient(transparent 58%, var(--marker) 58%); padding: 0 2px; }

/* 精算レシート（このページで唯一の装飾） */
.receipt {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; padding: 18px 16px 22px;
}
.receipt::after {
  content: ""; position: absolute; left: -1px; right: -1px; bottom: -10px; height: 10px;
  background: radial-gradient(circle at 8px 0, transparent 7px, var(--surface) 7.5px) -8px 0 / 16px 10px repeat-x;
}
.receipt-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-bottom: 12px; border-bottom: 2px dashed var(--line); }
.receipt-title { font-family: var(--font-logo); font-size: 17px; letter-spacing: .04em; }
.progress { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.progress.done { background: var(--ok-bg); color: var(--ok); }
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx { padding: 12px 0; border-bottom: 1px dashed var(--line); display: grid; gap: 6px; }
.tx:last-child { border-bottom: 0; }
.tx-main { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.tx-names { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.tx-names .arrow { color: var(--muted); margin: 0 6px; font-weight: 400; }
.tx-amount { font-size: 18px; font-weight: 600; text-align: right; }
.tx-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tx.is-done .tx-names, .tx.is-done .tx-amount { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--ok); text-decoration-thickness: 2px; }
.done-btn { margin-left: auto; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted); }
.done-btn[aria-pressed="true"] { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.methods {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  min-height: 34px; padding: 4px 8px 4px 4px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); cursor: pointer; color: var(--ink);
}
.methods:hover { border-color: var(--muted); }
.methods[aria-expanded="true"] .caret { transform: rotate(180deg); }
.caret { font-size: 11px; color: var(--muted); transition: transform .15s; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--ink); }
.payee { background: var(--bg); border-radius: 10px; padding: 4px 12px; display: grid; }
.pm { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.pm:last-child { border-bottom: 0; }
.pm-label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.pm-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pm-value { font-size: 14px; overflow-wrap: anywhere; min-width: 0; }
.btn-paypay { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.receipt-foot { margin-top: 18px; }
.notice { border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.notice-ok { background: var(--ok-bg); color: var(--ok); font-weight: 700; }

/* 立て替え一覧 */
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.item:last-child { border-bottom: 0; }
.item:hover .item-title { color: var(--accent); }
.item-title { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.item-amount { font-size: 16px; font-weight: 600; text-align: right; }
.item-meta { grid-column: 1 / -1; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* 内訳表 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 700; }
.plus { color: var(--ok); }
.minus { color: var(--danger); }

.project { display: grid; gap: 2px; text-decoration: none; color: inherit; }
.project:hover h2 { color: var(--accent); }

.confirm-box { border: 1px solid var(--danger); background: var(--danger-bg); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.member-row { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; translate: -50% 0; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 14px; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
@media (max-width: 340px) {
  .stats { grid-template-columns: 1fr; }
}
.field .input { font-weight: 400; }

/* 割り方の切り替え */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg); border-radius: 12px; }
.seg { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; font-size: 14px; cursor: pointer; }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* 人ごとの金額指定 */
.adjust { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.adj-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px minmax(88px, auto); align-items: center; gap: 8px; }
.adj-name { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.adj-input .adj-amt.input { width: 100%; min-height: 40px; padding: 0 10px 0 28px; font-size: 16px; text-align: right; }
.adj-result { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
