#fretboard-explorer-section:not([hidden]) {
  --fx-border: var(--panel-border);
  --fx-tone: var(--theme-accent, var(--accent));
  --scale-caged-button-scale: 1;
  display: block;
  gap: 0;
  width: min(100%, 1120px);
  height: auto;
  min-width: 0;
  container-type: inline-size;
  box-sizing: border-box;
  margin-inline: auto;
  overflow: clip;
  border: 1px solid var(--fx-border);
  border-radius: 16px;
  background: var(--surface-card);
  color: var(--ink);
}
/* The document owns vertical scrolling. Let the dock stick to its viewport. */
body.fretboard-explorer-active:not([class*="-open"]) { overflow-x: clip; overflow-y: visible; }

@media (orientation: landscape) and (min-width: 600px) and (min-height: 600px) {
  /* Center the Explorer in the space below the shared view heading. */
  body.is-native-app.fretboard-explorer-active:not(.platform-android) .app-shell {
    flex: 1 0 auto;
    align-content: stretch;
  }

  body.is-native-app.fretboard-explorer-active:not(.platform-android) #fretboard-explorer-section {
    margin-block: auto;
  }
}

#fretboard-explorer-section [hidden] { display: none !important; }
.fx-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.fx-scroll { min-width: 0; }
.fx-board { display: block; max-width: none; max-height: none; margin-inline: auto; user-select: none; }
.fx-board .scale-interval-label { font-size: var(--fx-label-size); }
.fx-board :is(.scale-string-label, .scale-fret-label) { font-size: 10px; }
.fx-board .scale-shape-contour { stroke-width: 3.4px; }
html.desktop-web-ui .fx-board .scale-shape-contour { stroke-width: 4px; }
.fx-board, .fx-board * { -webkit-tap-highlight-color: transparent; }
.fx-dot-backing { fill: var(--surface-card); }
.fx-hit { fill: transparent; cursor: pointer; }
.fx-marker, .fx-focus { pointer-events: none; }
#fretboard-explorer-section .fx-dot[data-chord-note] { fill: color-mix(in srgb, var(--chord-tone-color, var(--ink)) 72%, var(--ink)); }
.fx-board .fx-scale-context .fx-dot { opacity: .20; }
.fx-board .fx-scale-context .scale-interval-label { fill: var(--ink); font-weight: 600; }
.fx-board .fx-sounded .fx-scale-context .fx-dot { opacity: 1; }
.fx-board .fx-sounded .fx-scale-context .scale-interval-label { fill: var(--theme-on-note, white); }
.fx-board .fx-scale-context.fx-dim { opacity: .75; }
.fx-focus { fill: none; stroke: transparent; stroke-width: 2.5; }
.fx-board [data-cell]:focus { outline: 0; }
.fx-board [data-cell]:focus-visible:not(.fx-sounded) .fx-focus { stroke: var(--theme-playback); }
:is(.fx-preview-dot, .fx-preview-label) { display: none; }
.fx-sounded :is(.fx-preview-dot, .fx-preview-label) { display: inline; }
.fx-sounded .fx-preview-label + .scale-string-label { display: none; }
.fx-sounded .fx-marker { opacity: 1; }
.fx-readout {
  position: absolute; z-index: 1; inset: auto auto calc(100% + 8px) 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px; width: max-content; max-width: calc(100% - 20px);
  box-sizing: border-box; padding: 7px 12px; border-radius: 10px;
  background: var(--ink); color: var(--surface-card); border: 1px solid var(--surface-card);
  box-shadow: 0 3px 12px #0005; font: 600 12px/1.3 var(--sans-stack); pointer-events: none;
}
.fx-readout strong { font-size: 17px; }
.fx-readout span { border-inline-start: 1px solid currentColor; padding-inline-start: 9px; }

.fx-dock {
  padding: 7px 10px;
  position: sticky; bottom: 0; align-self: end; min-width: 0; --fx-control-height: 36px;
  border-top: 1px solid var(--fx-border); background: var(--panel-bg);
}
.fx-dock-window { overflow: clip; }
.fx-dock-content { display: grid; grid-template-columns: minmax(0,1fr); align-items: center; gap: 6px; }
.fx-tools, .fx-dock-body { min-width: 0; }
.fx-dock-body { grid-column: 1 / -1; }
.fx-detail-content { display: grid; align-items: center; gap: 6px; }
#fx-quick-actions button { white-space: nowrap; }

.fx-selection { display: flex; align-items: stretch; gap: 6px; min-width: 0; }
#fx-quick-actions { display: flex; flex: none; gap: 6px; }
#fx-quick-actions button { height: 100%; }
.fx-dock [data-action="full"] { display: inline-flex; align-items: center; gap: 6px; }
.fx-dock [data-action="full"]::before {
  content: ''; width: 13px; height: 13px; flex: none; box-sizing: border-box;
  border: 1px solid var(--muted); border-radius: 3px;
}
.fx-dock [data-action="full"][aria-pressed="true"]::before {
  content: '✓' / ''; background: var(--fx-tone); color: var(--theme-on-accent, white);
  border-color: var(--fx-tone); font: 700 11px/12px var(--sans-stack);
}
#fretboard-explorer-section .fx-dock .fx-dock-handle {
  position: absolute; top: -39px; inset-inline-end: 12px;
  display: grid; justify-items: center; align-items: start;
  width: 60px; height: 44px; padding: 23px 0 0;
  background: transparent; border: 0; touch-action: none;
}
.fx-dock-handle::before {
  content: ''; position: absolute; inset: 19px 0 auto; height: 20px; box-sizing: border-box;
  border: 1px solid var(--fx-border); border-bottom: 0; border-radius: 14px 14px 0 0;
  background: var(--panel-bg);
}
.fx-dock-handle svg { position: relative; width: 24px; height: 12px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.fx-dock-handle[aria-expanded="false"] .fx-dock-arrow { transform-box: fill-box; transform-origin: center; transform: rotate(180deg); }
.fx-dock-summary { display: none; }
.fx-selected-shapes { font: 600 11px var(--sans-stack); color: var(--muted); }
.fx-selected-shapes:empty { display: none; }
.fx-tone-key i { background: color-mix(in srgb, var(--chord-tone-color, var(--ink)) 72%, var(--ink)); }
.fx-shape-quick, .fx-shape-group { display: grid; align-items: center; min-width: 0; }
.fx-shape-quick { grid-template-areas: "buttons" "caption"; gap: 3px 8px; overflow-x: auto; scrollbar-width: none; }
.fx-shape-quick:has([data-action="full"]) { grid-template-areas: "full buttons" ". caption"; }
.fx-shape-group { grid-area: buttons; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
#fretboard-explorer-section .fx-shape-group button { padding-inline: 0; }

#fretboard-explorer-section .fx-dock [data-action="full"][aria-pressed="true"] { background: var(--surface-card); color: var(--accent-deep); border-color: var(--fx-tone); }
.fx-shape-quick > small { grid-area: caption; justify-self: center; text-align: center; font: 650 10px/12px var(--sans-stack); color: var(--muted); }
.fx-shape-quick [data-action="full"] { grid-area: full; white-space: nowrap; }

.fx-tools, .fx-legend, .fx-modes, .fx-grip { display: flex; align-items: center; gap: 6px; min-width: 0; }
.fx-legend { gap: 8px; flex-wrap: wrap; padding: 4px 6px; font-size: 11px; font-weight: 600; }
.fx-legend span { display: inline-flex; align-items: center; gap: 4px; }
.fx-legend i { width: 10px; height: 10px; box-sizing: border-box; border-radius: 50%; }
.fx-tools { justify-content: space-between; }
.fx-modes { flex: 1; gap: 2px; background: var(--surface-card); border: 1px solid var(--fx-border); border-radius: 10px; padding: 2px; }
#fretboard-explorer-section .fx-dock button:where(:not(.scale-caged-button)) {
  min-height: 33px; min-width: 0; padding: 5px 9px; border: 1px solid var(--fx-border); border-radius: 8px;
  background: var(--surface-card); color: var(--ink); font: 650 13px var(--sans-stack); box-shadow: none; cursor: pointer;
}
#fretboard-explorer-section .fx-modes button { flex: 1; border-color: transparent; background: transparent; }
#fretboard-explorer-section .fx-modes button[aria-pressed="true"] { background: var(--theme-accent, var(--accent)); color: var(--theme-on-accent, white); }
#fretboard-explorer-section .fx-toggle { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; flex: none; }
.fx-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#fretboard-explorer-section .fx-dock-body button { height: var(--fx-control-height); min-height: 0; }
.fx-grip { flex: 1; gap: 8px; }
.fx-strum { flex: none; }
#fretboard-explorer-section .fx-browse { display: inline-flex; flex: none; align-items: center; gap: 6px; padding-inline: 7px; }
.fx-browse svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.fx-grip-strip { display: flex; align-items: center; min-width: 0; gap: 4px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.fx-grip-strip::-webkit-scrollbar { display: none; }
#fretboard-explorer-section .fx-grip-strip button {
  display: flex; align-items: center; flex: none; gap: 4px; padding-inline: 6px;
  touch-action: manipulation;
}
.fx-grip-diagram { display: grid; place-items: center; --diagram-shift-x: 0px; }
.fx-grip-strip .fx-grip-diagram { --diagram-display-width: 26px; --diagram-hitbox-top-offset: 4px; --diagram-state-marker-size: 3px; --diagram-state-marker-gap: 1px; --diagram-state-marker-stroke: 1px; padding-top: 4px; }
.fx-grip-strip .diagram-finger, .fx-grip-strip .diagram-basefret-overlay { display: none; }
.fx-grip-caption { display: grid; gap: 3px; }
.fx-grip-caption small { font: 600 11px var(--sans-stack); }
#fretboard-explorer-section :is(.fx-grip-strip, .fx-voicings) button[aria-pressed="true"] {
  border-color: var(--fx-tone); background: color-mix(in srgb, var(--fx-tone) 12%, var(--surface-card));
}
#fx-voicings {
  position: fixed; inset: 0; margin: auto; width: min(480px, calc(100% - 28px)); height: fit-content;
  max-height: min(75dvh, 590px); box-sizing: border-box; padding: 12px; border-radius: 14px; overflow: hidden;
}
#fx-voicings:not([open]) { display: none; }
#fx-voicings[open] { display: grid; grid-template-rows: auto minmax(0,1fr) auto; gap: 10px; }
#fx-voicings::backdrop { background: rgba(24,17,12,.38); }
.fx-gallery-grid { min-height: 0; overflow: auto; overscroll-behavior: contain; display: grid; grid-template-columns: repeat(auto-fit,minmax(100px,1fr)); align-content: start; gap: 7px; padding: 2px; }
.fx-gallery-grid button, .fx-gallery-actions button { background: var(--surface-card); color: var(--ink); border: 1px solid var(--fx-border); border-radius: 9px; box-shadow: none; cursor: pointer; }
.fx-gallery-grid button { display: grid; grid-template-rows: 83px auto; align-items: start; gap: 4px; padding: 7px 6px; line-height: 1.2; }
.fx-gallery-grid .fx-grip-diagram { --diagram-display-width: 64px; --diagram-hitbox-top-offset: 9px; --diagram-state-marker-size: 6px; --diagram-state-marker-gap: 1px; --diagram-state-marker-stroke: 1.2px; padding-top: 9px; }
.fx-gallery-grid strong { font-size: 12px; }
.fx-gallery-grid .fx-grip-caption { align-self: stretch; grid-template-rows: 1fr auto; align-items: start; }
.fx-gallery-grid small { color: var(--muted); }
.fx-gallery-actions { display: grid; grid-template-columns: minmax(0,1.4fr) repeat(2,minmax(0,1fr)); gap: 7px; }
.fx-gallery-actions button { min-height: 38px; font-weight: 650; }
.fx-gallery-actions .fx-done { background: var(--fx-tone); color: var(--theme-on-accent, white); border-color: var(--fx-tone); }
.fx-gallery-actions button[aria-disabled="true"] { opacity: .55; cursor: default; }
#fretboard-explorer-section .fx-strum { color: var(--theme-on-action); background: var(--theme-action); border-color: var(--theme-action); }
#fx-controls {
  inset: auto var(--safe-right, 0px) max(9px, var(--safe-bottom, 0px)) var(--safe-left, 0px);
  margin-inline: auto; width: min(420px, calc(100% - 18px)); max-height: min(74dvh, 660px);
  padding: 12px; border-radius: 14px; box-shadow: 0 12px 40px #20140955; overflow: hidden;
}
#fx-controls:not([open]) { display: none; }
#fx-controls[open] { display: grid; grid-template-rows: auto minmax(0,1fr); gap: 9px; animation: fx-open .15s ease-out; }
.fx-control-options { display: grid; gap: 9px; align-content: start; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#fx-controls::backdrop { background: rgba(24, 17, 12, .38); }
@keyframes fx-open { from { transform: translateY(6px); } }
.fx-controls header { font-size: 16px; }
#fretboard-explorer-section .fx-dock .fx-subject {
  flex: 1 1 auto; display: grid; align-content: center; gap: 1px; text-align: start;
  min-height: 40px; padding-block: 4px; padding-inline: 10px 30px;
  border-radius: 8px;
}
@media (orientation: portrait) {
  /* The dock already includes the bottom safe area. End the page at the dock. */
  body.is-native-app.fretboard-explorer-active .page-shell,
  body.is-native-app.fretboard-explorer-active .control-deck {
    padding-block-end: 0;
  }

  body.is-native-app.fretboard-explorer-active .page-footer {
    display: none;
  }

  body.is-native-app.fretboard-explorer-active :is(.control-deck, #fretboard-explorer-section) {
    border-block-end: 0;
  }

  body.is-native-app.fretboard-explorer-active #fretboard-explorer-section {
    border-end-start-radius: 0;
    border-end-end-radius: 0;
  }

  .fx-dock { --fx-summary-height: 40px; }
  /* Slide two fully laid-out surfaces past the clip edge as the drawer moves. */
  .fx-dock-track { position: relative; translate: 0 calc(var(--fx-summary-height) * (1 - var(--fx-open, 1))); }
  .fx-dock-summary {
    position: absolute; inset: auto 0 100%; height: var(--fx-summary-height);
    display: flex; align-items: center; justify-content: center; gap: 7px;
  }
  #fretboard-explorer-section .fx-dock-summary .fx-subject { flex: 0 1 auto; max-inline-size: 16rem; }
  .fx-dock:has(.fx-dock-handle[aria-expanded="false"]) .fx-dock-window { height: var(--fx-summary-height); }
  .fx-dock:has(.fx-dock-handle[aria-expanded="false"]) { touch-action: pan-x pinch-zoom; }
}
#fretboard-explorer-section .fx-subject::after { top: 50%; right: auto; inset-inline-end: 10px; }
.fx-subject small { color: var(--muted); font: 600 10px/1.15 var(--sans-stack); }
.fx-subject strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 700 14px/1.2 var(--sans-stack); }
.fx-controls fieldset { margin: 0; padding: 0; min-width: 0; border: 0; }
.fx-controls legend { box-sizing: border-box; width: 100%; border-top: 1px solid var(--fx-border); padding: 8px 6px 4px; }
.fx-controls legend { font-size: 12px; font-weight: 650; color: var(--muted); }
.fx-shape-settings { margin: 4px 0 9px; }
.fx-shape-settings label { display: flex; align-items: flex-start; gap: 7px; padding: 5px; cursor: pointer; }
.fx-shape-settings input { flex: none; width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--theme-accent); }
.fx-shape-settings small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 3px; }
.fx-controls .scale-highlight-option { box-shadow: none; letter-spacing: normal; text-transform: none; }
.fx-controls .scale-highlight-option[aria-pressed="true"] { background: color-mix(in srgb, var(--fx-tone) 13%, transparent); }

#fretboard-explorer-section .has-shape-outlines .scale-caged-button.is-active {
  --scale-caged-active-color: var(--scale-shape-color);
  background: color-mix(in srgb, var(--scale-shape-color) 12%, var(--surface-card));
}
@container (max-width: 460px) {
  #fretboard-explorer-section .fx-shape-quick [data-action="full"] { padding-inline: 5px; white-space: normal; line-height: 1.1; }
  @media (orientation: landscape) {
    #fretboard-explorer-section .fx-shape-quick [data-action="full"] { max-width: 35%; }
  }

  #fretboard-explorer-section .fx-dock .fx-subject { min-height: 40px; padding-inline: 8px 22px; }
  #fretboard-explorer-section .fx-subject::after { width: 10px; inset-inline-end: 7px; }

  .fx-subject strong { font-size: 13px; }
}
@container (max-width: 350px) {
  .fx-selection, #fx-quick-actions { gap: 4px; }
  #fretboard-explorer-section .fx-dock .fx-subject { padding-inline: 6px 19px; }
  #fretboard-explorer-section #fx-quick-actions .fx-browse { width: 40px; justify-content: center; }
  #fx-quick-actions .fx-browse span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media (orientation: landscape) {
  .fx-subject[data-action="scale"] { max-inline-size: 16rem; }
  .fx-subject[data-action="chord"] { max-inline-size: 12rem; }
  .fx-scroll { display: flex; align-items: center; height: clamp(152px, 42dvh, 260px); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
  .fx-dock { position: relative; }
  #fretboard-explorer-section .fx-dock .fx-dock-handle { display: none; }
  .fx-board { flex: none; }
  #fx-controls { inset: var(--safe-top, 0px) max(12px, var(--safe-right, 0px)) var(--safe-bottom, 0px) auto; margin-block: auto; width: min(355px, 65%); max-height: calc(100dvh - var(--safe-top, 0px) - var(--safe-bottom, 0px) - 16px); }
}
@media (orientation: landscape) and (max-width: 639px) {
  .fx-tools, .fx-selection { justify-self: center; max-width: 100%; }
}
@media (orientation: landscape) and (min-width: 640px) {
  .fx-dock-content { grid-template-columns: auto minmax(0, max-content) auto; justify-content: center; column-gap: 14px; }
  /* Fit the voicing strip beneath the pickers without widening their row. */
  .fx-dock-body { contain: inline-size; }
  .fx-tools { display: contents; }
  .fx-modes { grid-column: 1; grid-row: 1; }
  .fx-selection { grid-column: 2; grid-row: 1; max-width: 580px; }
  .fx-toggle { grid-column: -2 / -1; grid-row: 1; }
}
@media (orientation: landscape), (min-width: 600px) {
  .fx-shape-quick { justify-content: safe center; }
  .fx-shape-group { display: flex; gap: 8px; }
  #fretboard-explorer-section .scale-caged-button { flex: 0 1 auto; padding-inline: 0; }
  .fx-detail-content { min-height: var(--fx-control-height); }
}
@media (orientation: landscape) and (max-height: 520px) {
  .fx-scroll { --fx-board-scale: 1.25; height: calc(clamp(152px, 42dvh, 260px) * var(--fx-board-scale)); }
}
@media (orientation: landscape) {
  .fx-detail-content { min-height: calc(var(--fx-control-height) + 15px); }
  @container (min-width: 1024px) {
    .fx-dock-content {
      grid-template-columns: auto minmax(0,max-content) fit-content(28rem) auto;
      --fx-caption-space: 15px;
      padding-block-end: var(--fx-caption-space);
    }
    .fx-dock-body { grid-column: 3; grid-row: 1; contain: none; }
    .fx-detail-content { min-height: var(--fx-control-height); }
    /* Align the buttons themselves and let their caption occupy the space below the row. */
    .fx-shape-quick { margin-block-end: calc(-1 * var(--fx-caption-space)); }
  }
}
@media (orientation: portrait) and (max-width: 599px) {
  .fx-shape-quick:has([data-action="full"]) { grid-template-columns: fit-content(35%) minmax(0, 1fr); }
  #fretboard-explorer-section .scale-caged-button { width: 100%; max-width: none; }
}
@media (max-width: 599px), (pointer: coarse) {
  .fx-dock { padding-bottom: max(16px, calc(var(--safe-bottom, 0px) + 6px)); }
}
@media (pointer: coarse) {
  .fx-shape-group { --scale-caged-button-scale: 1.25; }
  .fx-dock { min-width: 0; --fx-control-height: 40px; }
}
@media (prefers-reduced-motion: reduce) { #fx-controls[open] { animation: none; } }
