/* ワリカンの神 — ベース: ~/Projects/DESIGN.base.md（最小文字14px） */
:root {
  --bg: #F4F6F2;
  --surface: #FFFFFF;
  --surface-2: #EBEFE7;
  --ink: #1B2320;
  --ink-2: #5A645F;
  --line: #D7DDD6;
  --line-strong: #AEB8B0;
  --accent: #1E5BB8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2EBFA;
  --accent-line: #98B4E6;
  --plus: #1B7F4F;
  --plus-soft: #DFF2E7;
  --minus: #B4482A;
  --minus-soft: #F8E6DF;
  --warn: #8A5A00;
  --warn-soft: #FAF0D5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 8px 24px -14px rgba(20, 30, 25, .22);
  --font-body: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-head: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131816;
    --surface: #1C2320;
    --surface-2: #252D29;
    --ink: #ECEFEA;
    --ink-2: #A2ACA6;
    --line: #313A35;
    --line-strong: #4B554F;
    --accent: #85ACEF;
    --accent-ink: #0E1A2E;
    --accent-soft: #22314D;
    --accent-line: #3E5B8F;
    --plus: #62C892;
    --plus-soft: #1C3529;
    --minus: #EF9375;
    --minus-soft: #3F261D;
    --warn: #E6B44E;
    --warn-soft: #3A2F14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -14px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131816;
  --surface: #1C2320;
  --surface-2: #252D29;
  --ink: #ECEFEA;
  --ink-2: #A2ACA6;
  --line: #313A35;
  --line-strong: #4B554F;
  --accent: #85ACEF;
  --accent-ink: #0E1A2E;
  --accent-soft: #22314D;
  --accent-line: #3E5B8F;
  --plus: #62C892;
  --plus-soft: #1C3529;
  --minus: #EF9375;
  --minus-soft: #3F261D;
  --warn: #E6B44E;
  --warn-soft: #3A2F14;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -14px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.35; letter-spacing: .02em; margin: 0; text-wrap: balance; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--accent-line); outline-offset: 2px; border-radius: 6px; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(48px + env(safe-area-inset-bottom));
}

/* ヘッダー */
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 20px;
}
.brand {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: .04em;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 10px;
  vertical-align: 6px;
}
.tagline { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.top-actions { display: flex; gap: 6px; flex-shrink: 0; padding-top: 6px; }

/* カード・セクション */
.stack { display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
}
.card.muted { background: var(--surface-2); box-shadow: none; }
.sec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.sec-head h2 { font-size: 20px; font-weight: 700; }
.step {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: var(--accent-ink);
  flex-shrink: 0;
}
.count { margin-left: auto; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.empty, .hint { color: var(--ink-2); font-size: 14px; }
.hint-box {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink-2);
  font-size: 14px;
}

/* 入力 */
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .input { flex: 1; min-width: 0; }
.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.input::placeholder { color: var(--ink-2); opacity: .8; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 14px; font-weight: 700; color: var(--ink-2); letter-spacing: .02em; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; }
.amount-wrap { display: flex; align-items: center; gap: 8px; }
.amount-wrap .input { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; text-align: right; }
.unit { color: var(--ink-2); }
.link {
  background: none; border: 0; padding: 4px 6px;
  color: var(--accent); font-size: 14px; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
  min-height: 32px;
}

/* チップ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px;
  padding: 4px 6px 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-weight: 500;
}
.chip-x {
  width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-2);
  font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.chip-x:hover { background: var(--surface-2); color: var(--ink); }
.chips.select .chip {
  padding: 4px 14px;
  min-height: 44px;
  transition: background .12s, border-color .12s;
}
.chips.select .chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.chips.select .chip.on::before { content: "✓"; font-size: 14px; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  align-self: flex-start;
}
.seg button {
  min-height: 44px; padding: 6px 16px;
  border: 0; background: var(--surface); color: var(--ink-2); font-weight: 500;
}
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg button { white-space: nowrap; }
@media (max-width: 480px) {
  /* 4択が横に入りきらない幅では 2×2 に並べる */
  .seg { display: grid; grid-template-columns: 1fr 1fr; align-self: stretch; }
  .seg button + button { border-left: 0; }
  .seg button:nth-child(2n) { border-left: 1px solid var(--line-strong); }
  .seg button:nth-child(n+3) { border-top: 1px solid var(--line-strong); }
}

/* 割合入力 */
.pct-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  display: flex; flex-direction: column; gap: 8px;
}
.pct-row { display: grid; grid-template-columns: 1fr 88px auto auto; align-items: center; gap: 8px; }
.pct-row .share-preview { min-width: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 500; }
.pct-row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pct-row .input { text-align: right; font-variant-numeric: tabular-nums; padding-right: 8px; }
.pct-tag {
  font-size: 14px; color: var(--ink-2); min-width: 3.5em;
}
.pct-tag.auto { color: var(--accent); font-weight: 700; }
.pct-sum { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); border-top: 1px dashed var(--line-strong); padding-top: 8px; margin-top: 2px; }
.pct-sum.bad { color: var(--minus); font-weight: 700; }
.pct-sum.ok .val { color: var(--plus); font-weight: 700; }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.error { color: var(--minus); font-size: 14px; font-weight: 500; }

/* ボタン */
.btn {
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-weight: 700;
  white-space: nowrap;
  transition: background .12s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); font-weight: 500; padding: 8px 10px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.icon { width: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.select-input {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%235A645F' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; font-weight: 500; }
.btn.danger { color: var(--minus); }
.btn:disabled { opacity: .5; cursor: default; }

/* 立て替え一覧 */
.list-card { background: var(--surface-2); box-shadow: none; }
.list { display: flex; flex-direction: column; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line-strong); }
.list-head h2 { font-size: 18px; font-weight: 700; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.item.editing { background: var(--accent-soft); margin: 0 -18px; padding: 12px 18px; border-radius: 8px; }
.item .title { font-weight: 700; }
.item .amt { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; text-align: right; white-space: nowrap; }
.item .meta { grid-column: 1 / -1; color: var(--ink-2); font-size: 14px; }
.item .meta b { color: var(--ink); font-weight: 500; }
.item .actions { grid-column: 1 / -1; display: flex; gap: 4px; justify-content: flex-end; }
.item .warn { color: var(--warn); font-weight: 500; }

/* 精算 */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: right; font-size: 14px; white-space: nowrap; }
.table td:first-child { white-space: normal; word-break: break-all; min-width: 4em; }
.table th { color: var(--ink-2); font-weight: 500; }
.table th:first-child, .table td:first-child { text-align: left; }
.table td:first-child { font-weight: 500; font-size: 16px; }
.table .net { font-weight: 700; font-size: 16px; }
.net.plus { color: var(--plus); }
.net.minus { color: var(--minus); }
.table-wrap { overflow-x: auto; margin: 0 -4px; }

.transfers { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.transfers h3 { font-size: 18px; margin-bottom: 4px; }
.person {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.person.pays { border-left: 4px solid var(--minus); }
.person.gets { border-left: 4px solid var(--plus); }
.person.even { border-left: 4px solid var(--line-strong); color: var(--ink-2); }
.person .who { font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.person .who .badge { font-size: 14px; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.badge.pays { background: var(--minus-soft); color: var(--minus); }
.badge.gets { background: var(--plus-soft); color: var(--plus); }
.tline { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.tline .arrow { color: var(--ink-2); margin: 0 6px; }
.tline .money { font-weight: 700; white-space: nowrap; }
.settle-note { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.result-box { position: relative; margin-top: 18px; background: var(--surface-2); border-radius: 12px; padding: 14px; }
.result-box .btn { position: absolute; top: 10px; right: 10px; background: var(--surface); }
.result-text {
  font: inherit; font-size: 15px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-all;
  margin: 0; padding-top: 34px;
  font-variant-numeric: tabular-nums;
}

/* トースト */
.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (max-width: 420px) {
  .top { flex-direction: column; }
  .top-actions { padding-top: 0; }
  .brand { font-size: 26px; }
  .card { padding: 16px 14px; }
  .item.editing { margin: 0 -14px; padding: 12px 14px; }
}

/* ---- 旅行ごとの共有（サーバー保存）に伴う追加 ---- */
.eyebrow {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 32px;
}
.eyebrow::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.trip-name { font-size: 26px; font-weight: 900; letter-spacing: .03em; word-break: break-all; }
.home-card h2 { font-size: 20px; margin-bottom: 8px; }
.trip-list { display: flex; flex-direction: column; margin-top: 8px; border-top: 1px solid var(--line); }
.trip-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-weight: 500; min-height: 48px;
}
.trip-list a:hover { background: var(--surface-2); }
.trip-list .when { color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.status-card { text-align: center; padding: 40px 18px; color: var(--ink-2); }
.status-card .btn { margin-top: 14px; }
.syncing { opacity: .6; }
.btn.busy { opacity: .6; pointer-events: none; }
.sub-note { color: var(--ink-2); font-size: 14px; margin-top: 10px; }

/* ---- タブ（①メンバー ②立て替え登録 ③精算） ---- */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 18px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 6px 8px;
  border: 0; border-radius: 11px;
  background: transparent;
  color: var(--ink-2);
  font: inherit; font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.tab .step { width: 24px; height: 24px; background: var(--line-strong); color: var(--ink-2); }
.tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 700; }
.tab.on .step { background: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; margin-top: 14px; min-height: 52px; font-size: 16px; }
@media (max-width: 420px) {
  .tab { flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 14px; }
}

/* 作者の他のアプリ（apps.kenroom.com）への導線 */
.site-foot { margin: 32px auto 8px; text-align: center; font-size: 14px; }
.site-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; }
.site-foot a:hover { color: var(--ink); }
