/* =====================================================================
   Chordpad — base theme (architect).
   Builders: append module-specific rules at the END of this file inside
   a section headed "=== <module> ===". Do not edit other sections.
   ===================================================================== */

:root {
  --bg: #1c1c1c;
  --bg-2: #232323;
  --panel: #2e2e2e;
  --panel-2: #383838;
  --panel-3: #444;
  --border: #555;
  --border-soft: #3c3c3c;
  --text: #e8e8e8;
  --text-dim: #9a9a9a;
  --text-faint: #6d6d6d;
  --accent: #c8741f;          /* play button orange */
  --accent-hi: #e08a2e;
  --select: #ffffff;
  --cursor: #3aa0ff;
  --playhead: #ff9d2e;
  --loop: #4f8fd6;
  --active: #3a8ee6;
  --danger: #d9534f;
  --radius: 6px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .55);

  /* scale-degree colors */
  --deg-1: #c0302b;  /* I   red    */
  --deg-2: #c8661f;  /* ii  orange */
  --deg-3: #c9ad1d;  /* iii yellow */
  --deg-4: #4fae28;  /* IV  green  */
  --deg-5: #2f9fc4;  /* V   blue   */
  --deg-6: #8a2cc7;  /* vi  purple */
  --deg-7: #c22bb1;  /* vii pink   */
  --deg-1-dim: #5a2422;
  --deg-2-dim: #5c3a20;
  --deg-3-dim: #5a5020;
  --deg-4-dim: #2d4f22;
  --deg-5-dim: #21475a;
  --deg-6-dim: #43245c;
  --deg-7-dim: #5a2455;
  --rest: #5a5a5a;
  --rest-dim: #333;

  --staff-h: 50px;
  --header-h: 20px;
  --loopbar-h: 14px;
  --gutter: 46px;

  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { cursor: default; opacity: .45; }
input, select, textarea { font: inherit; color: var(--text); user-select: text; }
svg { fill: currentColor; }
.hidden { display: none !important; }

/* degree color helper: sets --c / --c-dim */
.deg-1 { --c: var(--deg-1); --c-dim: var(--deg-1-dim); }
.deg-2 { --c: var(--deg-2); --c-dim: var(--deg-2-dim); }
.deg-3 { --c: var(--deg-3); --c-dim: var(--deg-3-dim); }
.deg-4 { --c: var(--deg-4); --c-dim: var(--deg-4-dim); }
.deg-5 { --c: var(--deg-5); --c-dim: var(--deg-5-dim); }
.deg-6 { --c: var(--deg-6); --c-dim: var(--deg-6-dim); }
.deg-7 { --c: var(--deg-7); --c-dim: var(--deg-7-dim); }
.rest  { --c: var(--rest);  --c-dim: var(--rest-dim); }

/* ---------------------------------------------------------------- generic controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 28px; padding: 4px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text);
}
.btn:hover:not(:disabled) { background: var(--panel-3); }
.btn.active { background: var(--active); border-color: var(--active); color: #fff; }
.btn-primary { background: var(--active); border-color: var(--active); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4c9cf0; }
.btn-danger { color: #fff; background: #8e2f2c; border-color: #a33a36; }
.btn-small { min-height: 22px; padding: 2px 10px; font-size: 12px; }
.icon-btn { width: 28px; height: 28px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--panel-3); }
.icon-btn svg { width: 16px; height: 16px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.seg-btn { padding: 3px 9px; min-width: 30px; background: var(--panel-2); border-right: 1px solid var(--border); font-size: 12px; }
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--panel-3); }
.seg-btn.active { background: var(--active); color: #fff; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label, .field-label { color: var(--text-dim); font-size: 12px; }
.field-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input[type=text], input[type=number], select, .opt-select {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; min-height: 28px;
}
input[type=range] { accent-color: var(--active); width: 100%; }
input[type=checkbox] { accent-color: var(--active); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; background: var(--panel-3); font-size: 11px; color: var(--text-dim); }
kbd { background: var(--panel-3); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 3px; padding: 0 5px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

/* ---------------------------------------------------------------- menubar */
#menubar {
  flex: 0 0 auto; height: 30px; display: flex; align-items: center; gap: 4px;
  padding: 0 8px; background: #2a2a2a; border-bottom: 1px solid #111;
}
#menubar .logo { display: flex; margin-right: 4px; }
#menubar .app-name { font-weight: 700; margin-right: 14px; letter-spacing: .2px; }
.menus { display: flex; gap: 2px; }
.menu-btn { padding: 4px 9px; border-radius: 4px; color: #d8d8d8; }
.menu-btn:hover, .menu-btn.active { background: var(--panel-3); }
.menu-btn .caret { font-size: 9px; opacity: .8; }
.project-title { margin-left: auto; color: var(--text-dim); padding: 4px 8px; border-radius: 4px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-title:hover { background: var(--panel-3); color: var(--text); }

/* ---------------------------------------------------------------- top bar */
#topbar {
  flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px 6px; background: var(--bg-2); border-bottom: 1px solid #111;
}
.tb-group { display: flex; align-items: flex-start; gap: 6px; }
.tb-btn, .prop-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  min-width: 54px; padding: 2px 6px 4px; border-radius: var(--radius); color: #ddd;
}
.tb-btn:hover:not(:disabled), .prop-btn:hover { background: #2f2f2f; }
.tb-icon { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
.tb-icon svg { width: 22px; height: 22px; }
.tb-label { font-size: 13px; margin-top: 2px; }
.tb-sub { font-size: 9px; color: var(--text-dim); margin-top: -2px; }
.tb-btn.active .tb-icon { color: var(--active); }
.tb-btn.active .tb-label { color: #fff; }

.play-circle { border-radius: 50%; background: var(--accent); color: #fff; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.play-btn:hover .play-circle { background: var(--accent-hi); }
.play-circle svg { width: 24px; height: 24px; }
.play-btn .icon-stop { display: none; }
.play-btn.active .icon-play { display: none; }
.play-btn.active .icon-stop { display: block; }
.play-btn.active .tb-icon { color: #fff; }

.prop-btn { min-width: 64px; }
.prop-value { font-size: 20px; line-height: 24px; font-weight: 400; }
.prop-sub { font-size: 10px; line-height: 12px; color: #cfcfcf; margin-bottom: 8px; }

/* ---------------------------------------------------------------- toolbar */
#toolbar {
  flex: 0 0 auto; display: flex; align-items: flex-start; gap: 28px; flex-wrap: wrap;
  padding: 10px 16px 12px; background: var(--panel); border-bottom: 1px solid #111;
}
.tool-group { display: flex; flex-direction: column; gap: 6px; }
.tool-title { font-size: 13px; color: #ddd; }

/* duration selector */
#duration-panel { width: 140px; }
#duration-bars { display: flex; flex-direction: column; gap: 2px; }
.dur-row { display: flex; align-items: center; gap: 6px; cursor: pointer; height: 10px; }
.dur-label { width: 26px; text-align: right; font-size: 11px; line-height: 10px; color: #ddd; }
.dur-bar {
  flex: 1; height: 9px; background: #4a4a4a; position: relative;
  background-image: linear-gradient(to right, transparent calc(25% - 1px), #2e2e2e calc(25% - 1px), #2e2e2e 25%, transparent 25%);
  background-size: 25% 100%;
}
.dur-fill { position: absolute; left: 0; top: 0; bottom: 0; background: #d8d8d8; }
.dur-row:hover .dur-bar { background-color: #555; }
.dur-row.active .dur-fill { background: var(--active); }
.dur-actions { display: flex; gap: 6px; margin-top: 4px; }
.dur-actions .btn { flex: 1; }

/* chord palette */
#chord-palette { display: flex; gap: 6px; }
.palette-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 52px; }
.palette-btn .pb-roman {
  width: 52px; height: 48px; display: flex; align-items: center; justify-content: center;
  font-family: Georgia, "Times New Roman", serif; font-size: 26px; color: #eee;
  background: #4d4d4d; border-radius: var(--radius);
  border-top: 5px solid var(--c, #666); border-bottom: 5px solid var(--c, #666);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.palette-btn .pb-name { font-size: 15px; color: #ddd; }
.palette-btn:hover .pb-roman { background: #5a5a5a; }
.palette-btn:active .pb-roman { transform: translateY(1px); }
.palette-btn.rest .pb-roman { border-color: transparent; background: #444; }

/* helper buttons */
#helpers-panel { flex-direction: row; gap: 14px; }
.helper-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.helper-icon {
  width: 72px; height: 48px; border-radius: var(--radius); background: #4d4d4d;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.helper-btn:hover .helper-icon { background: #5a5a5a; }
.magic-icon svg { width: 26px; height: 26px; color: #eee; }
.magic-icon { border-bottom: 5px solid transparent; border-image: linear-gradient(90deg, var(--deg-1), var(--deg-2), var(--deg-3), var(--deg-4), var(--deg-5), var(--deg-6), var(--deg-7)) 1; }
.bars-icon { align-items: flex-end; gap: 3px; padding: 6px 8px 4px; }
.bars-icon i { width: 7px; display: block; }
.prog-icon { gap: 2px; padding: 0 5px; }
.prog-icon i { font-style: normal; font-family: Georgia, serif; font-size: 11px; flex: 1; text-align: center; padding: 6px 0; background: #3b3b3b; border-top: 3px solid var(--c); }

/* chord options panel */
#chord-options { display: none; flex-direction: row; flex-wrap: wrap; gap: 14px; padding-left: 18px; border-left: 1px solid var(--border-soft); }
#chord-options.visible { display: flex; }
.opt-group { display: flex; flex-direction: column; gap: 6px; }
.opt-label { font-size: 12px; color: var(--text-dim); }

/* measure operations panel */
#measure-panel {
  display: none; flex: 0 0 auto; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 16px; background: #26303a; border-bottom: 1px solid #111;
}
#measure-panel.visible { display: flex; }
#measure-panel .mp-label { font-weight: 600; margin-right: 8px; }

/* ---------------------------------------------------------------- grid */
#grid-scroll { flex: 1 1 auto; overflow: auto; background: var(--bg); padding: 36px 40px 80px 10px; }
#grid { position: relative; min-width: 640px; }
.grid-line { position: relative; margin-bottom: 38px; padding-left: var(--gutter); }
.measure-headers, .loop-bar {
  display: grid; grid-template-columns: repeat(var(--measures, 8), 1fr);
}
.measure-headers { height: var(--header-h); margin-bottom: 3px; }
.measure-header {
  position: relative; border: 1px solid #777; border-right: 0; background: transparent;
  font-size: 12px; color: #aaa; padding: 1px 3px; cursor: pointer; display: flex; align-items: center; gap: 4px; overflow: hidden;
}
.measure-header:last-child { border-right: 1px solid #777; }
.measure-header:hover { background: #2a2a2a; }
.measure-header.selected { background: #2d4d6e; color: #fff; }
.measure-num { flex: 0 0 auto; }
.measure-badges { display: flex; gap: 3px; margin-left: auto; }
.badge { font-size: 10px; line-height: 13px; padding: 0 4px; border-radius: 3px; background: #444; color: #eee; white-space: nowrap; }
.badge-key { background: #6b3a8c; }
.badge-meter { background: #2f6b8c; }
.badge-tempo { background: #8c5a2f; }

.loop-bar { height: var(--loopbar-h); margin-bottom: 4px; }
.loop-cell { border: 1px solid #666; border-right: 0; cursor: pointer; position: relative; }
.loop-cell:last-child { border-right: 1px solid #666; }
.loop-cell:hover { background: #2a2a2a; }
.loop-cell.in-loop { background: rgba(79, 143, 214, .25); }
.loop-cell.in-loop.loop-on { background: var(--loop); }
.loop-cell.loop-start::before {
  content: "⟳"; position: absolute; left: 3px; top: -2px; font-size: 11px; color: #ddd;
}

.chord-staff {
  position: relative; display: flex; height: var(--staff-h);
  border: 1px solid #777; background: #2b2b2b;
}
.measure-cell { position: relative; flex: 1 1 0; border-right: 1px solid #777; }
.measure-cell:last-of-type { border-right: 0; }
.beat-line { position: absolute; top: 0; bottom: 0; width: 1px; pointer-events: none; }
.beat-line.group { background: #474747; }
.beat-line.sub { background: #363636; }

.chord-block {
  position: absolute; top: 2px; bottom: 2px; z-index: 2;
  background: var(--c-dim); border: 2px solid var(--c); border-radius: 4px;
  display: flex; flex-direction: column; justify-content: center; padding: 0 6px;
  overflow: hidden; white-space: nowrap; cursor: pointer; color: #fff;
}
.chord-block:hover { filter: brightness(1.15); }
.chord-block.rest { background: repeating-linear-gradient(135deg, #333 0 6px, #2c2c2c 6px 12px); border-color: #5a5a5a; color: #aaa; }
.chord-block.selected { box-shadow: 0 0 0 2px var(--select), 0 0 10px rgba(255,255,255,.35); z-index: 3; }
.chord-block.borrowed { background-image: repeating-linear-gradient(135deg, rgba(0,0,0,.25) 0 5px, transparent 5px 10px); }
.chord-block.secondary { border-style: dashed; }
.chord-block.cont-left { border-left-width: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.chord-block.cont-right { border-right-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.chord-roman { font-family: Georgia, "Times New Roman", serif; font-size: 17px; line-height: 19px; }
.chord-fig { font-size: 10px; vertical-align: super; margin-left: 1px; }
.chord-sec { font-size: 13px; }
.chord-name { font-size: 11px; line-height: 13px; color: rgba(255,255,255,.75); }
.chord-resize { position: absolute; top: 0; right: -2px; bottom: 0; width: 8px; cursor: ew-resize; z-index: 4; }
.chord-resize:hover { background: rgba(255,255,255,.25); }

.cursor-caret { position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px; background: var(--cursor); z-index: 5; pointer-events: none; animation: caret-blink 1.1s steps(1) infinite; }
@keyframes caret-blink { 50% { opacity: .35; } }
.split-marker { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed #fff; z-index: 6; pointer-events: none; }
.chord-staff.split-mode, .chord-staff.split-mode .chord-block { cursor: crosshair; }
.staff-hint { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 700; color: #cfcfcf; pointer-events: none; z-index: 1; }

.playhead { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--playhead); z-index: 8; pointer-events: none; }
.playhead-handle { position: absolute; top: 0; left: -6px; width: 14px; height: var(--header-h); pointer-events: auto; cursor: ew-resize; }
.playhead-handle::after { content: ""; position: absolute; left: 1px; top: 0; border: 6px solid transparent; border-top: 8px solid var(--playhead); }

/* ---------------------------------------------------------------- overlays */
#popover-layer, #dialog-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#dialog-layer { z-index: 60; }
#popover-layer > *, #dialog-layer > * { pointer-events: auto; }

.popover {
  position: absolute; min-width: 180px; max-width: 420px; max-height: 70vh; overflow: auto;
  background: #333; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px;
}
.popover-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); padding: 4px 8px 6px; }
.menu-item { display: flex; justify-content: space-between; align-items: center; gap: 24px; width: 100%; padding: 6px 10px; border-radius: 4px; text-align: left; }
.menu-item:hover:not(:disabled) { background: var(--active); color: #fff; }
.menu-item .shortcut { color: var(--text-dim); font-size: 11px; }
.menu-item:hover .shortcut { color: #e8f0ff; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }

.pop-chord {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 58px; height: 50px; margin: 3px; padding: 0 6px;
  background: var(--c-dim); border: 2px solid var(--c); border-radius: var(--radius); color: #fff;
}
.pop-chord:hover { filter: brightness(1.25); }
.pop-chord .pc-roman { font-family: Georgia, serif; font-size: 16px; }
.pop-chord .pc-name { font-size: 11px; opacity: .8; }
.pop-prog { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border-radius: 4px; text-align: left; }
.pop-prog:hover { background: #444; }
.pop-prog .pp-name { min-width: 150px; }
.pop-prog .pp-chords { display: flex; gap: 2px; }
.pop-prog .pp-chords > span { font-family: Georgia, serif; font-size: 12px; padding: 2px 5px; background: var(--c-dim); border-top: 3px solid var(--c); }

.dialog-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.dialog {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 64px); display: flex; flex-direction: column;
  background: #2f2f2f; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); font-size: 15px; font-weight: 600; }
.dialog-body { padding: 16px; overflow: auto; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border-soft); }
.tonic-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.tonic-grid .seg-btn { border: 1px solid var(--border); border-radius: 4px; padding: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 80;
  background: #444; color: #fff; padding: 8px 16px; border-radius: 6px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #444; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

@media (max-width: 900px) {
  #topbar { flex-wrap: wrap; gap: 8px; padding: 6px 16px; }
  #toolbar { gap: 16px; padding: 8px 16px; }
  #grid-scroll { padding: 20px 16px 60px 0; }
  .tb-btn, .prop-btn { min-width: 46px; }
}

/* =====================================================================
   Module sections (append below)
   ===================================================================== */

/* === grid === */
.chord-block.narrow { padding: 0 3px; }
.chord-block.narrow .chord-name { display: none; }
.chord-block.narrow .chord-roman { font-size: 14px; }
.chord-block.tiny { padding: 0 1px; border-width: 1px; }
.chord-block.tiny .chord-roman, .chord-block.tiny .chord-name { display: none; }
.measure-cell.compound .beat-line.group { background: #5a5a5a; width: 2px; margin-left: -1px; }
.loop-cell.loop-end::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.35); }

/* === share (view mode, share dialog) === */
#view-banner {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 16px; background: #1f3550; border-bottom: 1px solid #2c4d75; color: #e6f0ff;
}
#view-banner.hidden { display: none; }
#view-banner .vb-badge { font-weight: 700; letter-spacing: .2px; }
#view-banner .vb-title { color: #b9cbe4; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#view-banner .vb-key { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: #b9cbe4; font-size: 12px; }
#view-banner .vb-key select { min-height: 24px; padding: 2px 6px; }
/* read-only view: editing surfaces hidden or inert; playback, loop, click and mixer stay */
body.view-mode #toolbar,
body.view-mode #measure-panel,
body.view-mode #menu-edit,
body.view-mode #btn-record,
body.view-mode #btn-transpose,
body.view-mode .chord-resize,
body.view-mode .cursor-caret,
body.view-mode .staff-hint { display: none !important; }
body.view-mode #song-props .prop-btn,
body.view-mode #project-title { pointer-events: none; }
.share-link { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* === sheet (chord sheet preview + print) === */
.dialog[data-dialog="pdf"] { width: min(880px, calc(100vw - 32px)); }
.pdf-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 16px; }
.sheet-preview { margin-top: 4px; background: #fff; border-radius: 4px; padding: 28px 32px; max-height: 52vh; overflow: auto; }
.sheet-preview.hidden { display: none; }

.sheet {
  color: #000; background: #fff; user-select: text; -webkit-user-select: text;
  font-family: "Helvetica Neue", Helvetica, Arial, "Segoe UI Symbol", "Noto Music", "DejaVu Sans", sans-serif; font-size: 11pt; line-height: 1.2;
}
.sheet-header { text-align: center; margin: 0 0 16pt; break-after: avoid; page-break-after: avoid; }
.sheet-header-min { margin-bottom: 12pt; }
.sheet-title { font-size: 20pt; font-weight: 700; margin: 0 0 5pt; letter-spacing: .2pt; }
.sheet-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: 4pt 18pt; font-size: 10pt; }
.sheet-meta b { font-weight: 700; }
.sheet-transposed { font-style: italic; }
.sheet-line { display: grid; margin: 0 0 12pt; break-inside: avoid; page-break-inside: avoid; }
.sheet-mpl-4 .sheet-line { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sheet-mpl-8 .sheet-line { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.sheet-bar { position: relative; min-width: 0; }
.sheet-marks { display: flex; gap: 5pt; align-items: baseline; padding: 0 0 1pt 4pt; font-size: 8pt; font-style: italic; white-space: nowrap; min-height: 0; }
.sheet-line.has-marks .sheet-marks { min-height: 12pt; }
.sheet-mark { font-weight: 600; }
.sheet-mark.mark-meter { font-style: normal; font-weight: 700; }
.sheet-bar-body { position: relative; display: flex; align-items: center; height: 30pt; border-left: 1.2pt solid #000; }
.sheet-labels-both .sheet-bar-body { height: 38pt; }
.sheet-bar:last-child .sheet-bar-body, .sheet-bar.final .sheet-bar-body { border-right: 1.2pt solid #000; }
.sheet-bar.final .sheet-bar-body { border-right: 4pt double #000; }
.sheet-bar.loop-start .sheet-bar-body { border-left: 3.5pt double #000; }
.sheet-bar.loop-end:not(.final) .sheet-bar-body { border-right: 3.5pt double #000; }
.sheet-bar-empty .sheet-bar-body { border: 0; }
.sheet-chord {
  flex: 0 1 auto; min-width: max-content; box-sizing: border-box; padding: 0 3pt 0 5pt;
  display: flex; flex-direction: column; white-space: nowrap; line-height: 1.15;
}
.sc-name { font-weight: 700; font-size: 15pt; }
.sc-roman { font-family: Georgia, "Times New Roman", serif; font-size: 10pt; }
.sc-roman sup { font-size: 70%; vertical-align: super; line-height: 0; }
.sheet-labels-roman .sc-roman { font-size: 15pt; }
.sheet-chord.cont .sc-name, .sheet-chord.cont .sc-roman { font-weight: 400; }
.sheet-chord.rest .sc-name { font-weight: 400; }
.sheet-mpl-8 .sc-name, .sheet-mpl-8.sheet-labels-roman .sc-roman { font-size: 11pt; }
.sheet-mpl-8 .sc-roman { font-size: 8pt; }
.sheet-chord.narrow .sc-name { font-size: 11.5pt; }
.sheet-mpl-8 .sheet-chord { padding: 0 2pt 0 3pt; }
.sheet-mpl-8 .sheet-chord.narrow .sc-name { font-size: 9pt; }
.sheet-repeat { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 17pt; font-weight: 700; }
.sheet-num { display: none; position: absolute; left: 2pt; bottom: -9pt; font-size: 6.5pt; color: #444; }
.sheet-bar:first-child .sheet-num { display: block; }
.sheet-loopmark { font-family: "Segoe UI Symbol", "DejaVu Sans", Arial, sans-serif; font-weight: 700; font-style: normal; font-size: 9pt; }
.sheet-loopmark.end { position: absolute; right: 4pt; top: 1pt; }

#print-sheet { display: none; }
@media print {
  @page { margin: 14mm 12mm; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; color: #000 !important; display: block !important; }
  body > :not(#print-sheet) { display: none !important; }
  #print-sheet { display: block !important; }
  .sheet { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* === projects (song sidebar, draft banner, project dialogs, project sheet) === */
#main-row { flex: 1 1 auto; display: flex; min-height: 120px; } /* the grid never collapses under bottom panels */
#main-row > #grid-scroll { min-width: 0; }
#sidebar {
  flex: 0 0 236px; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-2); border-right: 1px solid #111; overflow: hidden;
}
#sidebar.hidden { display: none; }
.sb-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 2px 10px; }
.sb-project-name {
  flex: 1 1 auto; min-width: 0; font-weight: 700; font-size: 14px;
  background: transparent !important; border: 1px solid transparent !important; padding: 3px 6px !important;
}
.sb-project-name:hover, .sb-project-name:focus { border-color: var(--border) !important; background: var(--bg) !important; }
.sb-project-name.ro { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sub { padding: 0 16px 8px; color: var(--text-dim); font-size: 11px; }
.sb-list { list-style: none; margin: 0; padding: 0 6px; overflow: auto; flex: 1 1 auto; }
.sb-song {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 4px 6px 6px; margin-bottom: 2px;
  border-radius: 5px; cursor: pointer; border: 1px solid transparent;
}
.sb-song:hover { background: var(--panel); }
.sb-song:focus-visible { outline: 2px solid var(--cursor); outline-offset: -2px; }
.sb-song.active { background: var(--panel-2); border-color: var(--border); }
.sb-song.active .sb-num { background: var(--active); color: #fff; }
.sb-song.dragging { opacity: .45; }
.sb-song.drop-before { box-shadow: inset 0 2px 0 var(--cursor); }
.sb-song.drop-after { box-shadow: inset 0 -2px 0 var(--cursor); }
.sb-num { flex: 0 0 auto; min-width: 20px; height: 20px; border-radius: 10px; background: var(--panel-3); color: var(--text-dim); font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.sb-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.sb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-summary { color: var(--text-dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-actions { flex: 0 0 auto; display: flex; opacity: 0; }
.sb-song:hover .sb-actions, .sb-song.active .sb-actions, .sb-song:focus-within .sb-actions { opacity: 1; }
.sb-actions .icon-btn { width: 20px; height: 22px; font-size: 10px; color: var(--text-dim); }
.sb-actions .icon-btn:hover:not(:disabled) { color: var(--text); }
.sb-actions .sb-menu-btn { font-size: 15px; }
.sb-foot { padding: 8px 10px 12px; }
.sb-foot .sb-add { width: 100%; }
.sb-menu { min-width: 150px; }
body.view-mode #sidebar .sb-song { cursor: pointer; }

.project-title .pt-project { color: var(--text-faint); }
.project-title .pt-sep { color: var(--text-faint); }
.project-title .pt-song { color: var(--text); }

#view-banner.draft { background: #3b3120; border-bottom-color: #6b5429; color: #fff3de; }
#view-banner .vb-note { color: #e2d2b3; font-size: 12px; }
#view-banner.draft .vb-title { color: #e2d2b3; }
#view-banner .vb-spacer { flex: 1 1 auto; }

.project-list { display: flex; flex-direction: column; gap: 4px; }
.project-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 4px; background: var(--panel-2); }
.project-row.current { background: var(--panel-3); }
.project-row .pr-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-row .pr-count, .project-row .pr-date { white-space: nowrap; }
.dialog[data-dialog="load"], .dialog[data-dialog="share"] { width: min(560px, calc(100vw - 32px)); }
.share-warn { margin: -4px 0 12px; padding: 8px 10px; border-radius: 4px; background: #4a3a1c; border: 1px solid #7a5d25; color: #ffe7b8; font-size: 12px; }
.share-warn.hidden { display: none; }

.sheet-toc-list { margin: 8pt 0 0; padding-left: 20pt; font-size: 12pt; }
.sheet-toc-item { padding: 5pt 0; border-bottom: .6pt solid #bbb; }
.sheet-toc-item::marker { font-weight: 700; }
.sheet-toc-title { font-weight: 700; margin-right: 10pt; }
.sheet-toc-meta { color: #333; font-size: 10pt; }
.sheet-new-page { break-before: page; page-break-before: always; }
.sheet-preview .sheet-new-page { margin-top: 18pt; padding-top: 18pt; border-top: 1.5px dashed #999; }

@media (max-width: 900px) {
  #sidebar { flex-basis: 190px; }
}
/* phones: the song list is an overlay drawer over the grid (closed by default), the grid keeps full width */
@media (max-width: 600px) {
  #main-row { position: relative; }
  #sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 30;
    width: min(280px, 86vw); box-shadow: 4px 0 18px rgba(0, 0, 0, .5);
  }
}
/* touch screens have no hover: keep the song actions visible */
@media (hover: none) {
  .sb-actions { opacity: 1; }
}

/* === account (ui/account.js: account menu, sync status, auth dialogs, admin panel; share tabs) === */
.account-area { display: flex; align-items: center; gap: 6px; margin-left: 6px; }
.account-area.hidden { display: none; }
.acct-btn { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 3px; border-radius: 12px; color: var(--text); }
.acct-btn:hover { background: var(--panel-3); }
.acct-avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--active); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.acct-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-btn .caret { font-size: 9px; opacity: .8; }
.acct-role { text-transform: capitalize; }
.acct-sync { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 10px; font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.acct-sync:hover { background: var(--panel-3); color: var(--text); }
.acct-sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.acct-sync.sync-synced .dot { background: #4fae28; }
.acct-sync.sync-pending .dot, .acct-sync.sync-saving .dot, .acct-sync.sync-connecting .dot { background: var(--cursor); }
.acct-sync.sync-offline { color: #ffd38a; }
.acct-sync.sync-offline .dot { background: #e0a030; }
.acct-sync.sync-conflict, .acct-sync.sync-error, .acct-sync.sync-signedOut { color: #ffb3b0; }
.acct-sync.sync-conflict .dot, .acct-sync.sync-error .dot, .acct-sync.sync-signedOut .dot { background: var(--danger); }
.acct-menu { min-width: 220px; }
.acct-note { margin: 0 0 12px; line-height: 1.45; }
.acct-error { margin: 4px 0 8px; padding: 6px 10px; border-radius: 4px; background: #4a2322; border: 1px solid #7a3431; color: #ffd0cd; font-size: 12px; }
.acct-error.hidden { display: none; }
.btn-google { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 36px; margin: 0 0 4px; background: #fff; border-color: #dadce0; color: #3c4043; font-weight: 500; }
.btn-google:hover:not(:disabled) { background: #f1f3f4; }
.btn-google .g-logo { display: inline-grid; place-items: center; width: 18px; height: 18px; font: 700 15px/1 Arial, sans-serif; color: #4285f4; }
.acct-or { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--text-dim); font-size: 12px; }
.acct-or::before, .acct-or::after { content: ''; flex: 1; border-top: 1px solid currentColor; opacity: .4; }
.acct-section-title { display: flex; align-items: center; margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.acct-section-title:first-child { margin-top: 0; }
.acct-choices { margin: 0; padding-left: 18px; line-height: 1.6; }
.acct-kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin-bottom: 14px; }
.acct-kv > span:nth-child(odd) { color: var(--text-dim); }
.acct-import-list { max-height: 280px; overflow: auto; }
.acct-import-list .project-row { cursor: pointer; }
.dialog input[type=password], .dialog input[type=email], .dialog input[type=search] { background: var(--bg-2); border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; min-height: 28px; color: var(--text); }
.dialog .field input[type=text], .dialog .field input[type=password], .dialog .field input[type=email] { width: 100%; }
.dialog[data-dialog="load"] .project-row .chip { white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.project-row.dead { opacity: .55; }
.share-tabs { margin-bottom: 12px; }
.share-inline-actions { justify-content: flex-end; margin-top: 8px; }

.dialog[data-dialog="admin"] { width: min(1100px, calc(100vw - 32px)); height: calc(100vh - 64px); }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.admin-stat { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 6px; background: var(--panel-2); }
.admin-stat b { font-size: 18px; text-transform: capitalize; }
.admin-filters { flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.admin-filters input[type=search] { flex: 1 1 200px; }
.admin-create { padding: 8px 10px; margin-bottom: 10px; border-radius: 6px; background: var(--panel); border: 1px solid var(--border-soft); }
.admin-create.hidden { display: none; }
.admin-create .field-row { flex-wrap: wrap; gap: 6px; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th { text-align: left; font-weight: 600; color: var(--text-dim); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 5px 8px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.admin-table td.num { text-align: right; white-space: nowrap; }
.admin-table .admin-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-table .admin-details { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
.admin-row { cursor: pointer; }
.admin-row:hover, .admin-row.open { background: var(--panel-2); }
.admin-row.disabled td { color: var(--text-faint); }
.admin-detail > td { background: var(--panel); padding: 10px 12px; }
.admin-actions { display: flex; flex-direction: column; gap: 8px; }
.admin-actions .field-row { flex-wrap: wrap; gap: 6px; }
.admin-confirm { padding: 6px 8px; border-radius: 4px; background: #4a2322; }
.admin-secret { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; padding: 8px 10px; border-radius: 6px; background: #1f3a24; border: 1px solid #2f6a38; }
.admin-secret code { font-size: 13px; padding: 2px 6px; background: var(--bg); border-radius: 3px; user-select: all; word-break: break-all; }
.chip.role-owner { background: #6b4a12; color: #ffe2a8; }
.chip.role-admin { background: #1f3a5a; color: #cfe3ff; }
.chip.status-disabled, .chip.status-revoked, .chip.status-expired { background: #4a2322; color: #ffd0cd; }
.chip.status-active, .chip.status-pending { background: #1f3a24; color: #c8f0cf; }
@media (max-width: 700px) {
  .acct-name, .acct-role { display: none; }
  .project-title { max-width: 140px; }
}

/* === lyrics (lyric lane in the grid, lyrics panel, paste dialog, lyric layouts of the chord sheet) === */
#lyrics-panel {
  display: none; flex: 0 0 auto; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 16px; background: #2d2a3a; border-bottom: 1px solid #111;
}
#lyrics-panel.visible { display: flex; }
#lyrics-panel .lp-label { font-weight: 600; margin-right: 4px; }
#lyrics-panel .lp-verse { min-height: 24px; padding: 2px 6px; max-width: 220px; }
#lyrics-panel .lp-hint { color: var(--text-dim); font-size: 11px; }
body.view-mode #lyrics-panel { display: none !important; }

.lyric-lane { position: relative; margin-top: 3px; border: 1px solid #555; border-top: 0; background: #242226; }
.lyric-row { position: relative; display: flex; height: 22px; border-top: 1px solid #3a3740; cursor: text; }
.lyric-row.active { background: #2c2934; }
.lyric-row.active .lyric-label { color: #fff; background: #5a4a8a; }
.lyric-label {
  position: absolute; left: calc(-1 * var(--gutter) + 6px); top: 3px; min-width: 18px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: #3a3740; color: var(--text-dim); font-size: 10px; line-height: 16px; text-align: center;
  overflow: hidden; white-space: nowrap; max-width: calc(var(--gutter) - 10px); pointer-events: none;
}
.lyric-cell { flex: 1 1 0; border-right: 1px solid #3a3740; pointer-events: none; }
.lyric-cell:last-of-type { border-right: 0; }
.lyric-word {
  position: absolute; top: 2px; height: 17px; padding: 0 2px; z-index: 2;
  font-size: 11.5px; line-height: 17px; color: #eee; white-space: nowrap; overflow: hidden; text-overflow: clip;
  border-radius: 3px; cursor: grab; border-left: 2px solid #7c6bbd;
}
.lyric-word:hover { background: #3d3850; }
.lyric-word .lw-hyph { color: var(--text-dim); margin-left: 1px; }
.lyric-word.selected { background: #4b3f7a; box-shadow: 0 0 0 1px var(--select); z-index: 3; }
.lyric-word.dragging { opacity: .85; background: #4b3f7a; z-index: 5; max-width: none !important; }
.lyric-word.dragging.blocked { background: #7a3f4b; outline: 1px dashed #e06c75; cursor: not-allowed; }
.lyric-word.current { background: var(--playhead); color: #111; border-left-color: #fff; max-width: none !important; z-index: 4; }
.lyric-input {
  position: absolute; top: 1px; z-index: 20; height: 20px; min-height: 0 !important; padding: 0 4px !important;
  font-size: 12px; background: #111 !important; border: 1px solid var(--cursor) !important; border-radius: 3px;
  color: #fff; outline: none; box-shadow: 0 0 0 2px rgba(58, 160, 255, .35);
}
.lyric-break { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed #b48cff; z-index: 6; pointer-events: none; }
.lyric-break::before { content: "↵"; position: absolute; left: -12px; top: -1px; font-size: 10px; color: #b48cff; }
body.view-mode .lyric-row, body.view-mode .lyric-word { cursor: default; }

.lyrics-textarea { width: 100%; min-height: 150px; resize: vertical; background: var(--bg-2); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; font: 13px/1.45 inherit; font-family: inherit; }
.dialog[data-dialog="pasteLyrics"] { width: min(560px, calc(100vw - 32px)); }

/* chart + lyrics: small lyrics under each bar box, proportional to their position in the bar */
.sheet-bar-lyrics { padding: 2pt 0 0 0; font-size: 8.5pt; line-height: 1.25; }
.sbl-row { position: relative; white-space: nowrap; height: 1.25em; min-height: 10.5pt; overflow: hidden; }
.sbl-word { position: absolute; top: 0; overflow: hidden; text-overflow: clip; }
.sbl-word.clip { text-overflow: ellipsis; }
.sheet-line.has-lyrics { margin-bottom: 14pt; }
.sheet-line.has-lyrics .sheet-num { bottom: auto; top: -8pt; }
.sheet-block-title { font-size: 13pt; font-weight: 700; margin: 12pt 0 6pt; break-after: avoid; page-break-after: avoid; }

/* lyric sheet: chord symbols over the syllables (column widths are measured in sheet.js) */
.ls-line { display: flex; flex-wrap: wrap; align-items: flex-start; margin: 0 0 9pt; break-inside: avoid; page-break-inside: avoid; }
.ls-cell { flex: 0 0 auto; display: flex; flex-direction: column; white-space: pre; }
.ls-chord { line-height: 1.25; min-height: 1.25em; }
.ls-chord.rest { font-weight: 400 !important; font-style: italic; }
.ls-text { display: flex; line-height: 1.35; }
.ls-syl { white-space: pre; }
.ls-hyph { flex: 1 1 auto; text-align: center; }
.ls-vnum { width: 18pt; color: #555; }
.ls-vnum .ls-text { font-size: 9pt; line-height: 1.8; }
.ls-inst { align-items: baseline; gap: 0 6pt; white-space: nowrap; }
.ls-barline { font-weight: 400; color: #333; }
.ls-bar { display: inline-flex; gap: 0 12pt; min-width: 36pt; }
.ls-ichord.held { font-weight: 400; }

/* =====================================================================
   === key menu ===  (circle-of-fifths key popover, Hookpad style)
   ===================================================================== */
.popover.key-popover { max-width: 460px; width: 440px; padding: 14px 18px 12px; background: #2b2b2b; }
.key-picker { display: flex; flex-direction: column; gap: 14px; }
.kp-top { display: flex; align-items: flex-start; gap: 22px; }
.key-wheel { width: 160px; height: 160px; flex: none; user-select: none; }
.kw-seg path { fill: #3d3d3d; stroke: #2b2b2b; stroke-width: 1.5; transition: fill .12s; }
.kw-seg text { fill: #cfcfcf; font-size: 13px; pointer-events: none; }
.kw-seg { cursor: pointer; outline: none; }
.kw-seg:hover path, .kw-seg:focus-visible path { fill: #4d4d4d; }
.kw-seg.active path { fill: var(--active); }
.kw-seg.active text { fill: #fff; font-weight: 600; }
.key-wheel.disabled .kw-seg { cursor: not-allowed; }
.key-wheel.disabled .kw-seg:not(.active) text { fill: var(--text-faint); }
.key-wheel.disabled .kw-seg:hover path { fill: #3d3d3d; }
.key-wheel.disabled .kw-seg.active path { fill: #2d5f94; }
.kp-scales { display: flex; flex-direction: column; gap: 1px; padding-top: 2px; }
.kp-radio { display: flex; align-items: center; gap: 6px; cursor: pointer; line-height: 1.35; white-space: nowrap; }
.kp-radio input { accent-color: var(--active); margin: 0; cursor: pointer; }
.kp-change { display: flex; align-items: flex-start; gap: 10px; padding-left: 40px; }
.kp-change-label { padding-top: 1px; white-space: nowrap; }
.kp-note { color: var(--text-dim); font-size: 11.5px; line-height: 1.4; }
.kp-hint { margin: 10px 0 0; line-height: 1.45; }
.kp-sep { border: 0; border-top: 1px solid #d0d0d0; opacity: .8; margin: 16px 0 12px; }
.kp-pt-label { margin-bottom: 6px; }
.kp-pt-label em { color: var(--text-dim); }
.kp-transpose { display: block; width: 100%; margin: 4px 0 0; }
.kp-ticks { display: flex; justify-content: space-between; padding: 2px 4px 0; font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.kp-ticks span { width: 20px; text-align: center; }
.kp-ticks .zero { color: var(--text); }
.kp-result { margin-top: 4px; }
.prop-btn.transposed .prop-sub { color: var(--active); }
@media (max-width: 600px) {
  .popover.key-popover { width: calc(100vw - 24px); padding: 12px; }
  .kp-top { gap: 12px; }
  .key-wheel { width: 132px; height: 132px; }
  .kp-change { padding-left: 0; flex-wrap: wrap; }
}

/* =====================================================================
   === settings panel ===  (Settings dialog, color schemes, primary labels, pickup, line wrap)
   ===================================================================== */
/* second color of a split (Major Centric: a pitch between two major-scale degrees) */
.deg2-1 { --c2: var(--deg-1); --c2-dim: var(--deg-1-dim); }
.deg2-2 { --c2: var(--deg-2); --c2-dim: var(--deg-2-dim); }
.deg2-3 { --c2: var(--deg-3); --c2-dim: var(--deg-3-dim); }
.deg2-4 { --c2: var(--deg-4); --c2-dim: var(--deg-4-dim); }
.deg2-5 { --c2: var(--deg-5); --c2-dim: var(--deg-5-dim); }
.deg2-6 { --c2: var(--deg-6); --c2-dim: var(--deg-6-dim); }
.deg2-7 { --c2: var(--deg-7); --c2-dim: var(--deg-7-dim); }
.chord-block.split, .pop-chord.split {
  background: linear-gradient(90deg, var(--c-dim) 0 50%, var(--c2-dim) 50% 100%);
  border-color: var(--c) var(--c2) var(--c2) var(--c);
}
.chord-block.split.borrowed {
  background: repeating-linear-gradient(135deg, rgba(0,0,0,.25) 0 5px, transparent 5px 10px), linear-gradient(90deg, var(--c-dim) 0 50%, var(--c2-dim) 50% 100%);
}
.palette-btn.split .pb-roman { border-top-color: var(--c); border-bottom-color: var(--c2); background: linear-gradient(90deg, #4d4d4d 0 50%, #555 50% 100%); }
.pop-prog .pp-chords > span.split { background: linear-gradient(90deg, var(--c-dim) 0 50%, var(--c2-dim) 50% 100%); border-image: linear-gradient(90deg, var(--c) 0 50%, var(--c2) 50% 100%) 1; }

/* Primary Labels = Absolute: the chord name is the big label, the roman numeral the small one */
body.labels-absolute .chord-block .chord-name { order: -1; font-size: 15px; line-height: 18px; font-weight: 600; color: #fff; }
body.labels-absolute .chord-block .chord-roman { font-size: 11px; line-height: 13px; color: rgba(255,255,255,.75); }
body.labels-absolute .chord-block .chord-roman .chord-fig { font-size: 8px; }
body.labels-absolute .chord-block .chord-roman .chord-sec { font-size: 10px; }
body.labels-absolute .chord-block.narrow .chord-name { display: block; font-size: 12px; }
body.labels-absolute .chord-block.narrow .chord-roman { display: none; }
body.labels-absolute .chord-block.rest .chord-name { font-weight: 400; color: #aaa; }
body.labels-absolute .pop-chord .pc-name { order: -1; font-size: 15px; font-weight: 600; opacity: 1; }
body.labels-absolute .pop-chord .pc-roman { font-size: 11px; opacity: .8; }
.palette-btn.abs .pb-roman { font-family: "Segoe UI", system-ui, sans-serif; font-size: 20px; font-weight: 600; }
.palette-btn.abs .pb-name { font-family: Georgia, "Times New Roman", serif; font-size: 14px; }

/* pickup measure and manual line breaks in the grid */
.measure-header.pickup { color: var(--text-dim); font-style: italic; }
.measure-cell.pickup { background: repeating-linear-gradient(135deg, rgba(255,255,255,.025) 0 6px, transparent 6px 12px); }
.measure-header.line-break::before { content: "↵"; position: absolute; right: 2px; top: 0; font-size: 10px; color: var(--cursor); opacity: .8; }
.measure-header.line-break .measure-badges { margin-right: 12px; }

/* Settings dialog (Hookpad style: section heading, rounded card of label/control rows, Done bottom-right) */
.dialog[data-dialog="settings"] { width: min(470px, calc(100vw - 32px)); max-height: min(720px, calc(100vh - 48px)); background: #2b2b2b; }
.dialog[data-dialog="settings"] .dialog-header { background: #232323; border-radius: 8px 8px 0 0; font-size: 14px; }
.dialog[data-dialog="settings"] .dialog-body { padding: 18px 20px 22px; background: #333; scrollbar-color: #666 #2b2b2b; }
.dialog[data-dialog="settings"] .dialog-footer { background: #2b2b2b; border-radius: 0 0 8px 8px; padding: 12px 18px; }
.dialog[data-dialog="settings"] .dialog-footer .btn-primary { min-width: 64px; min-height: 34px; border-radius: 4px; font-size: 14px; }
.set-heading { margin: 4px 0 6px 20px; font-size: 15px; font-weight: 600; color: #e0e0e0; }
.set-heading:not(:first-child) { margin-top: 24px; }
.set-subtitle { margin: 0 0 14px 20px; color: #c8c8c8; font-size: 13px; }
.set-card { background: #3e3e3e; border-radius: 10px; overflow: hidden; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 46px; padding: 10px 20px; border-top: 1px solid #4c4c4c;
}
.set-row:first-child { border-top: 0; }
.set-label { color: #d6d6d6; font-size: 13px; line-height: 1.3; }
.set-sub { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.set-control { flex: 0 0 auto; display: flex; align-items: center; justify-content: flex-end; min-width: 170px; }
.set-radios { display: flex; flex-direction: column; gap: 4px; min-width: 170px; }
.set-radio { display: flex; align-items: center; gap: 6px; cursor: pointer; color: #e6e6e6; line-height: 1.35; white-space: nowrap; }
.set-radio input { margin: 0; width: 14px; height: 14px; accent-color: var(--active); cursor: pointer; }
.set-mpl { min-width: 14px; display: inline-block; text-align: right; }
.set-mpl-ctl { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; }
.set-stepper { display: inline-flex; align-items: center; gap: 2px; }
.set-step { width: 20px; height: 20px; border-radius: 4px; font-size: 16px; line-height: 18px; color: #e6e6e6; }
.set-step:hover:not(:disabled) { background: #555; }
.set-pickup { display: flex; align-items: center; gap: 12px; }
.set-pickup-len { display: inline-flex; align-items: center; gap: 4px; color: #e6e6e6; }
.set-pickup-text { min-width: 56px; }
/* iOS-style switch */
.set-switch { position: relative; display: inline-block; width: 30px; height: 16px; cursor: pointer; flex: none; }
.set-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.set-slider { position: absolute; inset: 3px 0; border-radius: 6px; background: #777; transition: background .15s; }
.set-slider::before {
  content: ""; position: absolute; left: -1px; top: -4px; width: 18px; height: 18px; border-radius: 50%;
  background: #f2f2f2; box-shadow: 0 1px 2px rgba(0,0,0,.4); transition: transform .15s, background .15s;
}
.set-switch input:checked + .set-slider { background: #3d7fcc; }
.set-switch input:checked + .set-slider::before { transform: translateX(14px); background: var(--active); }
.set-switch input:focus-visible + .set-slider { outline: 2px solid var(--cursor); outline-offset: 3px; }
.set-switch.disabled { opacity: .45; cursor: not-allowed; }
.set-switch.disabled input { cursor: not-allowed; }
@media (max-width: 600px) {
  .set-row { padding: 10px 14px; flex-wrap: wrap; }
  .set-heading, .set-subtitle { margin-left: 4px; }
  .set-control, .set-radios { min-width: 0; }
}

/* chord sheet: pickup bar (unnumbered, narrow first column) and "both, roman numerals big" */
.sheet-line.has-pickup .sheet-bar:nth-child(2) .sheet-num { display: block; }
.sheet-bar.pickup .sheet-bar-body { border-left-style: dotted; }
.sheet-labels-both-roman .sheet-bar-body { height: 38pt; }
.sheet-labels-both-roman .sc-roman { font-size: 15pt; }
.sheet-labels-both-roman .sc-name { font-size: 10pt; font-weight: 400; }
.sheet-mpl-8.sheet-labels-both-roman .sc-roman { font-size: 11pt; }
.sheet-mpl-8.sheet-labels-both-roman .sc-name { font-size: 8pt; }

/* =====================================================================
   === melody ===  (note staff above the chord staff, piano/guitar panel)
   ===================================================================== */
.note-staff {
  position: relative; display: flex; margin-bottom: 4px;
  border: 1px solid #777; background: #262626; cursor: text;
}
.note-staff > .measure-cell { z-index: 1; pointer-events: none; }
.ns-row { position: absolute; left: 0; right: 0; z-index: 0; border-top: 1px solid rgba(0, 0, 0, .28); pointer-events: none; }
.ns-row:first-child { border-top: 0; }
.ns-row.tint { background: var(--c-dim); }
.ns-row.tint.split { background: linear-gradient(90deg, var(--c-dim) 0 50%, var(--c2-dim) 50% 100%); }
.ns-row.chromatic { background: #1f1f1f; }
.note-staff.plain .ns-row { border-top-color: #333; }
.note-staff.plain .ns-row.tonic { background: rgba(192, 48, 43, .12); }
.ns-label {
  position: absolute; left: calc(-1 * var(--gutter) + 2px); width: calc(var(--gutter) - 6px);
  font-size: 9.5px; color: #d8d8d8; white-space: nowrap; overflow: hidden; pointer-events: none;
}
.ns-label.tonic { color: #ff5a4f; }
.ns-label.chromatic { color: var(--text-faint); font-size: 8px; }
.note-staff.expanded .ns-label { font-size: 9px; } /* expanded rows are 10px: labels never overlap */
.note-staff.expanded .ns-label.chromatic { font-size: 8px; }
.ns-label sub { font-size: 7px; vertical-align: baseline; margin-left: 1px; color: var(--text-dim); }
.ns-guide { position: absolute; z-index: 0; background: var(--c); opacity: .42; pointer-events: none; border-top: 1px solid rgba(0, 0, 0, .3); }
.ns-guide.root { opacity: .7; }
.ns-guide.split { background: linear-gradient(90deg, var(--c) 0 50%, var(--c2) 50% 100%); }
.ns-note {
  position: absolute; z-index: 3; background: var(--c); border: 1px solid rgba(0, 0, 0, .45); border-radius: 2px;
  color: #fff; font-size: 9px; font-weight: 700; line-height: 9px; overflow: hidden; white-space: nowrap; cursor: grab;
  display: flex; align-items: center; padding-left: 2px; text-shadow: 0 0 2px rgba(0, 0, 0, .7);
}
.ns-note:hover { filter: brightness(1.18); }
.ns-note.split { background: linear-gradient(90deg, var(--c) 0 50%, var(--c2) 50% 100%); }
.ns-note.rest { background: repeating-linear-gradient(135deg, rgba(120,120,120,.28) 0 5px, rgba(80,80,80,.16) 5px 10px); border: 1px dashed #777; z-index: 2; }
.ns-note.selected { box-shadow: 0 0 0 2px var(--select), 0 0 8px rgba(255, 255, 255, .45); z-index: 4; }
.ns-note.dragging { opacity: .85; z-index: 6; cursor: grabbing; }
.ns-note.cont-left { border-left-width: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.ns-note.cont-right { border-right-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ns-note.tiny .ns-txt { display: none; }
.ns-resize { position: absolute; top: 0; right: -1px; bottom: 0; width: 6px; cursor: ew-resize; }
.ns-resize:hover { background: rgba(255, 255, 255, .35); }
.note-staff.split-mode, .note-staff.split-mode .ns-note { cursor: crosshair; }
.ns-caret { top: 0; bottom: 0; }
.ns-hint { font-size: 12px; z-index: 2; text-shadow: 0 0 3px #000; }
/* the staff that receives typing (the one last clicked) when both are shown */
.note-staff.focused, .chord-staff.focused { box-shadow: 0 0 0 1px var(--cursor); }
.grid-line .note-staff.focused::before, .grid-line .chord-staff.focused::before {
  content: ""; position: absolute; left: -5px; top: 0; bottom: 0; width: 3px; border-radius: 2px; background: var(--cursor); opacity: .8;
}
body.view-mode .note-staff, body.view-mode .ns-note { cursor: default; }

/* Show Piano/Guitar: bottom panel with a 2-octave keyboard and a guitar chord diagram */
#instrument-panel {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 28px;
  padding: 8px 16px 10px; background: #262626; border-top: 1px solid #111; min-height: 128px;
}
#instrument-panel.hidden { display: none; }
.ip-block { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ip-title { font-size: 12px; color: var(--text-dim); min-height: 16px; }
.ip-title b { color: var(--text); font-weight: 600; margin-right: 6px; }
.ip-piano { display: block; }
.ip-piano .wk { fill: #f2f2f2; stroke: #222; stroke-width: 1; }
.ip-piano .bk { fill: #1a1a1a; stroke: #000; stroke-width: 1; }
.ip-piano .on { fill: var(--c); }
.ip-piano .bass-dot { fill: #fff; stroke: #000; stroke-width: 1; }
.ip-piano .mel-dot { fill: var(--playhead); stroke: #000; stroke-width: 1; }
.ip-piano text { font-size: 8px; fill: #111; text-anchor: middle; pointer-events: none; }
.ip-piano text.lt { fill: #fff; }
.ip-guitar line { stroke: #bbb; stroke-width: 1; }
.ip-guitar .nut { stroke: #eee; stroke-width: 4; }
.ip-guitar .dot { fill: var(--c); stroke: #000; stroke-width: .8; }
.ip-guitar .barre { fill: var(--c); opacity: .85; }
.ip-guitar text { font-size: 10px; fill: #ddd; text-anchor: middle; }
.ip-guitar text.fret { font-size: 10px; text-anchor: start; fill: var(--text-dim); }
.ip-legend { font-size: 10.5px; color: var(--text-dim); display: flex; gap: 10px; }
.ip-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: -1px; margin-right: 3px; border: 1px solid #000; }
.ip-empty { color: var(--text-faint); font-size: 12px; }
/* narrow / short windows: piano and guitar side by side, scaled to the panel's height; the panel shrinks first
   (capped at 30vh / 160px; the grid keeps its min-height), so it never covers the staffs */
@media (max-width: 700px), (max-height: 700px) {
  #instrument-panel {
    flex: 0 0 auto; gap: 10px; flex-wrap: nowrap; align-items: stretch; padding: 4px 8px 6px;
    min-height: 0; height: 30vh; max-height: 160px; overflow: hidden;
  }
  #instrument-panel .ip-block { min-width: 0; min-height: 0; flex: 1 1 auto; justify-content: flex-start; }
  #instrument-panel .ip-block:last-child { flex: 0 1 28%; }
  #instrument-panel .ip-block svg { flex: 1 1 0; min-height: 0; width: 100%; height: 100%; }
  #instrument-panel .ip-legend { display: none; }
  #instrument-panel .ip-title { flex: 0 0 auto; font-size: 11px; min-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #instrument-panel .ip-empty { height: auto !important; }
}
/* phones with the piano/guitar panel on: the tall palette toolbar scrolls inside itself instead of pushing the grid
   and the panel off the screen (the grid keeps >= 120px, the panel ~110px) */
@media (max-width: 600px) {
  body:has(#instrument-panel:not(.hidden)) #toolbar { flex-shrink: 1; min-height: 90px; overflow-y: auto; }
  #instrument-panel { height: 110px; flex-shrink: 0; }
}
