/* Layout: スマホ縦1列（共有→あなた→メンバー→入力→一覧→精算）。広い画面では右に精算レシートを固定 */
:root {
  --bg: #e9ede6;
  --surface: #ffffff;
  --fg: #23271f;
  --muted: #69705f;
  --line: #d3d9cc;
  --accent: #d9531e;
  --accent-soft: #fbe3d6;
  --good: #2f7a4b;
  --good-soft: #dcefe1;
  --chip-off: #f1f3ee;
  --font-display: "Dela Gothic One", "Hiragino Sans", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1c18; --surface: #24271f; --fg: #eceee6; --muted: #a2a897; --line: #3a3e33;
    --accent: #f07a45; --accent-soft: #4a2a1c; --good: #7fcf9b; --good-soft: #1f3a29; --chip-off: #2e3229;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
.wrap { max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(30px, 6vw, 44px); line-height: 1.1; margin: 0; letter-spacing: .02em; }
h1 .home { color: inherit; text-decoration: none; }
h1 span { color: var(--accent); }
.event { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 240px; max-width: 420px; }
.cap { font-size: 12px; color: var(--muted); letter-spacing: .08em; font-weight: 700; }
input, select, button { font: inherit; color: inherit; }
input[type=text], input[type=number], select {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 8px;
  padding: 10px 12px; min-width: 0; width: 100%; font-size: 16px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.status { border-radius: 10px; padding: 9px 12px; font-size: 13px; background: var(--chip-off); color: var(--muted); }
.status.warn { background: var(--accent-soft); color: var(--fg); }
.status.live { background: var(--good-soft); color: var(--good); font-weight: 700; }
.grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }
.col { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
h2 { font-family: var(--font-display); font-weight: 400; font-size: 20px; margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
h2 small { font-family: var(--font-body); font-size: 13px; color: var(--muted); font-weight: 500; }
.btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn.danger { color: var(--accent); }
.btn.armed { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* トップ */
.landing { display: flex; flex-direction: column; gap: 28px; max-width: 560px; }
.recent { display: flex; flex-direction: column; gap: 8px; }
.recent a { display: block; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; color: inherit; text-decoration: none; font-weight: 700; }
.recent a:hover { border-color: var(--fg); }

/* 共有 */
.share { background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.share-text { display: flex; flex-direction: column; gap: 4px; flex: 1 1 260px; min-width: 0; }
.share-text input { font-family: var(--font-num); font-size: 13px; background: var(--bg); }
.share-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.share .toast { flex-basis: 100%; }

/* あなた */
.me-card { background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.me-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.me-row select { flex: 1 1 160px; width: auto; }
.me-status { font-size: 15px; font-weight: 700; }
.me-status.soft { font-weight: 500; color: var(--muted); }
.me-status .amt { font-family: var(--font-num); color: var(--accent); }
.me-status.ok { color: var(--good); }

/* メンバー */
.members { display: flex; flex-wrap: wrap; gap: 8px; }
.member { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 12px; font-weight: 700; }
.member.me { border-color: var(--accent); }
.member .you { font-size: 11px; color: var(--accent); font-weight: 700; }
.icon-x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1; padding: 6px 8px; border-radius: 999px; white-space: nowrap; }
.icon-x:hover, .icon-x.armed { color: #fff; background: var(--accent); }
.add-member { display: flex; gap: 8px; }
.add-member input { max-width: 260px; }

/* フォーム */
.form { background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.form.editing { border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.amount { position: relative; }
.amount::before { content: "¥"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: var(--font-num); }
.amount input { padding-left: 28px; font-family: var(--font-num); text-align: right; font-variant-numeric: tabular-nums; }
.targets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1.5px solid transparent; border-radius: 999px; padding: 4px 12px; font-size: 14px; cursor: pointer; background: var(--good-soft); color: var(--good); font-weight: 700; }
.chip[aria-pressed="false"] { background: var(--chip-off); color: var(--muted); text-decoration: line-through; font-weight: 500; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* 一覧 */
.items { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; }
.item .nm { font-weight: 700; overflow-wrap: anywhere; }
.item .am { font-family: var(--font-num); font-weight: 600; font-size: 16px; text-align: right; }
.item .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .acts { display: flex; gap: 6px; justify-content: flex-end; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 0 8px; margin-left: 6px; vertical-align: 1px; }
.empty { color: var(--muted); font-size: 14px; padding: 16px; border: 1.5px dashed var(--line); border-radius: 12px; text-align: center; }

/* レシート */
.receipt-wrap { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); }
@media (max-width: 820px) { .receipt-wrap { position: static; } }
.receipt {
  background: var(--surface); border-radius: 4px; padding: 22px 20px 32px;
  box-shadow: 0 1px 0 var(--line), 0 10px 30px -18px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: 16px;
  -webkit-mask: radial-gradient(circle 6px at 50% 100%, transparent 5.5px, #000 6px) 0 0 / 16px 100% repeat-x;
          mask: radial-gradient(circle 6px at 50% 100%, transparent 5.5px, #000 6px) 0 0 / 16px 100% repeat-x;
}
.r-head { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.r-head .t { font-family: var(--font-display); font-size: 18px; }
.r-head .d { font-size: 12px; color: var(--muted); }
.dash { border: 0; border-top: 2px dashed var(--line); margin: 0; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.big { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big div { display: flex; flex-direction: column; gap: 2px; }
.big .v { font-family: var(--font-num); font-size: 26px; font-weight: 600; line-height: 1.15; }
.big .v.accent { color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .06em; text-align: right; padding: 0 0 6px; }
th:first-child, td:first-child { text-align: left; }
td { padding: 5px 0; text-align: right; border-top: 1px solid var(--line); }
tr.me td:first-child { color: var(--accent); font-weight: 700; }
td.pos { color: var(--good); }
td.neg { color: var(--accent); }
.tbl { overflow-x: auto; }
.transfers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.transfers li { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) auto; gap: 8px; align-items: center; background: var(--bg); border-radius: 8px; padding: 9px 12px; border: 1.5px solid transparent; }
.transfers li.me { border-color: var(--accent); }
.transfers .who { font-weight: 700; overflow-wrap: anywhere; }
.transfers .arrow { color: var(--muted); font-size: 13px; }
.transfers .amt { font-family: var(--font-num); font-weight: 600; color: var(--accent); font-size: 16px; }
.transfers li.msg { display: block; text-align: center; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin: 0; }
.r-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.units { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.units button { border: 0; background: transparent; padding: 6px 11px; font-size: 13px; cursor: pointer; font-family: var(--font-num); }
.units button[aria-pressed="true"] { background: var(--fg); color: var(--surface); }
.toast { font-size: 13px; color: var(--good); font-weight: 700; min-height: 1.2em; }
.toast.err { color: var(--accent); }
#copyFallback { width: 100%; min-height: 140px; font-family: var(--font-num); font-size: 12px; background: var(--bg); color: var(--fg); border: 1.5px solid var(--line); border-radius: 8px; padding: 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
.share .toast:empty { display: none; }

/* 最近開いた割り勘・削除 */
.recent-row { display: flex; align-items: center; gap: 8px; }
.recent-row a { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.danger-zone { margin-top: 12px; padding-top: 20px; border-top: 2px dashed var(--line); display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.danger-zone h2 { font-size: 16px; }

/* 割り方・負担割合 */
.mode-switch { display: inline-flex; align-self: flex-start; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.mode-switch button { border: 0; background: transparent; padding: 8px 18px; font-weight: 700; font-size: 14px; cursor: pointer; }
.mode-switch button[aria-pressed="true"] { background: var(--fg); color: var(--surface); }
.weights-box { background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.w-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.weights { display: flex; flex-direction: column; }
.w-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(5.5em, auto); gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.w-row:first-child { border-top: 0; }
.w-row.me .w-name { color: var(--accent); }
.w-name { font-weight: 700; overflow-wrap: anywhere; }
.w-ctl { display: inline-flex; align-items: center; gap: 4px; }
.w-ctl input[type=number] { width: 4.2em; padding: 6px 4px; text-align: center; font-family: var(--font-num); }
.w-btn { width: 34px; height: 34px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; font-size: 16px; cursor: pointer; line-height: 1; }
.w-btn:hover { border-color: var(--fg); }
.w-amt { text-align: right; font-weight: 600; }
.wtag { font-family: var(--font-num); font-size: 11px; color: var(--accent); margin-left: 4px; }

/* メンバー名の変更 */
.m-name { border: 0; background: transparent; padding: 0; font-weight: 700; cursor: text; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.rename-input { width: 7em; padding: 2px 6px !important; font-size: 15px !important; border-radius: 6px !important; }
#memberToast:empty { display: none; }

/* 全体で一律：請求金額 */
.bill-box { background: var(--surface); border: 1.5px solid var(--accent); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
#itemFieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.panel.off .form, .panel.off .items { opacity: .45; }
.panel.off .items { pointer-events: none; }
.off-note { margin: 0; font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; }
