:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #1c2024;
    --muted: #6b7280;
    --line: #d9dde3;
    --accent: #1f618d;
    --accent-soft: rgba(31, 97, 141, 0.16);
    --gutter-bg: #f2f4f7;
    --hover: #f3f5f8;
    --active: #e8ecf1;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Noto Sans Mono", monospace;
    --danger: #c0392b;
    /* lint の警告。赤 (--danger) はエラー用に取ってあるので、
       「入力は受け付けた上での助言」と分かる黄/橙にする */
    --warning: #b7791f;
    --radius: 8px;
    /* 指板/コード図で弦とフレットの線に使う灰色。2つの図が別々に持つと
       ずれるので1箇所にまとめる */
    --string: #8a9099;
    /* 指板の列。fretboard.rs の MAX_FRET + 1 (弦名の列 + 0-12fr の
       13列) と噛み合わせる必要がある */
    --fretboard-cols: 56px repeat(13, 34px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
        "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

/* ---- ヘッダ ---- */

.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.app-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.app-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.app-tagline {
    color: var(--muted);
    font-size: 12px;
}

.app-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--panel);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(16, 24, 40, 0.07);
}

.footer-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px 20px;
}

midi-player {
    display: block;
    width: 100%;
}

midi-visualizer {
    display: block;
    /* ピアノロールの高さは曲の音域で決まるので固定値だと足りない。
       64px 固定にしていたときは中身 126px が切り取られ、低い音が
       見えなかった。上限まで content に合わせ、超えたらスクロールする */
    height: auto;
    max-height: 144px;
    /* ピアノロールは縦にも横にも伸びるので両方スクロールで見られるようにする */
    overflow: auto;
    /* 再生するまで中身は空なので、描画抜けに見えないよう下地を敷く */
    background: var(--gutter-bg);
    border-bottom: 1px solid var(--line);
}

midi-visualizer.is-empty {
    height: 0;
    max-height: 0;
    border-bottom: none;
}

.app-footer > midi-visualizer {
    border-bottom: 1px solid var(--line);
}

/* ---- タブ ---- */

.tabs {
    display: flex;
    gap: 4px;
    padding: 0 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.tab {
    appearance: none;
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
}

.tab:hover {
    color: var(--ink);
}

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

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;
}

/* ---- パネル ---- */

.panel {
    max-width: 1100px;
    margin: 0 auto;
    /* 固定フッタのぶんを空けておく。フッタの最大の高さは
       ピアノロール 144 + 境界 1 + プレイヤー 79 = 224 */
    padding: 20px 20px 240px;
}

.editor-wrap {
    display: flex;
    align-items: stretch;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.editor-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.gutter {
    flex: none;
    width: 44px;
    padding: 10px 8px 10px 0;
    background: var(--gutter-bg);
    border-right: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.7;
    text-align: right;
    overflow: hidden;
    user-select: none;
}

.gutter-line {
    height: calc(13px * 1.7);
}

/* パースが止まった行 */
.gutter-line.is-error {
    background: var(--danger);
    color: #fff;
    font-weight: 600;
}

.editor {
    flex: 1;
    min-width: 0;
    display: block;
    padding: 10px 12px;
    background: transparent;
    color: inherit;
    border: none;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.7;
    tab-size: 2;
    resize: vertical;
    overflow-x: auto;
}

.editor:focus {
    outline: none;
}

.editor::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

.editor::selection {
    background: var(--accent-soft);
}

.error {
    margin: 8px 0 0;
    padding: 8px 12px;
    background: #fdecea;
    border-left: 3px solid var(--danger);
    border-radius: 0 4px 4px 0;
    color: var(--danger);
    /* 本文の下に `^` を並べて列を指すので等幅にする */
    font-family: var(--mono);
    font-size: 13px;
    white-space: pre-wrap;
}

/* .error と同じ形だが、色だけ変えて「エラーではなく助言」に見せる。
   警告が出ていても再生は止まらない */
.warning {
    margin: 8px 0 0;
    padding: 8px 12px;
    background: #fdf6e3;
    border-left: 3px solid var(--warning);
    border-radius: 0 4px 4px 0;
    color: var(--warning);
    font-size: 13px;
    white-space: pre-wrap;
}

/* ---- コントロール ---- */

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 24px;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field > label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.field-value {
    min-width: 3ch;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.block {
    margin-top: 16px;
}

.block-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

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


/* ---- ボタン ---- */

.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 1px 1px rgba(16, 24, 40, 0.04);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease,
        box-shadow 0.12s ease, transform 0.06s ease;
}

.btn:hover:not(:disabled) {
    background: var(--hover);
    border-color: #c2c9d2;
}

.btn:active:not(:disabled) {
    background: var(--active);
    box-shadow: none;
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn:disabled {
    background: var(--bg);
    color: var(--muted);
    box-shadow: none;
    cursor: default;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(31, 97, 141, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: #1a5378;
    border-color: #1a5378;
    color: #fff;
}

.btn-primary:active:not(:disabled) {
    background: #164764;
    border-color: #164764;
}

/* 進行プリセットは名前とディグリーの2段。.btn の height と align-items を
   上書きするので、必ず .btn より後ろに置く */
.preset {
    height: auto;
    min-height: 30px;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 5px 12px;
}

.preset-name {
    font-weight: 600;
    line-height: 1.3;
}

.preset-degrees {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10px;
    line-height: 1.3;
}

.preset:hover .preset-degrees {
    color: inherit;
}

/* キーの ♭ / ♯ は記号だけの正方形ボタン */
.btn-icon {
    width: 30px;
    padding: 0;
    font-size: 15px;
}

/* ---- セレクト ---- */

select {
    appearance: none;
    height: 30px;
    padding: 0 28px 0 10px;
    background-color: var(--panel);
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    color: inherit;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 1px 1px rgba(16, 24, 40, 0.04);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

select:hover {
    border-color: #c2c9d2;
}

select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- スライダ ---- */

input[type="range"] {
    appearance: none;
    width: 160px;
    height: 18px;
    background: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(
        to right,
        var(--accent) 0 var(--fill, 50%),
        var(--line) var(--fill, 50%) 100%
    );
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    background: var(--panel);
    border: 2px solid var(--accent);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
}

input[type="range"]:active::-webkit-slider-thumb {
    background: var(--accent);
}

input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--line);
}

input[type="range"]::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--panel);
    border: 2px solid var(--accent);
}

input[type="range"]:focus-visible {
    outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- ループ再生のスイッチ ---- */

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.switch > input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-track {
    position: relative;
    width: 34px;
    height: 20px;
    flex: none;
    border-radius: 10px;
    background: #cbd2da;
    transition: background 0.15s ease;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.3);
    transition: transform 0.15s ease;
}

.switch > input:checked + .switch-track {
    background: var(--accent);
}

.switch > input:checked + .switch-track::after {
    transform: translateX(14px);
}

.switch > input:focus-visible + .switch-track {
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.switch-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.switch > input:checked ~ .switch-label {
    color: var(--ink);
}

.ast {
    margin-top: 20px;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.ast > summary,
.side-panel > summary,
.syntax-ref > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.ast > summary::-webkit-details-marker,
.side-panel > summary::-webkit-details-marker,
.syntax-ref > summary::-webkit-details-marker {
    display: none;
}

.ast > summary::before,
.side-panel > summary::before,
.syntax-ref > summary::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 5px solid var(--muted);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.12s ease;
}

.ast[open] > summary::before,
.side-panel[open] > summary::before,
.syntax-ref[open] > summary::before {
    transform: rotate(90deg);
}

.ast > summary:hover,
.side-panel > summary:hover,
.syntax-ref > summary:hover {
    color: var(--ink);
}

.ast > pre {
    margin: 8px 0 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
    white-space: pre-wrap;
}

/* 解釈結果の表示3択。.btn-icon の正方形を打ち消してラベル幅に合わせる */
.ast-forms {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.ast-forms .btn {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
}

/* .is-active の見た目は .tab 側にしか無いので、ここで別に当てる */
.ast-forms .btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.ast-forms .btn.is-active:hover {
    background: #1a5378;
    border-color: #1a5378;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 48px 0;
}

/* ---- 押さえ方ダイアグラム ---- */

.fingerings {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 14px 0;
}

/* 1小節分のカードをまとめ、右端に小節線を引く */
.measure {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px;
    border-right: 2px solid var(--line);
}

.measure-cards {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* pat() が掛かっている小節に、そのリズムをそのまま出す */
.rhythm {
    min-height: 15px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 15px;
    letter-spacing: 2px;
    color: var(--muted);
}

/* $定義 から展開された小節。名前は範囲の先頭だけに出し、
   続きは下線で「どこまでか」を示す。枠は常に置いて上端を揃える */
.section {
    min-height: 15px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 15px;
    color: var(--accent);
    font-weight: 600;
    border-bottom: 2px solid transparent;
}

.measure.in-section .section {
    border-bottom-color: var(--accent-soft);
}

/* 入力の改行位置でカードの並びを折り返す */
.line-break {
    flex-basis: 100%;
    height: 0;
}

.chord-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 3px solid var(--chord-color, var(--ink));
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chord-name {
    color: var(--chord-color, var(--ink));
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
    text-align: center;
    /* 別名が付いて長くなったら折り返す。カード幅は図に合わせて揃える */
    max-width: 124px;
}

.chord-alias {
    color: var(--muted);
    font-size: 10px;
    font-weight: 400;
}

.diagram {
    display: flex;
    flex-direction: column;
    margin-top: 6px;
}

.grid {
    display: grid;
    grid-template-columns: 14px repeat(5, 22px);
    grid-auto-rows: 16px;
}

.marker {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
}

/* 弦はセルの中央を横切る線、フレットはセルの右の縦線 */
.cell {
    position: relative;
    border-right: 1px solid var(--string);
    background: linear-gradient(var(--string), var(--string)) 0 50% / 100% 1px no-repeat;
}

.cell.nut {
    border-left: 3px solid var(--ink);
}

/* ナットより先から描き始めるときの左端はただのフレット線 */
.cell.edge {
    border-left: 1px solid var(--string);
}

.dot {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    font-size: 9px;
    line-height: 14px;
    text-align: center;
}

/* 指板の下のフレット番号。実ギターのポジションマークと同じ位置に出す */
.fret-numbers {
    display: grid;
    grid-template-columns: 14px repeat(5, 22px);
    margin-top: 3px;
}

.fret-number {
    color: var(--muted);
    font-size: 9px;
    line-height: 1.2;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* 押さえ方が無いときも幅と高さを揃えて並びを崩さない */
.diagram-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 124px;
    height: 96px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    border: 1px dashed var(--line);
    border-radius: 4px;
}

/* ---- 指板（逆引き）: エディタタブの textarea の下 ---- */

.fretboard-help {
    color: var(--muted);
    font-size: 12px;
    margin: 0 0 12px;
}

/* 12フレットぶんは横に長いので、狭い画面では横スクロールさせる */
.fretboard-scroll {
    overflow-x: auto;
    padding-bottom: 4px;
}

.fretboard-grid {
    display: grid;
    grid-template-columns: var(--fretboard-cols);
    grid-auto-rows: 28px;
    width: max-content;
}

/* 横スクロールしても弦名の列だけは見えたままにする */
.fretboard-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 8px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
}

/* fretboard-numbers 側の左端スペーサ。fretboard-label と同じ幅ぶんを固定する */
.fretboard-numbers-spacer {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
}

.fretboard-value {
    color: var(--ink);
    font-family: var(--mono);
    font-size: 12px;
}

/* 弦はセルの中央を横切る線、フレットはセルの右の縦線。
   実体は <button> なので、地の見た目を消して線の描画だけ残す */
.fretboard-cell {
    position: relative;
    cursor: pointer;
    appearance: none;
    padding: 0;
    font: inherit;
    border-top: 0;
    border-bottom: 0;
    border-radius: 0;
    border-right: 1px solid var(--string);
    background: linear-gradient(var(--string), var(--string)) 0 50% / 100% 1px no-repeat;
}

.fretboard-cell:hover {
    background-color: var(--hover);
}

/* 0列は開放弦。ナットの左なのでフレット線は引かない */
.fretboard-cell.is-open {
    border-right: none;
}

.fretboard-cell.is-nut {
    border-left: 3px solid var(--ink);
}

.fretboard-dot {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    /* 指が分かっている形では中に「人/中/薬/親」が入る。
       自分で押した形は空のまま */
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    text-align: center;
}

.fretboard-numbers {
    display: grid;
    grid-template-columns: var(--fretboard-cols);
    width: max-content;
    margin-top: 3px;
}

.fretboard-number {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.fretboard-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fretboard-card {
    min-width: 200px;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.fretboard-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.fretboard-card-name {
    font-weight: 700;
    font-size: 15px;
}

.fretboard-badge {
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--active);
    color: var(--muted);
    font-size: 10px;
    line-height: 1.6;
}

.fretboard-badge.is-data {
    background: var(--accent-soft);
    color: var(--accent);
}

.fretboard-alias {
    color: var(--muted);
    font-size: 11px;
}

.fretboard-card-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}

.fretboard-notation {
    font-family: var(--mono);
    font-size: 13px;
}

.fretboard-note {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

/* ---- エディタタブの2段組と記法パネル ---- */

.editor-tab {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 280px);
    gap: 16px;
    align-items: start;
}

/* textarea が grid の列をはみ出さないようにする */
.editor-main {
    min-width: 0;
}

.side-panel {
    padding: 8px 12px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    /* エディタを見ながら使う。フッタのプレイヤーのぶんを引いて収める */
    position: sticky;
    top: 12px;
    /* パネルの実際の上端はヘッダとタブのぶん約 118px 下にあるので、
       ビューポート上端から引くだけでは足りない。フッタは高さが変わる
       (ピアノロールが出ると伸びる) ので最大の 224px を見込む。
       118 + 224 + 余白 で 360px 引く */
    max-height: calc(100vh - 360px);
    overflow-y: auto;
}

.side-panel-body > .block:first-child {
    margin-top: 8px;
}

/* ---- 記法パネル: 関数ボタン ---- */

.palette {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* .btn の幅は文字数任せで、記法なので等幅にする */
.palette .btn {
    padding: 0 8px;
    font-family: var(--mono);
    font-size: 12px;
}

/* ---- 記法パネル: リズム入力 ---- */

.rhythm-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.rhythm-preview {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--muted);
    overflow-x: auto;
}

.rhythm-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 8px;
}

/* マスは実ボタン。o / . / x の文字をそのまま出す */
.rhythm-cell {
    appearance: none;
    width: 24px;
    height: 28px;
    padding: 0;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.rhythm-cell:hover {
    background: var(--hover);
}

.rhythm-cell.is-rest {
    background: var(--gutter-bg);
    color: var(--muted);
}

.rhythm-help {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

/* ---- 記法パネル: 定義チップ ---- */

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

/* 進行プリセットの2段ボタンと区別が付くよう、等幅1段にする */
.chip {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
    font-family: var(--mono);
    font-weight: 600;
}

.chips-empty {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

/* ---- 記法パネル: 記法表 ---- */

.syntax-ref {
    margin-top: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.syntax-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.syntax-table td {
    padding: 2px 4px 2px 0;
    vertical-align: top;
    border-bottom: 1px solid var(--line);
}

.syntax-table code {
    font-family: var(--mono);
    font-size: 11px;
    white-space: nowrap;
}

.syntax-example {
    color: var(--muted);
}

/* 関数と入れ子は 1 項目を縦に積む。幅 280px のパネルに 3 列も 4 列も入らず、
   表にすると説明列が 1 文字ずつ折り返して読めなくなる */
.syntax-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.syntax-entry {
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
    font-size: 11px;
    line-height: 1.5;
}

.syntax-entry:last-child {
    padding-bottom: 0;
    border-bottom: none;
}

.syntax-entry-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}

.syntax-entry-head code {
    font-family: var(--mono);
    font-size: 11px;
}

/* 何を受けて何を返すか */
.syntax-kind {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
}

@media (max-width: 640px) {
    .app-header {
        padding: 10px 14px;
    }

    .app-tagline {
        display: none;
    }

    .tabs {
        padding: 0 14px;
    }

    .panel {
        padding: 14px 14px 140px;
    }

    .footer-inner {
        padding: 8px 14px;
    }

    /* 狭い画面ではパネルをエディタの下に回す */
    .editor-tab {
        grid-template-columns: minmax(0, 1fr);
    }

    .side-panel {
        position: static;
        max-height: none;
    }
}

/* 記法表の例はクリックでカーソル位置に挿入できる。押せると分かる見た目にする */
.syntax-example {
    cursor: pointer;
}

.syntax-example:hover {
    background: var(--accent-soft, #e8f0f7);
}

/* ---- コード表タブ ---- */

.chord-table {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ルート名の列 + 品質の列。横に長いので狭い画面ではスクロールさせる */
.chord-table-grid {
    display: grid;
    grid-template-columns: 44px repeat(11, minmax(56px, 1fr));
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.chord-table-head {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.chord-table-root {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.chord-table-cell {
    padding: 6px 4px;
    font-size: 12px;
    white-space: nowrap;
}

.chord-table-cell.is-active {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.chord-table-detail {
    padding-top: 4px;
    border-top: 1px solid var(--line);
}

.chord-table-name {
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 600;
}

/* 選んだコードの押さえ方の亜種。`.btn-icon` は幅 30px 固定で ♭/♯
   専用なので、文字が入るこちらには使わない */
.chord-table-variants {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}

.chord-table-variant.is-active {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}
