:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1b1f27;
  --sub: #5e6573;
  --line: #e2e5ea;
  --accent: #1f2a44;
  --accent-ink: #ffffff;
  --gold: #b8860b;
  --danger: #c0392b;
  --soft: #eef1f6;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px; line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--sub); }
.center { text-align: center; }
.pad { padding: 24px 16px; }
.num { font-variant-numeric: tabular-nums; }

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
}
.bar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-back, .bar-btn {
  background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 8px;
  padding: 6px 12px; font-size: 14px; min-height: 36px;
}

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 48px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--sub); font-weight: 700; letter-spacing: .02em; }
.card h3 { font-size: 14px; margin: 14px 0 6px; color: var(--sub); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 8px; text-align: center; }
.stat .k { font-size: 11px; color: var(--sub); }
.stat .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .v small { font-size: 12px; font-weight: 600; }

.tabs { position: sticky; top: 56px; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  background: var(--bg); padding: 6px 0 10px; }
.tab { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 0; font-size: 14px; font-weight: 600; color: var(--sub); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

label.f { display: block; font-size: 13px; color: var(--sub); margin: 8px 0 4px; }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  padding: 10px 12px; font-size: 16px; min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fb0d6; outline-offset: 0; border-color: #9fb0d6; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }
.row > .shrink { flex: 0 0 auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 14px;
  font-size: 15px; font-weight: 600; min-height: 44px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions > .btn { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 15px; min-height: 38px; }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .who { font-weight: 700; }
.list .what { color: var(--sub); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .idx { width: 22px; color: var(--sub); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }

.trip-link { display: block; text-decoration: none; color: inherit; }
.trip-link .t { font-weight: 700; font-size: 16px; }
.trip-link .m { font-size: 13px; color: var(--sub); }
.tag { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; color: var(--sub); margin-left: 6px; vertical-align: 2px; }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: 0; }
.rank .pos { font-weight: 800; font-size: 18px; color: var(--sub); text-align: center; font-variant-numeric: tabular-nums; }
.rank li.top1 .pos { color: var(--gold); }
.rank .nm { font-weight: 700; }
.rank .ct { font-size: 13px; color: var(--sub); }
.rank .tt { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.rank .bar-bg { grid-column: 2 / 4; height: 4px; background: var(--soft); border-radius: 2px; overflow: hidden; }
.rank .bar-fg { height: 100%; background: var(--accent); }
.rank li.zero .nm, .rank li.zero .tt { color: var(--sub); font-weight: 600; }

table.sum { width: 100%; border-collapse: collapse; }
table.sum td { padding: 6px 0; border-top: 1px solid var(--line); }
table.sum tr:first-child td { border-top: 0; }
table.sum td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
table.sum tr.total td { font-size: 17px; }

pre.line { white-space: pre-wrap; word-break: break-all; background: var(--soft); border-radius: 10px; padding: 12px; font-size: 13px; line-height: 1.6; margin: 10px 0 0; font-family: inherit; }

.preview li.bad { background: #fff6f5; }
.preview .err { color: var(--danger); font-size: 12px; }
.preview select, .preview input { min-height: 38px; padding: 6px 8px; font-size: 15px; }
.preview .pa { width: 92px; flex: 0 0 92px; }

.edit-box { background: var(--soft); border-radius: 10px; padding: 10px; width: 100%; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--sub); white-space: nowrap; }
.check input { width: 18px; height: 18px; }
.note { font-size: 12px; color: var(--sub); margin: 6px 0 0; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1b1f27; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }
