/* スケール帳(/scale/<id>)とレッスン(/lesson/<slug>)の3Dのステージ・操作・指板の図。
   色・書体・カードは pages.css(ガイド記事と同じ)。骨組みはコード帳(index.html)と同じ:
   スマホは ヘッダー → 3D → 選ぶバー → 下のタブ、パソコンは 左に3D・右に選ぶバー。再生の設定はシート(スマホ)・3Dに重ねるパネル(パソコン) */
.scale-page { width: 100%; max-width: 1280px; margin: 0 auto; display: grid; gap: 14px; align-content: start; padding-top: 8px; }
.scale-page h1 { margin: 2px 0 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(1.3rem, 1.05rem + 1.2vw, 1.85rem); line-height: 1.35; letter-spacing: .02em; text-wrap: balance; }
.scale-page h1 .h1-sub { display: block; margin-top: 4px; font-family: var(--font-body); font-weight: 700; font-size: .52em; letter-spacing: .02em; color: var(--muted); }
/* (下の文章は読みやすい幅に) */
.scale-page > .scale-doc, .scale-page > .other-scales, .scale-page > .lesson-next { width: 100%; max-width: 1080px; justify-self: center; box-sizing: border-box; }

/* パソコン: 左に3D、右に選ぶバー(レッスンは目標と練習メニューも) */
.play-area { display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 28vw, 400px); grid-template-areas: "stage side"; gap: 16px; align-items: start; }
.stage-wrap { grid-area: stage; position: relative; min-width: 0; }
.side { grid-area: side; display: grid; gap: 12px; align-content: start; min-width: 0; }
.side > * { margin: 0; }

/* ステージ(コード帳と同じ) */
.stage { position: relative; height: clamp(420px, calc(100vh - 210px), 720px); background: var(--stage); border-radius: var(--radius); overflow: hidden; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.hud { position: absolute; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-name { top: 14px; left: 18px; right: 300px; display: grid; gap: 4px; justify-items: start; }
.step-badge { font-size: .7rem; font-weight: 700; letter-spacing: .1em; color: var(--brass); background: var(--brass-soft); border-radius: 999px; padding: 0 9px; }
.scale-name { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(1.4rem, 3.2vw, 2.3rem); line-height: 1.1; }
.scale-full { color: var(--muted); font-size: .86rem; }
.hud-views { top: 14px; right: 14px; }
.seg { display: flex; flex-wrap: wrap; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; backdrop-filter: blur(6px); }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; font: inherit; font-size: .8rem; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button small { margin-left: 5px; font-family: var(--font-mono); font-size: .7rem; opacity: .8; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.hud-views .seg button { min-height: 36px; }
.v-long { display: inline; }
/* 今鳴らしている音 */
.now-note { left: 50%; bottom: 74px; transform: translateX(-50%); display: flex; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 24px);
  background: var(--ink); color: var(--surface); padding: 5px 16px; border-radius: 999px; font-size: .84rem; white-space: nowrap; }
.now-note b { font-size: 1.05rem; }
.now-note span:nth-of-type(1) { font-family: var(--font-mono); font-weight: 700; }
/* 3Dの下の操作: 1音もどる・再生・1音すすむ ｜ 再生の設定 */
.hud-play { left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; }
.stage .btn { padding: 8px 16px; font-size: .88rem; min-height: 44px; }
.btn.round { width: 44px; height: 44px; padding: 0; justify-content: center; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:disabled { opacity: .4; cursor: default; }
#play { min-width: 8.5em; justify-content: center; }
#play .i-pause, #play[aria-pressed="true"] .i-play { display: none; }
#play[aria-pressed="true"] .i-pause { display: block; }
.hud-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.icon-btn[aria-expanded="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.stage-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; pointer-events: none; }
.fallback { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
@media (max-width: 1180px) {
  /* 再生の設定はアイコンだけ */
  .hud-play .icon-btn { width: 44px; padding: 0; justify-content: center; }
  .hud-play .icon-btn .btn-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---- 選ぶバー(スケール帳: キー・ポジション・スケール、レッスン: レッスン・パターン) ---- */
.pick { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.pick-line { display: grid; gap: 6px; min-width: 0; }
.pick-label { font-size: .72rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; white-space: nowrap; }
.pick-row { position: relative; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.key-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.pick-row > button, .pick-row > a { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; min-height: 44px; min-width: 44px; padding: 2px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 700; line-height: 1.2; text-decoration: none; cursor: pointer; box-sizing: border-box; }
.pick-row > button:hover, .pick-row > a:hover { border-color: var(--muted); }
.key-row > button { font-family: var(--font-mono); padding-inline: 4px; }
.pick-row > button small, .pick-row > a small { margin: 0; font-family: var(--font-mono); font-size: .66rem; font-weight: 500; opacity: .8; }
.pick-row > [aria-pressed="true"], .pick-row > [aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.pick-scale { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.pick-scale:hover { border-color: var(--muted); }
.pick-scale b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.pick-change { color: var(--brass); font-weight: 700; font-size: .86rem; white-space: nowrap; }
.pick-toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

/* ---- 再生の設定・スケールの一覧(シート。開け閉めは playui.js) ---- */
.sheet:not(.is-open) { display: none; }
.sheet-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 79; background: rgba(8, 10, 14, .5); }
.sheet-head { display: flex; align-items: center; gap: 8px; width: 100%; }
.sheet-grip { display: none; }
.sheet-head b { flex: 1; font-size: .95rem; }
.sheet-close { flex: none; width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--bg); color: var(--ink); font-size: 1.2rem; line-height: 1; cursor: pointer; }
.sheet-sub { flex-basis: 100%; width: 100%; margin: 2px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: .72rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; }
.scale-sheet-list h3:first-child { margin-top: 4px; }
.scale-sheet-list ul { gap: 6px; }
.scale-sheet-list a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink); text-decoration: none; }
.scale-sheet-list a:hover { border-color: var(--muted); }
.scale-sheet .scale-sheet-list a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
@media (min-width: 768px) {
  /* 再生の設定: 3Dの右下に重ねて開く(コード帳の表示の設定と同じ) */
  .panel.sheet.is-open { position: absolute; right: 14px; bottom: 72px; z-index: 7; width: min(480px, calc(100% - 28px)); max-height: calc(100% - 140px); overflow-y: auto; box-sizing: border-box;
    box-shadow: 0 14px 36px color-mix(in srgb, var(--ink) 18%, transparent); border-radius: 14px; padding: 14px 16px; gap: 10px 18px; }
  :root[data-handed="left"] .panel.sheet.is-open { right: auto; left: 14px; }
  /* スケールの一覧: 画面の真ん中に、後ろを暗くして */
  .scale-sheet.is-open { display: grid; gap: 8px; position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 80; width: min(680px, calc(100vw - 48px)); max-height: 82vh; overflow-y: auto; box-sizing: border-box;
    background: var(--surface); border-radius: 16px; padding: 16px 20px 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
}

/* 操作のパネル(再生の設定の中) */
.panel { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tool { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.tool-label { font-size: .72rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; min-width: 4.5em; }
.panel .seg { background: var(--bg); backdrop-filter: none; }
.panel.sheet .tool { width: 100%; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); cursor: pointer; min-height: 32px; }
.toggle input { accent-color: var(--brass); margin: 0; width: 18px; height: 18px; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); padding: 0; cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }
.swatch-sep { width: 1px; height: 20px; background: var(--line); }
.look { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); border-radius: 14px; padding: 2px 10px 2px 3px; font: inherit; font-size: .78rem; cursor: pointer; }
.look[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.look i { width: 20px; height: 20px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 18%, transparent); }
.look-clear i { background: linear-gradient(rgba(220, 159, 120, .55), rgba(220, 159, 120, .55)), repeating-conic-gradient(var(--line) 0 25%, var(--surface) 0 50%) 0 0 / 8px 8px; }
.panel-foot { flex-basis: 100%; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; }
.spec, .hint { margin: 0; font-size: .74rem; color: var(--muted); }
.spec { font-family: var(--font-mono); }
kbd { font-family: var(--font-mono); font-size: .7rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--bg); color: var(--ink); }
@media (hover: none) { .hint { display: none; } }

/* 指板全体の図(scalebook.js の ScaleBook.svg)。細い画面では横にスクロール */
.fretmap { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 8px; display: grid; gap: 6px; }
.fretmap-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fb { display: block; width: 100%; min-width: 760px; height: auto; }
.fb-board { fill: color-mix(in srgb, var(--brass) 10%, var(--surface)); }
.fb-pos { fill: var(--brass-soft); stroke: var(--brass); stroke-width: 1.5; }
.fb-fret { stroke: var(--muted); stroke-width: 1.4; opacity: .7; }
.fb-nut { stroke: var(--ink); stroke-width: 5; }
.fb-str { stroke: var(--muted); }
.fb-inlay { fill: var(--line); }
.fb-num { fill: var(--muted); font: 600 11px var(--font-mono); text-anchor: middle; }
.fb-dot circle { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.fb-dot text { fill: var(--ink); font: 700 10px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.fb-root circle { fill: #d23a3a; stroke: #d23a3a; }
.fb-root text { fill: #fff; }
.fb-dim { opacity: .3; }
.fretmap figcaption { font-size: .76rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; }
.fretmap figcaption span { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; }
.fretmap figcaption em { font-style: normal; }
.fm-root { background: #d23a3a; }
.fm-note { background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink); }
.fm-dim { background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink); opacity: .3; }

/* 下の文章 */
.scale-doc h2 { margin: 22px 0 8px; font-size: 1.12rem; line-height: 1.4; }
.scale-doc h2:first-child { margin-top: 0; }
.scale-doc h3 { margin: 18px 0 6px; font-size: 1rem; }
.scale-doc p, .scale-doc ul, .scale-doc ol { margin: 0 0 10px; max-width: 42em; }
.scale-doc ul, .scale-doc ol { padding-left: 1.3em; }
.scale-doc li + li { margin-top: 4px; }
.scale-doc table { min-width: 0; }
.scale-doc td:first-child { font-weight: 700; font-family: var(--font-mono); }
.chord-list span { margin-left: .6em; font-size: .86rem; color: var(--muted); }
.chord-list a { font-family: var(--font-mono); font-weight: 700; }
.pos-steps b { font-family: var(--font-mono); }
.other-scales h2 { margin: 0 0 10px; font-size: 1.05rem; }
.other-scales h3 { margin: 12px 0 4px; font-size: .78rem; letter-spacing: .1em; color: var(--muted); }
.other-scales ul { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; padding: 0; list-style: none; font-size: .9rem; }
.other-scales a[aria-current="page"] { color: var(--ink); font-weight: 700; text-decoration: none; }

/* ---- レッスン(/lesson/<slug>) ---- */
/* 目標(3Dの下) */
.goal { display: flex; align-items: baseline; gap: 10px; margin: 0; padding: 12px 14px; border-radius: var(--radius); background: var(--brass-soft); color: var(--ink); font-size: .92rem; line-height: 1.7; }
.goal b { flex: none; font-size: .72rem; letter-spacing: .12em; color: var(--brass); }
/* パターンの切り替え(レッスン2) */
.pattern-row > button { align-items: flex-start; text-align: left; padding: 6px 12px; }
.pattern-row > button small { font-family: inherit; font-size: .7rem; }
.shift-btn { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 5px 14px; min-height: 40px; font: inherit; font-size: .8rem; font-weight: 700; cursor: pointer; }
.shift-btn[aria-pressed="true"] { background: var(--brass-soft); border-color: var(--brass); }
/* 練習メニュー(3Dの下) */
.practice-card h2 { margin: 0 0 10px; font-size: 1.02rem; line-height: 1.4; }
.practice { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.practice li + li { margin-top: 0; }
.practice label { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; font-size: .92rem; line-height: 1.6; }
.practice input { accent-color: var(--brass); width: 18px; height: 18px; margin: 2px 0 0; flex: none; }
.practice input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.practice-done { margin: 10px 0 0; font-weight: 700; color: var(--brass); }
.lesson-next { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.lesson-next .btn { text-decoration: none; }
.scale-doc td.hl { color: var(--brass); }

/* タブレット(768〜1023px): 3Dを全幅にして、その下に選ぶバーなど */
@media (max-width: 1023px) {
  .play-area { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "side"; }
  .stage { height: clamp(380px, 60vh, 600px); }
  .key-row { grid-template-columns: repeat(12, minmax(0, 1fr)); }
}

/* ===== スマホ(幅 768px 未満): 3D → 選ぶバー → 下のタブで1画面。再生の設定・スケールの一覧は下から出るシート ===== */
@media (max-width: 767px) {
  .scale-page { gap: 10px; padding-top: 2px; }
  .scale-page h1 { font-size: 1.05rem; line-height: 1.4; }
  .scale-page h1 .h1-sub { display: none; }
  .play-area { gap: 10px; }
  .stage { height: 380px; border-radius: 20px; }
  /* 3Dの上: 左にスケール名、右に視点 */
  .hud-name { top: 12px; left: 14px; right: 168px; gap: 2px; }
  /* (名前はすぐ上の見出しにあるので、3Dの上はキーとポジションだけ) */
  .scale-name { display: none; }
  .scale-full { font-size: .76rem; }
  .step-badge { font-size: .64rem; }
  .hud-views { top: 10px; right: 10px; }
  .hud-views .seg { padding: 2px; }
  .hud-views .seg button { padding: 0 9px; font-size: .78rem; }
  .v-long { display: none; }
  .now-note { bottom: 66px; font-size: .78rem; padding: 4px 12px; gap: 2px 10px; }
  .hud-play { bottom: 10px; left: 10px; right: 10px; transform: none; justify-content: center; }
  .hud-sep { display: none; }
  #play { min-width: 7.5em; }
  /* 選ぶバー: 1行ずつ、横にスクロール */
  .pick { gap: 8px; padding: 10px 0 12px; border-radius: 16px; }
  .pick-line { grid-template-columns: 5.2em minmax(0, 1fr); align-items: center; gap: 0; padding-left: 12px; }
  .pick-row, .key-row { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; padding-right: 12px; }
  .pick-row::-webkit-scrollbar { display: none; }
  .pick-row > button, .pick-row > a { flex: none; }
  .pick-scale { margin-inline: 12px; min-height: 44px; padding: 0 12px; }
  .pick-toggles { padding-inline: 12px; }
  .pattern-row > button { max-width: 15em; }
  /* シート */
  html.sheet-open, html.sheet-open body { overflow: hidden; }
  .sheet.is-open, .panel.sheet.is-open { display: grid; align-content: start; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; max-height: 86vh; max-height: 86dvh; overflow-y: auto; overscroll-behavior: contain;
    margin: 0; border-radius: 20px 20px 0 0; border: 0; background: var(--surface); box-shadow: 0 -12px 40px rgba(0, 0, 0, .25); gap: 14px;
    padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    animation: sheet-up .22s ease-out; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
  .sheet-head { display: grid; grid-template-columns: 44px 1fr 44px; position: sticky; top: 0; z-index: 2; background: var(--surface); padding: 14px 0 8px; gap: 0; }
  .sheet-grip { display: block; grid-column: 1 / -1; justify-self: center; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin-bottom: 8px; }
  .sheet-head b { grid-column: 2; text-align: center; font-size: 1rem; }
  .sheet-close { grid-column: 3; width: 44px; height: 44px; font-size: 1.4rem; }
  .panel.sheet .seg button { min-height: 40px; }
  .swatch { width: 32px; height: 32px; }
  .scale-sheet-list a { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) { .sheet.is-open { animation: none !important; } }
