/* Overlays (Option A, PR 1). Kit controls (gn-k-*) keep their kit paint: this file only places them.
   Paint here belongs to content: the placed marks on the music, the decorative wheel ring and the
   chord-symbol glyphs. */

/* The legacy reader (glow=0) keeps its old stamp palette. */
html:not([data-gn-glow]) .overlays-head { display: none; }

/* Stamp clicks into Overlays: the card covers the Annotate panel it opened from (680 x 700 in both
   orientations), so the wheel and every tab fit without scrolling. Back returns to the tools. */
html[data-gn-glow] body.stamps-mode #annotationToolbar.annotation-rail > #stampPalette {
  position: absolute;
  inset: 8px;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  z-index: 4;
  width: auto;
  height: auto;
  max-height: none;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  gap: 6px;
  padding: 6px 12px;
  overflow: hidden;
}
/* The chord reason line speaks for the Chords tab, so the general hint steps aside to give the wheel room. */
html[data-gn-glow] #stampPalette:has(#overlayChords:not([hidden])) > #stampPanelNote { display: none; }
html[data-gn-glow] body.stamps-mode #annotationToolbar.annotation-rail { min-height: min(700px, calc(100vh - 16px)); }
html[data-gn-glow] body.stamps-mode #annotationToolbar.annotation-rail > :not(#stampPalette) { visibility: hidden; }
html[data-gn-glow] body.stamps-mode #annotationToolbar.annotation-rail > #stampPalette > .annotation-stage-panel-header { display: none; }

html[data-gn-glow] .overlays-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
html[data-gn-glow] .overlays-head > .gn-k-title { flex: 1 1 auto; }
html[data-gn-glow] #overlayRecentTab { padding: 0 12px; }
html[data-gn-glow] #stampPalette > #stampCategories {
  display: grid;
  /* Thirteen tabs, fifteen with the builders (Recent is a header button): eight across keeps them on two rows. */
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0 2px;
}
html[data-gn-glow] .overlays-body { min-height: 0; }
/* The Overlays card's top bar: drag it to move the card (Jeff: panels over the music are always movable). */
.gn-ov-grip { display: none; }
html[data-gn-glow] body.stamps-mode #stampPalette > .gn-ov-grip {
  display: grid;
  place-items: center;
  width: 100%;
  height: 22px;
  min-height: 0;
  margin: -4px 0 -6px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}
html[data-gn-glow] body.stamps-mode #stampPalette > .gn-ov-grip > span {
  width: 40px;
  height: 5px;
  border-radius: 9px;
  background: var(--gn-k-rule-strong, rgba(58, 40, 32, .3));
}
/* Phones: the tabs ride one row that scrolls sideways instead of crushing into two. */
@media (max-width: 599px) {
  html[data-gn-glow] #stampPalette > #stampCategories {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-auto-columns: max-content;
    overflow-x: auto;
    scrollbar-width: none;
  }
}

/* Chords tab (Option B, GN-ANNOT-UPGRADE): the Overlays card shrinks to the chord card and floats on its own. The
   Annotate tools under it step out of the layout instead of holding 700 px of hidden space. */
html[data-gn-glow] body.stamps-mode.gn-chord-card #annotationToolbar.annotation-rail {
  width: min(712px, calc(100vw - 16px));
  min-height: 0;
  /* Clear of the transport bar under it; the card scrolls inside when a phone is too short. */
  max-height: var(--gn-ov-card-max, calc(100dvh - 128px));
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
html[data-gn-glow] body.stamps-mode.gn-chord-card #annotationToolbar.annotation-rail > :not(#stampPalette) { display: none; }
html[data-gn-glow] body.stamps-mode.gn-chord-card #annotationToolbar.annotation-rail > #stampPalette {
  position: relative;
  inset: auto;
  grid-row: 1;
  /* styles.css forces display: grid !important here, so every row is sized to its content and the card scrolls. */
  grid-template-rows: none;
  grid-auto-rows: max-content;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
html[data-gn-glow] body.stamps-mode.gn-chord-card #stampPalette > .gn-ov-grip {
  position: sticky;
  top: -6px;
  z-index: 7;
}
html[data-gn-glow] .overlays-chords:not([hidden]) {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "wheel panes"
    "wheel pane"
    "ring suggest"
    ". recent"
    "reason reason";
  grid-template-rows: auto auto auto 1fr auto auto;
  gap: 6px 12px;
  align-items: start;
}
/* Phones: the suggestions ride just under the wheel, the quickest pick within reach before the chip grid. */
html[data-gn-glow] .overlays-chords[data-layout="narrow"]:not([hidden]) {
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "wheel ring"
    "wheel foot"
    "suggest suggest"
    "recent recent"
    "panes panes"
    "pane pane"
    "reason reason";
  grid-template-rows: auto auto 1fr auto auto auto auto auto;
}
html[data-gn-glow] .gn-ov-card-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-card-head { flex-wrap: wrap; row-gap: 0; }
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-card-head > [data-part="editing"] { order: 3; flex-basis: 100%; }
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-keypick { margin-left: auto; }
html[data-gn-glow] .gn-ov-card-head > [data-part="editing"] { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[data-gn-glow] .gn-ov-keypick { display: inline-flex; align-items: center; gap: 6px; }
html[data-gn-glow] .gn-ov-keypick > select { min-height: 44px; max-width: 150px; font: inherit; }
html[data-gn-glow] .overlays-chords > .gn-ov-wheel { grid-area: wheel; }
html[data-gn-glow] .gn-ov-ring-row { grid-area: ring; }
html[data-gn-glow] .gn-ov-pane-row { grid-area: panes; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
html[data-gn-glow] .gn-ov-pane-row > [data-overlay-all-types] { padding: 0 10px; margin-left: auto; }
html[data-gn-glow] .gn-ov-pane { grid-area: pane; display: grid; gap: 4px; align-content: start; min-width: 0; }
html[data-gn-glow] .gn-ov-quality-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
html[data-gn-glow] .gn-ov-quality-grid > .gn-k-btn { min-width: 0; padding: 0 4px; font: 600 16px/1 "Crimson Pro", Georgia, serif; }
html[data-gn-glow] .gn-ov-suggest { grid-area: suggest; display: grid; gap: 4px; min-width: 0; }
html[data-gn-glow] .gn-ov-suggest > [data-part="caption"] { margin: 0; }
/* Option A's Recent chords: the same chips as the suggestions, newest first. */
html[data-gn-glow] .gn-ov-recent { grid-area: recent; display: flex; align-items: center; gap: 8px; min-width: 0; }
html[data-gn-glow] .gn-ov-recent > [data-part="caption"] { flex: none; }
html[data-gn-glow] .gn-ov-recent > .gn-ov-suggest-row { flex: 1 1 auto; min-width: 0; }
/* One row, nearest fits first; the rest of the key scrolls sideways. */
html[data-gn-glow] .gn-ov-suggest-row { display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
html[data-gn-glow] .gn-ov-suggest-row > .gn-k-btn {
  position: relative;
  flex: none;
  flex-direction: column;
  gap: 0;
  min-width: 52px;
  padding: 2px 8px;
  line-height: 1.05;
  font: 600 16px/1.05 "Crimson Pro", Georgia, serif;
}
html[data-gn-glow] .gn-ov-suggest-row [data-part="rn"] { font-size: 12.5px; font-weight: 700; color: var(--gn-k-gold-deep, #7A6020); }
/* Gold dot: this chord holds the melody note. */
html[data-gn-glow] .gn-ov-fit {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gn-k-gold, #C49A45);
}
html[data-gn-glow] .overlays-chords[data-layout="wide"] .gn-ov-ring-row { align-self: end; }
html[data-gn-glow] .gn-ov-card-head > .gn-k-btn { padding: 0 10px; }
html[data-gn-glow] .gn-ov-foot { grid-area: foot; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
html[data-gn-glow] .overlays-chords > #overlayChordReason { grid-area: reason; }
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-ring-row,
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-foot { display: grid; gap: 6px; justify-content: stretch; }
html[data-gn-glow] .overlays-chords[data-layout="narrow"] .gn-ov-ring-row > .gn-k-seg { display: grid; grid-template-columns: minmax(0, 1fr); }
html[data-gn-glow] .gn-ov-ring-row > [data-overlay-bass],
html[data-gn-glow] .gn-ov-foot > .gn-k-btn { padding: 0 10px; }
html[data-gn-glow] .overlays-dividers:not([hidden]) {
  display: grid;
  align-content: start;
  gap: 8px;
}
html[data-gn-glow] .gn-ov-dividers-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
html[data-gn-glow] body.stamps-mode #annotationToolbar.annotation-rail > #stampPalette > .stamp-settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding-top: 0;
}
html[data-gn-glow] .overlays-size {
  display: grid;
  gap: 6px;
}
html[data-gn-glow] #stampPalette .overlays-size .annotation-range-control { grid-template-columns: 112px minmax(0, 1fr) 48px; }

/* Chord wheel: kit buttons sit on a decorative ring. */
html[data-gn-glow] .gn-ov-wheel {
  position: relative;
  width: var(--gn-ov-wheel, 320px);
  height: var(--gn-ov-wheel, 320px);
  align-self: start;
}
/* Option B wheel: one ring of roots, the key's seven shaded with Roman numerals inside. */
html[data-gn-glow] .gn-ov-wheel[data-card="b"] .gn-ov-ring circle { fill: none; stroke: var(--gn-k-rule, rgba(58, 40, 32, .14)); }
html[data-gn-glow] .gn-ov-wheel[data-card="b"] .gn-ov-ring circle:last-of-type { fill: rgba(255, 255, 255, .55); stroke: rgba(196, 154, 69, .55); stroke-width: 1.2; }
html[data-gn-glow] .gn-ov-keyarc { fill: rgba(196, 154, 69, .16); stroke: rgba(196, 154, 69, .55); }
html[data-gn-glow] .gn-ov-rn { font: 700 12.5px/1 system-ui, -apple-system, sans-serif; fill: var(--gn-k-gold-deep, #7A6020); text-anchor: middle; dominant-baseline: middle; }
html[data-gn-glow] .gn-ov-wheel[data-card="b"] .gn-k-btn[data-part="root"] { min-width: 44px; min-height: 44px; border-radius: 999px; padding: 0 4px; font-size: 16px; }
html[data-gn-glow] .gn-ov-wheel[data-card="b"] .gn-ov-centre { width: 46%; height: 46%; grid-template-rows: auto auto; align-content: center; gap: 2px; font-size: 32px; }
html[data-gn-glow] .gn-ov-wheel[data-card="b"] .gn-ov-centre > .gn-k-sub { font-size: 12.5px; }
html[data-gn-glow] .gn-ov-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
html[data-gn-glow] .gn-ov-ring circle {
  fill: rgba(251, 243, 228, .55);
  stroke: rgba(58, 40, 32, .16);
  stroke-width: 1;
}
html[data-gn-glow] .gn-ov-ring circle:last-child {
  fill: #FFFFFF;
  stroke: #C49A45;
  stroke-width: 1.5;
}
html[data-gn-glow] .gn-ov-wheel .gn-k-btn {
  position: absolute;
  min-width: 44px;
  padding: 0 4px;
  transform: translate(-50%, -50%);
}
html[data-gn-glow] .gn-ov-wheel .gn-k-btn[data-part="root"] {
  min-width: 52px;
  font: 600 17px/1 "Crimson Pro", Georgia, serif;
}
html[data-gn-glow] .gn-ov-wheel .gn-k-btn[data-part="quality"] { font-size: 13px; }
html[data-gn-glow] .gn-ov-centre {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 128px;
  height: 128px;
  transform: translate(-50%, -50%);
  color: #3A2820;
  font-size: 34px;
  pointer-events: none;
}

html[data-gn-glow] .gn-ov-controls {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}
html[data-gn-glow] .gn-ov-ring-row,
html[data-gn-glow] .gn-ov-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 4px;
}
html[data-gn-glow] .gn-ov-chips > .gn-k-btn { padding: 0 8px; }
/* All 74 types rides the ring row so the reason line below the chips has room for two lines. */
html[data-gn-glow] .gn-ov-ring-row > [data-overlay-all-types] { padding: 0 8px; margin-left: auto; }
html[data-gn-glow] #overlayChordReason { min-height: 18px; margin: 0; }

/* All 74 types: covers the Overlays card until a type is chosen. */
html[data-gn-glow] .gn-ov-types {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 10px 12px;
  background: #F8F4EC;
}
html[data-gn-glow] .gn-ov-types-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
html[data-gn-glow] .gn-ov-types .gn-ov-chips > .gn-k-btn { padding: 0 6px; }

/* Chord symbols: Crimson Pro letters with Bravura accidentals; the suffix sits small and raised. */
.gn-ov-chord {
  display: inline-flex;
  align-items: baseline;
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.gn-ov-ext {
  margin-left: .04em;
  font-size: .62em;
  transform: translateY(-.62em);
}
.gn-ov-chord[data-kind="chip"] .gn-ov-ext {
  margin-left: 0;
  font-size: inherit;
  transform: none;
}
.gn-ov-acc {
  width: auto;
  height: .78em;
  margin: 0 .03em;
  fill: currentColor;
  transform: translateY(.06em);
  overflow: visible;
}

/* Placed marks. */
.annotation-stamp.overlay-chord,
.annotation-stamp.overlay-divider {
  width: auto;
  height: auto;
  padding: .06em .16em;
  font-family: "Crimson Pro", Georgia, serif;
  line-height: 1;
  filter: none;
}
.annotation-stamp.overlay-divider { padding: .1em; }
.gn-ov-divider {
  display: block;
  width: 1.042em;
  height: 1.216em;
  fill: currentColor;
}
/* Sticker: a page-colour backing and a thin outline so the mark reads over the music. Stamp: no backing. */
.annotation-stamp.overlay-sticker {
  border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
  border-radius: 6px;
  background: #FFFFFF;
  filter: none;
}
/* The figure owns its exact ink box; the sticker border sits outside it. */
.annotation-stamp.overlay-rhythm {
  box-sizing: content-box;
  padding: 0;
  filter: none;
}
.annotation-stamp.overlay-rhythm > .overlay-rhythm-figure,
.stamp-tile > .overlay-rhythm-figure {
  display: block;
  flex: none;
  line-height: 0;
}
.overlay-rhythm-figure > svg {
  display: block;
}
/* Engraved glyphs are filled shapes, not kit line icons, wherever they sit (tiles, chips, the page). */
html[data-gn-glow] svg.gn-ov-divider,
html[data-gn-glow] svg.gn-ov-acc,
html[data-gn-glow] svg.gn-ov-divider path,
html[data-gn-glow] svg.gn-ov-acc path {
  fill: currentColor;
  stroke: none;
}

/* Spans (W-SP): the tab's tile grid and option row, the reader's span layer, and the selected span's handles.
   Handles and the delete dot reuse the selection-handle look; hits are measured in app.js, so none take events. */
html[data-gn-glow] .overlays-spans:not([hidden]) {
  display: grid;
  align-content: start;
  gap: 8px;
}
html[data-gn-glow] .overlays-spans .span-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
}
html[data-gn-glow] #stampPalette .overlays-spans .stamp-tile.span-tile {
  width: auto;
  min-width: 64px;
  height: 48px;
  min-height: 48px;
  display: grid;
  grid-template-rows: 28px auto;
  gap: 1px;
  padding: 3px 2px;
}
html[data-gn-glow] .overlays-spans .span-tile svg {
  width: 49px;
  height: 28px;
  overflow: visible;
}
html[data-gn-glow] .overlays-spans .span-tile-name {
  font-size: 10.5px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62px;
}
html[data-gn-glow] .overlays-spans .span-options {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}
html[data-gn-glow] .overlays-spans .span-option select { min-height: 44px; }
html[data-gn-glow] .overlays-spans .span-options > .gn-k-btn { min-height: 44px; padding: 0 12px; }
html[data-gn-glow] .overlays-spans .span-hint { flex-basis: 100%; margin: 0; }

.annotation-span-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.annotation-span-layer .annotation-span-ink {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.annotation-span-layer .annotation-span-text { fill: currentColor; }
.annotation-span-layer .annotation-span-halo {
  fill: none;
  stroke: rgba(255, 181, 55, 0.45);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.annotation-span-layer .annotation-span-preview { opacity: 0.72; }
.annotation-span-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.annotation-span-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid #9A7F43;
  border-radius: 50%;
  background: #FFFDF8;
  box-shadow: 0 1px 4px rgba(74, 59, 50, 0.3);
}
.annotation-span-handle.curve,
.annotation-span-handle.opening { border-color: #4A7A9E; }
.annotation-span-delete {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  display: grid;
  place-items: center;
  border: 1px solid #A04A2C;
  border-radius: 50%;
  background: #FFFDF8;
  color: #A04A2C;
  box-shadow: 0 3px 8px rgba(74, 59, 50, 0.22);
  font: 900 18px/1 var(--font-sans);
}
/* The Spans tab scrolls inside the card on a short screen; its own hint replaces the general one. */
html[data-gn-glow] .overlays-body:has(> #overlaySpans:not([hidden])) { overflow-y: auto; overscroll-behavior: contain; }
html[data-gn-glow] #stampPalette:has(#overlaySpans:not([hidden])) > #stampPanelNote { display: none; }
