:root {
  --bg: #16161d;
  --surface: #22222c;
  --surface-2: #2d2d39;
  --text: #f2f2f5;
  --muted: #9a9aab;
  --accent: #f5a623;
  --accent-text: #1a1206;
  --line: #4a4a5a;
  --fret-wood: #3a2c22;
  --string: #c9c2b4;
  --fret-wire: #9c9c9c;
  --nut: #e8e2d4;
  --error: #ff6b6b;
  --good: #4cd38a;
}

* { 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", sans-serif;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

button { cursor: pointer; -webkit-tap-highlight-color: transparent; font: inherit; }

/* ---------- アップデートのお知らせ ---------- */
.banner {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(10px + env(safe-area-inset-top));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
}

.banner[hidden] { display: none; }
.banner span { flex: 1; }

.banner-button {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--accent-text);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- ヘッダーとタブ ---------- */
.app-header { padding-top: calc(10px + env(safe-area-inset-top)); max-width: 560px; margin: 0 auto; }

h1 { font-size: 1rem; margin: 0 0 10px; text-align: center; color: var(--muted); font-weight: 600; }

/* 下のメニュー（アイコン付き）：親指で押しやすいように画面の下に固定 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--surface-2);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; border-radius: 12px; padding: 6px 0; background: transparent; color: var(--muted);
  font-size: 0.75rem; font-weight: 600;
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] svg { stroke-width: 2.2; }
body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* カード（ひとまとまりの機能） */
.card { background: var(--surface); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-title { font-size: 1rem; margin: 0; }
.open-card .file-button { min-height: 64px; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; }
.open-card.compact .hint, .open-card.compact .song-help { display: none; }
.open-card.compact .file-button { min-height: 46px; font-size: 0.95rem; }
.settings-card { border-top: 1px solid var(--surface-2); padding-top: 8px; }
.settings-card summary, .song-help summary, .mini-help summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 4px 0; }
.settings-card[open] { display: flex; flex-direction: column; gap: 10px; }

/* 曲のプレイヤー（動画・コードの帯・今のコード・操作）：スクロールしても上に残す */
.player { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: calc(4px + env(safe-area-inset-top)) 0 6px; display: flex; flex-direction: column; gap: 6px; }
#song-result .song-media { max-height: 28vh; }
#song-result .song-media.audio-only { display: none; }
.now-row { display: flex; align-items: center; gap: 10px; }
.now-row .song-now { flex: 1; text-align: left; margin: 0; }
.edit-toggle { flex: none; }
.edit-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.edit-toggle span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--line); font-weight: 700; color: var(--text); }
.edit-toggle input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.edit-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#song-result.fixing .chord-strip, #song-result.fixing .song-chords, #song-result.fixing .sb-view { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 10px; }
.mini-help .hint { margin: 4px 0; }

/* 曲の画面の切り替え（コード・歌本・タブ譜） */
.subtabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface); border-radius: 12px; padding: 4px; }
.subtab { border: 0; border-radius: 9px; padding: 10px 0; background: transparent; color: var(--muted); font-size: 0.95rem; font-weight: 600; }
.subtab[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 700; }
#song-result .song-section[hidden] { display: none; }

main { max-width: 560px; margin: 12px auto 0; }

.panel { display: flex; flex-direction: column; gap: 12px; }
.panel[hidden] { display: none; }

.primary-button {
  border: 0;
  border-radius: 12px;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button.active { background: var(--surface-2); color: var(--text); }

.secondary-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  min-height: 42px;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}

.error { color: var(--error); margin: 0; }
.status { color: var(--muted); margin: 0; min-height: 1.4em; text-align: center; }

/* ---------- 結果 ---------- */
.result {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 16px;
  min-height: 132px;
}

/* 指板をスクロールしても結果が見えるように上に固定する */
.result.sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 0 0 8px var(--bg);
}

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.chord-name {
  font-size: clamp(2.2rem, 11vw, 3.2rem);
  font-weight: 800;
  line-height: 1.1;
  word-break: break-all;
}

.chord-name.empty { color: var(--muted); text-align: center; padding-top: 24px; }

.confidence { font-size: 1.2rem; color: var(--accent); font-weight: 700; }

.tones { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.tone {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

.tone b { font-size: 1.05rem; }
.tone small { color: var(--muted); }

.others { margin-top: 8px; color: var(--muted); font-size: 0.85rem; }
.other { color: var(--text); font-weight: 700; margin-right: 10px; }
.other small { color: var(--muted); font-weight: 400; }

/* ---------- 聞こえている音 ---------- */
.chroma {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
  height: 90px;
}

.bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.bar .fill {
  width: 100%;
  background: var(--accent);
  opacity: 0.8;
  transition: height 80ms linear;
  margin-bottom: 18px;
}

.bar small { position: absolute; bottom: 2px; font-size: 0.6rem; color: var(--muted); }

/* ---------- 指板の操作 ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

select.capo { width: auto; min-height: 42px; padding: 0 8px; }

.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.segmented button {
  border: 0;
  border-radius: 7px;
  padding: 0 12px;
  min-height: 34px;
  background: transparent;
  color: var(--muted);
}

.segmented button[aria-checked="true"] { background: var(--surface-2); color: var(--text); font-weight: 700; }

.settings { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }

select, input[type="text"] {
  font: inherit;
  font-size: 16px; /* iOS で入力時に拡大されないように */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  width: 100%;
}

#shape-input { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.1em; }

/* ---------- 指板 ---------- */
.fretboard { --cell: min(52px, calc((100vw - 32px - 28px) / 6)); }

.board { display: grid; justify-content: center; position: relative; }

.board.vertical {
  grid-template-columns: 28px repeat(6, var(--cell));
  grid-template-rows: 20px repeat(16, 44px);
}

.board.horizontal {
  grid-template-columns: 40px repeat(16, minmax(0, 1fr));
  grid-template-rows: repeat(6, 46px) 20px;
  justify-content: stretch;
}

.string-label, .fret-number {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.7rem;
}

.fret-number { font-size: 0.8rem; }

.cell {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

/* 弦（線）とフレット（区切り）。縦向きと横向きで向きを入れ替える */
.vertical .cell:not(.nut) {
  background:
    linear-gradient(to right, transparent calc(50% - 1px), var(--string) calc(50% - 1px), var(--string) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--fret-wood);
  border-bottom: 2px solid var(--fret-wire);
}
.vertical .nut { border-bottom: 6px solid var(--nut); }

.horizontal .cell:not(.nut) {
  background:
    linear-gradient(to bottom, transparent calc(50% - 1px), var(--string) calc(50% - 1px), var(--string) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--fret-wood);
  border-right: 2px solid var(--fret-wire);
}
.horizontal .nut { border-right: 6px solid var(--nut); }
.horizontal.lefty .cell:not(.nut) { border-right: 0; border-left: 2px solid var(--fret-wire); }
.horizontal.lefty .nut { border-right: 0; border-left: 6px solid var(--nut); }

.cell.muted { color: var(--error); font-size: 1.4rem; }

.dot, .open {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.dot { background: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 2px var(--bg); }
.open { border: 2px solid var(--text); }

/* ポジションマーク（3・5・7・9・12・15フレット）：弦をまたぐ帯の中に丸を置く */
.marker-band { position: relative; pointer-events: none; z-index: 2; }

.marker {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.vertical .marker { top: 50%; left: var(--pos); }
.horizontal .marker { left: 50%; top: var(--pos); }

/* ---------- コード名から探す ---------- */
.search-results { display: flex; flex-wrap: wrap; gap: 8px; }
.search-results:empty { display: none; }

.voicing {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
}

.voicing b { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.05em; }
.voicing small { color: var(--muted); font-size: 0.75rem; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }

.settings .check { flex-direction: row; align-items: center; gap: 8px; font-size: 0.95rem; color: var(--text); }
.check input { width: 20px; height: 20px; }

.approx {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

/* ---------- コードの履歴 ---------- */
.history-row { display: flex; align-items: center; gap: 8px; }

.history {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  padding: 4px 0;
  scrollbar-width: none;
}

.history-chord { background: var(--surface); border: 0; color: var(--text); border-radius: 8px; padding: 6px 10px; font-weight: 700; }
.history-chord:last-child { background: var(--surface-2); color: var(--accent); }
.arrow { color: var(--muted); }

/* ---------- チューナー ---------- */
.tuner { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.tuner-note-row { display: flex; align-items: baseline; gap: 12px; }
.tuner-note { font-size: 5rem; font-weight: 800; line-height: 1; }
.tuner-cents { font-size: 1.4rem; color: var(--muted); min-width: 3ch; }

.meter {
  --meter-color: var(--accent);
  position: relative;
  width: 100%;
  height: 64px;
  background: var(--surface);
  border-radius: 12px;
}

.meter.in-tune { --meter-color: var(--good); }

.meter::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: 22px;
  width: 2px;
  margin-left: -1px;
  background: var(--line);
}

.meter-scale {
  position: absolute;
  inset: auto 10px 4px;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
}

.needle {
  position: absolute;
  top: 6px;
  bottom: 20px;
  width: 6px;
  margin-left: -3px;
  left: calc(50% + (50% - 14px) * var(--cents, 0) / 50);
  border-radius: 3px;
  background: var(--meter-color);
  transition: left 100ms ease-out;
}

.meter.in-tune .needle { box-shadow: 0 0 12px var(--good); }

.tuner-freq { color: var(--muted); margin: 0; min-height: 1.2em; }

.tuner-strings { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: 100%; }

.tuner-string {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  background: var(--surface);
  border-radius: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}

.tuner-string small { color: var(--muted); font-weight: 400; font-size: 0.7rem; }
.tuner-string.active { background: var(--surface-2); color: var(--accent); }

/* ---------- タブレットなどの横長の画面 ---------- */
@media (orientation: landscape) and (min-width: 700px) {
  .app-header, main { max-width: 1100px; }

  .fret-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 12px 16px;
  }

  .fret-panel .result { grid-column: 1; grid-row: 1; position: static; box-shadow: none; }
  .fret-panel .toolbar { grid-column: 2; grid-row: 1; align-self: center; flex-wrap: wrap; }
  .fret-panel .fretboard { grid-column: 1 / -1; grid-row: 2; }
  .fret-panel .settings {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  .fret-panel .settings .search-results { grid-column: 1 / -1; }
}

/* スマホでもツールバーが1行に収まるよう、余白を詰める */
.toolbar { gap: 6px; }
.toolbar .secondary-button { padding: 0 8px; }
.toolbar .segmented button { padding: 0 7px; }
.toolbar select.capo { padding: 0 4px; }
.play-button { width: 46px; padding: 0; font-size: 1.1rem; color: var(--accent); }
.toolbar .clear { margin-left: auto; }

/* ---------- 曲（録画・音声ファイル）から ---------- */
.file-button { display: block; text-align: center; cursor: pointer; }
.song-mode { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }

.progress[hidden] { display: none; }
.progress-bar { height: 10px; border-radius: 5px; background: var(--surface); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 200ms; }

#song-result { display: flex; flex-direction: column; gap: 12px; }
#song-result[hidden] { display: none; }
.song-media { width: 100%; max-height: 40vh; border-radius: 12px; background: #000; }

.play-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.play-buttons .secondary-button { min-height: 46px; font-weight: 700; font-size: 0.9rem; white-space: normal; padding: 6px 8px; min-width: 0; }

.song-now { text-align: center; font-size: clamp(2.4rem, 12vw, 3.4rem); font-weight: 800; }

.song-section h2 { font-size: 1rem; margin: 8px 0; }
.song-section h2 small { color: var(--muted); font-weight: 400; font-size: 0.8rem; margin-left: 6px; }

.song-chords { display: flex; flex-wrap: wrap; gap: 6px; }

.song-chord {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.chord-seek {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 76px;
  padding: 6px 8px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.to-fret { border: 0; background: transparent; padding: 0 6px 6px; display: flex; justify-content: center; }
.chord-diagram { display: block; }
.chord-diagram .cd-line { stroke: var(--muted); stroke-width: 1; }
.chord-diagram .cd-nut { stroke: var(--text); stroke-width: 3; }
.chord-diagram .cd-dot { fill: var(--accent); }
.chord-diagram .cd-open { fill: none; stroke: var(--text); stroke-width: 1.2; }
.chord-diagram .cd-mark { fill: var(--error); font-size: 9px; text-anchor: middle; }
.chord-diagram .cd-fret { fill: var(--muted); font-size: 9px; }
.song-chord.active .cd-line { stroke: var(--text); }

.song-chord small { color: var(--muted); font-size: 0.7rem; }
.song-chord b { font-size: 1.1rem; }
.song-chord span { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 0.7rem; }
.song-chord.active { border-color: var(--accent); background: var(--surface-2); }
.song-chord.active b { color: var(--accent); }

.tab-blocks { display: flex; flex-direction: column; gap: 6px; }

.tab-block {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 10px;
  overflow-x: auto;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.35;
  cursor: pointer;
}

.tab-block.active { border-color: var(--accent); }

.song-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.song-actions .secondary-button { padding: 0 14px; }

.song-help { color: var(--muted); font-size: 0.85rem; }
.song-help summary { cursor: pointer; color: var(--text); }
.song-help ol { padding-left: 1.4em; }


/* ---------- 全弦チューナー ---------- */
.tuner-mode { align-self: center; }
.tuner-all[hidden], .tuner[hidden] { display: none; }
.tuner-all { display: flex; flex-direction: column; gap: 8px; }
#tuner-all-rows { display: flex; flex-direction: column; gap: 6px; }
.string-row { display: grid; grid-template-columns: 52px 1fr 96px; align-items: center; gap: 10px; background: var(--surface); border-radius: 10px; padding: 8px 10px; }
.string-row.missing { opacity: 0.5; }
.string-name { display: flex; flex-direction: column; font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.string-name small { color: var(--muted); font-weight: 400; font-size: 0.7rem; }
.mini-meter { position: relative; height: 18px; border-radius: 9px; background: var(--surface-2); }
.mini-meter::before { content: ""; position: absolute; left: 50%; top: 2px; bottom: 2px; width: 2px; margin-left: -1px; background: var(--line); }
.mini-needle { position: absolute; top: 2px; bottom: 2px; width: 6px; margin-left: -3px; border-radius: 3px; left: calc(50% + (50% - 6px) * var(--cents, 0) / 50); background: var(--accent); transition: left 120ms ease-out; }
.string-row.in-tune .mini-needle { background: var(--good); box-shadow: 0 0 8px var(--good); }
.string-row.missing .mini-needle { display: none; }
.string-cents { font-size: 0.85rem; text-align: right; color: var(--muted); }
.string-row.in-tune .string-cents { color: var(--good); font-weight: 700; }

/* ---------- 押さえ方チェック ---------- */
.shape-check { display: flex; flex-direction: column; gap: 8px; }
.check-button { min-height: 46px; font-weight: 700; }
.check-button.active { border-color: var(--accent); color: var(--accent); }
.check-results[hidden] { display: none; }
.check-results { background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.check-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.check-mark { display: flex; flex-direction: column; align-items: center; font-size: 1.4rem; font-weight: 800; }
.check-mark small { color: var(--muted); font-size: 0.7rem; font-weight: 400; }
.check-mark.ok { color: var(--good); }
.check-mark.missing, .check-mark.wrong, .check-mark.muted-ringing { color: var(--error); }
.check-mark.unsure, .check-mark.muted { color: var(--muted); }
.check-summary { margin: 8px 0 0; font-size: 0.9rem; }
.check-summary.good { color: var(--good); font-weight: 700; }
.check-summary.bad { color: var(--error); }

/* ---------- 練習（速さ・くり返し・キーとカポ） ---------- */
.practice-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.practice-row .speed { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.practice-row .speed select { width: auto; padding: 8px; }
.practice-row .secondary-button { min-height: 40px; }
.practice-row .secondary-button.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.practice-row .secondary-button:disabled { opacity: 0.4; }
.song-key[hidden] { display: none; }
.song-key { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 10px; }
.song-key b { font-size: 1.1rem; color: var(--accent); }

#mic-to-fret { min-height: 42px; }

/* ---------- 聞き取る距離 ---------- */
.mic-distance { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.mic-distance label { font-size: 0.9rem; font-weight: 700; }
.distance-row { display: flex; align-items: center; gap: 8px; }
.distance-row small { color: var(--muted); white-space: nowrap; }
.distance-row input { flex: 1; accent-color: var(--accent); }
.level-meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.level-meter span { display: block; height: 100%; width: 0; background: var(--good); transition: width 80ms linear; }
.mic-distance .hint { margin: 0; font-size: 0.78rem; }

/* ---------- シークバーに合わせたコードの帯 ---------- */
.chord-strip-wrap { margin-top: -4px; }
.chord-strip { overflow-x: auto; background: var(--surface); border-radius: 10px; cursor: pointer; scrollbar-width: thin; }
.strip-inner { position: relative; height: 64px; }
.strip-seg { position: absolute; top: 16px; height: 30px; border-radius: 6px; background: var(--surface-2); display: flex; align-items: center; padding: 0 6px; overflow: hidden; white-space: nowrap; font-size: 0.85rem; }
.strip-seg.alt { background: #34344a; }
.strip-seg.active { background: var(--accent); color: var(--accent-text); }
.strip-tick { position: absolute; bottom: 4px; width: 1px; height: 8px; background: var(--muted); }
.strip-tick.strum { height: 12px; width: 2px; background: var(--text); }
.strip-tick.legato { height: 10px; width: 2px; background: #4fc3f7; }
.tick-key { display: inline-block; width: 2px; height: 10px; margin: 0 3px 0 6px; vertical-align: middle; }
.strip-time { position: absolute; top: 1px; font-size: 0.65rem; color: var(--muted); transform: translateX(2px); }
.strip-head { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--error); box-shadow: 0 0 6px var(--error); pointer-events: none; }
.strip-hint { margin: 0; font-size: 0.75rem; }

/* 楽譜のようなタブ譜 */
.tab-block { padding: 6px 4px; font-family: inherit; overflow: visible; cursor: pointer; }
.tab-staff { display: block; width: 100%; height: auto; }
.tab-staff text { font-family: system-ui, -apple-system, sans-serif; }
.ts-line { stroke: var(--muted); stroke-width: 0.6; opacity: 0.7; }
.ts-bar { stroke: var(--text); stroke-width: 1; opacity: 0.8; }
.ts-name { fill: var(--muted); font-size: 8px; text-anchor: end; }
.ts-num { fill: var(--muted); font-size: 7px; }
.ts-chord { fill: var(--accent); font-size: 10px; font-weight: 700; }
.ts-bg { fill: var(--surface); }
.ts-fret { fill: var(--text); font-size: 10px; font-weight: 600; text-anchor: middle; }
.ts-stem { stroke: var(--muted); stroke-width: 1; }
.ts-stem.ts-strum { stroke: var(--text); stroke-width: 2; }
.ts-stem.ts-legato { stroke: #4fc3f7; stroke-width: 1.5; }
.ts-cursor { stroke: #ff5a5a; stroke-width: 1.5; }

/* AI（歌声を取り除く）のダウンロード */
.ai-panel { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--surface); border-radius: 10px; }
.ai-toggle { display: flex; gap: 8px; align-items: flex-start; font-size: 0.92rem; line-height: 1.4; }
.ai-toggle input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.ai-toggle:has(input:disabled) { opacity: 0.55; }
.ai-status { margin: 6px 0; font-size: 0.82rem; color: var(--muted, #9aa); }
.ai-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-buttons .secondary-button { min-height: 40px; padding: 0 14px; }
.ai-buttons [hidden] { display: none; }
.song-chord .real-name { display: block; font-size: 0.6rem; }

/* 歌本（歌詞の上にコード） */
#lyrics-input { width: 100%; box-sizing: border-box; font-size: 1rem; padding: 8px; border-radius: 8px; background: var(--surface); color: inherit; border: 1px solid var(--surface); }
.sb-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.sb-tools .secondary-button { min-height: 40px; padding: 0 12px; }
.sb-sync { margin: 8px 0; padding: 10px; border: 1px solid var(--accent); border-radius: 10px; }
.sb-next { font-size: 1.05rem; font-weight: 700; margin: 6px 0; }
.sb-tap { min-height: 56px; min-width: 140px; font-size: 1.1rem; font-weight: 700; border-radius: 12px; border: 0; background: var(--accent); color: #111; }
.sb-tap:disabled { opacity: 0.4; }
.sb-view { font-size: 1.15rem; line-height: 1; }
.sb-line { padding: 4px 4px 6px; border-radius: 8px; display: flex; flex-wrap: wrap; align-items: flex-end; row-gap: 4px; }
.sb-line.now { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.sb-line.untimed { opacity: 0.55; }
.sb-gap { height: 0.8em; }
.sb-seg { display: inline-flex; flex-direction: column; align-items: flex-start; }
.sb-chord { min-height: 1.2em; padding: 0 6px 2px 0; font-size: 0.85rem; font-weight: 700; color: #ff6b6b; background: none; border: 0; white-space: nowrap; line-height: 1.2; cursor: pointer; text-align: left; }
.sb-none { cursor: default; }
.sb-text { white-space: nowrap; }
.sb-char { display: inline-block; line-height: 1.3; }
.sb-tail { display: inline-flex; gap: 8px; margin-left: 10px; align-self: flex-start; }
.sb-view.moving .sb-char { outline: 1px dashed var(--muted); outline-offset: -1px; }
.sb-consent { margin-top: 10px; font-size: 0.82rem; }
.chord-edit { border: 1px solid var(--surface); border-radius: 12px; background: var(--bg, #15151c); color: inherit; max-width: 92vw; }
.chord-edit::backdrop { background: rgba(0,0,0,0.5); }
.chord-edit input { width: 100%; box-sizing: border-box; font-size: 1.1rem; padding: 8px; border-radius: 8px; border: 1px solid var(--surface); background: var(--surface); color: inherit; }
.chord-edit-cands { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chord-edit-cands .secondary-button { min-height: 36px; padding: 0 10px; }

/* コードを直す窓：画面の下から出す（指で押しやすいように） */
.chord-edit[open] { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: none; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.chord-edit h3 { margin: 0 0 10px; }
.chord-edit .song-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chord-edit .song-actions .secondary-button { min-height: 46px; }
#chord-edit-ok { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }

/* コードの画面のいちばん上：マイクで弾いて調べる（使っていないときはボタンだけ） */
.mic-card { padding: 10px; gap: 8px; }
.mic-card:not(.listening) #mic-result, .mic-card:not(.listening) #mic-to-fret, .mic-card:not(.listening) #mic-status { display: none; }
.mic-card:not(.listening) .history-row { display: none; }
.song-capo { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 8px; color: var(--muted); font-size: 0.85rem; }
.song-capo b { color: var(--text); }
.song-capo .secondary-button { padding: 4px 10px; font-size: 0.8rem; }

/* 譜面を保存・印刷 */
.icon-button { flex: none; min-width: 46px; min-height: 44px; border-radius: 22px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 1.2rem; }
.sheet-dialog { border: 0; border-radius: 16px; background: var(--surface); color: inherit; width: min(560px, 94vw); max-height: 92vh; padding: 14px; }
.sheet-dialog::backdrop { background: rgba(0,0,0,0.6); }
.sheet-head { display: flex; gap: 8px; }
.sheet-head input { flex: 1; font-size: 1.05rem; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: inherit; }
.sheet-pages { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; overflow: auto; margin: 8px 0; }
.sheet-pages img { width: 100%; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,0.4); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-actions button { min-height: 50px; }
.print-area { display: none; }
@media print {
  body { padding: 0 !important; background: #fff !important; }
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area { display: block !important; position: absolute; left: 0; top: 0; width: 100%; }
  .print-area img { display: block; width: 100%; page-break-after: always; break-after: page; }
  .bottom-nav, .banner { display: none !important; }
  @page { size: A4; margin: 0; }
}

/* よく使う「鳴らす」ボタンは、プレイヤーのすぐ下に大きく */
.quick-play { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-play .secondary-button { min-height: 48px; font-weight: 700; font-size: 0.92rem; white-space: normal; line-height: 1.2; }

/* ===== 作曲ツールのような編集画面 ===== */
.ed-transport { display: flex; align-items: center; gap: 10px; }
.ed-big { width: 58px; height: 58px; border-radius: 29px; border: 0; background: var(--accent); color: var(--accent-text); font-size: 1.5rem; font-weight: 900; flex: none; }
.ed-tb { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 1rem; flex: none; }
.ed-tb[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-2); }
.ed-speed { min-height: 40px; border-radius: 10px; flex: none; width: auto !important; max-width: 96px; padding: 0 8px; }
.ed-time { flex: 1; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.ed-mix { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; background: var(--surface); border-radius: 12px; padding: 8px 10px; font-size: 0.8rem; }
.ed-seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.ed-seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 0; font-size: 0.82rem; }
.ed-seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.ed-mix input[type="range"] { width: 100%; }
.ed-c-orig { color: #4fc3f7; } .ed-c-chord { color: #ff8a65; }
#ed-vol-orig { accent-color: #4fc3f7; } #ed-vol-chord { accent-color: #ff8a65; }

.ed-tracks { display: flex; border-radius: 12px; overflow: hidden; background: var(--surface); }
.ed-names { flex: 0 0 52px; display: flex; flex-direction: column; font-size: 0.7rem; color: var(--muted); border-right: 1px solid var(--surface-2); }
.ed-names span { display: flex; align-items: center; justify-content: center; border-top: 1px solid var(--surface-2); }
.ed-names .ed-n-ruler { height: 20px; border-top: 0; }
.ed-names span:nth-child(2) { height: 48px; } .ed-names span:nth-child(3) { height: 54px; } .ed-names span:nth-child(4) { height: 34px; } .ed-names span:nth-child(5) { height: 42px; }
.ed-scroller { flex: 1; overflow-x: auto; overflow-y: hidden; position: relative; -webkit-overflow-scrolling: touch; touch-action: pan-x; }
.ed-ruler { position: relative; height: 20px; font-size: 0.68rem; color: var(--muted); }
.ed-ruler span { position: absolute; top: 2px; padding-left: 3px; border-left: 1px solid var(--line); height: 18px; }
.ed-lane-body { position: relative; border-top: 1px solid var(--surface-2); background-image: linear-gradient(90deg, var(--surface-2) 1px, transparent 1px); }
.ed-wave { height: 48px; } .ed-wave svg { position: absolute; top: 2px; left: 0; } .ed-wave polygon { fill: #4fc3f7; opacity: 0.7; }
.ed-chords { height: 54px; }
.ed-lyrics { height: 34px; }
.ed-notes { height: 42px; } .ed-notes i { position: absolute; height: 4px; border-radius: 2px; background: #9ccc65; }
.ed-blk { position: absolute; top: 6px; bottom: 6px; border-radius: 8px; background: #3a3a4a; border: 1px solid #55556a; display: flex; align-items: center; padding: 0 7px; overflow: visible; white-space: nowrap; cursor: pointer; }
.ed-blk b { font-size: 0.95rem; overflow: hidden; text-overflow: clip; }
.ed-blk.sel { background: color-mix(in srgb, var(--accent) 32%, #2d2d39); border: 2px solid var(--accent); z-index: 2; }
.ed-h { position: absolute; top: 50%; width: 16px; height: 34px; margin-top: -17px; border-radius: 5px; background: var(--accent); touch-action: none; z-index: 3; }
.ed-h.l { left: -9px; } .ed-h.r { right: -9px; }
.ed-lyr { position: absolute; top: 8px; font-size: 0.78rem; color: #ddd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-empty { position: absolute; left: 8px; top: 9px; font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.ed-head { position: absolute; top: 0; bottom: 0; width: 2px; background: #ff5252; pointer-events: none; z-index: 4; }
.ed-panel { background: var(--surface); border-radius: 14px; padding: 10px; }
.ed-sel { margin: 0 0 8px; font-size: 0.8rem; color: var(--muted); } .ed-sel b { color: var(--text); font-size: 0.95rem; }
.ed-palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-pc { border: 1px solid transparent; border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 8px 0; font-size: 1.05rem; font-weight: 800; }
.ed-pc small { display: block; font-size: 0.65rem; color: var(--muted); font-weight: 600; }
.ed-pc.cur { border-color: var(--accent); color: var(--accent); }
.ed-variants { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }
.ed-var { flex: none; border: 1px solid var(--line); border-radius: 16px; background: transparent; color: var(--text); padding: 6px 12px; font-size: 0.9rem; }
.ed-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-tools button { border: 0; border-radius: 10px; background: var(--surface); color: var(--text); padding: 7px 0; font-size: 1.1rem; }
.ed-tools small { display: block; font-size: 0.65rem; color: var(--muted); }
.tab-play { min-height: 46px; width: 100%; margin-bottom: 8px; font-weight: 700; }
#song-result .song-media:not(.audio-only) { max-height: 22vh; }
.ocr-button { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; cursor: pointer; }

/* ===== 歌詞にコードを置く画面（全画面） ===== */
.sb-place { width: 100%; min-height: 52px; font-size: 1.05rem; }
body.se-open { overflow: hidden; }
.se-root { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: flex; flex-direction: column; }
.se-root[hidden] { display: none; }
.se-head { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; border-bottom: 1px solid var(--surface-2); }
.se-head b { flex: 1; font-size: 1rem; }
.se-hb { min-width: 44px; min-height: 40px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 1rem; }
.se-done { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 800; padding: 0 16px; }
.se-help { font-size: 0.78rem; color: var(--muted); padding: 6px 12px 0; line-height: 1.5; }
.se-help b { color: var(--text); }
.se-actions { display: flex; gap: 8px; padding: 6px 12px; }
.se-auto { border: 1px solid var(--line); border-radius: 16px; background: transparent; color: var(--text); padding: 6px 12px; font-size: 0.85rem; }
.se-lines { flex: 1; overflow-y: auto; padding: 14px 12px 40px; -webkit-overflow-scrolling: touch; }
.se-line { display: flex; flex-wrap: wrap; align-items: flex-end; padding: 2px 0 10px; border-bottom: 1px dashed var(--surface-2); }
.se-gap { height: 18px; }
.se-ch { display: inline-flex; flex-direction: column; align-items: center; min-width: 1.35em; padding: 0 1px; border-radius: 6px; cursor: pointer; }
.se-ch.sel { background: color-mix(in srgb, var(--accent) 25%, transparent); outline: 2px solid var(--accent); }
.se-ch.target { background: color-mix(in srgb, #4fc3f7 30%, transparent); outline: 2px solid #4fc3f7; }
.se-slot { height: 30px; display: flex; align-items: flex-end; justify-content: flex-start; width: 100%; position: relative; }
.se-t { font-size: 1.45rem; line-height: 1.3; }
.se-chip { display: inline-flex; align-items: center; justify-content: center; min-height: 28px; padding: 0 8px; border-radius: 8px; font-weight: 800; white-space: nowrap; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.se-chip.placed { position: absolute; left: 0; bottom: 1px; background: #ff6b6b; color: #fff; font-size: 0.95rem; z-index: 1; box-shadow: 0 1px 4px rgba(0,0,0,0.4); }
.se-tail { display: inline-flex; gap: 6px; margin-left: 10px; align-self: flex-start; margin-top: 4px; }
.se-after { color: #ff8a80; font-weight: 800; font-size: 0.95rem; }
.se-tray { border-top: 1px solid var(--surface-2); background: var(--surface); padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); transition: background 0.15s; }
.se-tray.drop-del { background: #5a2323; }
.se-tray.drop-del .se-tray-label::after { content: '　← ここで離すと消えます'; color: #ff8a80; }
.se-tray-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.se-chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 128px; overflow-y: auto; }
.se-chip.tray { min-height: 44px; min-width: 56px; font-size: 1.1rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.se-plus { font-size: 0.9rem !important; color: var(--muted) !important; }
.se-ghost { position: fixed; z-index: 80; transform: translate(-50%, -50%); padding: 8px 14px; border-radius: 10px; background: #ff6b6b; color: #fff; font-weight: 900; font-size: 1.2rem; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,0.5); }
.se-pop { position: fixed; z-index: 85; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); max-width: 92vw; }
.se-pop[hidden] { display: none; }
.se-pop-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.se-pop-row b { font-size: 1.1rem; margin-right: 4px; }
.se-pop button { min-height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 0.95rem; }
.se-root { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
