#openShapeSheet {
  flex: none;
  min-height: 42px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  white-space: nowrap;
  font-size: .8rem;
}

#openShapeSheet:hover { background: var(--raised); }

@media (min-width: 701px) {
  #explore .learn-title-row { flex-wrap: wrap; }
  .lab-workspace #openShapeSheet { min-height: 38px; }
}

.shape-sheet {
  width: min(900px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100dvh - 40px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 24px 80px #0008;
}

.shape-sheet[open] { display: flex; flex-direction: column; }
.shape-sheet::backdrop { background: #080d14b3; backdrop-filter: blur(4px); }
body:has(.shape-sheet[open]) { overflow: hidden; }

.shape-sheet-header {
  display: grid;
  gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.shape-sheet-heading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.shape-sheet-heading h2 {
  flex: 1;
  margin: 0;
  font-size: clamp(1.2rem, 3.2vw, 1.65rem);
  line-height: 1.18;
}

.shape-sheet-heading .dialog-close {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
}

.shape-sheet-chord {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--muted);
}

.shape-sheet-chord select { min-height: 40px; font-size: .86rem; }

.shape-sheet-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  flex-wrap: wrap;
}

.shape-sheet-legend,
.shape-sheet-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.shape-sheet-legend .tone-key { padding: 3px 8px; font-size: .75rem; }
.shape-sheet-groups .small-btn { min-height: 36px; padding: 5px 10px; font-size: .76rem; }

.shape-sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px 24px 24px;
}

.shape-sheet-group + .shape-sheet-group {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.shape-sheet-group h3 {
  scroll-margin-top: 12px;
  margin: 0 0 8px;
  font-size: .98rem;
}

.shape-sheet-position + .shape-sheet-position { margin-top: 10px; }
.shape-sheet-position h4 { margin: 0 0 6px; color: var(--muted); font-size: .75rem; }

.shape-sheet-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.shape-sheet-card {
  margin: 0;
  padding: 8px 12px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.shape-sheet-card figcaption {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  margin-bottom: 5px;
  font-size: .78rem;
  font-weight: 650;
}

.shape-sheet-card figcaption small { color: var(--muted); font-size: .68rem; font-weight: 500; }

.shape-sheet-grid {
  display: grid;
  grid-template-columns: 14px repeat(var(--sheet-frets), minmax(0, 1fr));
  align-items: center;
  text-align: center;
  font-size: .71rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.shape-sheet-string { text-align: start; color: var(--text); font-weight: 700; }
.shape-sheet-fret {
  position: relative;
  display: grid;
  place-items: center;
  height: 23px;
  border-right: 1px solid var(--fret);
}
.shape-sheet-fret::before {
  content: '';
  position: absolute;
  inset: 50% 0 auto;
  border-top: 1px solid var(--fret);
}
.shape-sheet-fret.is-open { border-right: 2px solid var(--text); }
.shape-sheet-fret b {
  z-index: 0;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  padding-inline: 1px;
  font-size: .66rem;
  line-height: 1;
}

@media (max-width: 700px) {
  #openShapeSheet { min-height: 44px; padding-inline: 8px; font-size: .72rem; }
  .shape-sheet {
    width: 100%;
    max-height: 92dvh;
    margin: auto auto 0;
    border-radius: 20px 20px 0 0;
  }
  .shape-sheet-header { padding: 12px 14px 10px; gap: 8px; }
  .shape-sheet-heading { flex-wrap: wrap; gap: 6px 10px; }
  .shape-sheet-heading h2 { flex-basis: calc(100% - 54px); }
  .shape-sheet-heading .dialog-close { order: 1; }
  .shape-sheet-chord { order: 2; }
  .shape-sheet-chord select, .shape-sheet-groups .small-btn { min-height: 44px; }
  .shape-sheet-groups .small-btn { padding-inline: 9px; }
  .shape-sheet-body { padding: 12px 14px max(18px, env(safe-area-inset-bottom)); }
  .shape-sheet-card { padding-inline: 7px; }
}

@media (max-width: 460px) {
  .shape-sheet-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-height: 450px) and (orientation: landscape) {
  .shape-sheet-header { padding-block: 6px; gap: 5px; }
  .shape-sheet-heading h2 { flex-basis: auto; }
  .shape-sheet-chord { order: 0; }
}
