/* Mobile-specific styles for Music Notation Editor */
/* Imports shared variables and base styles */
@import url("./shared.css");

/* Developer-only elements are hidden by default, shown on localhost via JS */
[data-dev-only] { display: none !important; }

/* Mobile-specific variables */
:root {
  --menu-width: 280px;
  --keyboard-height: 170px; /* Pitch row (134) + padding/gaps (~36) — nav/symbol rows moved to symbols-bar */
}

/* ============================================
   Viewport Classes (LAYOUT_CONTRACT.md Section 7.1)
   ============================================

   Applied by LayoutCoordinator based on viewport dimensions.
   These classes enable viewport-specific styling without media queries.

   Breakpoints:
   - tiny:   < 360px width OR < 480px height
   - small:  360-599px width
   - medium: 600-1023px width
   - large:  >= 1024px width
*/

/* Viewport-class rules and debug indicators removed.
   All responsive layout is now driven by @container app-layout queries
   at the bottom of this file. */

/* ============================================
   Toolbelt Bar (LAYOUT_CONTRACT.md Section 7.5)
   Fixed bar at top - contains tool chips, menu, view buttons
   ============================================ */

#toolbelt-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  padding-top: 7px; /* Extra padding for accent stripe */
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  position: relative; /* For accent stripe pseudo-element */
}

#osk-menu-btn,
#osk-view-btn,
#osk-play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

#osk-view-btn {
  font-size: 28px;
  line-height: 1;
}

#osk-menu-btn:hover,
#osk-view-btn:hover,
#osk-play-btn:hover {
  background: var(--bg-hover);
}

#osk-play-btn.playing {
  color: var(--primary-color);
}

/* Toolbelt Insert button (desktop palette drawer toggle) */
.toolbelt-insert-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border-color, #444);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #aaa);
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  height: 30px;
  transition: background-color 150ms, border-color 150ms;
}
.toolbelt-insert-btn:hover { background: var(--bg-hover, #2a2a3e); }
.toolbelt-insert-btn:active { background: var(--bg-hover, #2a2a3e); }
.toolbelt-insert-btn[data-active="true"] {
  background: var(--accent-bg, #2d3a55);
  border-color: var(--accent-color, #3b82f6);
  color: var(--text-primary, #e0e0e0);
}
.toolbelt-insert-btn .insert-btn-icon {
  font-size: 15px;
  line-height: 1;
}

/* Piano button uses tab styling - active state when piano keyboard is shown */
#osk-piano-btn.active {
  background: var(--primary-color);
  color: white;
}

/* Old .osk-tab and .osk-mode-tabs removed — replaced by ToolRegistry tri-state chips */

/* ============================================
   YOLO Mode Toggle (Auto-detect content type)
   ============================================ */
/* Stream status strip — "Detected: X" label above editor */
.stream-status {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 24px;
  padding: 0 12px;
  background: var(--bg-primary, #181825);
  flex-shrink: 0;
}
.stream-status-label {
  font-size: 11px;
  color: var(--text-secondary, #888);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

/* Constraint pill — shows active scale constraint */
.constraint-pill {
  font-size: 11px;
  color: var(--text-secondary, #888);
  padding: 1px 8px;
  margin-left: 8px;
  border-left: 3px solid transparent;
  border-radius: 2px;
  background: rgba(255,255,255,0.06);
  white-space: nowrap;
  user-select: none;
}
.constraint-pill.hidden {
  display: none;
}

/* Snap toast — transient feedback near caret */
.snap-toast {
  position: absolute;
  font-size: 11px;
  color: var(--text-accent, #cba6f7);
  background: var(--bg-elevated, #1e1e2e);
  border: 1px solid var(--border-subtle, #313244);
  border-radius: 4px;
  padding: 2px 6px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease-out;
}
.snap-toast.fade-out {
  opacity: 0;
}

/* Stream label in desktop toolbelt bar */
.stream-label-desktop {
  font-size: 11px;
  color: var(--text-secondary, #888);
  pointer-events: none;
  user-select: none;
  padding: 0 8px;
  white-space: nowrap;
}

.osk-bar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Keyboard toggle button in OSK bar */
.osk-keyboard-toggle {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
}

.osk-keyboard-toggle:hover {
  background: var(--bg-hover);
}

/* Active state when keyboard is visible */
.osk-keyboard-toggle.active {
  background: var(--primary-color);
  color: white;
}

/* Hide insert-panel-header on all viewports (OSK selector bar replaces it) */
.insert-panel-header {
  display: none !important;
}

/* Preview pane hidden on tiny/small — now in @container app-layout (width < 600px) */

/* ============================================
   Panel State Classes (LAYOUT_CONTRACT.md Section 7.4)
   ============================================ */

/* Ensure panel has position context for accent stripe */
#insert-panel {
  position: relative;
}

/* ============================================
   Symbols Bar (persistent — always visible, even with native keyboard)
   ============================================ */

.symbols-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  background: var(--bg-secondary, #f5f5f5);
  border-top: 1px solid var(--border-color, #ddd);
  flex-shrink: 0;
  overflow: hidden;
}

.symbols-bar-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px;
}

.symbols-bar button {
  min-width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-tertiary, #e8e8e8);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.symbols-bar button svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  pointer-events: none;
}

.symbols-bar button:active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

/* Caret navigation arrows — pinned at far edges of symbols bar */
.caret-nav {
  display: none;
  flex-shrink: 0;
  min-width: 52px;
  height: 52px;
  font-size: 18px;
  font-weight: bold;
}

.caret-nav-left {
  margin-left: 4px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.caret-nav-right {
  margin-right: 4px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Show caret arrows only when native OSK is visible */
body.keyboard-open .caret-nav {
  display: flex;
  align-items: center;
  justify-content: center;
}

.symbols-separator {
  width: 1px;
  height: 20px;
  background: var(--border-color, #ccc);
  margin: 0 2px;
  flex-shrink: 0;
}

/* Panel hidden (fully removed from layout) */
#insert-panel.panel-hidden {
  display: none !important;
}

/* Panel forced indicator - subtle visual cue that state was forced by keyboard/view */
#insert-panel.panel-forced::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  background: var(--primary-color);
  border-radius: 50%;
  opacity: 0.6;
}

/* ============================================
   Mode-Specific Accent Stripe
   A colored top border indicates the active OSK type
   ============================================ */

#insert-panel::before,
#toolbelt-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  transition: background-color 0.2s ease;
}

/* Pitch mode: Blue */
#insert-panel[data-mode="pitch"]::before,
#toolbelt-bar[data-mode="pitch"]::before {
  background: #3b82f6;
}

/* Chords mode: Purple */
#insert-panel[data-mode="chords"]::before,
#toolbelt-bar[data-mode="chords"]::before {
  background: #8b5cf6;
}

/* Figures mode: Emerald */
#insert-panel[data-mode="figures"]::before,
#toolbelt-bar[data-mode="figures"]::before {
  background: #10b981;
}

/* Tabla mode: Amber */
#insert-panel[data-mode="tabla"]::before,
#toolbelt-bar[data-mode="tabla"]::before {
  background: #f59e0b;
}

/* Text mode: Slate */
#insert-panel[data-mode="text"]::before,
#toolbelt-bar[data-mode="text"]::before {
  background: #64748b;
}

/* ============================================
   Text Mode (Native Keyboard)
   ============================================
   In text mode, the custom OSK is hidden and the native
   OS keyboard is used instead. The panel header remains
   visible for mode switching and menu access.
*/

/* Text mode - hide custom keyboard content, user uses native OS keyboard */
#insert-panel[data-mode="text"] .insert-panel-content {
  display: none !important;
}

/* Hide entire bottom panel in text mode (OSK selector is at top) */
#insert-panel[data-mode="text"] {
  display: none !important;
}


/* ============================================
   Editor Visibility (LAYOUT_CONTRACT.md Section 7.2)
   ============================================ */


/* ============================================
   View Presentation Classes (LAYOUT_CONTRACT.md Section 7.3)
   ============================================

   These complement the existing view-controller.ts classes.
   The presentation classes help with fullscreen/overlay/docked styling.
*/


/* Mobile-specific touch handling */
html,
body {
  -webkit-overflow-scrolling: touch;
}

/* App container */
#mobile-app {
  container-type: inline-size;
  container-name: app-layout;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  height: var(--vvh, 100dvh); /* Tracks visualViewport when JS active */
  padding-top: var(--safe-area-top);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* Headerless mode - no top bar, more space for content */
#mobile-app.headerless #mobile-header {
  display: none;
}

#mobile-app.headerless #mobile-main {
  padding-top: 8px;
}

/* Header */
#mobile-header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 8px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 100;
}

#doc-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s;
}

.header-btn:hover,
.header-btn:active {
  background: var(--bg-hover);
}

.header-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.header-btn:disabled:hover {
  background: transparent;
}

.header-actions {
  display: flex;
  gap: 4px;
}

/* Menu backdrop */
.menu-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  z-index: 999; /* Contract 4.1: Just below menu (1000) */
}

.menu-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

/* Slide-out menu */
#mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--menu-width);
  height: 100%;
  background: var(--bg-primary);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000; /* Contract 4.1: Menu is highest at 1000 */
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

#mobile-menu.menu-open {
  transform: translateX(0);
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.menu-title {
  font-size: 18px;
  font-weight: 600;
}

.menu-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
}

.menu-close-btn:hover {
  background: var(--bg-hover);
}

.menu-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.menu-section {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.menu-section:last-child {
  border-bottom: none;
}

.menu-section-title {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s;
}

.menu-item:hover,
.menu-item:active {
  background: var(--bg-hover);
}

.menu-arrow {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 14px;
}

.tools-pref-menu-row {
  gap: 8px;
}

.tools-pref-menu-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary-color);
}

.tools-pref-menu-row input[type="checkbox"]:disabled {
  opacity: 0.5;
}

/* Pitch systems button in desktop menu tools submenu */
.pitch-systems-btn {
  font-size: 13px;
  color: var(--primary-color);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.pitch-systems-btn:hover {
  background: var(--bg-hover);
}

/* Pitch row in modal customize toolbar — flex with button on right */
.tools-pref-pitch-row {
  justify-content: space-between;
}

.tools-pref-pitch-row label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tools-pref-pitch-row .pitch-systems-btn {
  font-size: 18px;
  padding: 2px 8px;
  line-height: 1;
}

.menu-divider {
  height: 1px;
  background: var(--border-color);
  margin: 8px 16px;
}

.menu-icon {
  width: 24px;
  margin-right: 12px;
  text-align: center;
  font-size: 18px;
}

.menu-chevron {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 20px;
}

.menu-check {
  width: 24px;
  margin-right: 12px;
  text-align: center;
  color: var(--primary-color);
  font-weight: bold;
}

.menu-sublabel {
  padding: 6px 16px 2px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}

/* Menu search results */
.menu-search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.menu-search-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* Submenu */
.submenu {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--menu-width);
  height: 100%;
  background: var(--bg-primary);
  z-index: 1001; /* Above menu (1000) */
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.submenu.visible {
  transform: translateX(0);
}

.submenu.hidden {
  transform: translateX(100%);
}

.submenu-header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 8px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.submenu-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--primary-color);
  cursor: pointer;
  border-radius: 8px;
}

.submenu-back:hover {
  background: var(--bg-hover);
}

.submenu-title {
  font-size: 17px;
  font-weight: 600;
  margin-left: 8px;
}

.submenu-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Barlines submenu */
.barline-section {
  padding: 12px 16px;
}

.barline-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.barline-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.barline-btn {
  min-width: 48px;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: "NotationFont", monospace;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.barline-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.barline-btn:active {
  background: var(--primary-color);
  color: white;
}

/* Barline buttons using notation font glyphs */
.barline-glyph {
  font-size: 24px;
  line-height: 1;
}

/* Main content: Textarea → Strip → Bar → Preview */
#mobile-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding-bottom: var(--safe-area-bottom);
  /* No padding-bottom needed - elements are in flow */
}

/* Editor pane - takes available space */
#editor-pane {
  flex: 1 1 auto;
  min-height: 100px;
  overflow: hidden;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

#editor-container {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

/* Mobile notation editor adjustments */
#editor-pane .notation-editor {
  font-size: 28px;
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#editor-pane .notation-line {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#editor-pane .line-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#editor-pane .notation-textarea {
  font-size: 28px;
  padding: 4px 8px;
  flex: 1;
  height: 100%;
  min-height: 100%;
}

/* Preview pane - in-flow element, not fixed */
#preview-pane {
  flex-shrink: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  transition: height 0.2s ease;
}

/* Preview states - handled by preview-tabs.css */
/* Note: preview-hidden, preview-peek, preview-expanded classes are now in preview-tabs.css */

/* Hide insert panel when staff is expanded to allow 50/50 split */
body.staff-expanded #insert-panel {
  display: none;
}



/* ============================================
   Paragraph Staff Containers (Paragraph = Score)
   ============================================ */

/* Each paragraph renders as an independent staff system */
.paragraph-staff {
  margin-bottom: 0;
  position: relative;
}


/* Visual separator between paragraphs */
.paragraph-separator {
  height: 20px;
  margin: 8px 0;
  border-bottom: 1px dashed var(--border-color);
  opacity: 0.5;
}

/* First paragraph doesn't need top margin */
.paragraph-staff:first-child {
  margin-top: 0;
}

/* Paragraph staff hover state for debugging */
.paragraph-staff[data-paragraph]:hover::before {
  content: "¶" attr(data-paragraph);
  position: absolute;
  left: -24px;
  top: 4px;
  font-size: 10px;
  color: var(--text-secondary);
  opacity: 0.5;
}

/* .hidden is defined in shared.css */

/* Touch-friendly interactions */
@media (hover: none) {
  .menu-item:hover {
    background: transparent;
  }

  .menu-item:active {
    background: var(--bg-hover);
  }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --header-height: 48px;
  }

  .header-btn {
    width: 40px;
    height: 40px;
  }

  #doc-title {
    font-size: 15px;
  }

  .menu-item {
    padding: 10px 16px;
  }
}

/* Very small screens - style adjustments */
@media (max-width: 320px) {
  :root {
    --menu-width: 260px;
  }

  #doc-title {
    font-size: 15px;
  }

  .menu-item {
    font-size: 15px;
    padding: 12px 14px;
  }

  #editor-pane .notation-textarea {
    font-size: 24px;
  }
}

/* Small screens (phones in portrait) */
@media (max-width: 420px) and (min-width: 321px) {
  .keyboard-key {
    min-width: 40px;
    min-height: 44px;
    padding: 6px 10px;
    font-size: 18px;
  }

  .keyboard-key--structure {
    min-width: 34px;
  }

  .keyboard-row,
  .keyboard-pitch-row {
    gap: 5px;
  }

  .keyboard-main-row {
    gap: 10px;
  }

  .octave-lock-seg {
    height: 36px;
    min-width: 28px;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Fix for iOS bottom bar */
  #mobile-app {
    height: -webkit-fill-available;
    height: var(--vvh, -webkit-fill-available);
  }

  /* Prevent zoom on input focus */
  input,
  textarea,
  select {
    font-size: 16px;
  }
}

/* Loading state */
#mobile-app.loading::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* Animation for play button */
#play-btn.playing svg {
  fill: var(--primary-color);
}

#play-btn.playing {
  color: var(--primary-color);
}

/* Toast notifications (for save confirmation, etc.) */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.toast.visible {
  opacity: 1;
  pointer-events: auto;
}

.toast-action {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: inherit;
  font-size: 0.85rem;
  padding: 2px 10px;
  margin-left: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Bottom Bar REMOVED - functionality moved to insert panel header and drawer */

/* Convert bar removed — functionality moved to hamburger menu */

/* ============================================
   Context Bar (appears when selection exists)
   ============================================ */

.context-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  position: relative; /* For picker popover positioning */
}

.context-bar.hidden {
  display: none;
}

.context-bar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  min-width: 48px;
  min-height: 44px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s,
    transform 0.1s;
}

.context-bar button:active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

.context-bar button.active {
  background: var(--primary-color);
  color: white;
}

.context-bar button.active .label {
  color: white;
}

.context-bar button .icon {
  font-size: 18px;
  line-height: 1;
}

.context-bar button .label {
  font-size: 10px;
  margin-top: 2px;
  color: var(--text-secondary);
}

.context-bar button:active .label {
  color: white;
}

.context-bar .separator {
  width: 1px;
  height: 32px;
  background: var(--border-color);
  flex-shrink: 0;
}

/* ============================================
   Octave Stepper - Unified segmented control
   ============================================ */

.octave-stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.octave-stepper button {
  border: none;
  background: transparent;
  padding: 8px 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text-primary);
  min-height: 40px;
}

.octave-stepper button:active {
  background: var(--primary-color);
  color: white;
}

.stepper-btn {
  font-size: 18px;
  font-weight: 600;
  padding: 8px 10px;
}

.stepper-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* Separators between segments */
.stepper-left {
  border-right: 1px solid var(--border-color);
}

.stepper-right {
  border-left: 1px solid var(--border-color);
}

/* Center value - fixed width to prevent jitter */
.stepper-value {
  min-width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}

/* Lock indicator shown when locked */
.stepper-value.locked {
  background: var(--bg-hover);
}

/* Picker popover */
.picker-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 200;
}

.picker-popover.hidden {
  display: none;
}

.picker-popover button {
  min-width: 36px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  color: var(--text-primary);
}

.picker-popover button:hover {
  background: var(--bg-hover);
}

.picker-popover button:active {
  background: var(--primary-color);
  color: white;
}

.picker-popover button.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Drawer octave stepper row */
.octave-stepper-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.octave-stepper-row .octave-label {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.octave-stepper-row .octave-stepper {
  flex: 1;
  justify-content: center;
}

/* ============================================
   Split Resizer (between editor area and keyboard)
   ============================================ */

.split-resizer {
  flex-shrink: 0;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: row-resize;
  touch-action: none;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  user-select: none;
  -webkit-user-select: none;
}

.split-resizer-handle {
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  transition: background-color 0.15s;
}

.split-resizer:hover .split-resizer-handle,
.split-resizer.dragging .split-resizer-handle {
  background: var(--primary-color);
}

/* Hide resizer when keyboard is hidden (staff expanded) */
body.staff-expanded .split-resizer {
  display: none;
}

/* Bottom bar keyboard styles REMOVED */

/* Tiny viewport - hide preview */
body.keyboard-open.tiny-vv #preview-pane:not(.preview-expanded) {
  transform: translateY(100%);
  pointer-events: none;
}

/* Toast position - above the visible content */
.toast {
  bottom: calc(20px + var(--safe-area-bottom));
}

/* ============================================
   More Bottom Sheet
   ============================================ */

.mobile-bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.mobile-bottom-sheet.hidden {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-area-bottom));
  box-shadow: var(--shadow-lg);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-section {
  margin-bottom: 16px;
}

.sheet-section:last-child {
  margin-bottom: 0;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.sheet-buttons {
  display: flex;
  gap: 12px;
}

.sheet-buttons button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.sheet-buttons button:active {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.sheet-buttons button .icon {
  font-size: 24px;
  margin-bottom: 4px;
}

/* Row with many buttons (e.g., 5 octave buttons) */
.sheet-buttons-row {
  flex-wrap: wrap;
  gap: 8px;
}

.sheet-buttons-row button {
  flex: 0 0 calc(20% - 8px);
  min-width: 56px;
  padding: 12px 4px;
  font-size: 11px;
}

.sheet-buttons-row button .icon {
  font-size: 18px;
  margin-bottom: 2px;
}

/* 3-column layout for file section */
.sheet-buttons:has(> button:nth-child(3)) button {
  flex: 0 0 calc(33.333% - 8px);
}

/* ============================================
   Pitch Context Sheet
   ============================================ */

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

/* Sheet header title */
.sheet-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Line indicator in sheet headers */
.sheet-line-indicator {
  font-size: 0.8rem;
  color: var(--text-secondary, #666);
  margin-left: auto;
  padding: 2px 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  white-space: nowrap;
}

/* Jump to line button in sheet headers */
.sheet-jump-btn {
  width: 28px;
  height: 28px;
  margin-left: 4px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sheet-jump-btn:hover {
  background: var(--primary-color);
  color: white;
}

.sheet-jump-btn:active {
  background: var(--primary-hover, var(--primary-color));
}

.sheet-close-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary-color);
  color: white;
  font-size: 14px;
  font-weight: 500;
}

.sheet-close-btn:active {
  background: var(--primary-hover);
}

/* X close button variant */
.sheet-close-x {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px;
  background: transparent;
  border: none;
  font-size: 24px;
  font-weight: 300;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  line-height: 1;
}

.sheet-close-x:active {
  color: var(--text-primary, #111827);
}

.pitch-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pitch-btn {
  min-width: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
}

.pitch-btn.selected {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.pitch-btn:active {
  background: var(--bg-hover);
}

.pitch-btn.selected:active {
  background: var(--primary-hover);
}

.keysig-picker {
  justify-content: center;
}

.keysig-hint {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* REMOVED: staves-picker - system grouping now inferred from blank lines */

/* REMOVED: keyboard-type-picker, keyboard-mode-toggle — piano is now a standalone tool */

/* ============================================
   Mobile Textarea - Simple textarea + mirror
   ============================================ */

/* Override #editor-container's overflow:auto when used as mobile textarea container */
#editor-container.mobile-textarea-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 0; /* Remove padding from #editor-container */
}

.mobile-notation-textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  margin: 0;
  border: none;
  outline: none;
  resize: vertical;
  overflow: auto;
  -webkit-overflow-scrolling: touch;

  /* Notation font */
  font-family: "NotationFont", monospace;
  font-size: 28px;
  line-height: 1.8;
  white-space: pre; /* Must match textarea to prevent misalignment */

  background: var(--bg-primary);
  color: var(--text-primary);
  caret-color: var(--primary-color);

  /* Disable mobile autocorrect features */
  -webkit-text-size-adjust: 100%;
}

/* Native selection styling */
.mobile-notation-textarea::selection {
  background: rgba(59, 130, 246, 0.3);
}

.mobile-notation-mirror {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  overflow: auto; /* Allows scrollTop/scrollLeft to work */
  pointer-events: none;
  user-select: none;

  /* Hide scrollbar - textarea handles scrolling */
  scrollbar-width: none;
  -ms-overflow-style: none;

  /* Match textarea font */
  font-family: "NotationFont", monospace;
  font-size: 28px;
  line-height: 1.8;
  white-space: pre; /* Must match textarea to prevent misalignment */

  /* Visible text for glyphs - background shows through transparent textarea */
  color: var(--text-primary);
  background: var(--bg-primary);
}

.mobile-notation-mirror::-webkit-scrollbar {
  display: none;
}

/* ============================================
   Mobile Drawer (persistent, non-modal)
   ============================================ */

.mobile-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  z-index: 150;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--safe-area-bottom);
}

.mobile-drawer.hidden {
  display: none;
}

.drawer-handle {
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 8px auto;
}

.drawer-content {
  padding: 8px 12px 12px;
}

.drawer-section {
  margin-bottom: 12px;
}

.drawer-section:last-child {
  margin-bottom: 0;
}

/* Play button with accent styling */
.drawer-playback-section .drawer-play-btn {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.drawer-playback-section .drawer-play-btn:active {
  background: var(--primary-color-hover, #1a8cff);
  border-color: var(--primary-color-hover, #1a8cff);
}

/* Undo/Redo row with smaller buttons */
.drawer-undo-redo-row {
  margin-top: 8px;
}

.drawer-undo-redo-row button {
  padding: 10px 8px;
}

.drawer-row {
  display: flex;
  gap: 8px;
}

.drawer-row button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.drawer-row button:active {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.drawer-row button .icon {
  font-size: 16px;
}

/* Buttons directly in drawer-section (not in a row) */
.drawer-section > button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.drawer-section > button:active {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.drawer-section > button .icon {
  font-size: 16px;
}

/* Drawer toggle (expandable section header) */
.drawer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}

.drawer-toggle:active {
  background: var(--bg-hover);
}

.drawer-toggle.expanded {
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}

.toggle-chevron {
  transition: transform 0.2s;
}

.drawer-toggle.expanded .toggle-chevron {
  transform: rotate(180deg);
}

/* Drawer subpanel (for notation options) */
.drawer-subpanel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--bg-primary);
}

.drawer-subpanel.hidden {
  display: none;
}

.drawer-subpanel button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

.drawer-subpanel button:active {
  background: var(--bg-hover);
}

.drawer-subpanel button .icon {
  width: 20px;
  text-align: center;
}

/* Tools preferences rows */
.tools-pref-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 4px;
}

.tools-pref-row:hover {
  background: var(--bg-hover);
}

.tools-pref-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary-color);
}

.tools-pref-row input[type="checkbox"]:disabled {
  opacity: 0.5;
}

/* Settings button at bottom of drawer */
.drawer-settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}

.drawer-settings-btn:active {
  background: var(--bg-hover);
}

/* ============================================
   Mobile Modal (Settings, truly modal)
   ============================================ */

.mobile-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
}

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

.mobile-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.mobile-modal .modal-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(16px + var(--safe-area-bottom));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary-color);
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.modal-close-btn:active {
  background: var(--primary-hover);
}

.modal-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.modal-section:last-child {
  border-bottom: none;
}

.modal-buttons {
  display: flex;
  gap: 12px;
}

.modal-buttons button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 8px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.modal-buttons button:active {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.modal-buttons button .icon {
  font-size: 24px;
}

/* On wider screens, center the customize toolbar modal as a dialog */
@media (min-width: 600px) {
  #customize-toolbar-modal .modal-content {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    width: 400px;
    max-height: 70vh;
    border-radius: 16px;
    padding-bottom: 16px;
  }
}

.customize-toolbar-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.customize-toolbar-list .tools-pref-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
}

.customize-toolbar-list .tools-pref-row:active {
  background: var(--bg-hover);
}

.customize-toolbar-list .tools-pref-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-color);
}

.customize-toolbar-list .tools-pref-row input[type="checkbox"]:disabled {
  opacity: 0.5;
}

/* Additional pitch systems checkboxes */
.additional-pitch-systems {
  padding-left: 24px;
}
.additional-pitch-label {
  font-size: 11px;
  color: var(--text-secondary, #888);
  padding: 4px 12px 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tools-pref-indent {
  padding-left: 8px;
}

/* ============================================
   Notation Strip (in-flow, directly below textarea)
   ============================================ */

.notation-strip {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 44px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.notation-strip button {
  flex: 1;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: "NotationFont", monospace;
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.notation-strip button:active {
  background: var(--bg-hover);
}

/* Keyboard Popover (for long-press variants) */
.keyboard-popover {
  position: fixed;
  display: flex;
  gap: 6px;
  padding: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 200;
  animation: popup-appear 0.15s ease-out;
}

.keyboard-popover.hidden {
  display: none;
}

.keyboard-popover button {
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 20px;
  font-family: "NotationFont", monospace;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.1s,
    background-color 0.1s;
}

.keyboard-popover button:active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

/* Barline popover with two rows */
.keyboard-popover.barline-popover {
  flex-direction: column;
  gap: 8px;
}

.keyboard-popover .popover-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.keyboard-popover .popover-row-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.keyboard-popover .volta-btn {
  font-size: 14px;
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  padding: 0 12px;
}

.keyboard-popover .tala-btn {
  font-size: 18px;
  font-family: "NotationFont", monospace;
}

/* ================================================
   Unified Insert Panel (Phase 1: Mechanical Fix)
   ================================================ */

.insert-panel {
  display: flex;
  flex-direction: column;
  height: var(--keyboard-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  position: relative;
  z-index: 800; /* Contract 4.1: Panel at 800, always in flow */
  touch-action: none; /* Prevent page scroll during swipe */
}


.insert-panel.hidden {
  display: none;
}

/* Old .insert-panel-header, .mode-tab, .insert-panel-mode-tabs removed — replaced by ToolRegistry chips */

/* REMOVED: .keyboard-type-toggle — piano is now a standalone tool in the toolbelt */

/* Old collapse/close/menu/view buttons in insert-panel-header removed — header is hidden, toolbelt-bar buttons replace these */

/* Panel Content: Contains all mode keyboards */
.insert-panel-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Mode Content Areas */
.insert-mode-content {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
}

.insert-mode-content.active {
  display: flex;
}

/* Old collapsed-row, keyboard-toggle, collapsed state rules removed — ToolRegistry chips replace these */

/* ================================================
   Panel Mode Classes (Contract Section 7.4)
   ================================================

   Mode classes on .insert-panel control which content is visible:
   - mode-pitch: Show pitch keyboard (default)
   - mode-chords: Show chord entry UI
   - mode-figures: Show figured bass UI
   - mode-tabla: Show tabla bols UI
*/

/* Mode-specific content is shown via .insert-mode-content.active parent */
/* No need to hide/show based on mode class - the parent handles visibility */

/* Chords Mode Content */
.chords-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0;
}

/* Figures Mode Content */
.figures-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0;
}

/* Tabla Mode Content - inherits standard keyboard-row styling */

/* ================================================
   Figures Toolbar (Figured Bass Entry)
   ================================================ */

.figures-toolbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.figures-toolbar.hidden {
  display: none;
}

.figures-toolbar-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.figure-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "NotationFont", monospace;
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.1s;
}

.figure-btn:hover {
  background: var(--bg-hover);
}

.figure-btn:active {
  background: var(--primary-color);
  color: white;
}

.figure-btn-text {
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
}

/* Indicate figures toolbar is auto-open because on figures line */
.figures-toolbar.auto-open {
  border-left: 3px solid var(--primary-color);
}

/* ================================================
   Chords Toolbar
   ================================================ */

.chords-toolbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.chords-toolbar.hidden {
  display: none;
}

.chords-toolbar-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.chord-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "NotationFont", monospace;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chord-btn:hover {
  background: var(--bg-hover);
}

.chord-btn:active {
  background: var(--primary-color);
  color: white;
}

.chord-btn-text {
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
}

.chord-root-btn {
  font-weight: 600;
  font-size: 20px;
}

.chord-root-btn.selected {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Indicate chords toolbar is auto-open because on chords line */
.chords-toolbar.auto-open {
  border-left: 3px solid var(--primary-color);
}

/* ================================================
   Mobile Keyboard (Pitch Entry)
   ================================================ */

.mobile-keyboard-container {
  position: relative;
}

.mobile-keyboard-container.hidden {
  display: none;
}

.mobile-keyboard.hidden {
  display: none;
}

.mobile-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 8px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  touch-action: none; /* Prevent page scroll during swipe */
  flex-shrink: 0;
  height: var(--keyboard-height);
  position: relative;
  z-index: 10; /* Above mobile-bottom-bar to prevent click interception */
}

.keyboard-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}


.keyboard-pitch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* Main row: octave lock column + pitch keys */
.keyboard-main-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* Octave lock chip (horizontal segmented control: ↓ | Off | ↑) */
.octave-lock-chip {
  display: flex;
  flex-direction: row;
  align-self: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.octave-lock-seg {
  height: 40px;
  min-width: 32px;
  border: none;
  border-right: 1px solid var(--border-color);
  background: var(--bg-tertiary, #f0f0f0);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.octave-lock-seg:last-child {
  border-right: none;
}

/* Center state segment - wider to fit label */
.octave-lock-seg--state {
  min-width: 36px;
  font-size: 13px;
  padding: 0 8px;
  white-space: nowrap;
}

.octave-lock-seg:active,
.octave-lock-seg--pressed {
  transform: scale(0.95);
  background: var(--bg-secondary, #e0e0e0);
}

/* Active chip = locked state */
.octave-lock-chip--active {
  border-color: var(--primary-color, #3b82f6);
}

.octave-lock-chip--active .octave-lock-seg--state {
  background: var(--primary-color, #3b82f6);
  color: white;
}

.octave-lock-chip--active .octave-lock-seg--state:active,
.octave-lock-chip--active .octave-lock-seg--state.octave-lock-seg--pressed {
  background: var(--primary-color-dark, #2563eb);
}

/* Three-row keyboard layout */
.pitch-row button {
  flex: 1;
  min-width: 40px;
  max-width: 52px;
  min-height: 48px;
  padding: 8px 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--notation-font, "NotationFont", monospace);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.symbol-row button {
  flex: 1;
  min-width: 40px;
  max-width: 56px;
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-row button {
  flex: 1;
  min-width: 40px;
  max-width: 56px;
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary, #f0f0f0);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pitch-row button:active,
.symbol-row button:active,
.nav-row button:active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

.keyboard-key {
  min-width: 44px;
  min-height: 48px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--notation-font, "NotationFont", monospace);
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.1s ease,
    background-color 0.1s ease;
}

.keyboard-key:active,
.keyboard-key--active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

.keyboard-key--swiping {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.keyboard-key--alternate {
  background: var(--bg-tertiary, #e8e8e8);
  font-size: 16px;
}

.keyboard-key--disabled {
  opacity: 0.3;
  pointer-events: none;
}

.keyboard-key--structure {
  min-width: 36px;
  font-size: 16px;
  background: var(--bg-tertiary, #f0f0f0);
}

/* Paragraph button needs system font (pilcrow ¶ not in NotationFont) */
.keyboard-key[data-action="paragraph"] {
  font-family: system-ui, -apple-system, sans-serif;
}

/* Octave indicator (floating +1/-1 shown during swipe) */
.keyboard-octave-indicator {
  position: absolute;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  font-size: 14px;
  font-weight: 600;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 100;
}

.keyboard-octave-indicator.octave-up {
  background: var(--success-color, #22c55e);
}

.keyboard-octave-indicator.octave-down {
  background: var(--warning-color, #f59e0b);
}

/* Dev tools octave hint (shown when using Shift+Up/Down) */
.devtools-octave-hint {
  position: fixed;
  top: 10px;
  right: 10px;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  pointer-events: none;
}

/* Keyboard close button */
.keyboard-key--close {
  background: var(--bg-hover, #e5e7eb);
  color: var(--text-secondary, #6b7280);
}

/* Keyboard toggle button in notation strip */
.notation-strip .keyboard-toggle {
  background: var(--bg-hover, #f3f4f6);
  border-left: 1px solid var(--border-color, #e5e7eb);
}

/* Long-press state */
.keyboard-key--long-press {
  background: var(--primary-hover, #2563eb);
  color: white;
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* No alternates shake animation */
.keyboard-key--no-alternates {
  animation: shake 0.2s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* ================================================
   Tabla Keyboard (shown when pitch system is Tabla)
   ================================================ */

.tabla-keyboard {
  /* Uses same base styles as .mobile-keyboard */
}

.tabla-main-row,
.tabla-second-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.tabla-main-row button,
.tabla-second-row button {
  flex: 1;
  min-width: 38px;
  max-width: 52px;
  min-height: 44px;
  padding: 8px 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background-color 0.1s ease;
}

.tabla-main-row button:active,
.tabla-second-row button:active {
  background: var(--primary-color);
  color: white;
  transform: scale(0.95);
}

/* Baya (bass) buttons are visually distinct */
.tabla-second-row .baya-btn {
  background: var(--bg-tertiary, #f0f0f0);
  border-color: var(--border-color);
  font-weight: 600;
}

.tabla-second-row .baya-btn:active {
  background: var(--warning-color, #f59e0b);
  color: white;
}

/* Divider between tabla and baya buttons */
.tabla-second-row .tabla-divider {
  flex: 0 0 2px;
  width: 2px;
  height: 36px;
  align-self: center;
  background: var(--border-color);
  pointer-events: none;
}

/* Tabla nav row - combined symbols + navigation for 3-row layout */
.tabla-nav-row {
  gap: 4px;
}

.tabla-nav-row button {
  flex: 1;
  min-width: 32px;
  max-width: 48px;
}

/* ================================================
   Structure Tool Palette
   ================================================ */

.structure-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.structure-row button {
  flex: 1;
  min-width: 38px;
  max-width: 60px;
  min-height: 40px;
  padding: 6px 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background-color 0.1s ease;
}

.structure-row button:active {
  background: #94a3b8;
  color: white;
  transform: scale(0.95);
}

/* ================================================
   Alternates Popup (Long-Press Menu)
   ================================================ */

.keyboard-alternates-popup {
  position: fixed;
  display: flex;
  gap: 6px;
  padding: 10px;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  animation: popup-appear 0.15s ease-out;
}

@keyframes popup-appear {
  0% {
    opacity: 0;
    transform: scale(0.9) translateY(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.keyboard-alternate-key {
  min-width: 48px;
  min-height: 48px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  background: var(--bg-secondary, #f9fafb);
  color: var(--text-primary, #1f2937);
  font-family: var(--notation-font, "NotationFont", monospace);
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.1s ease,
    background-color 0.1s ease;
}

.keyboard-alternate-key:hover {
  background: var(--bg-hover, #f3f4f6);
}

.keyboard-alternate-key:active {
  background: var(--primary-color, #3b82f6);
  color: white;
  transform: scale(0.95);
}

/* ================================================
   System Indicator Overlay (grouped lines bar)
   ================================================ */

/* Mobile textarea wrapper - flexbox row with gutter */
.mobile-textarea-wrapper {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
}

/* Mobile textarea container - fills remaining space */
.mobile-textarea-wrapper .mobile-textarea-container {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* ================================================
   View Overlay - Full-screen/Overlay/Docked Staff View
   ================================================ */

.view-overlay {
  position: fixed;
  inset: 0;
  z-index: 900; /* Contract 4.1: View fullscreen/overlay at 900 */
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.view-overlay.view-closed {
  visibility: hidden;
}

.view-overlay.view-open {
  visibility: visible;
  pointer-events: auto;
}

/* Backdrop - only visible in overlay/fullscreen modes */
.view-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.view-overlay.view-open .view-backdrop {
  opacity: 1;
}

.view-overlay.view-docked .view-backdrop {
  display: none;
}

/* View Surface - the actual content area */
.view-surface {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  box-shadow: var(--shadow-lg);
  transition: transform 0.25s ease;
}

/* Full-screen mode (mobile < 700px) */
.view-overlay.view-fullscreen .view-surface {
  inset: 0;
  border-radius: 0;
  transform: translateY(100%);
}

.view-overlay.view-fullscreen.view-open .view-surface {
  transform: translateY(0);
}


/* Overlay mode (tablet 700-1199px) - also full-screen like mobile
   Uses doubled selector .view-overlay.view-overlay for specificity.
   This matches when element has 'view-overlay' but NOT 'view-fullscreen' or 'view-docked'.
   The doubled selector ensures this rule has lower specificity than the mode-specific rules. */
.view-overlay.view-overlay .view-surface {
  inset: 0;
  border-radius: 0;
  transform: translateY(100%);
}

.view-overlay.view-overlay.view-open .view-surface {
  transform: translateY(0);
}

/* Docked mode (desktop ≥ 1200px) */
.view-overlay.view-docked {
  position: relative;
  inset: auto;
  z-index: auto;
  pointer-events: auto;
}

.view-overlay.view-docked .view-surface {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  transform: none;
  box-shadow: none;
  border-left: 1px solid var(--border-color);
}

/* When docked view is open, grid layout from preview-tabs.css handles the 50/50 split */

/* View Header */
.view-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  flex-shrink: 0;
  min-height: 52px;
}

/* Back button (mobile full-screen) */
.view-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--primary-color);
  cursor: pointer;
  flex-shrink: 0;
}

.view-back-btn:active {
  background: var(--bg-hover);
}

/* Hide back button in docked mode */
.view-overlay.view-docked .view-back-btn {
  display: none;
}

/* View Tabs */
.view-tabs {
  display: flex;
  flex: 1;
  gap: 4px;
  padding-left: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar {
  display: none;
}

.view-tab {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.view-tab:hover {
  background: var(--bg-hover);
}

.view-tab.active {
  background: var(--primary-color);
  color: white;
}

/* View Tabs Dropdown (tiny/small viewports per LAYOUT_CONTRACT.md Section 8.4) */
.view-tabs-dropdown {
  display: none; /* Hidden by default, shown on tiny/small */
  position: relative;
  flex: 0 0 auto; /* Don't expand - size to content */
  margin-left: 8px;
  margin-right: auto; /* Push right-side buttons to the edge */
}

.view-tabs-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: var(--primary-color);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.view-tabs-dropdown-btn .dropdown-arrow {
  font-size: 12px;
  opacity: 0.8;
}

.view-tabs-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 120px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  padding: 4px;
}

.view-tabs-dropdown-menu.hidden {
  display: none;
}

.view-dropdown-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.view-dropdown-item:hover {
  background: var(--bg-hover);
}

.view-dropdown-item.active {
  background: var(--primary-light, rgba(59, 130, 246, 0.1));
  color: var(--primary-color);
  font-weight: 500;
}

.view-dropdown-item .icon {
  font-size: 14px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 8px;
}


/* Play button */
.view-play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.view-play-btn:active {
  background: var(--primary-color);
  color: white;
}

/* Header Draw button (shown only on LilyPond tab) */
.view-header-draw-btn {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: var(--primary-color);
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}

.view-header-draw-btn:not(.hidden) {
  display: flex;
}

.view-header-draw-btn:active {
  background: var(--primary-hover);
}


/* View Options Button and Popover */
.view-options-container {
  position: relative;
  display: flex;
  align-items: center;
}

.view-options-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.view-options-btn:hover {
  background: var(--bg-hover);
}

.view-options-btn:active {
  background: var(--bg-tertiary);
}

.view-options-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 200px;
  padding: 8px 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 1000;
}

.view-options-popover.hidden {
  display: none;
}

.view-options-title {
  padding: 4px 12px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.view-option-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.1s;
}

.view-option-toggle:hover {
  background: var(--bg-hover);
}

.view-option-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary-color);
}

.view-option-toggle span {
  font-size: 14px;
  color: var(--text-primary);
}

/* "← Edit" escape hatch button — always visible, prominent */
.view-edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 14px;
  border: none;
  border-radius: 14px;
  background: var(--primary-color, #3b82f6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.15s;
}

.view-edit-btn:hover {
  background: #2563eb;
}

.view-edit-btn:active {
  background: #1d4ed8;
}

/* View Content Area */
.view-content {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.view-tab-content {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 12px;
}

.view-tab-content.active {
  display: block;
}

/* Markup and Edit Markup tabs need flex layout for textarea sizing */
.view-tab-content[data-view-tab="markup"].active,
.view-tab-content[data-view-tab="edit-markup"].active {
  display: flex;
  flex-direction: column;
}

/* Staff container in view */
.view-staff-container {
  width: 100%;
  height: 100%;
  min-height: 200px;
  position: relative;
}

/* VexFlow container in view */
.view-vexflow-container {
  min-height: 100%;
}

/* Font inspector container in view */
.view-font-inspector-container {
  width: 100%;
  height: 100%;
  display: flex;
}

.view-font-inspector-container .font-inspector-container {
  width: 100%;
  height: 100%;
}

/* LilyPond container */
.view-lilypond-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}

/* Code/Markup textareas in view */
.view-tab-content .lilypond-code-textarea,
.view-tab-content .markup-code-textarea {
  width: 100%;
  height: 100%;
  min-height: 300px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
}

/* Markup tab textarea needs flex sizing */
.view-tab-content[data-view-tab="markup"] .markup-code-textarea {
  flex: 1;
  min-height: 0;
}

/* Edit markup container needs flex sizing */
.view-tab-content[data-view-tab="edit-markup"] .edit-markup-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Responsive adjustments for view tabs */
@media (max-width: 500px) {
  .view-tab {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* Hide original preview pane when view overlay is open (mobile/tablet) */
#mobile-main[data-view="open"] #preview-pane {
  display: none;
}


/* ============================================
   Container Query Rules
   Container: #mobile-app (container-name: app-layout)
   ============================================ */

/* --- Tiny viewport (<360px) --- */
@container app-layout (width < 360px) {
  #mobile-main { --menu-width: 260px; }
  #doc-title { font-size: 15px; }
  .menu-item { font-size: 15px; padding: 12px 14px; }
  #editor-pane .notation-textarea { font-size: 24px; }
  .keyboard-main-row { flex-wrap: nowrap; gap: 6px; }
  .keyboard-pitch-row { flex: 1; min-width: 0; }
  .pitch-row button { min-width: 28px; min-height: 36px; padding: 4px 2px; font-size: 16px; }
  .view-tab { padding: 6px 10px; font-size: 12px; }
}

/* Tiny + view open: hide panel, show floating button */
@container app-layout (width < 360px) {
  #mobile-main[data-view="open"] #insert-panel { display: none !important; }
  #mobile-main[data-view="open"] .insert-panel-show-btn { display: flex !important; }
}

/* Tiny + view open: editor hidden */
@container app-layout (width < 360px) {
  #mobile-main[data-view="open"] #editor-pane { display: none !important; }
}

/* Height-tiny: same as width-tiny for editor/panel visibility */
#mobile-main[data-height-tiny="true"][data-view="open"] #insert-panel { display: none !important; }
#mobile-main[data-height-tiny="true"][data-view="open"] .insert-panel-show-btn { display: flex !important; }
#mobile-main[data-height-tiny="true"][data-view="open"] #editor-pane { display: none !important; }

/* --- Small viewport (360-599px) --- */
@container app-layout (360px <= width < 600px) {
  .keyboard-key { min-width: 40px; min-height: 44px; padding: 6px 10px; font-size: 18px; }
  .keyboard-key--structure { min-width: 34px; }
  .keyboard-row, .keyboard-pitch-row { gap: 5px; }
  .keyboard-main-row { flex-wrap: nowrap; gap: 8px; }
  .keyboard-pitch-row { flex: 1; min-width: 0; }
  .pitch-row button { min-width: 32px; min-height: 40px; padding: 6px 2px; font-size: 18px; }
  .octave-lock-seg { height: 36px; min-width: 28px; font-size: 13px; }
  .octave-lock-seg--state { font-size: 12px; padding: 0 6px; }
  .view-tab { padding: 6px 10px; font-size: 12px; }
}

/* Small + view open: editor hidden */
@container app-layout (360px <= width < 600px) {
  #mobile-main[data-view="open"] #editor-pane { display: none !important; }
}

/* --- Hide in-flow preview pane below desktop (view overlay handles it) --- */
@container app-layout (width < 1024px) {
  #preview-pane { display: none !important; }
}

/* --- View tabs: dropdown on <1024, inline on >=1024 --- */
@container app-layout (width < 1024px) {
  .view-tabs { display: none; }
  .view-tabs-dropdown { display: block; }
  .view-play-btn { display: none; }
}

@container app-layout (width >= 1024px) {
  .view-header-draw-btn { display: none !important; }
}

/* --- View overlay: bottom offset for fullscreen modes --- */
@container app-layout (360px <= width < 600px) {
  #view-overlay.view-fullscreen.view-open .view-surface { bottom: 0; }
}
@container app-layout (width < 360px) {
  #view-overlay.view-fullscreen.view-open .view-surface { bottom: 0; }
}

/* --- View surface offset below desktop menu bar on medium+ --- */
@container app-layout (width >= 600px) {
  .view-overlay:not(.view-docked) .view-surface { top: 28px; }
}

/* ============================================================
 * NEW UNIFIED TOOLBAR (Phase 0+)
 * All new styles scoped to avoid affecting existing toolbar.
 * ============================================================ */

/* --- Unified Bar (single row, docked above OSK) --- */
.unified-bar {
  display: flex;
  align-items: center;
  height: 44px;
  background: var(--bg-secondary, #1e1e2e);
  border-top: 1px solid var(--border-color, #333);
  padding: 0 4px;
  gap: 2px;
  flex-shrink: 0;
  z-index: 40;
  user-select: none;
  -webkit-user-select: none;
}

.unified-bar.hidden { display: none; }

/* On mobile (< 1024px), unified bar replaces old toolbelt.
   Old toolbelt and symbols-bar hidden; unified-bar and assist-strip shown. */
@container app-layout (width < 1024px) {
  #toolbelt-bar { display: none !important; }
  #symbols-bar { display: none !important; }
  #insert-panel { display: none !important; }
  #split-resizer { display: none !important; }
  #context-bar { display: none !important; }
}

/* On desktop (>= 1024px), keep old toolbelt, hide unified-bar & assist-strip.
   Desktop adaptation happens in Phase 8. */
@container app-layout (width >= 1024px) {
  .unified-bar { display: none !important; }
  .assist-strip { display: none !important; }
  #insert-panel::before { display: none; }
}

.unified-bar-menu {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary, #aaa);
  font-size: 18px;
  cursor: pointer;
  border-radius: 8px;
}

.unified-bar-menu:active { background: var(--bg-hover, #2a2a3e); }

/* Insert button */
.unified-bar-insert {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-color, #444);
  border-radius: 17px;
  background: var(--bg-secondary, #1e1e2e);
  color: var(--text-secondary, #aaa);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms, border-color 150ms;
  flex-shrink: 0;
}
.unified-bar-insert:active { background: var(--bg-hover, #2a2a3e); }
.unified-bar-insert[data-active="true"] {
  background: var(--bg-secondary, #1e1e2e);
  border-color: var(--text-secondary, #aaa);
  color: var(--text-primary, #e0e0e0);
}
.insert-btn-icon {
  font-size: 16px;
  line-height: 1;
}
.insert-btn-label {
  font-size: 12px;
}

/* Line type pill */
.unified-bar-pill {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: none;
  color: var(--text-tertiary, #888);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms, color 150ms;
  flex-shrink: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unified-bar-pill:active { background: var(--bg-hover, #2a2a3e); }
.unified-bar-pill.locked {
  color: var(--text-secondary, #aaa);
  font-weight: 600;
  border-color: var(--border-color, #444);
  background: var(--bg-secondary, #1e1e2e);
}
.unified-bar-pill.auto {
  color: var(--text-tertiary, #888);
}
.unified-bar-pill.uncertain {
  border-color: var(--warning-color, #d4a843);
  color: var(--text-secondary, #aaa);
}

/* Tag As sheet */
.tag-as-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9998;
  opacity: 0;
  transition: opacity 200ms ease;
}
.tag-as-scrim.visible { opacity: 1; }

.tag-as-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-primary, #181825);
  border-top: 1px solid var(--border-color, #444);
  border-radius: 16px 16px 0 0;
  z-index: 9999;
  padding: 12px 0 env(safe-area-inset-bottom, 16px);
  transform: translateY(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.tag-as-sheet.visible { transform: translateY(0); }

.tag-as-header {
  padding: 8px 20px 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #e0e0e0);
}

.tag-as-divider {
  height: 1px;
  margin: 6px 16px;
  background: var(--border-color, #333);
}

.tag-as-more-header {
  padding: 6px 20px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary, #888);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag-as-options {
  display: flex;
  flex-direction: column;
}

.tag-as-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-secondary, #ccc);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.tag-as-option:active { background: var(--bg-hover, #2a2a3e); }
.tag-as-option.active {
  color: var(--text-primary, #e0e0e0);
  font-weight: 600;
}

.tag-as-radio {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.tag-as-option.active .tag-as-radio {
  color: var(--accent-color, #6366f1);
}

.tag-as-label { flex: 1; }

.tag-as-lock-icon {
  font-size: 12px;
  opacity: 0.5;
}

/* Detection section in Tag As sheet */
.tag-as-detection-section {
  padding: 8px 20px;
}
.tag-as-detection-current {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text-primary, #e0e0e0);
}
.tag-as-detection-label {
  font-weight: 600;
}
.tag-as-detection-confidence {
  font-size: 12px;
  color: var(--text-tertiary, #888);
}
.tag-as-alternatives {
  padding: 4px 0 0;
}
.tag-as-alternative-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
}
.tag-as-alternative-label {
  flex: 1;
}
.tag-as-override-btn {
  padding: 3px 10px;
  border: 1px solid var(--border-color, #444);
  border-radius: 10px;
  background: none;
  color: var(--accent-color, #6366f1);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.tag-as-override-btn:active {
  background: var(--bg-hover, #2a2a3e);
}

/* Right section: fixed width buttons */
.unified-bar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.unified-bar-right button {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary, #aaa);
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
}

.unified-bar-right button:active { background: var(--bg-hover, #2a2a3e); }
.unified-bar-kb-toggle { font-size: 18px; }

/* Attach Target pill — shown when picker is open */
.attach-target-pill {
  display: none;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  border-radius: 14px;
  background: var(--bg-tertiary, #252538);
  border: 1px solid var(--border-color, #444);
  color: var(--text-secondary, #aaa);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 150ms, background-color 150ms;
}
.attach-target-pill.visible {
  display: flex;
}
.attach-target-pill .attach-label {
  opacity: 0.7;
}
.attach-target-pill .attach-value {
  color: var(--text-primary, #e0e0e0);
  font-weight: 500;
}


/* --- Assist Strip (Row 1: symbols always visible, Row 2: nav collapsible) --- */
.assist-strip {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary, #1e1e2e);
  border-top: 1px solid var(--border-color, #333);
  flex-shrink: 0;
  z-index: 40;
  user-select: none;
  -webkit-user-select: none;
}

.assist-strip.hidden { display: none; }

/* --- Row dimensions --- */
.assist-strip-row1,
.assist-strip-row2 {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 4px 8px;
}

/* --- Row 1: left-scroll + right-fixed layout --- */
.assist-strip-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-width: 0;
  scrollbar-width: none;           /* Firefox */
}
.assist-strip-left::-webkit-scrollbar {
  display: none;                   /* Chrome/Safari */
}

.assist-strip-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: 8px;
}

/* --- Row 2: keep centered flex (only 4 arrow buttons) --- */
.assist-strip-row2 {
  justify-content: center;
  gap: 6px;
}

/* Mid-range screens (600–800px): intermediate sizes between full and narrow */
@container app-layout (width < 800px) {
  .assist-btn-backspace {
    flex: 0 0 80px !important;
    max-width: 80px !important;
  }
  .assist-btn-return {
    flex: 0 0 96px !important;
    max-width: 96px !important;
  }
  .assist-strip-row1 button,
  .assist-strip-row2 button {
    min-width: 44px;
    height: 48px;
  }
  .assist-strip-row1,
  .assist-strip-row2 {
    height: 52px;
    padding: 3px 6px;
  }
  .assist-strip-left button {
    flex: 0 0 44px;
    max-width: 44px;
  }
  .assist-overflow-btn {
    flex: 0 0 44px !important;
    max-width: 44px !important;
  }
}

/* On narrow screens (< 600px), shrink further */
@container app-layout (width < 600px) {
  .assist-btn-backspace {
    flex: 0 0 64px !important;
    max-width: 64px !important;
  }
  .assist-btn-return {
    flex: 0 0 72px !important;
    max-width: 72px !important;
  }
  .assist-strip-row1 button,
  .assist-strip-row2 button {
    min-width: 40px;
    height: 44px;
  }
  .assist-strip-row1,
  .assist-strip-row2 {
    height: 48px;
    padding: 2px 4px;
  }
  .assist-strip-left button {
    flex: 0 0 40px;
    max-width: 40px;
  }
  .assist-overflow-btn {
    flex: 0 0 40px !important;
    max-width: 40px !important;
  }
}

/* --- Base button style (all buttons in both rows) --- */
.assist-strip-row1 button,
.assist-strip-row2 button {
  flex: 0 0 auto;
  min-width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary, #252538);
  border: 1px solid var(--border-color, #333);
  border-radius: 12px;
  color: var(--text-primary, #e0e0e0);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* SVG icon sizing for all assist strip buttons */
.assist-strip-row1 button svg,
.assist-strip-row2 button svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  pointer-events: none;
}

/* --- Pressed state for ALL buttons --- */
.assist-strip-row1 button:active,
.assist-strip-row2 button:active {
  background: var(--bg-hover, #2a2a3e);
  transform: translateY(1px);
}

/* --- Left-side symbol chips: fixed width in scroll container --- */
.assist-strip-left button {
  flex: 0 0 52px;
  max-width: 52px;
  padding: 0 4px;
}

/* --- Tier A: Primary keys (Enter, Backspace) — big friendly keys --- */
.assist-btn-primary {
  height: 52px;
  font-size: 18px;
  font-weight: 700;
  background: var(--bg-tertiary, #252538);
  border: 1.5px solid var(--border-color, #444);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.assist-btn-primary:active {
  background: var(--bg-hover, #2a2a3e);
  box-shadow: 0 0 1px rgba(0,0,0,0.2);
  transform: translateY(1px);
}

/* Separate widths for keyboard proportions */
.assist-btn-backspace {
  flex: 0 0 104px !important;
  max-width: 104px !important;
}
.assist-btn-return {
  flex: 0 0 120px !important;
  max-width: 120px !important;
}

/* Primary key SVGs are larger to fill the wider buttons */
.assist-btn-primary svg {
  width: 28px;
  height: 28px;
}

/* --- Tier B: Secondary nav buttons (Row 2 arrows) --- */
.assist-btn-secondary {
  flex: 1;
  max-width: 72px !important;
  height: 52px;
  font-size: 18px;
}

/* --- Overflow button --- */
.assist-overflow-btn {
  flex: 0 0 52px !important;
  max-width: 52px !important;
  height: 52px;
  font-size: 16px;
  color: var(--text-secondary, #888) !important;
}


/* --- Picker Panels (bottom sheets) --- */
.picker-panel {
  position: fixed;
  left: 0;
  right: 0;
  /* Sit above unified-bar (44px) + assist-strip (~73px) */
  bottom: calc(var(--bottom-chrome-height, 133px) + var(--ime-bottom, 0px));
  z-index: 900; /* Above insert-panel (800) */
  background: var(--bg-secondary, #1e1e2e);
  border-top: 1px solid var(--border-color, #333);
  border-radius: 12px 12px 0 0;
  max-height: 50vh;
  overflow: hidden;
  /* GPU-composited for smooth animation */
  will-change: transform;
  transform: translateY(100%);
}

.picker-panel.hidden { display: none; }

/* Panel handle (swipe affordance) */
.picker-panel-handle {
  width: 36px;
  height: 4px;
  margin: 8px auto;
  background: var(--border-color, #555);
  border-radius: 2px;
}

.picker-panel-content {
  padding: 8px 12px 12px;
  min-height: 100px;
}

/* Picker-specific fixed heights */
#picker-chord { height: 200px; }
#picker-figure { height: 200px; }
#picker-music { height: 280px; }
#picker-more { height: 250px; }

/* --- Chord Picker (Phase 3) --- */
.chord-picker-status {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  padding: 0 4px 4px;
  height: 18px;
  line-height: 18px;
}

.chord-picker-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px;
}

.chord-picker-btn {
  flex: 1;
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary, #252538);
  border: 1px solid var(--border-color, #333);
  border-radius: 8px;
  color: var(--text-primary, #e0e0e0);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.chord-picker-btn:active { background: var(--bg-hover, #2a2a3e); }
.chord-picker-btn.selected {
  background: var(--accent-color, #3b82f6);
  color: #fff;
  border-color: var(--accent-color, #3b82f6);
}

.chord-picker-btn.disabled,
.chord-picker-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.chord-picker-mod {
  flex: 0 0 36px;
  font-size: 16px;
}

.chord-picker-sep {
  color: var(--border-color, #555);
  font-size: 20px;
  padding: 0 2px;
  flex: 0 0 auto;
}

/* --- Figure Picker (Phase 4) --- */
.figure-picker-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px;
}

.figure-picker-btn {
  flex: 1;
  min-width: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary, #252538);
  border: 1px solid var(--border-color, #333);
  border-radius: 8px;
  color: var(--text-primary, #e0e0e0);
  font-family: 'NotationFont', sans-serif;
  font-size: 24px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.figure-picker-btn:active { background: var(--bg-hover, #2a2a3e); }

.figure-picker-text {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 16px;
}

/* --- Music Keyboard Picker (Phase 5) --- */
/* --- Notes Picker (flat multi-system) --- */
.notes-picker-flat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 12px;
}

/* Octave lock row — centered chip */
.notes-picker-octave-row {
  display: flex;
  justify-content: flex-start;
  padding: 0 0 4px;
}
.notes-picker-octave-chip {
  display: inline-flex;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  overflow: hidden;
}
.notes-picker-octave-chip--active {
  border-color: var(--accent-color, #3b82f6);
}
.notes-picker-octave-seg {
  padding: 4px 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary, #888);
  font-size: 14px;
  cursor: pointer;
  min-width: 32px;
  text-align: center;
}
.notes-picker-octave-seg--state {
  border-left: 1px solid var(--border-color, #ddd);
  border-right: 1px solid var(--border-color, #ddd);
  font-weight: 600;
  min-width: 36px;
}
.notes-picker-octave-chip--active .notes-picker-octave-seg--state {
  color: var(--accent-color, #3b82f6);
}

/* System row: label + 7 pitch buttons */
.notes-picker-system-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border-radius: 8px;
  transition: background 0.15s;
}
.notes-picker-system-row.active {
  background: color-mix(in srgb, var(--accent-color, #3b82f6) 8%, transparent);
}
.notes-picker-system-label {
  width: 36px;
  flex-shrink: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary, #888);
}
.notes-picker-system-row.active .notes-picker-system-label {
  color: var(--accent-color, #3b82f6);
}
.notes-picker-pitches {
  display: flex;
  flex: 1;
  gap: 4px;
}
.notes-picker-key {
  flex: 1;
  min-height: 40px;
  min-width: 0;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #222);
  font-size: 18px;
  font-family: 'NotationFont', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.notes-picker-key:active {
  background: var(--accent-color, #3b82f6);
  color: #fff;
  border-color: var(--accent-color, #3b82f6);
}

/* Single-system mode: bigger buttons, no label column */
.notes-picker-single .notes-picker-system-row {
  gap: 0;
}
.notes-picker-single .notes-picker-key {
  min-height: 48px;
  font-size: 22px;
}
/* Multi-char solfège labels (Do, Re, Mi, Fa, Sol, La, Ti) need smaller text */
.notes-picker-single .notes-picker-system-row[data-system="8"] .notes-picker-key {
  font-size: 16px;
  letter-spacing: -0.3px;
}

/* Accidentals row (single-system mode) */
.notes-picker-accidentals-row {
  display: flex;
  gap: 6px;
  padding: 0 0 4px;
}
.notes-picker-accidental {
  height: 36px;
  min-width: 48px;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #222);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.notes-picker-accidental:active {
  background: var(--accent-color, #3b82f6);
  color: #fff;
  border-color: var(--accent-color, #3b82f6);
}

/* --- More Menu (Phase 6) --- */
.more-menu-section {
  padding: 6px 12px;
}
.more-menu-section + .more-menu-section {
  border-top: 1px solid var(--border-color, #333);
}
.more-menu-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 6px;
}
.more-menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.more-menu-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #333);
  background: var(--bg-hover, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  font-family: 'NotationFont', monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.more-menu-btn:active {
  background: var(--accent-color, #3b82f6);
  color: #fff;
}
.more-menu-baya {
  border-color: var(--accent-secondary, #f59e0b);
}
.more-menu-tala {
  font-family: 'NotationFont', sans-serif;
  font-size: 18px;
}
.more-menu-linetype-btn {
  min-width: 64px;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.more-menu-linetype-btn[data-active="true"] {
  background: var(--accent-color, #3b82f6);
  color: white;
  border-color: var(--accent-color, #3b82f6);
}
.more-menu-pin-btn {
  min-width: 36px;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  opacity: 0.5;
  transition: opacity 0.12s ease;
}
.more-menu-pin-btn[data-active="true"] {
  opacity: 1;
  background: var(--accent-color, #3b82f6);
  color: white;
  border-color: var(--accent-color, #3b82f6);
}

/* --- Palette Drawer Scrim --- */
.palette-drawer-scrim {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* Stop above unified-bar + assist-strip so Insert button stays tappable */
  bottom: calc(var(--bottom-chrome-height, 136px) + var(--ime-bottom, 0px));
  z-index: 899;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.palette-drawer-scrim.active {
  opacity: 1;
  pointer-events: auto;
}

/* --- Palette Drawer --- */
.palette-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-chrome-height, 48px) + var(--ime-bottom, 0px));
  z-index: 900;
  background: var(--bg-secondary, #1e1e2e);
  border-top: 1px solid var(--border-color, #333);
  border-radius: 12px 12px 0 0;
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  will-change: transform;
  transform: translateY(100%);
}

/* When drawer is open, shrink editor so textarea bottom is never hidden */
#editor-pane {
  transition: padding-bottom 250ms ease;
  padding-bottom: var(--drawer-inset, 0px);
}
.palette-drawer.hidden { display: none; }

.palette-drawer-handle {
  width: 48px;
  height: 5px;
  margin: 8px auto 4px;
  background: var(--text-secondary, #888);
  border-radius: 3px;
  flex-shrink: 0;
}

.palette-drawer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 8px;
  flex-shrink: 0;
}

.palette-drawer-back,
.palette-drawer-customize,
.palette-drawer-close {
  background: none;
  border: none;
  color: var(--text-secondary, #aaa);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.palette-drawer-back:hover,
.palette-drawer-customize:hover,
.palette-drawer-close:hover {
  background: var(--bg-hover, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
}

.palette-drawer-back[hidden],
.palette-drawer-customize[hidden] {
  display: none;
}

.palette-drawer-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.palette-drawer-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

/* --- Palette Search --- */
.palette-search-wrap {
  padding: 4px 12px 8px;
}
.palette-search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #333);
  background: var(--bg-primary, #1a1a2e);
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}
.palette-search-input:focus {
  border-color: var(--accent-color, #3b82f6);
}
.palette-search-input::placeholder {
  color: var(--text-secondary, #888);
}

/* --- Palette Sections --- */
.palette-section {
  padding: 4px 12px;
}
.palette-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 6px;
}

/* --- Palette Pinned/Recent Pills --- */
.palette-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.palette-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--picker-accent, var(--border-color, #333));
  background: var(--bg-hover, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
}
.palette-pill:active {
  background: var(--picker-accent, var(--accent-color, #3b82f6));
  color: #fff;
}
.palette-pill-icon {
  font-size: 16px;
}
.palette-pill-label {
  font-weight: 500;
}

/* --- Palette All Pickers List --- */
.palette-all-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.palette-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.palette-picker-row:hover {
  background: var(--bg-hover, #2a2a3e);
}
.palette-picker-row:active {
  background: var(--bg-hover, #2a2a3e);
}
.palette-row-icon {
  font-size: 18px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  color: var(--picker-accent, var(--text-secondary, #aaa));
}
.palette-row-label {
  flex: 1;
  font-weight: 500;
}
.palette-row-arrow {
  font-size: 18px;
  color: var(--text-secondary, #666);
}

.palette-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-secondary, #888);
  font-size: 13px;
}

/* --- Palette Customize Mode --- */
.palette-customize-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
}
.palette-customize-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
}
.palette-customize-done {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent-color, #3b82f6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.palette-customize-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}
.palette-customize-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-radius: 6px;
}
.palette-customize-row.hidden-picker {
  opacity: 0.4;
}
.palette-customize-handle {
  font-size: 14px;
  color: var(--text-secondary, #666);
  cursor: grab;
  padding: 0 4px;
}
.palette-customize-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
}
.palette-customize-label {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary, #e0e0e0);
}
.palette-customize-pin,
.palette-customize-vis {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-secondary, #888);
}
.palette-customize-pin[data-active="true"] {
  color: #f59e0b;
}
.palette-customize-vis:disabled {
  opacity: 0.3;
  cursor: default;
}
.palette-customize-reset {
  margin: 12px auto;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #333);
  background: none;
  color: var(--text-secondary, #aaa);
  font-size: 13px;
  cursor: pointer;
}
.palette-customize-reset:hover {
  color: var(--text-primary, #e0e0e0);
  border-color: var(--text-secondary, #aaa);
}

/* --- Shared Picker Button Styles (Tabla, Structure pickers) --- */
.picker-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #aaa);
  margin: 8px 0 6px;
  padding: 0 4px;
}
.picker-section-label:first-child {
  margin-top: 0;
}
.picker-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.picker-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #333);
  background: var(--bg-hover, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  font-family: 'NotationFont', monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.picker-btn:active {
  background: var(--accent-color, #3b82f6);
  color: #fff;
}
.picker-btn-baya {
  border-color: var(--accent-secondary, #f59e0b);
}
.picker-btn-tala {
  font-family: 'NotationFont', sans-serif;
  font-size: 18px;
}

/* --- Timed Text Picker --- */
.timed-text-picker {
  padding: 4px 0;
}
.timed-text-description {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary, #aaa);
  margin: 0 4px 8px;
}
.timed-text-examples {
  background: var(--bg-hover, #2a2a3e);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 0 4px 8px;
}
.timed-text-example {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.5;
}
.timed-text-example code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--text-primary, #e0e0e0);
  background: var(--bg-primary, #1a1a2e);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.timed-text-example-note {
  color: var(--text-secondary, #aaa);
  font-size: 12px;
}
.timed-text-convert-btn {
  display: block;
  width: calc(100% - 8px);
  margin: 12px 4px 4px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid #e11d48;
  background: rgba(225, 29, 72, 0.1);
  color: #fb7185;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.timed-text-convert-btn:active {
  background: #e11d48;
  color: #fff;
}

/* On desktop, hide the drag handle but keep the same bottom sheet layout */
@container app-layout (width >= 1024px) {
  .palette-drawer-handle { display: none; }
}

/* --- Attachment Highlight (Phase 7) --- */
/* Textarea glow when picker is open */
#editor-pane[data-picker-active="chord"] .mobile-notation-textarea {
  box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3);
}
#editor-pane[data-picker-active="figure"] .mobile-notation-textarea {
  box-shadow: inset 0 0 0 2px rgba(139, 92, 246, 0.3);
}
#editor-pane[data-picker-active="music"] .mobile-notation-textarea {
  box-shadow: inset 0 0 0 2px rgba(16, 185, 129, 0.3);
}
#editor-pane[data-picker-active] .mobile-notation-textarea {
  transition: box-shadow 150ms ease-out;
}
/* Pulse animation on insertion */
@keyframes picker-insert-pulse {
  0% { box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.6); }
  100% { box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3); }
}
@keyframes picker-insert-pulse-figure {
  0% { box-shadow: inset 0 0 0 2px rgba(139, 92, 246, 0.6); }
  100% { box-shadow: inset 0 0 0 2px rgba(139, 92, 246, 0.3); }
}
@keyframes picker-insert-pulse-music {
  0% { box-shadow: inset 0 0 0 2px rgba(16, 185, 129, 0.6); }
  100% { box-shadow: inset 0 0 0 2px rgba(16, 185, 129, 0.3); }
}
#editor-pane[data-picker-active="chord"] .mobile-notation-textarea.picker-pulse {
  animation: picker-insert-pulse 200ms ease-out;
}
#editor-pane[data-picker-active="figure"] .mobile-notation-textarea.picker-pulse {
  animation: picker-insert-pulse-figure 200ms ease-out;
}
#editor-pane[data-picker-active="music"] .mobile-notation-textarea.picker-pulse {
  animation: picker-insert-pulse-music 200ms ease-out;
}

/* --- Desktop adaptation --- */
@container app-layout (width >= 1024px) {
  /* Center picker panels with max-width and rounded corners.
     Use margin-based centering to avoid conflicting with JS inline transform. */
  .picker-panel {
    max-width: 600px;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    border-radius: 12px;
    border: 1px solid var(--border-color, #333);
  }
}
