/* =========================================================
   AURORA — Touch & small screens
   Loads last. Three jobs:
   1. Floating menus: an open dropdown is lifted out to <body> and
      placed inside the viewport (app.js does the placing). On a
      phone it becomes a sheet rising from the bottom edge.
   2. The right-hand tools on short and narrow screens: the Dock
      becomes a compact grid under the Placard so both always fit.
   3. Phones and tablets: a bottom tab bar replaces the Dock, the
      chart gets a compact layout, and every tap target is finger-sized.
   ========================================================= */

/* ---------- 1. Floating menus ---------- */
.star-select-menu.star-select-floating {
  position: fixed;
  z-index: 2000;
  margin: 0;
  min-width: 0;
  box-sizing: border-box;
}
.star-select-floating .star-select-option { white-space: nowrap; }

.star-select-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1999;
  background: rgba(2, 5, 12, 0.62);
  -webkit-tap-highlight-color: transparent;
}

.star-select-menu.star-select-sheet {
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  width: 100%;
  max-width: none;
  padding: 0 8px calc(12px + env(safe-area-inset-bottom, 0px));
  border-width: 1px 0 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -18px 44px rgba(0, 0, 0, 0.6);
  animation: sheet-rise 160ms ease-out;
  scroll-padding-top: 56px;
  -webkit-overflow-scrolling: touch;
}
.star-select-sheet::before {
  content: attr(data-title);
  position: sticky;
  top: 0;
  z-index: 1;
  display: block;
  margin: 0 -8px 4px;
  padding: 16px 18px 11px;
  background: linear-gradient(180deg, #07090c 82%, transparent);
  color: var(--touch-accent-bright);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.86rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.star-select-sheet .star-select-option {
  min-height: 48px;
  padding: 10px 12px;
  font-size: 1rem;
  white-space: normal;
}
.star-select-sheet .star-select-group-label { padding-top: 14px; }
@keyframes sheet-rise { from { transform: translateY(18%); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .star-select-menu.star-select-sheet { animation: none; } }

/* ---------- 2. Dock + Placard that always fit ---------- */
/* touch.js measures the Helm and publishes its height as --helm-h, so the
   Placard and Dock always start just beneath it however many rows it wraps to. */
body { --helm-h: 96px; --placard-h: 0px; }
.placard { top: calc(var(--helm-h) + 12px) !important; }
.dock { top: calc(var(--helm-h) + 12px + var(--placard-h)) !important; }
.dock-flyout {
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dock-flyout::before { display: none; }
.dock-rail { max-height: calc(100vh - var(--helm-h) - var(--placard-h) - 24px); overflow-y: auto; scrollbar-width: none; }
.dock-rail::-webkit-scrollbar { display: none; }

/* Wide enough for the full Placard: the Dock is a grid of the same
   width directly beneath it, a few rows tall instead of a tall rail. */
@media (min-width: 1180px) {
  body { --placard-h: 322px; }
  .dock-rail {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    width: 200px;
    box-sizing: border-box;
  }
  .dock-rail .dock-btn { width: auto; min-width: 0; padding: 6px 0 5px; }
  .dock-rail .dock-btn span { font-size: 0.5rem; letter-spacing: 0.04em; }
  .dock-rail .dock-gap { display: none; }
  .dock-flyout { right: calc(100% + 8px); left: auto; }
}
@media (min-width: 1640px) {
  body { --placard-h: 342px; }
  .dock-rail { width: 230px; }
  .dock-rail .dock-btn span { font-size: 0.56rem; letter-spacing: 0.06em; }
}
/* Short windows: tighten the Placard so the Dock grid still clears the bottom. */
@media (min-width: 1180px) and (max-height: 700px) {
  body { --placard-h: 236px; }
  .placard-inner { height: 224px !important; padding-top: 10px; }
  .placard-root { font-size: 3rem !important; }
  .placard-line, .placard-selection { display: none !important; }
}
/* Narrow laptops and landscape tablets: the Helm already names the chart,
   so the name rail steps aside and the Dock takes the whole margin. */
@media (min-width: 1000px) and (max-width: 1179px) {
  .placard { display: none; }
  body.has-placard, body.has-placard .helm { padding-right: 84px; }
  .dock-rail .dock-btn { padding: 4px 0 3px; }
}
@media (min-width: 1000px) and (max-width: 1179px) and (max-height: 760px) {
  .dock-rail { gap: 1px; padding: 4px 6px; }
  .dock-rail .dock-btn svg { width: 19px; height: 19px; }
  .dock-rail .dock-gap { margin: 1px 6px; }
}

/* ---------- 3. Phones and tablets ---------- */
html { -webkit-text-size-adjust: 100%; }
button, a, .star-select-trigger, .key, .fret-cell { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* Jump targets stop below the Helm, not under it. */
.panel, .key-block, .arp-block, .voicings-block, .fretboard-scroll, .keyboard-scroll, .scale-summary-heading, .diatonic-block, #listenPanel { scroll-margin-top: 76px; }

/* Bottom tab bar (built by touch.js) — only where the Dock is hidden. */
.tabbar { display: none; }
@media (max-width: 999px) {
  .tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 58;
    display: flex;
    justify-content: space-around;
    gap: 2px;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(92, 226, 166, 0.36);
    background: linear-gradient(180deg, rgba(9, 20, 24, 0.97), rgba(4, 9, 15, 0.98));
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
  }
  .tabbar a, .tabbar button {
    flex: 1 1 0;
    min-width: 0;
    display: grid;
    justify-items: center;
    gap: 2px;
    min-height: 46px;
    padding: 5px 2px 3px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
  }
  .tabbar svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar svg .dot { fill: currentColor; stroke: none; }
  .tabbar span { font-size: 0.6rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
  .tabbar .tab-active { color: var(--touch-accent-bright); border-color: rgba(92, 226, 166, 0.36); background: rgba(92, 226, 166, 0.09); }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }

  /* Helm: one tidy row — top, name, the three things worth a thumb. */
  .helm-inner { width: 100%; border-radius: 0; border-left: 0; border-right: 0; padding: 7px 10px 9px; gap: 6px 8px; flex-wrap: nowrap; }
  .helm-selects, .helm-notes, .helm-help, #helmDisplayBtn, #helmKeysBtn { display: none !important; }
  .helm-readout { flex: 1 1 auto; max-width: none; min-width: 0; }
  .helm-readout strong { font-size: 1rem; }
  .helm-tools { margin-left: 0; flex: 0 0 auto; flex-wrap: nowrap; gap: 5px; }
  .text-button.helm-tool { min-height: 38px; padding: 0 10px; font-size: 0.76rem; white-space: nowrap; }
  .helm-top { width: 36px; height: 36px; }

  /* Finger-sized controls everywhere. */
  .text-button, .secondary-button, .primary-button { min-height: 42px; }
  .star-select-trigger { min-height: 46px; }
  .note-chip { min-height: 42px; }
  .app-shell { width: calc(100% - 16px); padding-top: 14px; }
  .panel { padding-left: 14px; padding-right: 14px; }
  .section-heading { align-items: flex-start; }
  .note-action-buttons { justify-content: flex-start; }
}

/* Tool cards: explanation on top, controls underneath, so the text is
   never squeezed into a one-word column beside its buttons. */
@media (max-width: 999px) {
  .fret-focus-tool, .neck-view-tool, .strings-tool, .audio-tool { flex-direction: column; align-items: flex-start; min-height: 0; gap: 10px; }
  .fret-tool-copy { flex: 0 0 auto; width: 100%; }
  .fret-focus-controls, .neck-view-controls, .strings-controls, .audio-controls { justify-content: flex-start; width: 100%; }
}
/* Tablets (portrait): two columns where a phone gets one. */
@media (min-width: 641px) and (max-width: 999px) {
  .fret-tools { grid-template-columns: 1fr 1fr; }
  .voicing-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* Landscape tablets and small laptops: the Helm stays two rows —
   name and menus on top, the notes and the buttons beneath. */
@media (min-width: 1000px) and (max-width: 1240px) {
  .helm-notes { order: 5; flex: 1 1 200px; justify-content: flex-start; }
  .helm-tools { order: 6; margin-left: auto; }
  #helmDisplayBtn { display: none; }
}

@media (max-width: 640px) {
  .hero { padding: 16px 14px; }
  .brand-lockup { gap: 10px; }
  .logo-mark { width: 54px; height: 54px; flex: 0 0 auto; }
  .subtitle { font-size: 0.92rem; line-height: 1.5; }
  .help-button { width: 100%; justify-content: center; }
  .control-grid, .control-grid-6 { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .quick-actions, .quick-action-group { flex-direction: column; align-items: stretch; }
  .quick-action-group > * { width: 100%; }
  .custom-range { display: grid; grid-template-columns: 1fr 1fr; }
  .preset-select, .capo-select, .key-mode-select { width: 100%; min-width: 0; }
  .section-heading h2 { font-size: 1.25rem; }
  .pattern-guide-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .pattern-guide-actions .primary-button { width: 100%; }
  .maps-bar { flex-direction: column; align-items: stretch; }
  .maps-slots { display: grid; grid-template-columns: 1fr 1fr; }
  .legend { gap: 6px 14px; font-size: 0.78rem; }
  .session-row, .notes-actions { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* Phones on their side: little height, so the bars slim down. */
@media (max-height: 500px) and (max-width: 999px) {
  .tabbar a, .tabbar button { min-height: 36px; grid-auto-flow: column; align-items: center; gap: 5px; padding: 3px 4px; }
  .tabbar svg { width: 17px; height: 17px; }
  body { padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px)); }
  .helm-inner { padding: 4px 10px 6px; }
  .text-button.helm-tool { min-height: 32px; }
}

/* Credit line */
.site-credit {
  margin: 18px auto 6px;
  padding: 0 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
}
.site-credit strong { color: var(--touch-accent-bright); font-family: Georgia, "Times New Roman", serif; font-weight: 700; letter-spacing: 0.03em; }
.site-credit a, .site-credit .credit-author { white-space: nowrap; }
.site-credit a { color: var(--touch-accent-bright); text-decoration: none; border-bottom: 1px dotted currentColor; }
.site-credit a:hover { border-bottom-style: solid; }
.site-credit small { display: block; font-size: 0.72rem; opacity: 0.8; }

/* ---------- Aurora: the neck on a phone ---------- */
:root { --touch-accent: #5ce2a6; --touch-accent-bright: #a0f6cd; }
@media (max-width: 999px) {
  .fretboard-scroll { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .tone { touch-action: manipulation; }
  .key-controls { justify-content: flex-start; }
}
/* A phone on its side has width but no height: shorter rows so all six strings show. */
@media (max-height: 500px) and (max-width: 999px) {
  .fret-cell, .string-label { min-height: 38px !important; }
  .fret-header { min-height: 30px !important; height: 30px; }
  .tone { min-width: 28px !important; min-height: 28px !important; padding: 2px 4px !important; font-size: 0.78rem; }
}
@media (max-width: 640px) {
  /* Label column shrinks to the string's note and number; frets keep a
     thumb-wide 46px and the neck scrolls sideways under the labels. */
  .fretboard { grid-template-columns: 58px 46px repeat(var(--fretted-count), 46px) !important; }
  .string-word { display: none; }
  .string-toggle { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 0; padding: 4px 2px; }
  .string-toggle small { order: -1; font-size: 0.92rem !important; font-weight: 800; color: var(--text); white-space: normal !important; line-height: 1.1; }
  .string-toggle strong { font-size: 0.6rem !important; color: var(--muted); letter-spacing: 0.08em; }
  .string-toggle strong::before { content: "str "; }
  .string-toggle i { grid-column: 1; grid-row: auto; font-size: 0.6rem; line-height: 1; }
  .fret-header { font-size: 0.72rem; }
  .tuning-controls { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px; }
  .voicing-stage { padding: 12px; }
  .stage-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .prog-strip { gap: 6px; }
  .prog-arrow { display: none; }
  .prog-step { width: calc(50% - 3px); }
  .arp-stage-diagram { overflow-x: auto; }
}

