:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #efefec;
  --text: #1b1b1f;
  --muted: #74747c;
  --faint: #a8a8ae;
  --line: #e5e5e1;
  --accent: #3d55c4;
  --accent-ink: #ffffff;
  --accent-weak: #e9ecf9;
  --danger: #c53030;
  --radius: 14px;
  --nav-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --surface: #1a1a1d;
    --surface-2: #242428;
    --text: #ececef;
    --muted: #9c9ca5;
    --faint: #66666e;
    --line: #2b2b30;
    --accent: #8f9ff3;
    --accent-ink: #0f0f11;
    --accent-weak: #22274a;
    --danger: #f07a7a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  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.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
svg { display: block; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
}

/* ---------- 共通 ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 60px;
  padding-top: env(safe-area-inset-top);
}
h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: .01em; }
.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 40px 8px; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.card { background: var(--surface); border-radius: var(--radius); }
.card.pad { padding: 16px; }
.block-sec { margin-bottom: 28px; }
.sec-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 4px 8px; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; margin: 12px 0; }
.btn-row > .btn { flex: 1; }
.link { background: none; border: 0; padding: 8px 4px; color: var(--accent); font-weight: 600; cursor: pointer; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; vertical-align: 2px; margin-left: 6px; }

/* ---------- 下部ナビ ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 11px; font-weight: 600;
}
.tabbar a svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* ---------- 曲一覧 ---------- */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin-top: 10px; padding: 4px;
  background: var(--surface-2); border-radius: 12px;
}
.segmented button {
  min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.group { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 6px; }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list + .list { margin-top: 12px; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 16px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .t { font-weight: 700; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.row .a { font-size: 13px; color: var(--muted); line-height: 1.4; margin-top: 1px; overflow-wrap: anywhere; }
.row .side { text-align: right; flex-shrink: 0; }
.row .side .score { font-weight: 700; font-variant-numeric: tabular-nums; }
.row .side .sub { display: block; font-size: 12px; color: var(--muted); }
.row .time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; width: 42px; flex-shrink: 0; }
#song-list > .list:first-child { margin-top: 4px; }

/* ---------- 詳細 ---------- */
.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 600; }
.detail-head { margin: 4px 0 20px; }
.detail-title { font-size: 24px; font-weight: 700; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.detail-artist { color: var(--muted); margin: 4px 0 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; }
.setting-row .label { font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 12px 0; }
.stat { padding: 14px 8px; text-align: center; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat .v small { font-size: 13px; font-weight: 600; margin-left: 1px; }
.chart-card { padding: 14px 12px 12px; margin-bottom: 16px; }
.chart-card h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 4px 6px; }
.chart { width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .pt { outline: none; }
.chart .pt.sel .dot { fill: var(--accent); r: 6; }
.chart .pt:focus-visible .dot { stroke-width: 3; }
.chart-empty { color: var(--muted); text-align: center; margin: 28px 0; }
.chart-info { text-align: center; font-size: 14px; margin: 6px 0 0; min-height: 21px; }
.chart-info b { font-size: 16px; font-variant-numeric: tabular-nums; }
.history { margin-top: 20px; }
.history summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; padding: 10px 4px; list-style: none; }
.history summary::-webkit-details-marker { display: none; }
.history summary::after { content: " ›"; }
.history[open] summary::after { content: " ⌄"; }

/* ---------- キー（ステッパー） ---------- */
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .step {
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.stepper .step:disabled { opacity: .35; }
.stepper output { min-width: 64px; text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 採点記録 ---------- */
.field { display: block; margin-bottom: 18px; }
.field .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 4px 6px; }
.input-score { font-size: 28px; font-weight: 700; min-height: 60px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.suggest { margin: -12px 0 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.hint { font-size: 13px; color: var(--muted); margin: -12px 4px 18px; }
.error { color: var(--danger); font-size: 14px; margin: 0 4px 12px; white-space: pre-line; }
.last-saved {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px;
  margin-top: 20px; padding: 10px 14px;
  background: var(--surface); border-radius: 12px; font-size: 14px;
}
.last-saved .muted { font-size: 12px; width: 100%; }
.last-saved .t { font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.last-saved .num { font-variant-numeric: tabular-nums; }

/* ---------- 選曲 ---------- */
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick-card {
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 8px;
  min-height: 92px; padding: 14px; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--surface); text-align: left; font-size: 15px; font-weight: 700; cursor: pointer;
}
.pick-card.ready { border-color: var(--accent); }
.pick-card.ready .go { font-size: 12px; color: var(--accent); }
.pick-card.soon { color: var(--faint); }
.pick-card .badge { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 1px 7px; }
.pick-result { padding: 20px 16px 16px; margin-bottom: 16px; text-align: center; }
.pick-result .label { font-size: 12px; color: var(--muted); margin: 0; }
.pick-result .t { font-size: 22px; font-weight: 700; margin: 6px 0 2px; overflow-wrap: anywhere; }
.pick-result .a { color: var(--muted); margin: 0 0 14px; }
.pick-result .sub { font-size: 13px; color: var(--muted); margin: -8px 0 14px; }

/* ---------- カレンダー ---------- */
#calendar { padding: 8px 8px 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head span { font-weight: 700; }
.cal-nav { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; color: var(--accent); cursor: pointer; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .wd { font-size: 11px; color: var(--muted); padding: 4px 0; }
.cal-grid .wd.sun { color: #c86464; }
.cal-grid .wd.sat { color: #5a78c8; }
.day {
  position: relative; height: 44px; border: 0; border-radius: 10px; background: none;
  font-size: 15px; color: var(--faint); font-variant-numeric: tabular-nums;
}
.day.has { color: var(--text); font-weight: 700; cursor: pointer; }
.day.has::after { content: ""; position: absolute; left: 50%; bottom: 6px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--accent); }
.day.today { box-shadow: inset 0 0 0 1.5px var(--line); }
.day.sel { background: var(--accent); color: var(--accent-ink); }
.day.sel::after { background: var(--accent-ink); }
#cal-day { margin-top: 12px; }
.day-title { font-size: 14px; font-weight: 700; margin: 0 4px 8px; }

/* ---------- ダイアログ ---------- */
dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text);
  overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { font-size: 18px; margin: 0 0 14px; line-height: 1.4; overflow-wrap: anywhere; }
dialog p { margin: 0 0 14px; }
.dlg-actions { display: flex; flex-direction: row-reverse; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dlg-actions .btn { flex: 1 1 120px; }
.choice-list { display: grid; gap: 8px; }
.choice-list .row { border: 1px solid var(--line); border-radius: 12px; }
.choice-list .row + .row { border-top: 1px solid var(--line); }
.mini-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
.mini-list .row { min-height: 44px; cursor: default; }

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