:root {
  color-scheme: light;
  --bg: #f7f4f4;
  --surface: #ffffff;
  --surface-2: #f3eeee;
  --text: #222222;
  --muted: #777070;
  --border: #ebe3e3;
  --accent: #e5002d;
  --accent-dark: #b80024;
  --accent-soft: #fff0f2;
  --accent-text: #ffffff;
  --gold: #e09a00;
  --danger: #d0021b;
  --shadow: 0 2px 8px rgba(120, 0, 20, .06);
  --radius: 12px;
  --tabbar-h: 62px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- header / layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(184, 0, 36, .25);
}
.app-title { margin: 0; font-size: 1.2rem; letter-spacing: .02em; }
.icon-btn {
  border: 0; background: transparent; font-size: 1.3rem; width: 40px; height: 40px;
  border-radius: 50%; color: #fff;
}
.header-actions { display: flex; gap: 4px; }
.help-btn {
  font-size: 1.05rem; font-weight: 800; width: 32px; height: 32px; margin: 4px;
  border: 2px solid rgba(255, 255, 255, .9);
}
.icon-btn:hover { background: rgba(255, 255, 255, .18); }

.view {
  max-width: 680px; margin: 0 auto;
  padding: 14px 16px calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; max-width: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600;
}
.tabbar a .tab-ico { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.tabbar a.active .tab-ico { filter: none; opacity: 1; }

.fab {
  position: fixed; z-index: 15;
  right: max(18px, calc(50% - 340px + 18px));
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  height: 56px; min-width: 56px; padding: 0 20px;
  border: 0; border-radius: 28px;
  background: var(--accent); color: var(--accent-text);
  font-size: 1rem; font-weight: 700;
  box-shadow: 0 6px 18px rgba(229, 0, 45, .35);
}
.fab:active { transform: scale(.96); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.search {
  flex: 1; min-width: 0;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.select {
  padding: 10px 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); max-width: 45%;
}
.count-note { color: var(--muted); font-size: .8rem; margin: 0 2px 8px; }

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.item.tappable { cursor: pointer; }
.item.tappable:hover { border-color: var(--accent); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: .78rem; }
.item-memo { color: var(--muted); font-size: .82rem; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.link-btn {
  border: 0; background: none; padding: 0; text-align: left; width: 100%;
  display: block; cursor: pointer;
}

.score {
  flex: none; text-align: right; font-weight: 800; font-size: 1.35rem;
  font-variant-numeric: tabular-nums; color: var(--accent);
}
.score small { font-size: .7rem; font-weight: 600; color: var(--muted); display: block; line-height: 1; }
.score.none { color: var(--muted); font-weight: 600; font-size: 1rem; }
.key-badge {
  display: inline-block; font-size: .68rem; font-weight: 700;
  padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 1px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.best-badge {
  display: inline-block; font-size: .68rem; font-weight: 700;
  padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px;
  background: color-mix(in srgb, var(--gold) 20%, transparent); color: var(--gold);
}
.pill-btn {
  flex: none; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 700; white-space: nowrap;
}
.more-btn {
  flex: none; border: 0; background: transparent; color: var(--muted);
  width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem;
}
.more-btn:hover { background: var(--surface-2); }

.date-head { margin: 14px 4px 6px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.date-head:first-child { margin-top: 0; }

.empty {
  text-align: center; color: var(--muted); padding: 48px 16px;
}
.empty .big { font-size: 2.6rem; display: block; margin-bottom: 8px; }

/* ---------- detail ---------- */
.back-btn {
  border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px 0; margin-bottom: 8px;
}
.detail-head h2 { margin: 0; font-size: 1.35rem; line-height: 1.3; word-break: break-word; }
.detail-head .artist { color: var(--muted); margin-top: 2px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
@media (min-width: 520px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow);
}
.stat-label { font-size: .75rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: .95rem; }
.stat.best .stat-value { color: var(--gold); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h3 { margin: 0 0 8px; font-size: .9rem; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.card-head .select { padding: 6px 8px; font-size: .85rem; }
.chart-info { min-height: 1.4em; font-size: .82rem; margin-top: 4px; text-align: center; }
.chart-info b { color: var(--accent); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 14px; }
.chart .avg { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 5 4; }
.chart .avg-label { fill: var(--muted); font-size: 13px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .dot.best { fill: var(--gold); stroke: var(--gold); }
.section-title { font-size: .95rem; margin: 18px 2px 8px; }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- dialog ---------- */
dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 0; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(40, 0, 10, .45); }
.modal-body { padding: 18px 18px 14px; }
.modal-body h2 { margin: 0 0 14px; font-size: 1.15rem; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label, .field .label { font-size: .8rem; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.field input:focus, .field select:focus, .field textarea:focus, .search:focus, .select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px;
}
.field textarea { min-height: 64px; resize: vertical; }
.field .hint { font-size: .75rem; color: var(--muted); }
.score-input { font-size: 1.6rem !important; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; margin-bottom: 12px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding-top: 6px;
}
.btn {
  border: 1px solid var(--border); background: var(--surface-2);
  padding: 10px 18px; border-radius: 10px; font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn.left { margin-right: auto; }
.btn.block { width: 100%; margin-bottom: 8px; text-align: left; }
.settings-note { color: var(--muted); font-size: .82rem; margin: 0 0 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 100;
  bottom: calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- help ---------- */
.help { padding-bottom: 4px; }
.help-lead { margin: -6px 0 14px; color: var(--muted); font-size: .9rem; }
.help-step { display: flex; gap: 12px; margin-bottom: 14px; }
.help-ico {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.2rem;
  background: var(--accent-soft); color: var(--accent); font-weight: 800;
}
.help-step h3 { margin: 0 0 2px; font-size: .98rem; }
.help-step p { margin: 0; font-size: .86rem; color: var(--muted); }
.help-note {
  font-size: .8rem; color: var(--muted); background: var(--surface-2);
  border-radius: 10px; padding: 10px 12px; margin: 4px 0 12px;
}
