:root {
  --bg: #f3f1ec;
  --surface: #ffffff;
  --text: #1d1f24;
  --muted: #6b6f78;
  --line: #d9d6cf;
  --accent: #d2551e;
  --accent-text: #ffffff;
  --play: #2f6fdd;
  --paper: #fffdf8;
  --ink: #111;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 8px 28px rgba(0,0,0,.10);
  --font: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light;
}

/* ダーク: 「ダーク」選択時、または「端末に合わせる」で端末がダークモードのとき */
:root[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1e2129;
  --text: #e9e9ec;
  --muted: #9a9ea8;
  --line: #333845;
  --accent: #ff7a3d;
  --accent-text: #14161c;
  --play: #6aa0ff;
  --paper: #f7f4ec;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #14161c;
    --surface: #1e2129;
    --text: #e9e9ec;
    --muted: #9a9ea8;
    --line: #333845;
    --accent: #ff7a3d;
    --accent-text: #14161c;
    --play: #6aa0ff;
    --paper: #f7f4ec;
    color-scheme: dark;
  }
}

/* ベージュ: 明るく、やわらかい配色（端末のダークモードに関係なく常にこの色） */
:root[data-theme="beige"] {
  --bg: #f5efe4;
  --surface: #fcf9f3;
  --text: #4a3f36;
  --muted: #94877a;
  --line: #e6dccd;
  --accent: #c98a64;
  --accent-text: #ffffff;
  --play: #7b9bb8;
  --paper: #fffdf9;
  --ink: #2e2620;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(120,90,60,.06), 0 10px 30px rgba(120,90,60,.10);
  --font: "Zen Maru Gothic", system-ui, -apple-system, "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="beige"] .tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
:root[data-theme="beige"] .start.running { background: var(--text); color: var(--surface); }
:root[data-theme="beige"] .beats i.on { background: var(--accent); }
:root[data-theme="beige"] .beats i.on.first { background: var(--text); }
:root[data-theme="beige"] .icon-btn,
:root[data-theme="beige"] .tab,
:root[data-theme="beige"] .stepper button,
:root[data-theme="beige"] .chip { border-color: var(--line); box-shadow: 0 1px 2px rgba(120,90,60,.06); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.top h1 { font-size: 1.1rem; margin: 0; letter-spacing: .04em; }
.top .sub { color: var(--muted); font-weight: 400; font-size: .8rem; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 1.15rem; line-height: 1;
}

.tabs { display: flex; gap: 6px; padding: 0 16px; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

main {
  flex: 1; display: flex; flex-direction: column; gap: 12px;
  padding: 12px 16px 16px; max-width: 980px; width: 100%; margin: 0 auto;
}
.stage { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }

.status { display: flex; align-items: center; gap: 12px; min-height: 28px; }
.phase { font-weight: 700; letter-spacing: .08em; font-size: .95rem; min-width: 5em; }
.phase.read { color: var(--accent); }
.phase.play { color: var(--play); }
.beats { display: inline-flex; gap: 6px; }
.beats i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); transition: background .05s; }
.beats i.on { background: var(--text); }
.beats i.on.first { background: var(--accent); }
body:not(.mode-bpm) .beats { display: none; }
.counter { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .9rem; }

.card {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  min-height: 140px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  outline: 3px solid transparent;
  transition: outline-color .25s;
}
.card.flash { animation: flash .35s ease-out; }
@keyframes flash { from { outline-color: var(--accent); } to { outline-color: transparent; } }
.card.play { outline-color: var(--play); }
.score { width: 100%; padding: 1% 3%; }
.score svg { display: block; max-height: 56dvh; }
.card.hidden-notes .score { opacity: .35; }
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(1.6rem, 7vw, 3.4rem); font-weight: 800; letter-spacing: .2em;
  color: var(--play); pointer-events: none;
}
.overlay[hidden] { display: none; }

.answer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; display: flex; flex-direction: column; gap: 6px;
}
.answer[hidden] { display: none; }
.answer-names { font-size: 1.25rem; font-weight: 700; letter-spacing: .08em; text-align: center; word-spacing: .3em; }
.fretboard svg { width: 100%; height: auto; display: block; }
.fb-fret { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.fb-nut { stroke: var(--text); stroke-width: 4; }
.fb-string { stroke: var(--text); opacity: .75; }
.fb-inlay { fill: var(--line); }
.fb-num, .fb-sname { fill: var(--muted); font-size: 10px; text-anchor: middle; }
.fb-dot circle { fill: var(--play); }
.fb-dot.first circle { fill: var(--accent); }
.fb-dot text { fill: #fff; font-size: 9px; font-weight: 700; text-anchor: middle; }

.summary { margin: 0; color: var(--muted); font-size: .85rem; text-align: center; }

.controls { display: flex; flex-direction: column; align-items: center; gap: 10px; }
body.mode-bpm .ctl-card, body:not(.mode-bpm) .ctl-bpm { display: none; }
.ctl-bpm { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.stepper button {
  min-width: 42px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
.stepper output {
  min-width: 4.2em; text-align: center; font-size: 1.35rem; font-weight: 700;
  color: var(--text); font-variant-numeric: tabular-nums;
}
.chips { display: flex; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .9rem;
}
.start {
  width: min(360px, 100%); padding: 14px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-size: 1.15rem; font-weight: 700; letter-spacing: .1em;
}
.start.running { background: var(--text); color: var(--bg); }
.start.small { width: auto; padding: 10px 28px; font-size: 1rem; }
.hint { margin: 0; color: var(--muted); font-size: .75rem; }
@media (hover: none) { .hint { display: none; } }

/* 設定ダイアログ */
.settings {
  border: 0; padding: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
.settings::backdrop { background: rgba(0,0,0,.45); }
.settings-inner { padding: 0 16px 16px; }
.settings-head {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 12px 0;
}
.settings-head h2 { margin: 0; font-size: 1.1rem; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 12px; padding: 10px 12px 12px; }
legend { padding: 0 6px; font-weight: 700; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.row > label:not(.check) { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
.checks { gap: 8px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; }
.wide { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.wide input[type="range"] { flex: 1; accent-color: var(--accent); }
.wide output { min-width: 3em; color: var(--text); font-variant-numeric: tabular-nums; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
select, input[type="number"] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; min-width: 6.5em;
}
input[type="number"] { width: 6.5em; }
.note { color: var(--muted); font-size: .78rem; margin: 8px 0 0; line-height: 1.5; }
.settings-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; color: var(--muted); }

/* 横向きスマホ・全画面ではカードを最大化 */
@media (orientation: landscape) and (max-height: 520px) {
  .top, .tabs, .hint, .summary { display: none; }
  main { padding-top: 8px; flex-direction: row; align-items: stretch; max-width: none; }
  .stage { flex: 1; }
  .card { flex: 1; }
  .score svg { max-height: 80dvh; }
  .fretboard { display: none; }
  .answer { padding: 4px 8px; }
  .controls { width: 200px; justify-content: center; }
  .stepper { flex-wrap: wrap; justify-content: center; }
}
:fullscreen .tabs, :fullscreen .hint { display: none; }
