/* app.css — PatternLab webapp shell + Pattern tab.
   Reuses the dark theme palette from explorer.css. */
:root {
  color-scheme: dark;   /* native scrollbars/controls render dark */
  --bg-dark: #1A1A2E; --bg-mid: #16213E; --bg-panel: #0F3460; --bg-card: #1E2A45;
  --text-main: #E8EAF6; --text-dim: #7986CB; --text-muted: #455A7A;
  --green: #4CAF50; --green-hov: #388E3C; --amber: #FFC107; --accent: #4A9EFF;
  --accent-hov: #1565C0; --red: #C0392B; --red-hov: #922B21; --red-soft: #E57373;
  --inactive: #2A3A5A; --gold: #B8860B; --gold-hov: #9A7209;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg-dark); color: var(--text-main);
  font-family: system-ui, -apple-system, sans-serif; font-size: 14px;
  /* explorer.css (loaded for the embedded SE) pins ITS standalone shell to
     height:100vh + overflow:hidden; the app page must scroll naturally instead
     (short monitors need to reach the notation panel below the preview). */
  display: flex; flex-direction: column;
  height: auto; min-height: 100vh; overflow: visible;
}
#app { flex: 1; }
#app-header {
  padding: 10px 18px; background: var(--bg-mid);
  border-bottom: 1px solid var(--bg-panel);
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand .title { color: #F0862E; font-size: 20px; font-weight: 700; }
.brand .ver { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.brand .subtitle { color: var(--text-dim); font-size: 14px; font-weight: 400; }
#session-controls { display: flex; gap: 6px; white-space: nowrap; position: relative; }
.session-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.session-btn:hover { background: var(--accent-hov); }

/* Grouped "☰ ▾" header menu (Patterns + Session) */
.menu-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 6px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.menu-btn:hover { background: var(--accent-hov); }
.menu-panel {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  background: var(--bg-card); border: 1px solid var(--bg-panel); border-radius: 8px;
  padding: 6px; min-width: 220px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
/* [hidden] from the UA sheet is too low-specificity to beat `.menu-panel` above,
   so the panel would never hide — this makes the hidden state win. */
.menu-panel[hidden] { display: none; }
.menu-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding: 6px 10px 2px; }
.menu-item {
  background: transparent; color: var(--text-main); border: none; text-align: left;
  border-radius: 5px; padding: 7px 10px; font-size: 13px; cursor: pointer;
}
.menu-item:hover { background: var(--bg-panel); }
.menu-sep { height: 1px; background: var(--bg-panel); margin: 4px 2px; }

/* Pattern Manager modal */
.pm-modal {
  background: var(--bg-dark); border: 1px solid var(--bg-panel); border-radius: 10px;
  width: min(1080px, 96vw); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.pm-head { display: flex; align-items: center; gap: 14px; padding: 14px 18px; background: var(--bg-mid); border-bottom: 1px solid var(--bg-panel); }
.pm-title { font-size: 16px; font-weight: 700; color: var(--accent); }
.pm-sort { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.pm-sort-btn { background: var(--bg-panel); color: var(--text-dim); border: 1px solid var(--text-muted); border-radius: 5px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.pm-sort-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pm-close { padding: 5px 10px; }
.pm-list { overflow-y: auto; }
.pm-row { display: flex; align-items: center; gap: 8px; padding: 6px 18px; border-bottom: 1px solid var(--bg-mid); }
.pm-colhead { background: var(--bg-panel); color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.pm-cell { font-size: 13px; color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-cell.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.pm-c-name { flex: 0 0 200px; }
.pm-c-badge { flex: 0 0 40px; text-align: center; font-size: 11px; font-weight: 700; }
.pm-c-badge.triadPair { color: var(--amber); }
.pm-c-badge.poly { color: var(--accent); }
.pm-c-struct { flex: 0 0 170px; }
.pm-c-prev { flex: 1 1 220px; }
.pm-c-dir { flex: 0 0 100px; }
.pm-c-size { flex: 0 0 50px; text-align: center; }
.pm-c-act { flex: 0 0 200px; display: flex; gap: 4px; justify-content: flex-end; }
.pm-c-act button { border: none; border-radius: 5px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: #fff; }
.pm-load { background: var(--green); } .pm-load:hover { background: var(--green-hov); }
.pm-rename { background: var(--bg-panel); color: var(--text-dim) !important; border: 1px solid var(--text-muted) !important; }
.pm-delete { background: var(--red); }
.pm-empty { padding: 28px; text-align: center; }

/* "?" Getting Started help — modal styles live in helpPanel.js (self-contained,
   shared with the explorer.html shell); only the header button tweak is here. */
.help-btn { padding: 6px 12px; }

/* tab bar — centered amber pills (matches desktop) */
#app-tabs { flex: 1; display: flex; gap: 4px; justify-content: center; }
.app-tab {
  background: var(--bg-panel); color: var(--text-main); border: none; border-radius: 6px;
  padding: 8px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.app-tab.on { background: var(--amber); color: #1A1A2E; }
.app-tab:hover { background: #E6AC00; color: #1A1A2E; }

.pattern-tab { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* Structure Type card + Numeric Structure card (desktop-style split) */
.struct-cat { margin-top: 8px; font-size: 15px; font-weight: 600; }
.num-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.num-head .card-title { margin: 0; }
.num-head .struct-name { font-size: 15px; letter-spacing: 1px; }
.card.flex2 { flex: 2; }
.tp-line { margin: 4px 0; font-size: 13px; }
.tp-line.t1line { color: #E07040; }
.tp-line.t2line { color: var(--green); }
.key-explore-row { margin-top: 10px; }

/* global playback bar (footer) */
#app-footer { position: sticky; bottom: 0; background: var(--bg-mid); border-top: 1px solid var(--bg-panel); }
.playback-bar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; justify-content: flex-end; }
.play-btn {
  background: #5C6BC0; color: #fff; border: none; border-radius: 6px;
  padding: 7px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.play-btn:hover { background: #3949AB; }
.play-btn.stopping { background: #E53935; }
.play-btn.stopping:hover { background: #B71C1C; }
/* Export button shares the playback bar but sits on the far left, separated
   from the Play/Vol/BPM cluster (which stays right-aligned). */
.export-btn { margin-right: auto; background: var(--green); }
.export-btn:hover { background: var(--green-hov); }
.pb-slider { display: flex; align-items: center; gap: 6px; }
.pb-lbl { color: var(--text-main); font-size: 13px; }
.pb-val { color: var(--text-dim); font-size: 13px; min-width: 26px; text-align: right; }
.pb-range { width: 100px; accent-color: var(--accent); }
.pb-range:disabled { opacity: 0.5; }
.pb-status { color: var(--text-dim); font-size: 12px; min-width: 70px; }

/* triad arm buttons + assignment colours (Triad Pair tab) */
.arm-btn { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--text-muted); border-radius: 5px; padding: 5px 12px; }
.arm-btn.arm1.on { background: #E07040; color: #fff; border-color: #E07040; }
.arm-btn.arm2.on { background: var(--green); color: #fff; border-color: var(--green); }
.deg-btn.t1 { border-color: #E07040; box-shadow: inset 0 -3px 0 #E07040; }
.deg-btn.t2 { border-color: var(--green); box-shadow: inset 0 -3px 0 var(--green); }
/* align-items: stretch so cards in the same row share the tallest card's height */
.card-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: stretch; }
.card {
  background: var(--bg-card); border-radius: 8px; padding: 12px 14px;
  flex: 1; min-width: 240px; border: 1px solid var(--bg-panel);
}
/* Card titles: desktop FONT_HEAD ('SF Pro Display' 15 bold), Title Case, TEXT_MAIN */
.card-title { font-size: 15px; font-weight: 700; color: var(--text-main); margin-bottom: 8px; }
.amber { color: var(--amber); }
.dim { color: var(--text-dim); }
.lbl { color: var(--text-main); font-size: 12px; }

select.ctrl, .ctrl {
  background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--text-muted);
  border-radius: 5px; padding: 5px 8px; font-size: 13px; min-width: 70px;
}

button { cursor: pointer; font-family: inherit; }
.btn-accent, .btn-green, .btn-mute, .btn-red {
  border: none; border-radius: 5px; padding: 6px 12px; font-size: 13px; color: #fff;
}
.btn-accent { background: var(--accent); } .btn-accent:hover { background: var(--accent-hov); }
.btn-green { background: var(--green); } .btn-green:hover { background: var(--green-hov); }
.btn-green:disabled { background: var(--text-muted); cursor: not-allowed; opacity: .6; }
.btn-mute { background: var(--bg-panel); color: var(--text-dim); border: 1px solid var(--text-muted); }
/* Reset/Clear buttons — desktop parity (RED / RED_HOV / TEXT_MAIN) */
.btn-red { background: var(--red); color: var(--text-main); border: none; }
.btn-red:hover { background: var(--red-hov); }

/* structure */
.struct-name { font-weight: 600; margin-bottom: 6px; min-height: 18px; }
.deg-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.deg-pair { display: flex; flex-direction: column; gap: 2px; }
.deg-btn {
  background: var(--bg-panel); color: var(--text-dim); border: 1px solid var(--text-muted);
  border-radius: 4px; padding: 4px 8px; font-size: 12px; min-width: 34px;
}
.deg-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
/* 14px matches desktop FONT_MONO ('SF Mono', 14); colour token (TEXT_DIM) is identical */
.struct-notes { font-family: ui-monospace, monospace; font-size: 14px; margin-bottom: 8px; }
.row-btns, .range-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range-row { margin-top: 8px; }

/* moves */
.moves-wrap { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.move-row { display: flex; gap: 3px; align-items: center; }
/* Move-row segments — desktop parity: INACTIVE/TEXT_DIM at rest; active kind
   (Step/Skip) = GREEN, active direction (↑↓→) = ACCENT, both with TEXT_DARK. */
.seg {
  background: var(--inactive); color: var(--text-dim); border: 1px solid var(--inactive);
  border-radius: 4px; padding: 4px 9px; font-size: 13px; min-width: 30px;
}
.seg.on { background: var(--accent); color: #111; border-color: var(--accent); }
.seg-kind.on { background: var(--green); color: #111; border-color: var(--green); }
.seg-dir.on { background: var(--accent); color: #111; border-color: var(--accent); }
.seg-n { background: var(--gold); color: #111; border-color: var(--gold); }
.seg-n:hover { background: var(--gold-hov); }
.nlab { min-width: 20px; text-align: center; color: var(--text-main); font-family: ui-monospace, monospace; }
.del { background: transparent; border: none; color: var(--red); font-size: 15px; }

/* connector */
.mode-toggle { display: flex; gap: 4px; margin-bottom: 10px; }
.mode-btn { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--text-muted); border-radius: 5px; padding: 5px 12px; font-size: 13px; }
.mode-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.conn-panel { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.dir-btn { background: var(--inactive); color: var(--text-dim); border: 1px solid var(--inactive); border-radius: 4px; padding: 4px 10px; }
.dir-btn.on { background: var(--accent); color: #111; border-color: var(--accent); }
.pt-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0 10px; }

/* preview */
.preview-status { margin-bottom: 8px; font-size: 13px; }
/* Direction word colours — desktop _direction_text_and_color */
.pv-dir-asc { color: var(--green); }
.pv-dir-desc { color: var(--red-soft); }
.pv-dir-cyc { color: var(--amber); }
.preview-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; align-items: center; }
.pv-cell { display: flex; gap: 2px; padding: 6px 8px; background: var(--bg-panel); border-radius: 6px; }
.pv-col { display: flex; flex-direction: column; align-items: center; min-width: 30px; }
.pv-note { font-weight: 600; font-family: ui-monospace, monospace; }
.pv-arrow { color: var(--green); height: 16px; }
.pv-deg { color: var(--amber); font-size: 12px; }
.pv-conn { color: var(--green); font-size: 18px; }

.export-bar { display: flex; gap: 12px; align-items: center; padding-top: 4px; }
.status-lbl { font-size: 13px; }

/* notation preview (Verovio) */
.notation-wrap { margin-top: 10px; border-top: 1px solid var(--bg-panel); padding-top: 10px; }
.notation-bar { display: flex; gap: 10px; align-items: center; }
/* Desktop parity: the ♩ Notation button is indigo like Play (#5C6BC0 / #3949AB) */
.notation-toggle { background: #5C6BC0; color: #fff; border: none; }
.notation-toggle:hover { background: #3949AB; }
.notation-toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.notation-label { font-size: 12px; }
.notation-scroll {
  margin-top: 8px; background: #fff; border-radius: 6px; padding: 8px;
  overflow-x: auto; overflow-y: hidden; max-height: 340px; min-height: 60px;
}
.notation-scroll.loading { opacity: .5; }
.notation-scroll svg { height: auto; max-height: 320px; }
.notation-empty { color: #455A7A; font-size: 13px; padding: 16px; }

/* Page vertical scrollbar — themed like the Preview bar (dark track, dim thumb,
   accent on hover). Chrome/Edge via ::-webkit-scrollbar, Firefox via
   scrollbar-color (inherits, so in-app scrollables match too). Safari ignores
   scrollbar COLOURS — it shows its dark auto-hiding overlay (color-scheme);
   an exact Safari match would need a scrollbar.js vertical variant. */
:root { scrollbar-color: var(--text-dim) var(--bg-dark); }
html::-webkit-scrollbar { width: 10px; background: var(--bg-dark); }
html::-webkit-scrollbar-track { background: var(--bg-dark); border-radius: 5px; }
html::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 5px; }
html::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Custom horizontal scrollbar (scrollbar.js). Safari ignores ::-webkit-scrollbar
   colours, so the Preview/Notation bars are drawn as divs that render the same
   in every browser. The native bar is hidden on `.cbar-host`. */
.cbar-host { scrollbar-width: none; -ms-overflow-style: none; }
.cbar-host::-webkit-scrollbar { display: none; }
.cbar-track {
  position: relative; height: 10px; margin-top: 6px; border-radius: 5px;
  background: var(--bg-dark);              /* Preview: dark track on the dark card */
  touch-action: none;
}
.cbar-thumb {
  position: absolute; top: 1px; left: 0; height: 8px; min-width: 24px; border-radius: 4px;
  background: var(--text-dim);             /* Preview: lighter, visible thumb */
  cursor: grab; will-change: transform;
}
.cbar-thumb:hover { background: var(--accent); }
.cbar-thumb:active { cursor: grabbing; }
/* Notation sits on the white staff → light track, DARK thumb so it reads. */
.cbar-notation { background: #E0E4E8; }
.cbar-notation .cbar-thumb { background: #37474F; }
.cbar-notation .cbar-thumb:hover { background: #1C262B; }

/* SE modal + export dialog */
.se-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.se-modal {
  width: min(1100px, 94vw); height: min(760px, 90vh); background: var(--bg-dark);
  border-radius: 10px; overflow: hidden; display: flex; flex-direction: column;
  position: relative; border: 1px solid var(--bg-panel);
}
.se-close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.se-mount { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
/* embedded SE: keep the selection bar visible so the Apply affordance is obvious */
.se-mount #selbar { display: flex !important; flex-wrap: wrap; gap: 10px; align-items: center; }
.apply-btn {
  margin-left: auto; background: var(--green); color: #fff; border: none;
  border-radius: 6px; padding: 7px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.apply-btn:hover { background: var(--green-hov); }
.apply-hint { margin-left: auto; color: var(--text-dim); font-size: 12px; }
.export-dialog {
  background: var(--bg-card); border-radius: 10px; padding: 20px 24px;
  width: min(460px, 92vw); max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--bg-panel); display: flex; flex-direction: column; gap: 6px;
}
.export-dialog .opt { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.export-dialog .opt-group { height: 6px; }
.export-dialog .opt-list { display: flex; flex-direction: column; gap: 3px; }
.export-sec {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin-top: 12px; margin-bottom: 2px;
}
.export-custom-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px 8px;
  background: var(--bg-panel); border-radius: 8px; padding: 8px 10px;
}
.export-key-chk { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-main); }
.export-order-block {
  background: var(--bg-panel); border-radius: 8px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.export-order-head { display: flex; align-items: center; gap: 6px; }
.export-order-head .lbl { flex: 1; color: var(--text-main); }
.export-preset-row { display: flex; flex-wrap: wrap; gap: 4px; }
.export-chip-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.export-chip {
  background: var(--bg-card); color: var(--text-main);
  border: 1px solid var(--text-muted); border-radius: 5px; padding: 3px 8px; font-size: 12px; min-width: 50px;
}
.export-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.dialog-btns { display: flex; gap: 8px; margin-top: 12px; }
