:root {
  /* 配色はトップページ（marketing.css）と揃える */
  --fg: #1b2a26;
  --fg-weak: #3f4f4a;
  --muted: #5c6b66;
  --bg: #f6f4ee;
  --card: #fff;
  --border: #e6ebe9;
  --input-border: #dfe5e2;
  --primary: #0e7c66;
  --primary-hover: #0a5f4e;
  --primary-soft: #e3f1ec;
  --dark: #0b2b25;
  --danger: #c0392b;
  --line: #06c755;
  --plus: #0e7c66;
  --minus: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Zen Kaku Gothic New", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.7;
}

.container { max-width: 560px; margin: 0 auto; padding: 16px 20px 48px; }

h1 { font-size: 1.5rem; margin: 8px 0; }
h2 { font-size: 1.1rem; margin: 28px 0 8px; }
a { color: var(--primary); }
small { display: block; }
.muted { color: var(--muted); }
.plus { color: var(--plus); font-weight: bold; }
.minus { color: var(--minus); font-weight: bold; }


.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
  display: grid;
  gap: 12px;
}

label { display: grid; gap: 4px; font-weight: 600; }
label small { font-weight: normal; color: var(--muted); }

input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%;
  font-size: 16px; /* iOSでズームされないように */
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
legend { font-weight: 600; padding: 0 4px; }
label.radio, label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }
label.inline-field { grid-template-columns: 1fr 140px; align-items: center; font-weight: normal; }
[hidden] { display: none !important; }

.row { display: flex; gap: 8px; align-items: center; }
.row > input[type="text"] { flex: 1; }

.button {
  display: inline-block;
  font-size: 1rem;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--fg);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
}
.row .button { width: auto; flex: 1; }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: bold; }
.button.line { background: var(--line); border-color: var(--line); color: #fff; font-weight: bold; }
.button.danger { color: var(--danger); border-color: var(--danger); margin-top: 24px; }
.button.small { font-size: 0.85rem; padding: 6px 10px; width: auto; }
.button.block { display: block; }
.link { background: none; border: none; color: var(--primary); text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.9rem; }
form.inline, .inline { display: inline; }

.list { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.list li { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); }
.list li:first-child { border-top: none; }
.list li > span:first-child { flex: 1; }
.list li.mine { background: #eef8f5; }
.list .expense { display: flex; flex: 1; justify-content: space-between; gap: 12px; color: inherit; text-decoration: none; }

.settled { text-align: center; font-size: 1.2rem; font-weight: bold; color: var(--primary); }

.flash { background: #eef8f5; border-radius: 8px; padding: 10px 12px; }
.flash-alert { background: #fdecea; color: var(--danger); }
.errors { background: #fdecea; color: var(--danger); border-radius: 8px; padding: 10px 12px 10px 28px; margin: 0; }

.container:has(.totals) { padding-bottom: 96px; }

.totals {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
}
.totals div { text-align: center; }
.totals small { font-size: 13px; color: var(--muted); }
.totals strong { font-size: 18px; }

.fab {
  position: fixed; right: 20px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 30px; line-height: 56px; text-align: center;
  text-decoration: none; box-shadow: 0 8px 20px rgba(14, 124, 102, .4);
}

/* 残高タブ */
.balances li { display: grid; grid-template-columns: 5.5em 1fr 6.5em; gap: 8px; }
.balances .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balances .value { text-align: right; font-size: 0.9rem; }
.bar-track { position: relative; height: 20px; }
.bar-track::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; border-left: 1px solid var(--border); }
.bar { position: absolute; top: 2px; bottom: 2px; border-radius: 4px; }
.bar.plus { left: 50%; background: var(--plus); }
.bar.minus { right: 50%; background: var(--minus); }
.transfer small { display: inline; margin-left: 8px; font-size: 1rem; color: var(--fg); font-weight: bold; }

/* 支出フォーム */
input.amount { font-size: 1.5rem; font-weight: bold; }
.grow { flex: 1; }
.segmented { display: flex; border: 1px solid var(--primary); border-radius: 8px; overflow: hidden; }
.segmented label { flex: 1; display: block; font-weight: normal; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; text-align: center; padding: 8px 0; color: var(--primary); cursor: pointer; }
.segmented input:checked + span { background: var(--primary); color: #fff; font-weight: bold; }

.splits { list-style: none; margin: 0; padding: 0; }
.splits li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); min-height: 52px; }
.splits li:first-child { border-top: none; }
.splits label.check { flex: 1; }
.splits input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.splits .parts-input { width: 72px; }
.splits .amount-input { width: 120px; }
.splits .share { min-width: 6em; text-align: right; font-weight: bold; }
[data-split-mode="equal"] .parts-input,
[data-split-mode="equal"] .amount-input,
[data-split-mode="parts"] .amount-input,
[data-split-mode="custom"] .parts-input,
[data-split-mode="custom"] .share { display: none; }

.add-member { padding-top: 8px; border-top: 1px solid var(--border); }
.add-member input { flex: 1; }


/* 共通の部品（トップページのデザインに合わせる） */
.card { border: 0; border-radius: 20px; }
.list { border: 0; border-radius: 16px; }
input[type="text"], input[type="number"], input[type="date"], select { height: 46px; border: 1.5px solid var(--input-border); border-radius: 12px; padding: 0 14px; font-family: inherit; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 124, 102, .15); }
label { color: var(--fg-weak); font-size: 14px; font-weight: 700; }
.button { border-radius: 12px; font-family: inherit; font-weight: 700; }
.button.primary { height: 52px; font-size: 17px; }
.button.primary:hover { background: var(--primary-hover); }
.app-logo { display: flex; align-items: center; gap: 8px; height: 56px; margin-top: -16px; font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.app-logo svg { width: 28px; height: 28px; }
.back { margin: 0; }
.back a { text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.page-title { margin: 4px 0 14px; font-size: 24px; line-height: 1.3; }
.form-note { margin: 14px 4px 0; font-size: 14px; color: var(--muted); }

/* グループ画面：ヘッダー（白）＋タブ＋支出一覧（ベージュ） */
.g-welcome-wrap, .g-header, .tabs { margin-left: -20px; margin-right: -20px; background: #fff; }
.g-welcome-wrap { margin-top: -16px; padding: 12px 20px 0; }
.g-welcome { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; background: var(--primary-soft); font-size: 15px; line-height: 1.5; color: var(--dark); }
.g-header { margin-top: -16px; padding: 16px 20px 16px; }
.g-welcome-wrap + .g-header { margin-top: 0; padding-top: 14px; }
.g-title-row { display: flex; justify-content: space-between; align-items: flex-start; }
.g-title-row h1 { margin: 0; font-size: 24px; line-height: 1.3; }
.g-members { margin-top: 2px; font-size: 15px; color: var(--muted); }
.g-icon { width: 28px; height: 28px; margin-top: 4px; flex: none; }
.g-you { margin-top: 4px; font-size: 14px; color: var(--muted); }
.g-you strong { color: var(--fg); }
.g-you .link { margin-left: 4px; font-size: 14px; }

.share { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.share.small .button { width: auto; height: 40px; padding: 0 14px; font-size: 14px; display: inline-flex; align-items: center; }
.share.large { flex-direction: column; gap: 10px; }
.share.large .button { height: 52px; font-size: 17px; display: flex; align-items: center; justify-content: center; }
.share.large .button:not(.line) { height: 48px; font-size: 16px; border: 1.5px solid var(--input-border); }
.share .copied { width: 100%; margin: 0; font-size: 14px; color: var(--primary); }
.button.line:hover { background: #05b24c; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.tabs a { text-align: center; padding: 12px 0; color: var(--muted); text-decoration: none; font-weight: 700; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.g-body { padding-top: 4px; }
h2.date { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
.list li { padding: 14px 16px; }
.entry-title { display: block; font-weight: 700; }
.list small { font-size: 14px; }
.entry-amount { font-size: 18px; font-variant-numeric: tabular-nums; }
.g-added { display: flex; gap: 10px; align-items: center; margin: 16px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-size: 14px; font-weight: 700; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 72px 32px; text-align: center; }
.empty-icon { width: 56px; height: 56px; opacity: .9; }
.empty-title { margin: 6px 0 0; font-weight: 700; font-size: 17px; }
.empty p.muted { margin: 0; font-size: 15px; line-height: 1.6; }

.g-bird-avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; }
.g-bird-avatar svg { width: 30px; height: 30px; }
.g-bird-avatar.large { width: 88px; height: 88px; }
.g-bird-avatar.large svg { width: 66px; height: 66px; }

/* 作成直後：招待に集中する画面 */
body:has(.invitation) { background: #fff; }
.invitation { display: flex; flex-direction: column; min-height: calc(100vh - 64px); }
.invitation-hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 28px; }
.invitation-hero h1 { margin: 18px 0 6px; font-size: 24px; line-height: 1.4; }
.invitation-hero p { margin: 0; color: var(--fg-weak); }
.invitation-preview { margin: 24px 0 20px; padding: 14px 16px; border-radius: 16px; background: var(--bg); }
.invitation-preview-label { margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.invitation-preview-body { padding: 12px 14px; border-radius: 12px; background: #fff; font-size: 15px; line-height: 1.6; }
.invitation-url { display: block; color: var(--primary); text-decoration: underline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invitation-later { margin-top: auto; padding-top: 24px; min-height: 44px; display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--muted); }

/* 参加画面：名前を1つ選ぶ。一覧にないときだけ入力欄を開く */
.join-head { margin-top: 12px; text-align: center; }
.join-head h1 { margin: 4px 0; font-size: 28px; line-height: 1.3; }
.join-head .muted:first-child { font-size: 15px; }
.join-head strong { color: var(--fg); }
.join-card { margin-top: 20px; padding: 16px; border-radius: 20px; background: #fff; }
.join-question { margin-bottom: 12px; font-weight: 700; font-size: 18px; }
.join-options { display: flex; flex-direction: column; gap: 8px; }
.join-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 0 16px; border: 1.5px solid var(--input-border); border-radius: 12px; color: var(--fg); font-size: 16px; font-weight: 400; cursor: pointer; }
.join-option input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.join-option.joined { color: #8a9793; }
.join-joined { margin-left: auto; font-size: 13px; }
.join-check { display: none; color: var(--primary); }
.join-option:has(input:checked) { border: 2px solid var(--primary); background: var(--primary-soft); font-weight: 700; color: var(--fg); }
.join-option:not(.join-new):has(input:checked) .join-check { display: inline; }
.join-option:has(input:checked) .join-joined { display: none; }
.join-new { border-style: dashed; border-color: #b9c6c1; color: var(--muted); }
.join-new-field { display: none; }
.join-new:has(input[type="radio"]:checked) { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 14px; border-style: solid; }
.join-new:has(input[type="radio"]:checked) .join-new-label { display: none; }
.join-new:has(input[type="radio"]:checked) .join-new-field { display: flex; flex-direction: column; gap: 8px; }
.join-new-title { font-size: 14px; font-weight: 700; color: var(--primary); }
.join-submit { margin-top: 16px; }
.join-submit:disabled { opacity: .45; cursor: default; }
.join-pitch { margin: 16px 4px 0; font-size: 14px; color: var(--muted); text-align: center; line-height: 1.6; }

/* 支出フォーム：払った人（丸いボタン）・金額（円つき）・たたんだ分け方 */
.expense-form { gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; font-weight: 700; color: var(--fg-weak); }
.amount-field { display: flex; align-items: center; height: 52px; padding: 0 14px; border: 1.5px solid var(--input-border); border-radius: 12px; background: #fff; }
.amount-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 124, 102, .15); }
.amount-field input[type="text"] { flex: 1; min-width: 0; height: auto; padding: 0; border: 0; box-shadow: none; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg); }
.amount-field span { color: var(--muted); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; font-weight: 400; color: var(--fg); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; height: 44px; padding: 0 16px; border: 1.5px solid var(--input-border); border-radius: 999px; cursor: pointer; }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(14, 124, 102, .3); }
.split-collapsed { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 12px 14px; border-radius: 12px; background: var(--bg); color: var(--fg); font-weight: 400; }
.split-collapsed .link { font-weight: 700; text-decoration: none; }
.tabs + .list { margin-top: 16px; }
