/* Global layout */
:root {
  --bg-start: #0e122b;
  --bg-end: #1b1f3a;
  --card-bg: #ffffff;
  --card-border: #d9def2;
  --muted: #7c86ac;
  --text: #0c1020;
  --accent: #5568ff;
  --accent-strong: #3145ff;
  --surface: #f3f5ff;
  --key-white-base: #d8dbe1;
  --key-black-base: #5e6064;
  --pc-0: #ff6f6f;   /* C */
  --pc-1: #ff8d6f;   /* C#/Db */
  --pc-2: #ffad6f;   /* D */
  --pc-3: #ffd46f;   /* D#/Eb */
  --pc-4: #c6e16f;   /* E */
  --pc-5: #8ee58a;   /* F */
  --pc-6: #6fe1c6;   /* F#/Gb */
  --pc-7: #6fd2f0;   /* G */
  --pc-8: #6f9dff;   /* G#/Ab */
  --pc-9: #8b6dff;   /* A */
  --pc-10: #c26dff;  /* A#/Bb */
  --pc-11: #ff6de2;  /* B */
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #1f2450, var(--bg-start)), linear-gradient(135deg, var(--bg-start), var(--bg-end));
  display: flex;
  justify-content: center;
  padding: 20px 12px 36px;
  overflow-x: hidden;
}

/* Header */
.page-shell {
  width: 100%;
  max-width: 1100px;
}

.page-header {
  text-align: center;
  color: #f4f6ff;
  margin-bottom: 18px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-bottom: 4px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: #a9b4e2;
  margin: 0;
}

.info-button {
  width: clamp(20px, 3vw, 24px);
  height: clamp(20px, 3vw, 24px);
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f6ff;
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.info-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.info-button:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.sound-toggle {
  width: clamp(26px, 3.4vw, 28px);
  height: clamp(26px, 3.4vw, 28px);
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f6ff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, color 0.15s ease;
  padding: 0;
  position: relative;
}

.sound-toggle svg {
  width: 16px;
  height: 16px;
  position: relative;
  z-index: 2;
}

.sound-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.sound-toggle:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.sound-toggle.is-unmuted {
  background: rgba(85, 104, 255, 0.18);
  color: #fff;
  box-shadow: 0 8px 18px rgba(85, 104, 255, 0.35);
}

.sound-toggle.is-muted::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78%;
  height: 2px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  transform: translate(-50%, -50%) rotate(-45deg);
  z-index: 3;
}

.sound-toggle.is-unmuted::after {
  display: none;
}

.sound-toggle:focus-visible {
  outline: 2px solid #dfe3fb;
  outline-offset: 2px;
}

.panel {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 15px 40px rgba(6, 10, 50, 0.2);
}

.controls-panel {
  display: grid;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.harmony-strip {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px dashed #dfe3fb;
  border-radius: 12px;
  color: #0f1636;
  cursor: pointer;
  margin-bottom: 10px;
}

.harmony-strip-hint {
  font-size: 11px;
  color: #7b81a8;
}

.harmony-strip-label {
  font-weight: 700;
}

.scale-stack {
  display: grid;
  gap: 8px;
}

.pill-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-height: 64px;
  flex-wrap: nowrap;
}

.pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f4f6ff;
  color: #0f1636;
  border: 1px solid #dfe3fb;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
  min-height: 56px;
}

.pill-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7b81a8;
}

.pill-value {
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#keyPill {
  flex: 0 0 30%;
  min-width: 140px;
  justify-content: space-between;
}

.key-pill .pill-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  justify-content: flex-end;
}

.key-pill .pill-value {
  max-width: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.key-dual {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.key-dual:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.key-opt {
  font-weight: 600;
  opacity: 0.6;
}

.key-opt.is-active {
  font-weight: 800;
  opacity: 1;
}

.key-slash {
  opacity: 0.6;
}

#modePill {
  flex: 1 1 auto;
}

.eyebrow.subtle {
  margin: 0;
  color: var(--muted);
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
  letter-spacing: 0.1px;
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:active {
  transform: translateY(1px);
}

.ghost {
  background: #eef0ff;
  color: #1f2655;
  border: 1px solid #d3d9f4;
  box-shadow: none;
  padding: 10px 12px;
}

.ghost.micro {
  padding: 6px 8px;
  font-size: 12px;
}

.inline-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.inline-actions .ghost {
  padding: 6px 6px;
}

.inline-actions #fifthUp,
.inline-actions #fifthDown {
  padding: 4px 4px;
}

.output-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.is-hidden {
  display: none !important;
}

.scale-banner {
  background: linear-gradient(120deg, #5568ff, #7c6dff);
  color: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 16px;
  box-shadow: 0 10px 24px rgba(49, 69, 255, 0.3);
}

.scale-banner h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
}

.main-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr);
  align-items: start;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 12px 28px rgba(8, 12, 38, 0.12);
}

.card-heading {
  margin-bottom: 8px;
}

.card-heading h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.heading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.heading-row h2 {
  margin: 0 0 4px;
}

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

.chords-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chords-header {
  margin-bottom: 0;
  padding-bottom: 2px;
}

.chords-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.chords-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.chord-category-tabs {
  display: flex;
  gap: 6px;
  padding: 6px 0 8px;
  width: 100%;
  flex-wrap: nowrap;
  overflow: hidden;
}

.chord-tab {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid #dfe3fb;
  background: #f7f8ff;
  color: #1f2655;
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.chord-tab.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chord-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px rgba(85, 104, 255, 0.25);
}

.chord-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chord-category-panel {
  display: grid;
  gap: 8px;
}

.chords-scroll {
  flex: 1 1 auto;
  overflow: auto;
  max-height: calc(100dvh - 320px);
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.harmony-card {
  display: grid;
  gap: 6px;
  align-self: stretch;
  padding: 10px;
}

.harmony-header {
  display: grid;
  gap: 6px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  align-self: start;
}

.harmony-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 2px;
}

.harmony-keymode {
  font-weight: 800;
  font-size: 15px;
  color: #0f1636;
}

.harmony-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.harmony-grid-shell {
  border: 1px solid #e3e7fb;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
}

.harmony-grid {
  overflow-x: auto;
  --chord-col-min: 120px;
  --tone-col-min: 46px;
  --harmony-base-fill: 42%;
  --harmony-active-fill: 75%;
  --harmony-ghost-fill: 18%;
  position: relative;
  width: 100%;
}

.harmony-grid-header {
  display: grid;
  grid-template-columns: minmax(var(--chord-col-min), 1.6fr) repeat(var(--tone-count, 4), minmax(var(--tone-col-min), 1fr));
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #fdfdff, #f1f3ff);
  z-index: 1;
}

.harmony-grid-header .h-cell {
  padding: 2px 4px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  color: #4b5074;
  border-bottom: 1px solid #e3e7fb;
  cursor: pointer;
  border-radius: 8px;
}

.tone-head {
  border-left: 1px solid #e3e7fb;
  background: rgba(255, 255, 255, 0.9);
  transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.tone-head.is-active {
  color: #3145ff;
  box-shadow: none;
}

.tone-head:focus-visible {
  outline: 2px solid #5568ff;
  outline-offset: 2px;
}

/* Tone emphasis */
.pc-band.tone-root {
  background: var(--pc-color, #7c6dff) !important;
  color: #0c1020;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc-color, #7c6dff), transparent 40%);
}

.pc-band.tone-tone {
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 35%, #ffffff 65%) !important;
  color: #0c1020;
}

.pc-0 { --pc-color: var(--pc-0); --deg-color: var(--pc-0); }
.pc-1 { --pc-color: var(--pc-1); --deg-color: var(--pc-1); }
.pc-2 { --pc-color: var(--pc-2); --deg-color: var(--pc-2); }
.pc-3 { --pc-color: var(--pc-3); --deg-color: var(--pc-3); }
.pc-4 { --pc-color: var(--pc-4); --deg-color: var(--pc-4); }
.pc-5 { --pc-color: var(--pc-5); --deg-color: var(--pc-5); }
.pc-6 { --pc-color: var(--pc-6); --deg-color: var(--pc-6); }
.pc-7 { --pc-color: var(--pc-7); --deg-color: var(--pc-7); }
.pc-8 { --pc-color: var(--pc-8); --deg-color: var(--pc-8); }
.pc-9 { --pc-color: var(--pc-9); --deg-color: var(--pc-9); }
.pc-10 { --pc-color: var(--pc-10); --deg-color: var(--pc-10); }
.pc-11 { --pc-color: var(--pc-11); --deg-color: var(--pc-11); }

.tone-selected {
  box-shadow: 0 0 0 2px rgba(49, 69, 255, 0.45), 0 0 10px rgba(49, 69, 255, 0.35);
}

.harmony-grid-body {
  display: grid;
  grid-auto-rows: auto;
  position: relative;
  padding-bottom: 6px;
}

.harmony-grid-body.is-animating .harmony-row {
  animation: harmony-row-pop 0.18s ease;
}

.harmony-grid-body.is-animating .harmony-cell {
  transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.harmony-row {
  display: grid;
  grid-template-columns: minmax(var(--chord-col-min), 1.6fr) repeat(var(--tone-count, 4), minmax(var(--tone-col-min), 1fr));
  align-items: stretch;
  border-bottom: 1px solid #e8ecff;
  position: relative;
}

.harmony-row:last-child {
  border-bottom: none;
}

@keyframes harmony-row-pop {
  from {
    opacity: 0.72;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.h-cell, .harmony-cell {
  padding: 0 2px;
  text-align: center;
  position: relative;
  border-radius: 8px;
}

.harmony-cell {
  cursor: pointer;
  transition: background 0.12s ease, transform 0.1s ease, box-shadow 0.12s ease;
  overflow: hidden;
  border-right: 1px solid #e6e9f5;
  border-bottom: 1px solid #e6e9f5;
}

.harmony-cell .pc-band {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 4px;
  border-radius: 6px;
  background: transparent;
  color: rgba(10, 14, 28, 0.9);
  font-weight: 700;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

.root-cell {
  text-align: left;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
}

.root-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rn-cell {
  font-weight: 800;
  color: #4b5074;
  background: #fff;
  text-align: left;
  padding-left: 8px;
}

.chord-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 36%, #ffffff 64%);
  padding: 2px 4px;
}

.root-cell .degree {
  font-size: 11px;
  color: #4b5074;
  font-weight: 700;
}

.chord-chip {
  display: inline-block;
  min-width: 100px;
  max-width: 120px;
  padding: 2px 4px;
  border-radius: 6px;
  background: transparent;
  border: none;
  box-shadow: none;
  font-weight: 700;
  font-size: 12px;
  color: #151b36;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.harmony-cell.is-note-selected .pc-band {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--pc-color, #5568ff) 65%, transparent);
}

.tone-cell {
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 36%, #ffffff 64%);
}

.tone-cell.is-ghost {
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 14%, #ffffff 86%);
}

.harmony-cell[data-pc]::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--pc-color, #7c6dff), transparent 84%);
  opacity: 0.14;
  pointer-events: none;
  z-index: 0;
}

.harmony-cell.is-visible[data-pc]::before {
  opacity: 0.16;
}

.harmony-cell.is-ghost[data-pc]::before {
  opacity: 0.08;
}

.harmony-cell.is-ghost .pc-band {
  opacity: 0.18;
  filter: saturate(0.85);
}

.harmony-grid-header .root-head {
  text-align: left;
}

.rn-head {
  text-align: center;
}

.chord-head {
  text-align: left;
}

.harmony-grid .sticky-col {
  position: sticky;
  z-index: 2;
  background: #fff;
}

.harmony-grid .sticky-col.chord-cell,
.harmony-grid-header .chord-head {
  left: 0;
}

.harmony-grid .sticky-col.root-cell {
  z-index: 3;
}


.filter-status {
  font-size: 12px;
  color: #5c6385;
}

.info-modal .wheel-modal-content {
  max-width: 520px;
  max-height: min(80vh, 560px);
  gap: 0;
}

.info-body {
  display: grid;
  gap: 10px;
  color: #1e2340;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

.info-section ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: #1e2340;
}

.info-section li {
  margin: 4px 0;
  font-size: 14px;
}

.info-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  padding-bottom: 6px;
}

.info-howto ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: #1e2340;
}

.info-howto li {
  margin: 4px 0;
  font-size: 14px;
}

.info-modal .wheel-modal-header {
  align-items: flex-start;
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fff;
}

.info-modal .wheel-modal-header h3 {
  margin: 0;
  flex: 1 1 auto;
  font-size: 18px;
  text-align: left;
}

.card-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.selections-card {
  display: grid;
  gap: 12px;
}

.instruments-card {
  position: static;
  align-self: start;
  position: relative;
}

.instrument-stack {
  display: grid;
  gap: 8px;
  --instrument-height: clamp(110px, 20vw, 140px);
}

.instrument {
  background: #f8f9ff;
  border: 1px solid #e3e6f7;
  border-radius: 14px;
  padding: 8px;
  overflow: hidden;
  position: relative;
}

.instrument.fretboard {
  padding: 12px;
}

/* Keyboard */
.note-label.is-playing > div,
#keyboardVisualizer .key.is-playing,
#fretboardVisualizer .fret-note.is-playing {
  box-shadow: 0 0 0 2px rgba(85, 104, 255, 0.35), 0 8px 18px rgba(85, 104, 255, 0.35);
  filter: brightness(1.08);
  transform: translateY(-1px) scale(1.01);
  transition: box-shadow 0.08s ease, filter 0.08s ease, transform 0.08s ease;
}

#fretboardVisualizer .fret-note.is-playing {
  transform: translate(-50%, -50%) scale(1.12);
}

#keyboardVisualizer .key.spotlit,
#fretboardVisualizer .fret-note.spotlit {
  box-shadow: 0 0 0 2px rgba(85, 104, 255, 0.45), 0 8px 16px rgba(85, 104, 255, 0.25);
}

.keyboard {
  width: 100%;
}

.keyboard-black {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 52px;
  pointer-events: none;
  z-index: 20;
}

.keyboard-shell {
  position: relative;
  width: 100%;
  --white-count: 14;
  z-index: 1;
}

.keyboard-white {
  display: grid;
  grid-template-columns: repeat(var(--white-count), 1fr);
  gap: 4px;
  height: var(--instrument-height);
  align-items: stretch;
}

.key {
  --key-base: var(--key-white-base);
  border-radius: 8px;
  border: none;
  background: var(--key-base);
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  box-shadow: inset 0 0 0 1px #b8bcc8;
  z-index: 1;
  overflow: hidden;
}

.key.white {
  border: 1px solid #a6aab6;
  box-shadow: 0 3px 8px rgba(16, 20, 32, 0.16), inset 0 0 0 1px #c6cad6;
}

.key.black {
  --key-base: var(--key-black-base);
  position: absolute;
  top: 0;
  height: calc(var(--instrument-height) * 0.62);
  width: calc(100% / var(--white-count) * 0.6);
  background: var(--key-base);
  border: 1px solid #32363e;
  border-radius: 6px;
  transform: translateX(-50%);
  z-index: 10;
  box-shadow: 0 2px 6px rgba(10, 12, 22, 0.15);
}

.key.white::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: transparent;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 0;
}

.key.lit {
  background: var(--pc-color, var(--deg-color, #7c6dff));
  border-color: color-mix(in srgb, var(--pc-color, var(--deg-color, #7c6dff)), #000 20%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc-color, var(--deg-color, #7c6dff)), #000 12%);
}

.key.white.lit::before {
  opacity: 0;
}

.key.black.lit {
  background: var(--pc-color, var(--deg-color, #7c6dff));
  border-color: color-mix(in srgb, var(--pc-color, var(--deg-color, #7c6dff)), #000 35%);
}

/* Instrument tone emphasis */
#keyboardVisualizer .key.tone-root,
#fretboardVisualizer .fret-note.tone-root {
  background: var(--pc-color, #7c6dff);
  border: 3px solid color-mix(in srgb, var(--pc-color, #7c6dff), #000 28%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3), 0 0 0 3px color-mix(in srgb, var(--pc-color, #7c6dff), transparent 60%);
}

#keyboardVisualizer .key.tone-tone {
  background: color-mix(in srgb, var(--pc-color, #7c6dff), var(--key-base, --key-white-base) 28%);
}

#fretboardVisualizer .fret-note.tone-tone {
  background: color-mix(in srgb, var(--pc-color, #7c6dff), #e3e5eb 28%);
}

#keyboardVisualizer .key.tone-scale {
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 22%, var(--key-base, --key-white-base) 78%);
}

#fretboardVisualizer .fret-note.tone-scale {
  opacity: 1;
  background: color-mix(in srgb, var(--pc-color, #7c6dff) 22%, #e3e5eb 78%);
  box-shadow: 0 0 8px color-mix(in srgb, var(--pc-color, #7c6dff), transparent 65%);
}

#fretboardVisualizer .fret-note.tone-root {
  border: none;
  outline: 2px solid color-mix(in srgb, var(--pc-color, #7c6dff), #000 28%);
  outline-offset: 0;
  border-radius: 2px;
}

.key.dim {
  background: color-mix(in srgb, var(--key-base) 60%, #f8f9ff 40%);
}

.key.black.dim {
  background: color-mix(in srgb, var(--key-black-base) 60%, #f8f9ff 40%);
}

.fretboard {
  width: 100%;
}

.fretboard-shell {
  position: relative;
  width: 100%;
  height: var(--instrument-height);
  background: #e3e5eb;
  border-radius: 12px;
  border: 1px solid #d1d6e6;
  box-shadow: 0px 0px 12px rgba(22, 26, 48, 0.50);
}

.fretboard-lines,
.fretboard-markers,
.fretboard-notes {
  position: absolute;
  inset: 0;
}

.string-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(22, 26, 48, 0.25);
  top: calc(var(--string-index) * 100% / (var(--string-count) - 1));
}

.fret-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(22, 26, 48, 0.2);
  left: calc(var(--fret-index) * 100% / (var(--fret-count) - 1));
  z-index: 1;
}

.fret-line.nut {
  width: 6px;
  background: rgba(22, 26, 48, 0.7);
}

.fret-marker {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: rgba(80, 90, 125, 0.3);
  left: calc(var(--marker-index) * 100% / (var(--fret-count) - 1));
  top: var(--marker-y);
  transform: translate(-50%, -50%);
  z-index: 1;
}

.fret-note {
  position: absolute;
  width: calc((var(--instrument-height) / (var(--string-count) - 1)) * 0.4);
  height: calc((var(--instrument-height) / (var(--string-count) - 1)) * 0.4);
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  left: calc(var(--fret-index) * 100% / (var(--fret-count) - 1));
  top: calc(var(--string-index) * 100% / (var(--string-count) - 1));
  transform: translate(-50%, -50%);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  z-index: 2;
}

.fret-note.lit {
  opacity: 1;
  background: var(--pc-color, var(--deg-color, #7c6dff));
  box-shadow: 0 0 0 2px rgba(85, 104, 255, 0.45), 0 8px 16px rgba(85, 104, 255, 0.25);
  transform: translate(-50%, -50%) scale(1.05);
}

.scale-strip {
  background: #fff;
  border: 1px solid #e1e5f7;
  border-radius: 14px;
  padding: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}

.tile-viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 78px;
  --tile-gap: 6px;
  --tile-width: 52px;
  mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%),
              linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%),
                      linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
}

.scale-tiles {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--tile-gap);
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.18s ease;
  align-items: stretch;
  will-change: transform;
  position: relative;
  height: 100%;
}

.scale-tiles.vertical-track {
  flex-direction: column;
  gap: 0;
  align-items: stretch;
}

.tile-row {
  display: flex;
  gap: var(--tile-gap);
  width: 100%;
}
 
.tile-viewport::before,
.tile-viewport::after {
  content: "";
  position: absolute;
  pointer-events: none;
  inset: 0;
  z-index: 1;
}

.tile-viewport::before {
  background:
    linear-gradient(90deg, rgba(255,255,255,0.9), rgba(255,255,255,0) 18px),
    linear-gradient(270deg, rgba(255,255,255,0.9), rgba(255,255,255,0) 18px);
}

.tile-viewport::after {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(255,255,255,0) 18px),
    linear-gradient(0deg, rgba(255,255,255,0.9), rgba(255,255,255,0) 18px);
}

.scale-tile {
  border: 1px solid #c7ccdc;
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
  font-weight: 700;
  color: #111731;
  background: linear-gradient(140deg, #f7f8ff, #eef1ff);
  box-shadow: 0 6px 12px rgba(16, 20, 52, 0.08);
  flex: 0 0 var(--tile-width);
  min-width: 40px;
  white-space: nowrap;
}

.scale-tile small {
  display: block;
  color: #5c6385;
  font-size: 12px;
  font-weight: 600;
}

.scale-tile.tonic {
  border-color: var(--accent);
  background: linear-gradient(140deg, #dfe4ff, #f4f5ff);
  box-shadow: 0 8px 18px rgba(85, 104, 255, 0.25);
}

.slots-row {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  gap: var(--tile-gap);
  pointer-events: none;
  z-index: 3;
  padding-top: 4px;
}

.slot {
  flex: 0 0 var(--tile-width);
  min-width: 40px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding-left: 6px;
  color: #0f1636;
  font-weight: 800;
  font-size: 14px;
}

.notes-layer {
  position: absolute;
  inset: 0;
  display: flex;
  gap: var(--tile-gap);
  will-change: transform;
  pointer-events: auto;
  z-index: 2;
}

.notes-layer.vertical {
  flex-direction: column;
  gap: 0;
}

.note-label {
  flex: 0 0 var(--tile-width);
  min-width: 40px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #f7f8ff, #eef1ff);
  border: 1px solid #c7ccdc;
  border-radius: 10px;
  box-shadow: 0 6px 12px rgba(16, 20, 52, 0.08);
  color: #111731;
  font-weight: 800;
  cursor: pointer;
  position: relative;
}

.note-label.tonic {
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(85, 104, 255, 0.25);
}

.note-label.root-selected {
  outline: 2px solid #7c6dff;
  outline-offset: 2px;
}

.note-label.root-selected {
  outline: 2px solid #7c6dff;
  outline-offset: 2px;
}

.note-label small {
  display: block;
  color: #5c6385;
  font-size: 11px;
  font-weight: 600;
}

.note-label::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--deg-color, #7c6dff);
  opacity: 0.9;
  box-shadow: 0 4px 10px color-mix(in srgb, var(--deg-color, #7c6dff), transparent 55%);
}

.strip-hint {
  display: none;
}

.accordion {
  display: grid;
  gap: 8px;
}

.accordion-item {
  border: 1px solid #e5e8f6;
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  color: #0f1636;
  padding: 10px 12px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}

.accordion-panel {
  display: none;
  padding: 0 12px 12px;
  color: #1e2340;
}

.accordion-item.open .accordion-panel {
  display: grid;
  gap: 8px;
}

.accordion-item .chevron {
  transition: transform 0.2s ease;
}

.accordion-item.open .chevron {
  transform: rotate(180deg);
}

.chord-row {
  background: #fff;
  border: 1px solid #e2e6f6;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.chord-row.warning {
  border-style: dashed;
  border-color: #f0b64f;
}

.chord-row.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(85, 104, 255, 0.18);
}

.chord-name {
  font-weight: 800;
  color: #111731;
}

.chord-notes {
  color: #525a80;
  font-size: 13px;
}

.chord-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.chord-note::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--deg-color, #7c6dff);
  box-shadow: 0 0 8px color-mix(in srgb, var(--deg-color, #7c6dff), transparent 55%);
}

.chord-sep {
  color: #8a92b4;
  margin: 0 6px;
  font-weight: 600;
}

.wheel-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
}

.wheel-modal.hidden {
  display: none;
}

.wheel-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 20, 0.55);
}

.wheel-modal-content {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 12px;
  width: min(320px, 90vw);
  max-height: min(84vh, calc(100dvh - 40px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(5, 8, 30, 0.35);
}

.wheel-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wheel-modal-header h3 {
  margin: 0;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

#closeWheelModal,
#closeInfoModal,
#closeMetronome,
#closeTuner {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  display: grid;
  place-items: center;
}

.wheel-modal-list {
  overflow-y: auto;
  display: grid;
  gap: 6px;
  flex: 1 1 auto;
}

.wheel-modal-list button {
  width: 100%;
  text-align: left;
  background: #f6f7ff;
  color: #0f1636;
  border: 1px solid #e3e6f7;
  padding: 10px 12px;
}

.wheel-modal-list button.active {
  border-color: var(--accent);
  background: #e7eaff;
}

.tool-modal {
  width: min(420px, 92vw);
}

.tool-body {
  display: grid;
  gap: 12px;
  padding: 8px;
}

.tempo-display {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.tempo-display input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d7dcf2;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
}

.tempo-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tempo-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #6b74a3;
  font-weight: 700;
}

.meter-row {
  display: grid;
  gap: 6px;
}

.meter-row select {
  border-radius: 10px;
  border: 1px solid #d7dcf2;
  padding: 8px 10px;
  font-weight: 600;
}

.meter-custom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}

.meter-custom.is-hidden {
  display: none;
}

.meter-custom input {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d7dcf2;
  text-align: center;
  font-weight: 600;
}

.meter-slash {
  font-weight: 700;
  color: #7b81a8;
}

.toggle-row {
  display: flex;
  align-items: center;
}

.toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: #1e2340;
}

.metronome-actions,
.tuner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tuner-body {
  gap: 14px;
}

.tuner-readout {
  display: grid;
  gap: 4px;
  text-align: center;
}

.tuner-note {
  font-size: 32px;
  font-weight: 800;
  color: #101738;
}

.tuner-cents {
  font-size: 14px;
  color: #6b74a3;
}

.tuner-meter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.meter-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #e6e9f7;
}

.meter-needle {
  position: absolute;
  top: -4px;
  width: 12px;
  height: 16px;
  border-radius: 6px;
  background: var(--accent);
  transform: translateX(-50%);
  left: 50%;
  transition: left 0.08s ease;
}

.meter-label {
  font-size: 12px;
  color: #7b81a8;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.tuner-status {
  font-size: 13px;
  color: #5c6385;
  text-align: center;
}

/* --- Harmony grid compact/full-cell color overrides (v3) --- */
.harmony-grid-header .h-cell,
.harmony-row .harmony-cell {
  box-sizing: border-box;
  white-space: nowrap;
}

/* Remove pill look; make the whole cell carry the color */
.harmony-cell.tone-cell {
  padding: 0 !important;
  background: color-mix(in srgb, var(--pc-color) var(--harmony-base-fill), transparent);
}
.harmony-cell.tone-cell.is-visible {
  background: color-mix(in srgb, var(--pc-color) var(--harmony-active-fill), transparent);
}
.harmony-cell.tone-cell.is-ghost {
  background: color-mix(in srgb, var(--pc-color) var(--harmony-ghost-fill), transparent);
}

/* Inner band becomes just centered text; no background/border */
.harmony-cell .pc-band {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border-radius: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

/* Avoid tone-root/tone-tone overlays inside the harmony grid. */
.harmony-grid .pc-band.tone-root,
.harmony-grid .pc-band.tone-tone {
  background: transparent !important;
  box-shadow: none;
  color: inherit;
}

/* Keep selection emphasis via outline, but don't shrink content */
.harmony-cell.is-note-selected {
  outline: 2px solid color-mix(in srgb, var(--pc-color) 55%, #2c58ff);
  outline-offset: -2px;
}

.harmony-row-outline {
  grid-row: 1;
  position: absolute;
  top: 4px;
  bottom: 4px;
  pointer-events: none;
  border-radius: 8px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--row-color, #5568ff) 55%, #2c58ff);
  z-index: 3;
}

/* Chord column should also be a full-cell color block */
.harmony-cell.chord-cell {
  background: color-mix(in srgb, var(--pc-color) var(--harmony-active-fill), transparent);
}
.harmony-cell.chord-cell .pc-band {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.harmony-cell.chord-cell .roman-overlay {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  font-weight: 800;
  color: rgba(15, 22, 54, 0.7);
  text-transform: uppercase;
  pointer-events: none;
}

/* Roman numeral column stays plain and tight */
/* Slightly reduce row height for density */
.harmony-row .harmony-cell {
  min-height: 40px;
}

@media (hover: hover) {
  button:hover {
    background: var(--accent-strong);
    box-shadow: 0 12px 24px rgba(49, 69, 255, 0.25);
  }
}

@media (max-width: 768px) {
  body {
    padding: 12px 10px 28px;
  }

  .controls-panel {
    padding: 12px;
    gap: 10px;
    margin-bottom: 8px;
    transition: max-height 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    overflow: hidden;
  }

  .output-panel {
    gap: 8px;
  }

  .main-grid {
    gap: 8px;
    grid-template-columns: 1fr;
  }

  .card, .panel {
    padding: 14px;
  }

  .harmony-card {
    padding: 10px;
  }

  .harmony-strip {
    display: flex;
  }

  #keymodeStrip {
    display: none;
  }

  body.mobile-panel-keymode #harmonyStrip {
    display: flex;
  }

  body.mobile-panel-keymode #keymodeStrip {
    display: none;
  }

  body.mobile-panel-harmony #harmonyStrip {
    display: none;
  }

  body.mobile-panel-harmony #keymodeStrip {
    display: flex;
  }

  body.mobile-panel-harmony #inputArea {
    max-height: 0;
    opacity: 0;
    transform: translateY(-6px);
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-width: 0;
  }

  body.mobile-panel-keymode #inputArea {
    max-height: 1600px;
    opacity: 1;
    transform: translateY(0);
  }

  #harmonyContainer {
    transition: max-height 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    overflow: hidden;
  }

  body.mobile-panel-keymode #harmonyContainer .harmony-grid-shell {
    display: none;
  }

  body.mobile-panel-keymode #harmonyContainer {
    max-height: 0;
    opacity: 0;
    transform: translateY(-6px);
    padding: 0;
    border-width: 0;
    margin: 0;
  }

  body.mobile-panel-harmony #harmonyContainer {
    max-height: 2000px;
    opacity: 1;
  }

  .harmony-grid {
    --chord-col-min: 116px;
    --tone-col-min: 36px;
  }

  .harmony-grid-header .h-cell,
  .h-cell, .harmony-cell {
    padding: 2px;
  }

  .harmony-cell .pc-band,
  .root-cell .pc-band {
    padding: 3px 5px;
    border-radius: 6px;
    font-size: 13px;
  }

  .harmony-grid-header {
    z-index: 6;
  }

  .harmony-grid .sticky-col {
    z-index: 5;
  }
}

@media (max-width: 640px) {
  body {
    padding: 14px 10px 24px;
  }

  button {
    width: 100%;
  }

  .inline-actions button {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    padding: 2px 2px;
    font-size: 10px;
    white-space: nowrap;
    line-height: 1.1;
    text-align: center;
  }

  .scale-tiles {
    gap: 4px;
  }
}

@supports (-webkit-touch-callout: none) {
  @media (max-width: 640px) {
    .inline-actions button {
      padding: 1px 2px;
      font-size: 9px;
    }
  }
}

@media (min-width: 520px) and (max-width: 640px) {
  .inline-actions button {
    flex: 0 1 auto;
    min-width: 0;
    padding: 6px 10px;
    white-space: nowrap;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .inline-actions .ghost {
    padding: 8px 12px;
  }
}

@media (max-width: 520px) {
  .page-header {
    margin-bottom: 10px;
    padding: 2px 0 0;
  }

  .title-row {
    padding: 2px 0;
    gap: 6px;
  }

  .heading-row h2 {
    font-size: 17px;
  }
}

@media (max-width: 480px) {
  .page-header {
    margin-bottom: 8px;
  }

  .title-row {
    padding: 0;
  }

  .controls-panel {
    gap: 8px;
    padding: 12px;
    margin-bottom: 8px;
  }

  .scale-strip {
    padding: 4px;
  }

  .tile-viewport {
    height: 68px;
  }

  .scale-banner {
    padding: 10px 12px;
  }

  .main-grid {
    gap: 8px;
    grid-template-columns: 1fr;
  }

  .scale-tiles {
    gap: 3px;
  }

  .pill-row {
    min-height: 0;
  }

  .pill {
    min-height: 48px;
    padding: 6px 10px;
  }

  .pill-label {
    font-size: 11px;
  }

  .pill-value {
    font-size: 14px;
  }

  .inline-actions {
    margin-top: 2px;
    margin-bottom: 2px;
  }

  .instrument-stack {
    gap: 6px;
    --instrument-height: 78px;
  }

  .instrument {
    padding: 6px 8px;
    border-radius: 12px;
  }

  .card, .panel {
    padding: 12px;
  }

  .heading-row h2 {
    font-size: 17px;
  }
}

@media (min-width: 641px) {
  .inline-actions .ghost {
    padding: 8px 12px;
  }
}

/* Make grid more compact on desktop */
@media (min-width: 900px) {
  .harmony-grid {
    --tone-col-width: 66px;
    --chord-col-width: 200px;
  }
}

/* v3.1: correct vars + remove header underline */
@media (min-width: 900px) {
  .harmony-grid { --root-col: 220px; --tone-col: 66px; }
}
.tone-head.is-active { box-shadow: none !important; }


/* ==============================
   Harmony grid desktop polish (v4)
   ============================== */

@media (min-width: 900px) {
  .main-grid { align-items: stretch; }
  .instruments-card, .harmony-card { height: 100%; }

  .harmony-grid-wrap { flex: 1; min-height: 0; }

  /* tighter columns so 13 fits on desktop */
  .harmony-grid {
    --chord-col-min: 150px;
    --tone-col-min: 42px;
    border-radius: 22px;
    overflow: hidden;
  }

  .harmony-grid th,
  .harmony-grid td { padding: 10px 8px; }

  /* Rounded chord chip like the earlier style */
  .harmony-grid td.pc-chord .pc-band {
    border-radius: 16px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  }

  /* Slightly round note cells + soften selection borders */
  .harmony-grid td.pc-note { border-radius: 10px; }
  .harmony-grid td.pc-note.is-selected { outline-width: 2px; }
}
