/* =========================================================
   テーマ: dark（既定） / beige
   色や角丸はすべてトークン化し、[data-theme] で切り替える
   ========================================================= */
:root {
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Segoe UI Symbol", sans-serif;
  --bg: #121418;
  --panel: #1b1e24;
  --panel-2: #23272f;
  --line: #2e333d;
  --line-hover: #4a5160;
  --text: #e9e6df;
  --muted: #9aa0ab;
  --accent: #ff6b4a;
  --accent-2: #ffb199;
  --c-root: #ff6b4a;
  --c-3: #f5c542;
  --c-5: #4cc9f0;
  --c-7: #b388ff;
  --danger: #ff6b6b;
  --danger-line: #5a2d2d;

  --on-bg: var(--accent);
  --on-line: var(--accent);
  --on-text: #1a0f0b;
  --on-weight: 700;
  --primary-bg: var(--accent);
  --primary-text: #1a0f0b;
  --btn-bg: var(--panel-2);
  --chip-on-bg: #3a211a;
  --chip-on-line: var(--accent);
  --chip-on-sub: var(--accent-2);
  --edit-bg: #3a2a10;
  --edit-text: var(--c-3);
  --badge-line: #6b5216;
  --switch-off: #3a3f4a;
  --switch-on: var(--accent);

  --board-bg: linear-gradient(180deg, #3b2a1e, #2c1f16);
  --scroll-thumb: #6b5a4a;
  --ghost-fill: rgba(242, 237, 228, .14);
  --ghost-line: rgba(242, 237, 228, .25);
  --ghost-text: rgba(242, 237, 228, .55);
  --cand: rgba(245, 197, 66, .75);
  --cand-hover: rgba(245, 197, 66, .2);
  --playing-line: #fff;

  --radius: 12px;
  --radius-btn: 8px;
  --panel-shadow: none;
  --title-weight: 800;
  font-family: var(--font);
}

:root[data-theme="beige"] {
  --font: "DM Sans", "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", "Segoe UI Symbol", sans-serif;
  --bg: #f3ede3;
  --panel: #fbf8f2;
  --panel-2: #f5efe5;
  --line: #e6ddcf;
  --line-hover: #cbbda8;
  --text: #3d352d;
  --muted: #8f8474;
  --accent: #c0704f;
  --accent-2: #b0603f;
  --c-root: #c0704f;
  --c-3: #c9a04a;
  --c-5: #6f9c8f;
  --c-7: #9a86bb;
  --danger: #b5523f;
  --danger-line: #e7c6bb;

  --on-bg: #3d352d;
  --on-line: #3d352d;
  --on-text: #f7f2ea;
  --on-weight: 500;
  --primary-bg: #c0704f;
  --primary-text: #fffaf5;
  --btn-bg: transparent;
  --chip-on-bg: #3d352d;
  --chip-on-line: #3d352d;
  --chip-on-sub: #e3d8c8;
  --edit-bg: #f6ead2;
  --edit-text: #8a6a24;
  --badge-line: #e6d3a8;
  --switch-off: #ddd3c4;
  --switch-on: #c0704f;

  --board-bg: linear-gradient(180deg, #efe6d8, #e9dfcf);
  --scroll-thumb: #cdbfaa;
  --ghost-fill: rgba(61, 53, 45, .06);
  --ghost-line: rgba(61, 53, 45, .16);
  --ghost-text: rgba(61, 53, 45, .45);
  --cand: rgba(176, 96, 63, .7);
  --cand-hover: rgba(192, 112, 79, .15);
  --playing-line: #3d352d;

  --radius: 20px;
  --radius-btn: 999px;
  --panel-shadow: 0 1px 2px rgba(61, 53, 45, .04), 0 8px 24px rgba(61, 53, 45, .05);
  --title-weight: 500;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.5; -webkit-text-size-adjust: 100%; font-family: var(--font); transition: background .25s, color .25s; }

.top { padding: 14px 16px 4px; max-width: 1280px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 20px; letter-spacing: .02em; font-weight: var(--title-weight); }
.top h1 small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 8px; }

main { max-width: 1280px; margin: 0 auto; padding: 8px 16px 32px; display: grid; gap: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; box-shadow: var(--panel-shadow); }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.two { gap: 10px 28px; margin-top: 10px; }
.lbl { font-size: 12px; color: var(--muted); min-width: 56px; }

button, .file-btn {
  font: inherit; font-size: 14px; color: var(--text); background: var(--btn-bg);
  border: 1px solid var(--line); border-radius: var(--radius-btn); padding: 6px 12px; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover, .file-btn:hover { border-color: var(--line-hover); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-text); font-weight: 700; }
button.active-edit { background: var(--edit-bg); border-color: var(--edit-text); color: var(--edit-text); }
.danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger-line); }
.file-btn input { display: none; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button { padding: 6px 12px; }
.seg button.on { background: var(--on-bg); border-color: var(--on-line); color: var(--on-text); font-weight: var(--on-weight); }
.seg.keys button { min-width: 44px; padding: 6px 8px; }
.seg.small button { font-size: 13px; padding: 4px 10px; }

/* モード */
.mode-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.arrow { width: 48px; height: 48px; font-size: 18px; border-radius: 50%; }
.mode-title { text-align: center; min-width: 0; }
.mode-sub { font-size: 12px; color: var(--muted); }
.mode-name { font-size: 26px; font-weight: var(--title-weight); letter-spacing: .01em; }
.mode-name .root { color: var(--accent); }
.mode-ja { font-size: 14px; }
.mode-aka { font-size: 12px; color: var(--muted); min-height: 1.5em; }

.chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.chip { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; font-size: 12px; position: relative; line-height: 1.3; border-radius: calc(var(--radius) * .6); }
.chip b { font-size: 15px; font-weight: 600; }
.chip span { color: var(--muted); font-size: 11px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.chip.on { background: var(--chip-on-bg); border-color: var(--chip-on-line); color: var(--on-text); }
:root:not([data-theme="beige"]) .chip.on { color: var(--text); }
.chip.on span { color: var(--chip-on-sub); }
.chip .dot { position: absolute; top: 5px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--c-3); }

.formula { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.fcell { display: flex; flex-direction: column; align-items: center; min-width: 46px; padding: 4px 6px; border-radius: calc(var(--radius) * .5); background: var(--panel-2); border: 1px solid var(--line); }
.fcell .deg { font-weight: 700; }
.fcell .nm { font-size: 12px; color: var(--muted); }
.fcell.r { border-color: var(--c-root); } .fcell.r .deg { color: var(--c-root); }
.ct .fcell.t3 { border-color: var(--c-3); } .ct .fcell.t3 .deg { color: var(--c-3); }
.ct .fcell.t5 { border-color: var(--c-5); } .ct .fcell.t5 .deg { color: var(--c-5); }
.ct .fcell.t7 { border-color: var(--c-7); } .ct .fcell.t7 .deg { color: var(--c-7); }
.chord-line { text-align: center; margin-top: 8px; font-size: 14px; color: var(--muted); }
.chord-line strong { color: var(--text); font-size: 16px; }

/* 指板 */
.toolbar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.lbl-inline { font-size: 12px; color: var(--muted); margin-right: -8px; }
.toolbar.play { margin-top: 10px; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: var(--switch-off); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.switch input:checked + span { background: var(--switch-on); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.board-wrap { margin-top: 10px; overflow-x: auto; border-radius: calc(var(--radius) * .7); background: var(--board-bg); -webkit-overflow-scrolling: touch; scrollbar-color: var(--scroll-thumb) transparent; scrollbar-width: thin; }
.board-wrap::-webkit-scrollbar { height: 8px; }
.board-wrap::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }
.board-wrap::-webkit-scrollbar-track { background: transparent; }
#board { display: block; }
#board text { font-family: var(--font); pointer-events: none; }
#board .note { cursor: pointer; }
#board .note circle { transition: transform .1s; transform-box: fill-box; transform-origin: center; }
#board .note.playing circle { transform: scale(1.3); stroke: var(--playing-line); stroke-width: 3; }
#board .ghost circle { fill: var(--ghost-fill); stroke: var(--ghost-line); }
#board .ghost text { fill: var(--ghost-text); }
#board .cand circle { fill: transparent; stroke: var(--cand); stroke-dasharray: 3 3; stroke-width: 1.5; }
#board .cand text { fill: var(--cand); }
#board .cand:hover circle { fill: var(--cand-hover); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 18px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -2px; border: 1px solid var(--line); }

.bpm { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.bpm input { width: 140px; accent-color: var(--accent); }
.bpm output { min-width: 28px; color: var(--text); }

.play-status { font-size: 13px; color: var(--accent-2); font-weight: 600; }
.play-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.field[hidden] { display: none; }
.field select, .field input {
  font: inherit; font-size: 14px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: calc(var(--radius) * .5); padding: 7px 10px; width: 100%; min-width: 0;
}
.field input.invalid { border-color: var(--danger); }
.field select:focus-visible, .field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field.dim { opacity: .45; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--edit-bg); color: var(--edit-text); border: 1px solid var(--badge-line); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* beige テーマ固有の余白・質感（ミニマルに） */
:root[data-theme="beige"] main { gap: 16px; }
:root[data-theme="beige"] .panel { padding: 18px 20px; border-color: transparent; }
:root[data-theme="beige"] .top { padding-top: 22px; }
:root[data-theme="beige"] .top h1 { font-size: 22px; letter-spacing: .04em; }
:root[data-theme="beige"] .lbl,
:root[data-theme="beige"] .lbl-inline,
:root[data-theme="beige"] .field > span { letter-spacing: .08em; font-size: 11px; text-transform: uppercase; }
:root[data-theme="beige"] .arrow { background: var(--panel-2); border-color: transparent; }
:root[data-theme="beige"] .chip { background: var(--panel-2); border-color: transparent; }
:root[data-theme="beige"] .chip.on { background: var(--chip-on-bg); }
:root[data-theme="beige"] .fcell { background: transparent; }
:root[data-theme="beige"] .mode-name { font-size: 28px; letter-spacing: .02em; }

@media (max-width: 720px) {
  .top h1 small { display: block; margin-left: 0; margin-top: 2px; }
  .chips { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mode-name, :root[data-theme="beige"] .mode-name { font-size: 20px; }
  .arrow { width: 40px; height: 40px; }
  .lbl { min-width: 0; width: 100%; }
  .bpm input { width: 100px; }
  .formula { gap: 4px; }
  .fcell { min-width: 0; flex: 1 1 0; padding: 4px 2px; }
  :root[data-theme="beige"] .panel { padding: 14px 14px; }
}
