:root {
  font-family: "Segoe UI", Arial, sans-serif;
  color: #20252b;
  background: #e9edf2;
  font-synthesis: none;
  --panel: #f7f8fa;
  --border: #aeb8c4;
  --accent: #575c6b;
  --root: #4a90e2;
  --guide: #e6a23c;
  --other: #67c23a;
  --previous: #b8b8b8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 760px;
  margin: 0;
  background: #e9edf2;
  font-size: 13px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { cursor: default; opacity: .56; }

.menu-bar {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 2px;
  padding: 0 11px;
  background: var(--accent);
  color: white;
}

.app-name {
  margin-right: 13px;
  color: white;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.menu { position: relative; }
.menu > summary {
  padding: 6px 9px;
  border-radius: 3px;
  cursor: pointer;
  list-style: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary, .menu > summary:hover { background: #6a7080; }
.menu-items {
  position: absolute;
  z-index: 20;
  top: calc(100% + 1px);
  left: 0;
  display: grid;
  min-width: 230px;
  gap: 2px;
  padding: 5px;
  border: 1px solid #929aa5;
  border-radius: 3px;
  background: #fafbfc;
  box-shadow: 0 5px 16px #0003;
  color: #20252b;
}
.menu-items button {
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.menu-items button:hover { background: #e4e9ef; }
.menu-items button + button:nth-of-type(4) { border-top: 1px solid #c8cdd3; }
.menu-note { padding: 5px 8px; color: #68727d; font-size: 11px; }
.menu-items label { padding: 4px 8px 0; color: #4c5661; font-size: 11px; }
.menu-items select { margin: 0 7px 5px; }
.menu-spacer { flex: 1; }
.theme-toggle {
  min-height: 25px;
  padding: 3px 8px;
  border: 1px solid #aeb8c4;
  border-radius: 3px;
  background: transparent;
  color: white;
  font-size: 11px;
}
.theme-toggle:hover { background: #6a7080; }

main { padding: 10px 12px 16px; }
.chord-entry {
  display: flex;
  min-height: 37px;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}
.chord-entry > label { font-weight: 600; }
input[type="text"], input[type="number"], select {
  min-height: 28px;
  padding: 3px 7px;
  border: 1px solid #aeb7c2;
  border-radius: 3px;
  background: white;
  color: #20252b;
}
#chord-input { width: min(360px, 35vw); }
.button {
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid #aab3bf;
  border-radius: 3px;
  background: linear-gradient(#fff, #e9edf2);
  color: #20252b;
}
.button:hover:not(:disabled) { background: #e2e8ef; border-color: #7f8b99; }
.button:active:not(:disabled) { background: #d7dfe8; }
.button.secondary { background: #f4f5f7; }
.error-message { color: #a12622; font-size: 12px; }

.top-workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(250px, 1fr);
  gap: 8px;
  min-height: 290px;
  margin-bottom: 8px;
}
.table-panel, .control-panel, .visualizer-panel {
  min-width: 0;
  border: 1px solid #b7c0ca;
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 1px 2px #17202a12;
}
.table-panel { display: flex; min-height: 250px; flex-direction: column; padding: 6px; }
.progression-legend {
  display: flex;
  min-height: 31px;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
}
.legend-chip {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid #777;
  border-radius: 4px;
  color: #17202a;
  font-size: 11px;
  white-space: nowrap;
}
.root-color { background: var(--root); }
.guide-color { background: var(--guide); }
.other-color { background: var(--other); }
.previous-color { background: var(--previous); }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
#progression-table { min-width: 640px; }
th {
  padding: 7px 6px;
  border: 1px solid #c5ccd4;
  background: #e5e9ee;
  font-size: 12px;
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
}
td {
  height: 34px;
  padding: 3px 6px;
  border: 1px solid #d2d7de;
  background: #fff;
  white-space: nowrap;
}
tr.progression-row { cursor: default; }
tr.progression-row:hover td { background: #f1f5f9; }
tr.progression-row.selected td { background: #dce8f4; }
tr.progression-row.dragging { opacity: .42; }
tr.progression-row.drop-target td { box-shadow: inset 0 2px #3878b8; }
.notes-cell { display: flex; min-height: 26px; align-items: center; gap: 4px; }
.note-chip {
  display: inline-flex;
  width: 36px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  color: #17202a;
  font-size: 11px;
  font-weight: 700;
}
.pin-indicator { color: #3478b5; font-weight: 650; }
.remove-row {
  width: 27px;
  height: 25px;
  padding: 0;
  border: 1px solid #e5a09b;
  border-radius: 3px;
  background: #fce8e6;
  color: #a12622;
  font-weight: 700;
}
.remove-row:hover { background: #c0392b; color: white; }
.empty-table { display: grid; flex: 1; min-height: 130px; place-items: center; color: #707b88; }

.control-panel { display: flex; flex-direction: column; padding: 9px; }
h2 { margin: 0 0 10px; font-size: 15px; font-weight: 650; }
.melody-entry { display: flex; align-items: center; gap: 5px; }
.melody-entry label { white-space: nowrap; }
.melody-entry input { width: 68px; min-width: 0; }
.control-instructions { margin: 11px 0 5px; color: #48525d; font-size: 11px; }
.voicing-list {
  flex: 0 0 105px;
  overflow: auto;
  border: 1px solid #c4cbd3;
  background: white;
}
.voicing-group-title {
  padding: 5px 7px;
  background: #e8eef5;
  color: #243b53;
  font-weight: 700;
  text-transform: capitalize;
}
.voicing-option {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: 0;
  background: white;
  color: #20252b;
  text-align: left;
}
.voicing-option:hover { background: #eef3f8; }
.voicing-option.selected { background: #d4e4f3; }
.voicing-option small { margin-left: 4px; color: #687789; }
.no-selection { margin: 12px; color: #738090; font-size: 12px; }
.control-actions { display: flex; gap: 6px; margin-top: 7px; }

.visualizer-panel { padding: 8px; }
.visualizer-panel h2 { margin: 0 0 7px 3px; }
.visualizer-legend {
  display: flex;
  justify-content: flex-start;
  min-height: 31px;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid #d3d8de;
}
.previous-toggle { display: inline-flex; align-items: center; gap: 4px; margin-right: 7px; }
.previous-toggle input { margin: 0; }
.visualizer-legend > label:not(.previous-toggle) { white-space: nowrap; }
.visualizer-legend #tempo { width: 64px; }
.visualizer-legend #browser-volume { width: 100px; }
.visualizer-legend #volume-value { width: 34px; color: #596573; font-size: 11px; }
.browser-audio-note { color: #738090; font-size: 10px; white-space: nowrap; }
.views {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 8px;
  min-height: 250px;
  padding: 8px 0;
}
.view-frame {
  display: flex;
  min-width: 0;
  min-height: 220px;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid #bfc5cc;
  background: #f5f5f5;
}
canvas { display: block; width: 100%; height: 100%; min-height: 220px; }
.staff-frame { position: relative; flex-direction: column; }
.staff-frame canvas { flex: 1; min-height: 170px; }
.note-summary {
  min-height: 37px;
  padding: 3px 8px 5px;
  color: #222;
  font-size: 11px;
  line-height: 1.45;
}
dialog {
  width: min(1120px, calc(100vw - 32px));
  max-height: min(88vh, 760px);
  padding: 16px;
  border: 1px solid #929ca8;
  border-radius: 5px;
  background: #f8f9fa;
  color: #20252b;
  box-shadow: 0 12px 50px #0005;
}
dialog::backdrop { background: #10192375; }
.review-dialog { overflow: auto; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-header h2, .dirty-dialog h2 { margin-bottom: 0; font-size: 19px; }
.dialog-eyebrow { margin: 0 0 4px; color: #586574; font-size: 10px; letter-spacing: .12em; }
.close-dialog { border: 0; background: transparent; color: #596573; font-size: 23px; }
.review-instructions { margin: 10px 0; color: #56616d; font-size: 12px; }
.review-table-wrap { overflow: auto; }
.review-table { min-width: 930px; }
.review-table td { padding: 5px; }
.review-table input[type="text"] { width: 120px; }
.review-table .detected-text { color: #697684; }
.review-summary { color: #485766; font-size: 12px; }
.review-order { display: flex; gap: 2px; }
.review-order button { border: 1px solid #bec6cf; background: #f5f6f7; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 12px; }
.dirty-dialog { width: min(420px, calc(100vw - 32px)); margin: auto; }
.dirty-dialog p { margin: 12px 0; color: #56616d; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

html[data-theme="dark"] {
  color-scheme: dark;
  color: #e6e9ef;
  background: #25282e;
  --panel: #30343b;
  --border: #4b515c;
  --accent: #575c6b;
  --canvas-white: #e6e6e6;
  --canvas-key-outline: #15171b;
  --canvas-black: #111318;
  --canvas-key-label: #17191e;
}
html[data-theme="dark"] body { background: #25282e; }
html[data-theme="dark"] .menu[open] > summary,
html[data-theme="dark"] .menu > summary:hover,
html[data-theme="dark"] .theme-toggle:hover { background: #6a7080; }
html[data-theme="dark"] .menu-items {
  border-color: #555c67;
  background: #30343b;
  color: #e6e9ef;
}
html[data-theme="dark"] .menu-items button:hover { background: #414751; }
html[data-theme="dark"] .menu-items button + button:nth-of-type(4) { border-color: #555c67; }
html[data-theme="dark"] .menu-note,
html[data-theme="dark"] .menu-items label { color: #b0b8c4; }
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] select {
  border-color: #626a76;
  background: #24272d;
  color: #e6e9ef;
}
html[data-theme="dark"] input::placeholder { color: #929ba8; }
html[data-theme="dark"] .button {
  border-color: #626a76;
  background: linear-gradient(#424751, #363a43);
  color: #e6e9ef;
}
html[data-theme="dark"] .button:hover:not(:disabled) {
  border-color: #8793a2;
  background: #4b515c;
}
html[data-theme="dark"] .button:active:not(:disabled) { background: #565e69; }
html[data-theme="dark"] .button.secondary { background: #343840; }
html[data-theme="dark"] .table-panel,
html[data-theme="dark"] .control-panel,
html[data-theme="dark"] .visualizer-panel { border-color: #4b515c; }
html[data-theme="dark"] th {
  border-color: #505661;
  background: #3a3f48;
  color: #e6e9ef;
}
html[data-theme="dark"] td {
  border-color: #474d57;
  background: #2b2f36;
  color: #e6e9ef;
}
html[data-theme="dark"] tr.progression-row:hover td { background: #363d47; }
html[data-theme="dark"] tr.progression-row.selected td { background: #3c5268; }
html[data-theme="dark"] tr.progression-row.drop-target td { box-shadow: inset 0 2px #69a9e5; }
html[data-theme="dark"] .empty-table,
html[data-theme="dark"] .no-selection { color: #a7b0bd; }
html[data-theme="dark"] .control-instructions { color: #c1c8d2; }
html[data-theme="dark"] .voicing-list { border-color: #4f5661; background: #292d34; }
html[data-theme="dark"] .voicing-group-title { background: #3b4654; color: #d7e5f4; }
html[data-theme="dark"] .voicing-option { background: #292d34; color: #e6e9ef; }
html[data-theme="dark"] .voicing-option:hover { background: #363d47; }
html[data-theme="dark"] .voicing-option.selected { background: #3c5268; }
html[data-theme="dark"] .voicing-option small,
html[data-theme="dark"] #volume-value { color: #b0bac7; }
html[data-theme="dark"] .visualizer-legend { border-color: #474d57; }
html[data-theme="dark"] .view-frame { border-color: #505762; background: #30343b; }
html[data-theme="dark"] .staff-frame { background: #f5f5f5; }
html[data-theme="dark"] .staff-frame .note-summary { color: #222; }
html[data-theme="dark"] .note-summary { color: #d8dde5; }
html[data-theme="dark"] dialog {
  border-color: #59616d;
  background: #30343b;
  color: #e6e9ef;
}
html[data-theme="dark"] .dialog-eyebrow,
html[data-theme="dark"] .review-instructions,
html[data-theme="dark"] .review-summary,
html[data-theme="dark"] .dirty-dialog p { color: #b9c2ce; }
html[data-theme="dark"] .close-dialog { color: #d1d7e0; }
html[data-theme="dark"] .review-table .detected-text { color: #aeb8c4; }
html[data-theme="dark"] .review-order button {
  border-color: #59616d;
  background: #3a3f48;
  color: #e6e9ef;
}
html[data-theme="dark"] .theme-toggle { border-color: #8793a2; }

@media (min-width: 761px) and (min-height: 360px) {
  body { min-height: 100vh; display: flex; flex-direction: column; }
  main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .top-workspace {
    flex: 1 1 0;
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
  }
  .top-workspace > * { min-height: 0; }
  .table-panel, .control-panel { min-height: 0; }
  .table-scroll { flex: 1; min-height: 0; }
  .empty-table { min-height: 0; }
  .voicing-list { flex: 1 1 0; min-height: 0; }
  .visualizer-panel { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
  .views { flex: 1; min-height: 0; }
  .view-frame { min-height: 0; }
  canvas, .staff-frame canvas { min-height: 0; }
}

@media (max-width: 980px) {
  .top-workspace { grid-template-columns: minmax(0, 2fr) minmax(230px, 1fr); }
  .progression-legend { justify-content: flex-start; flex-wrap: wrap; padding-bottom: 4px; }
  .visualizer-legend { align-items: flex-start; padding: 5px 0; }
}
@media (max-width: 760px) {
  body { min-width: 360px; }
  .top-workspace { grid-template-columns: 1fr; }
  .control-panel { min-height: 245px; }
  .views { grid-template-columns: 1fr; }
  .view-frame { min-height: 205px; }
}
