:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #1b2333;
  --muted: #65708a;
  --line: #e2e7ef;
  --accent: #3a5bd9;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --gain: #14875a;
  --gain-soft: #e1f5ec;
  --owe: #d6453d;
  --owe-soft: #fde9e7;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

#app { max-width: 540px; margin: 0 auto; padding: 28px 16px 96px; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 8px; letter-spacing: 0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 8px; display: flex; align-items: baseline; gap: 8px; }
h3 { font-size: 0.85rem; margin: 16px 0 4px; color: var(--muted); font-weight: 600; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  background: var(--surface);
  transition: transform 0.1s ease, background 0.15s ease;
}
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.subtle { background: transparent; color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); outline-offset: 0; }

.card { margin-bottom: 36px; }
.title-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.title-row h1 { margin: 0; overflow-wrap: anywhere; }
.title-row button, .created button { white-space: nowrap; }
.created { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 28px; padding: 12px 16px; border-radius: var(--radius); background: var(--accent-soft); }
.created p { margin: 0; font-weight: 700; font-size: 0.9rem; }

.member-rows { display: flex; flex-direction: column; gap: 8px; }
.member-row { display: flex; gap: 8px; align-items: center; }
.member-row:not(.filled) .icon-button { visibility: hidden; }
.icon-button { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 10px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-button:hover { color: var(--owe); background: var(--owe-soft); }

.hero p { color: var(--muted); margin: 0 0 24px; }

.add-form { display: flex; gap: 8px; margin-top: 12px; }
.add-form input { flex: 1; min-width: 0; }

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stack label, .stack fieldset { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.stack button.primary { padding: 12px; font-size: 1rem; }
fieldset { border: 0; padding: 0; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip, .stack .chip {
  display: inline-flex; flex-direction: row; align-items: center; gap: 6px;
  border: 1.5px solid var(--line); border-radius: 999px; padding: 4px 14px;
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.segmented { display: flex; gap: 4px; padding: 4px; margin: 16px 0; border-radius: 999px; background: var(--line); }
.segmented .chip { flex: 1; justify-content: center; border: 0; padding: 6px 8px; font-size: 0.9rem; background: transparent; }
.segmented .chip:has(input:checked) { background: var(--surface); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

li.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
li.row .name { flex: 1; display: flex; flex-direction: column; overflow-wrap: anywhere; }
li.row small { color: var(--muted); }
li.row .amount { font-weight: 700; }
li.row .remove { border-color: transparent; background: transparent; color: var(--muted); padding: 4px 10px; font-size: 0.85rem; }
li.row .remove:hover { color: var(--owe); }

.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
  background: hsl(var(--hue) 70% 88%); color: hsl(var(--hue) 55% 28%);
}

.balance { font-size: 1.1rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; }
.balance.gain { color: var(--gain); background: var(--gain-soft); }
.balance.owe { color: var(--owe); background: var(--owe-soft); }

[data-testid="settle-section"] { padding: 20px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(30, 50, 110, 0.08); }
[data-testid="settle-section"] li.row:last-child { border-bottom: 0; }
[data-testid="settle-section"] button.primary { width: 100%; margin-top: 16px; padding: 12px; font-size: 1rem; }

.pool-total { margin: 8px 0 0; color: var(--muted); }
.pool-total strong { display: block; font-size: 2.2rem; line-height: 1.2; color: var(--ink); }
.note { font-size: 0.8rem; color: var(--muted); }
.empty { color: var(--muted); padding: 8px 0; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.actions button { color: var(--owe); border-color: var(--line); }

#toast-region { position: fixed; right: 16px; bottom: 16px; left: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: 100%; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 10px 18px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }

@media (prefers-reduced-motion: reduce) { button { transition: none; } button:active { transform: none; } }

.summary { margin: 0 0 4px; display: flex; flex-direction: column; }
.summary small { color: var(--muted); }
.summary strong { font-size: 1.8rem; line-height: 1.2; }

.history-item { border-bottom: 1px solid var(--line); }
.history-item summary { cursor: pointer; padding: 12px 0; }
.history-detail { padding-bottom: 12px; }
.history-detail li.row:last-child { border-bottom: 0; }
