/* ==========================================================================
   Guitar Repertoire Suite - Viewport Layout Styles & Billboard Engine
   ========================================================================== */

/* --------------------------------------------------------------------------
   Viewport Layout Switcher Container
   Supports .layout-top, .layout-bottom, .layout-split, .layout-hidden
   -------------------------------------------------------------------------- */
.viewport-container,
.repertoire-viewport,
.guitar-suite-app {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  box-sizing: border-box;
}

/* Key Slide Panel defaults */
.key-slide-panel,
.key-slide,
.slide-viewer {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-color: var(--border-color);
  border-style: solid;
  border-width: 0;
  transition: all var(--transition-normal);
  overflow: hidden;
  position: relative;
  z-index: 10;
  box-sizing: border-box;
}

/* Billboard Chord Sheet Panel defaults */
.billboard-sheet-panel,
.billboard-sheet,
.chord-sheet {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  background: var(--bg-primary);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1.5rem 3rem 1.5rem;
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Mode 1: .layout-top (Key Slide on Top, Chord Sheet below)
   -------------------------------------------------------------------------- */
.layout-top,
body.layout-top .viewport-container,
.viewport-container.layout-top {
  display: flex;
  flex-direction: column;
}

.layout-top .key-slide-panel,
.layout-top .key-slide,
body.layout-top .key-slide-panel,
.viewport-container.layout-top .key-slide-panel {
  order: 1;
  width: 100%;
  height: 38vh;
  min-height: 220px;
  max-height: 48vh;
  border-bottom-width: 2px;
  border-bottom-color: var(--border-color);
}

.layout-top .billboard-sheet-panel,
.layout-top .billboard-sheet,
body.layout-top .billboard-sheet-panel,
.viewport-container.layout-top .billboard-sheet-panel {
  order: 2;
  flex: 1 1 auto;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Mode 2: .layout-bottom (Key Slide on Bottom, Chord Sheet above)
   -------------------------------------------------------------------------- */
.layout-bottom,
body.layout-bottom .viewport-container,
.viewport-container.layout-bottom {
  display: flex;
  flex-direction: column;
}

.layout-bottom .billboard-sheet-panel,
.layout-bottom .billboard-sheet,
body.layout-bottom .billboard-sheet-panel,
.viewport-container.layout-bottom .billboard-sheet-panel {
  order: 1;
  flex: 1 1 auto;
  width: 100%;
}

.layout-bottom .key-slide-panel,
.layout-bottom .key-slide,
body.layout-bottom .key-slide-panel,
.viewport-container.layout-bottom .key-slide-panel {
  order: 2;
  width: 100%;
  height: 38vh;
  min-height: 220px;
  max-height: 48vh;
  border-top-width: 2px;
  border-top-color: var(--border-color);
}

/* --------------------------------------------------------------------------
   Mode 3: .layout-split (Side-by-Side Split View)
   -------------------------------------------------------------------------- */
.layout-split,
body.layout-split .viewport-container,
.viewport-container.layout-split {
  display: flex;
  flex-direction: row;
}

.layout-split .key-slide-panel,
.layout-split .key-slide,
body.layout-split .key-slide-panel,
.viewport-container.layout-split .key-slide-panel {
  order: 1;
  width: 42%;
  min-width: 340px;
  max-width: 50%;
  height: 100%;
  border-right-width: 2px;
  border-right-color: var(--border-color);
}

.layout-split .billboard-sheet-panel,
.layout-split .billboard-sheet,
body.layout-split .billboard-sheet-panel,
.viewport-container.layout-split .billboard-sheet-panel {
  order: 2;
  flex: 1 1 auto;
  height: 100%;
}

/* --------------------------------------------------------------------------
   Mode 4: .layout-hidden (Key Slide minimized/hidden, full-width Billboard sheet)
   -------------------------------------------------------------------------- */
.layout-hidden .key-slide-panel,
.layout-hidden .key-slide,
body.layout-hidden .key-slide-panel,
.viewport-container.layout-hidden .key-slide-panel {
  display: none !important;
  visibility: hidden;
  height: 0 !important;
  width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
}

.layout-hidden .billboard-sheet-panel,
.layout-hidden .billboard-sheet,
body.layout-hidden .billboard-sheet-panel,
.viewport-container.layout-hidden .billboard-sheet-panel {
  width: 100% !important;
  max-width: 100% !important;
  flex: 1 1 100%;
  height: 100%;
}

/* ==========================================================================
   Billboard Typography & Measure Grid
   Giant, high-contrast chord symbols legible 5-6 feet away
   ========================================================================== */

.measure-grid {
  display: grid;
  grid-template-columns: repeat(var(--measures-per-row, 4), minmax(0, 1fr));
  gap: 0.75rem 0.5rem;
  width: 100%;
  margin: 1.5rem 0;
  box-sizing: border-box;
}

.measure-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.measure,
.measure-box {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 120px;
  padding: 1.5rem 1rem 1rem 1rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast), transform var(--transition-fast);
  box-sizing: border-box;
  flex: 1 1 0;
}

/* Clear bar lines '|' styling */
.measure::after,
.measure-box::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: -1px;
  width: 3px;
  background-color: var(--border-color);
  border-radius: var(--radius-xs);
}

.bar-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--border-focus);
  font-family: var(--font-family-mono);
  font-size: 2.5rem;
  font-weight: 800;
  user-select: none;
  padding: 0 0.5rem;
}

.measure.double-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: -5px;
  width: 3px;
  background-color: var(--border-focus);
  box-shadow: -4px 0 0 var(--border-focus);
}

/* Measure Number Badges */
.measure-number,
.measure-badge {
  position: absolute;
  top: 6px;
  left: 8px;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--text-muted);
  background-color: var(--bg-underground);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color);
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

/* Giant Billboard Chord Symbols (Legible 5-6 feet away) */
.chord-symbol,
.chord,
.measure-chord {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-chord);
  font-weight: 800;
  line-height: 1.05;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  text-align: center;
  text-rendering: optimizeLegibility;
  user-select: none;
  word-break: break-all;
}

/* Subtitle Lyrics Styling: clean legible phrases directly under chords without brackets */
.subtitle-lyrics,
.lyrics-line,
.lyrics-phrase,
.lyrics {
  font-family: var(--font-family-sans);
  font-size: var(--font-size-lyrics);
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 0.5rem;
  white-space: normal;
  word-break: break-word;
  max-width: 95%;
}

/* Beat pulse indicators: subtle animated glow/border when a beat fires */
.beat-pulse,
.measure.beat-active,
.measure-box.beat-active,
.is-active-beat {
  animation: beatGlow 400ms cubic-bezier(0, 0, 0.2, 1);
  border-color: var(--accent-pulse) !important;
}

@keyframes beatGlow {
  0% {
    box-shadow: 0 0 0 2px var(--border-focus), 0 0 24px var(--accent-pulse);
    border-color: var(--accent-pulse);
    background-color: var(--beat-active-bg);
    transform: scale(1.015);
  }
  50% {
    box-shadow: 0 0 0 1px var(--accent-pulse), 0 0 14px var(--accent-pulse);
  }
  100% {
    box-shadow: none;
    border-color: var(--border-color);
    background-color: var(--bg-surface);
    transform: scale(1);
  }
}

.measure.current-measure,
.measure.active-measure {
  border-color: var(--border-focus);
  background-color: var(--bg-surface);
  box-shadow: 0 0 12px var(--beat-active-bg);
}

/* Metronome ball & trail visuals */
.ball-metronome {
  position: relative;
  width: 100%;
  height: 24px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.ball-metronome .bouncing-ball {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background-color: var(--ball-color);
  box-shadow: 0 0 12px var(--ball-color);
  position: absolute;
  top: 5px;
  left: 0;
  transition: transform var(--transition-fast);
}

.ball-metronome .ball-trail {
  height: 2px;
  width: 100%;
  position: absolute;
  top: 11px;
  background: linear-gradient(90deg, transparent, var(--trail-color), transparent);
}

/* ==========================================================================
   Mobile Optimization (Samsung Galaxy S23 Ultra & Screens < 768px)
   ========================================================================== */

/* Touch-friendly tap targets (min 48px) */
button,
.btn,
.tap-target,
.control-btn,
.layout-btn,
.theme-btn,
select,
input,
.tab-item {
  min-height: 48px;
  min-width: 48px;
  padding: 12px 16px;
  touch-action: manipulation;
  cursor: pointer;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  :root {
    --font-size-chord: clamp(2.2rem, 9vw, 3.2rem);
    --font-size-lyrics: clamp(0.95rem, 3.8vw, 1.15rem);
  }

  /* Responsive split layout stacking on mobile */
  .layout-split,
  body.layout-split .viewport-container,
  .viewport-container.layout-split {
    flex-direction: column;
  }

  .layout-split .key-slide-panel,
  .layout-split .key-slide,
  body.layout-split .key-slide-panel,
  .viewport-container.layout-split .key-slide-panel {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    height: 32vh;
    border-right-width: 0;
    border-bottom-width: 2px;
  }

  .layout-split .billboard-sheet-panel,
  .layout-split .billboard-sheet,
  body.layout-split .billboard-sheet-panel,
  .viewport-container.layout-split .billboard-sheet-panel {
    width: 100%;
    height: calc(100% - 32vh);
  }

  /* Measure grid responsiveness */
  .measure-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 1rem 0;
  }

  .measure,
  .measure-box {
    min-height: 95px;
    padding: 1.25rem 0.5rem 0.75rem 0.5rem;
  }

  .billboard-sheet-panel,
  .billboard-sheet,
  .chord-sheet {
    padding: 0.75rem 0.75rem 2.5rem 0.75rem;
  }

  /* Compact top/bottom slide heights for S23 Ultra in portrait */
  .layout-top .key-slide-panel,
  body.layout-top .key-slide-panel,
  .viewport-container.layout-top .key-slide-panel,
  .layout-bottom .key-slide-panel,
  body.layout-bottom .key-slide-panel,
  .viewport-container.layout-bottom .key-slide-panel {
    height: 30vh;
    min-height: 180px;
  }
}

/* Extra breakpoint for single-column measures on very narrow mobile screens */
@media (max-width: 420px) {
  .measure-grid.single-column-sm {
    grid-template-columns: 1fr;
  }
}
