/* ==========================================================================
   Intervals — Sleek Tactile Visual Instrument for iPad & Phone
   ========================================================================== */

:root {
  --bg-base: #06070b;
  --bg-elevated: rgba(18, 20, 28, 0.72);
  --surface-glass: rgba(255, 255, 255, 0.045);
  --surface-glass-hover: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text-primary: rgba(255, 255, 255, 0.94);
  --text-secondary: rgba(255, 255, 255, 0.54);
  --text-muted: rgba(255, 255, 255, 0.34);

  /* Active mode theme variables (dynamically updated by JS) */
  --accent: #f5a623;
  --accent-soft: #ffd27d;
  --accent-deep: #c85a17;
  --glow-rgb: 245, 166, 35;
  --secondary-rgb: 220, 94, 46;
  --bg-tint: rgba(245, 150, 35, 0.11);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --radius-bar: clamp(14px, 2.2vw, 26px);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* ==========================================================================
   Ambient Background Layer
   ========================================================================== */

.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  background:
    radial-gradient(65% 55% at 15% 8%, rgba(var(--glow-rgb), 0.14) 0%, transparent 72%),
    radial-gradient(60% 55% at 88% 92%, rgba(var(--secondary-rgb), 0.13) 0%, transparent 72%),
    radial-gradient(120% 85% at 50% 100%, rgba(var(--glow-rgb), 0.11) 0%, rgba(var(--secondary-rgb), 0.03) 42%, #06070b 82%);
  transition: background 0.6s ease;
}

.ambient-orb {
  display: none;
}

.ambient-grain {
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: radial-gradient(rgba(255, 255, 255, 0.8) 0.5px, transparent 0.5px);
  background-size: 24px 24px;
}

/* ==========================================================================
   Main App Shell
   ========================================================================== */

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding-top: max(14px, var(--safe-top));
  padding-right: max(16px, var(--safe-right));
  padding-bottom: max(8px, var(--safe-bottom));
  padding-left: max(16px, var(--safe-left));
  gap: 10px;
}

/* Discreet copyright & commit hash/date footer */
.app-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  font-size: 10.5px;
  line-height: 1.25;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  padding-top: 2px;
  text-align: center;
}

.footer-build {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.footer-hash {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.36);
}

.footer-sep {
  opacity: 0.5;
}

.footer-date {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Top Floating Control Bar
   ========================================================================== */

.top-bar {
  display: grid;
  grid-template-columns: minmax(140px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  z-index: 20;
}

/* Brand & Mode Subtitle */
.brand-cluster {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(var(--glow-rgb), 0.9);
  transition: background 0.5s ease, box-shadow 0.5s ease;
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.1;
}

.mode-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-hebrew {
  font-size: 13px;
  color: var(--accent-soft);
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: color 0.5s ease;
}

.meta-sep {
  opacity: 0.35;
}

.mode-alias {
  color: var(--text-secondary);
  font-weight: 400;
}

/* 4-Mode Segmented Control */
.mode-segmented {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  justify-self: center;
  width: 100%;
  max-width: 780px;
  padding: 4px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 8px 24px rgba(0, 0, 0, 0.28);
}

.mode-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  height: calc(100% - 8px);
  border-radius: 18px;
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.24) 0%,
    rgba(var(--glow-rgb), 0.12) 100%
  );
  border: 1px solid rgba(var(--glow-rgb), 0.42);
  box-shadow: 0 0 22px rgba(var(--glow-rgb), 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition:
    transform 0.42s var(--ease-spring),
    width 0.42s var(--ease-spring),
    background 0.5s ease,
    border-color 0.5s ease,
    box-shadow 0.5s ease;
  pointer-events: none;
  z-index: 0;
}

.mode-btn {
  position: relative;
  z-index: 1;
  appearance: none;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
  padding: 6px 8px;
  border-radius: 18px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: color 0.28s ease;
}

.mode-btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-btn-hebrew {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.4);
  transition: color 0.3s ease;
}

.mode-btn-alias {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.28);
  transition: color 0.3s ease;
}

.mode-btn:hover {
  color: rgba(255, 255, 255, 0.84);
}

.mode-btn:hover .mode-btn-hebrew {
  color: rgba(255, 255, 255, 0.6);
}

.mode-btn:hover .mode-btn-alias {
  color: rgba(255, 255, 255, 0.46);
}

.mode-btn.is-active {
  color: #ffffff;
  font-weight: 600;
}

.mode-btn.is-active .mode-btn-hebrew {
  color: var(--accent-soft);
  font-weight: 500;
}

.mode-btn.is-active .mode-btn-alias {
  color: rgba(255, 255, 255, 0.66);
}

/* Right Controls (Key & Sound Pills) */
.controls-cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.control-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 20px rgba(0, 0, 0, 0.24);
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    transform 0.18s ease,
    box-shadow 0.25s ease;
}

.control-pill:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--border-strong);
}

.control-pill:active {
  transform: scale(0.96);
}

.control-pill.is-open {
  background: rgba(var(--glow-rgb), 0.16);
  border-color: rgba(var(--glow-rgb), 0.45);
  box-shadow: 0 0 22px rgba(var(--glow-rgb), 0.2);
}

.pill-kicker {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.pill-value {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 16px;
  text-align: center;
}

.key-pill .pill-value {
  color: var(--accent-soft);
  font-size: 15px;
  letter-spacing: -0.02em;
  transition: color 0.4s ease;
}

.pill-chevron {
  width: 12px;
  height: 12px;
  color: var(--text-secondary);
  transition: transform 0.25s var(--ease-spring);
}

.control-pill.is-open .pill-chevron {
  transform: rotate(180deg);
}

.pill-icon {
  width: 16px;
  height: 16px;
  color: var(--accent-soft);
  transition: color 0.4s ease;
}

.drone-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--glow-rgb), 0.95);
  display: none;
  animation: dronePulse 2.4s ease-in-out infinite;
}

.sound-pill.has-drone .drone-indicator {
  display: inline-block;
}

.sound-pill.has-drone {
  border-color: rgba(var(--glow-rgb), 0.36);
}

/* Desktop-only Sweep (hover-to-play) toggle pill */
.sweep-pill {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .sweep-pill {
    display: inline-flex;
  }
}

.sweep-pill .sweep-icon {
  color: var(--text-secondary);
  transition: color 0.25s ease;
}

.sweep-pill .sweep-label {
  font-size: 13px;
  color: var(--text-secondary);
  transition: color 0.25s ease;
}

.sweep-pill.is-active {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.24) 0%,
    rgba(var(--glow-rgb), 0.12) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.55);
  box-shadow: 0 0 22px rgba(var(--glow-rgb), 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.sweep-pill.is-active .sweep-icon,
.sweep-pill.is-active .sweep-label {
  color: #ffffff;
}

/* Circular Hold-to-Sing Mic Pill */
.mic-pill {
  width: 40px;
  padding: 0;
  justify-content: center;
  touch-action: none;
}

.mic-pill .mic-icon {
  color: var(--text-secondary);
  transition: color 0.25s ease;
}

.mic-pill:hover .mic-icon {
  color: var(--text-primary);
}

.mic-pill.is-listening {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.3) 0%,
    rgba(var(--glow-rgb), 0.14) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.72);
  box-shadow: 0 0 24px rgba(var(--glow-rgb), 0.38);
}

.mic-pill.is-listening .mic-icon {
  color: #ffffff;
}

@keyframes dronePulse {
  0%, 100% { opacity: 0.45; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ==========================================================================
   3-Octave (24-Bar) Interactive Playing Stage
   ========================================================================== */

.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
}

.bars-stage {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 1.4vw, 18px);
  width: 100%;
  height: 100%;
  padding: 4px 0 2px;
  touch-action: none;
}

.octave-group {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 8px;
  transition: opacity 0.28s ease;
}

.octave-group.is-mid {
  flex: 1.08 1 0%;
  height: 100%;
}

.octave-group.is-wing {
  flex: 0.62 1 0%;
  height: 88%;
  align-self: center;
  opacity: 0.84;
}

.octave-group.is-wing:hover,
.octave-group.is-wing.is-mod-armed,
.octave-group.is-wing.has-active {
  opacity: 1;
}

.octave-group-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 18px;
  flex-shrink: 0;
  pointer-events: none;
}

.octave-tag {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color 0.22s ease, text-shadow 0.22s ease;
}

.octave-group.is-mid .octave-tag {
  color: rgba(var(--glow-rgb), 0.72);
}

.octave-mod-key {
  display: none;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.045);
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .octave-mod-key {
    display: inline-block;
  }
}

.octave-group.is-mod-armed .octave-tag {
  color: #ffffff;
  text-shadow: 0 0 12px rgba(var(--glow-rgb), 0.85);
}

.octave-group.is-mod-armed .octave-mod-key {
  background: rgba(var(--glow-rgb), 0.28);
  border-color: rgba(var(--glow-rgb), 0.72);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(var(--glow-rgb), 0.35);
}

.octave-bars {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(5px, 0.9vw, 12px);
}

.octave-group.is-wing .octave-bars {
  gap: clamp(3px, 0.5vw, 7px);
}

.octave-group.is-mod-armed .note-bar:not(.is-active) {
  border-color: rgba(var(--glow-rgb), 0.34);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 0 18px rgba(var(--glow-rgb), 0.11);
}

/* Wing bar sizing (sleek, slightly smaller flanking octaves) */
.octave-group.is-wing .note-bar {
  border-radius: clamp(9px, 1.35vw, 18px);
}

.octave-group.is-wing .bar-filament {
  top: 16px;
  bottom: 70px;
}

.octave-group.is-wing .bar-top-badge {
  top: 11px;
}

.octave-group.is-wing .badge-pip {
  width: 4.5px;
  height: 4.5px;
}

.octave-group.is-wing .bar-footer {
  padding: 0 2px clamp(10px, 1.8vh, 18px);
  gap: 3px;
}

.octave-group.is-wing .bar-number {
  font-size: clamp(14px, 1.9vw, 24px);
  color: rgba(255, 255, 255, 0.74);
}

.octave-group.is-wing .note-bar.is-root .bar-number {
  color: var(--accent-soft);
}

.octave-group.is-wing .bar-note {
  font-size: clamp(9px, 0.92vw, 11.5px);
  color: var(--text-muted);
}

/* Subtle vertical separator hairlines flanking the center octave */
.octave-divider {
  width: 1px;
  align-self: center;
  height: 62%;
  flex-shrink: 0;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 255, 255, 0.12) 25%,
    rgba(var(--glow-rgb), 0.28) 50%,
    rgba(255, 255, 255, 0.12) 75%,
    transparent 100%
  );
  pointer-events: none;
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* Individual Vertical Bar — Sculpted Luminous Monolith (NOT a piano!) */
.note-bar {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  border-radius: var(--radius-bar);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.055) 0%,
    rgba(255, 255, 255, 0.024) 48%,
    rgba(255, 255, 255, 0.042) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.11),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35),
    0 12px 32px rgba(0, 0, 0, 0.32);
  overflow: hidden;
  cursor: pointer;
  transition:
    border-color 0.22s ease,
    box-shadow 0.26s ease,
    transform 0.24s var(--ease-spring),
    background 0.3s ease;
  --touch-y: 0.5;
  --hover-y: 0.5;
  --wiggle: 0;
  --pitch-h: 25%;
}

/* Desktop hover magnetic glow & cursor-height whisper line */
.bar-hover-line {
  position: absolute;
  left: 16%;
  right: 16%;
  height: 1.5px;
  bottom: calc(var(--hover-y) * 100%);
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(var(--glow-rgb), 0.72) 50%,
    transparent 100%
  );
  opacity: 0;
  pointer-events: none;
  transform: translateY(50%);
  transition: opacity 0.18s ease;
}

.note-bar.is-hovered:not(.is-active) {
  border-color: rgba(var(--glow-rgb), 0.36);
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.11) 0%,
    rgba(255, 255, 255, 0.036) 50%,
    rgba(var(--glow-rgb), 0.08) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 0 24px rgba(var(--glow-rgb), 0.14);
  transform: translateY(-1px);
}

.note-bar.is-hovered:not(.is-active) .bar-hover-line {
  opacity: 0.85;
}

.note-bar.is-hovered:not(.is-active) .bar-filament {
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 255, 255, 0.24) 25%,
    rgba(var(--glow-rgb), 0.48) 55%,
    rgba(255, 255, 255, 0.12) 85%,
    transparent 100%
  );
}

.note-bar.is-hovered:not(.is-active) .bar-number {
  color: #ffffff;
}

.note-bar.is-hovered:not(.is-active) .bar-note {
  color: rgba(255, 255, 255, 0.85);
}

/* Latched / sustained chord bar indicator (Shift+Click or Right-Click on desktop) */
.note-bar.is-latched .bar-top-badge::after {
  content: '';
  position: absolute;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1.5px solid rgba(var(--glow-rgb), 0.9);
  box-shadow: 0 0 12px rgba(var(--glow-rgb), 0.75);
  animation: latchRing 2.2s ease-in-out infinite;
}

@keyframes latchRing {
  0%, 100% { transform: scale(0.9); opacity: 0.65; }
  50% { transform: scale(1.15); opacity: 1; }
}

/* Subtle architectural accent on Root (1) and Octave (8) bars */
.note-bar.is-root {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.095) 0%,
    rgba(255, 255, 255, 0.03) 50%,
    rgba(var(--glow-rgb), 0.07) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.2);
}

/* Subtle modal character glow on signature degrees (e.g. ♭2 & 3 in Ahava Raba) */
.note-bar.is-signature {
  border-color: rgba(var(--glow-rgb), 0.16);
}

/* Pitch-proportional ambient contour inside each bar (gives subtle harmonic silhouette) */
.bar-contour {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pitch-h);
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.11) 0%,
    rgba(var(--glow-rgb), 0.025) 65%,
    transparent 100%
  );
  border-top: 1px solid rgba(var(--glow-rgb), 0.16);
  pointer-events: none;
  transition: height 0.65s var(--ease-spring), opacity 0.35s ease, background 0.6s ease;
  opacity: 0.72;
}

.note-bar.is-active .bar-contour {
  opacity: 0.2;
}

/* Center vertical luminous filament */
.bar-filament {
  position: absolute;
  top: 22px;
  bottom: 102px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 255, 255, 0.09) 20%,
    rgba(var(--glow-rgb), 0.22) 55%,
    rgba(255, 255, 255, 0.06) 85%,
    transparent 100%
  );
  pointer-events: none;
  transition: opacity 0.25s ease, width 0.25s ease, background 0.35s ease, box-shadow 0.25s ease;
}

/* Liquid-light active column responding to Y-axis touch position */
.bar-energy {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transform-origin: bottom center;
  transform: scaleY(var(--touch-y));
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.85) 0%,
    rgba(var(--glow-rgb), 0.36) 22%,
    rgba(var(--secondary-rgb), 0.22) 68%,
    rgba(var(--glow-rgb), 0.12) 100%
  );
  transition: opacity 0.26s ease;
}

/* Luminous meniscus line following finger Y inside active bar */
.bar-meniscus {
  position: absolute;
  left: 10%;
  right: 10%;
  height: 3px;
  bottom: calc(var(--touch-y) * 100%);
  border-radius: 999px;
  background: #ffffff;
  box-shadow:
    0 0 14px 3px rgba(var(--glow-rgb), 0.95),
    0 0 36px 8px rgba(var(--glow-rgb), 0.55);
  opacity: 0;
  transform: translateY(50%) scaleX(0.6);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.22s var(--ease-spring);
}

/* Soft top specular aura when active */
.bar-halo {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    90% 45% at 50% 0%,
    rgba(var(--glow-rgb), 0.32) 0%,
    transparent 75%
  );
  transition: opacity 0.3s ease;
}

/* Active state when touched or swiped */
.note-bar.is-active {
  border-color: rgba(var(--glow-rgb), 0.72);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 0 32px rgba(var(--glow-rgb), 0.36),
    0 0 68px rgba(var(--glow-rgb), 0.16);
  transform: scaleX(1.015) translateY(-2px);
  z-index: 2;
}

.note-bar.is-active .bar-energy {
  opacity: 1;
  transition: opacity 0.06s linear;
}

.note-bar.is-active .bar-meniscus {
  opacity: 1;
  transform: translateY(50%) scaleX(1);
}

.note-bar.is-active .bar-halo {
  opacity: 1;
}

.note-bar.is-active .bar-filament {
  width: 2.5px;
  transform: translateX(calc(-50% + var(--wiggle) * 7px));
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 255, 255, 0.7) 30%,
    rgba(var(--glow-rgb), 0.95) 60%,
    transparent 100%
  );
  box-shadow: 0 0 12px rgba(var(--glow-rgb), 0.85);
}

/* Spatial light spill on immediate neighbor bars */
.note-bar.is-spill {
  border-color: rgba(var(--glow-rgb), 0.26);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 0 22px rgba(var(--glow-rgb), 0.12);
}

/* Top jewel indicator for root & signature modal intervals */
.bar-top-badge {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.badge-pip {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  transition: background 0.35s ease, transform 0.25s ease, box-shadow 0.35s ease;
}

.note-bar.is-root .badge-pip {
  width: 7px;
  height: 7px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--glow-rgb), 0.8);
}

.note-bar.is-signature .badge-pip {
  width: 6px;
  height: 6px;
  background: transparent;
  border: 1.5px solid var(--accent-soft);
  box-shadow: 0 0 8px rgba(var(--glow-rgb), 0.55);
}

.note-bar.is-active .badge-pip {
  background: #ffffff;
  border-color: #ffffff;
  transform: scale(1.35);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.95);
}

/* Bottom Hero Number (1–8) & Smaller Note Name Underneath */
.bar-footer {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 0 4px clamp(16px, 2.6vh, 28px);
  pointer-events: none;
}

.bar-number {
  font-size: clamp(26px, 3.6vw, 44px);
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.86);
  line-height: 0.95;
  transition: color 0.2s ease, transform 0.25s var(--ease-spring), text-shadow 0.25s ease;
}

.note-bar.is-root .bar-number {
  color: var(--accent-soft);
}

.note-bar.is-active .bar-number {
  color: #ffffff;
  transform: translateY(-4px) scale(1.08);
  text-shadow: 0 0 22px rgba(var(--glow-rgb), 0.95);
}

.bar-note {
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  line-height: 1.1;
  transition: color 0.22s ease, transform 0.25s var(--ease-spring);
}

.note-bar.is-signature .bar-note {
  color: rgba(var(--glow-rgb), 0.86);
}

.note-bar.is-active .bar-note {
  color: rgba(255, 255, 255, 0.94);
  transform: translateY(-2px);
}

/* Subtle Augmented 2nd Interval Marker (floating gracefully in the gutter) */
.aug-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
  opacity: 0.85;
  transition: left 0.5s var(--ease-spring), opacity 0.4s ease;
}

.aug-marker-line {
  width: 1.5px;
  height: 32px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(var(--glow-rgb), 0.85),
    transparent
  );
  box-shadow: 0 0 10px rgba(var(--glow-rgb), 0.65);
}

.aug-marker-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-soft);
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid rgba(var(--glow-rgb), 0.4);
  border-radius: 999px;
  padding: 2px 5px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Subtle initial gesture whisper */
.gesture-hint {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  pointer-events: none;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  transition: opacity 0.55s ease, transform 0.55s var(--ease-spring);
}

.gesture-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, -58%) scale(0.96);
}

.hint-line {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: rgba(255, 255, 255, 0.78);
  white-space: nowrap;
}

/* ==========================================================================
   Floating Voice-to-Key Tuner HUD
   ========================================================================== */

.voice-hud {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translate(-50%, -10px) scale(0.96);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(340px, calc(100% - 28px));
  padding: 12px 14px 12px 12px;
  border-radius: 20px;
  background: rgba(14, 16, 24, 0.9);
  border: 1px solid rgba(var(--glow-rgb), 0.42);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.6),
    0 0 32px rgba(var(--glow-rgb), 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.28s var(--ease-spring), border-color 0.25s ease;
  --voice-level: 0;
}

.voice-hud.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
}

.voice-hud.is-locked {
  border-color: rgba(var(--glow-rgb), 0.88);
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.6),
    0 0 42px rgba(var(--glow-rgb), 0.42);
}

.voice-hud-ring {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--glow-rgb), 0.16);
  border: 1px solid rgba(var(--glow-rgb), 0.48);
  color: var(--accent-soft);
  box-shadow: 0 0 calc(8px + var(--voice-level) * 24px) rgba(var(--glow-rgb), calc(0.22 + var(--voice-level) * 0.55));
  transform: scale(calc(1 + var(--voice-level) * 0.1));
  transition: transform 0.08s linear, background 0.25s ease;
}

.voice-hud-ring svg {
  width: 18px;
  height: 18px;
}

.voice-hud.is-locked .voice-hud-ring {
  background: rgba(var(--glow-rgb), 0.35);
  color: #ffffff;
}

.voice-hud-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.voice-hud-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.voice-hud-note {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-hud-cents {
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent-soft);
  flex-shrink: 0;
}

.voice-hud-meter {
  position: relative;
  width: 100%;
  height: 10px;
  display: flex;
  align-items: center;
}

.voice-hud-meter::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.voice-meter-center {
  position: absolute;
  left: 50%;
  width: 2px;
  height: 8px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.32);
}

.voice-meter-needle {
  position: absolute;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: var(--accent-soft);
  box-shadow: 0 0 10px rgba(var(--glow-rgb), 0.9);
  opacity: 0;
  transition: left 0.08s linear, opacity 0.16s ease, background 0.15s ease, transform 0.15s ease;
}

.voice-meter-needle.is-active {
  opacity: 1;
}

.voice-meter-needle.is-in-tune {
  background: #ffffff;
  transform: translateX(-50%) scale(1.2);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.95), 0 0 24px rgba(var(--glow-rgb), 0.8);
}

.voice-hud-sub {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hold-to-Sing CTA button inside Key & Register popover */
.sing-action-btn {
  appearance: none;
  touch-action: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  margin-bottom: 12px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(var(--glow-rgb), 0.36);
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.18) 0%,
    rgba(var(--glow-rgb), 0.08) 100%
  );
  color: #ffffff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.16s ease, box-shadow 0.22s ease;
}

.sing-action-btn:hover {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.28) 0%,
    rgba(var(--glow-rgb), 0.14) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.6);
  box-shadow: 0 0 20px rgba(var(--glow-rgb), 0.2);
}

.sing-action-btn:active {
  transform: scale(0.97);
}

.sing-action-icon {
  width: 16px;
  height: 16px;
  color: var(--accent-soft);
}

/* ==========================================================================
   Floating Glass Popovers (Key Picker & Sound Settings)
   ========================================================================== */

.popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 4, 8, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.popover-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.glass-popover {
  position: fixed;
  top: calc(max(14px, var(--safe-top)) + 56px);
  right: max(16px, var(--safe-right));
  z-index: 50;
  width: min(360px, calc(100vw - 32px));
  padding: 20px;
  border-radius: 24px;
  background: rgba(16, 18, 26, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(34px) saturate(140%);
  -webkit-backdrop-filter: blur(34px) saturate(140%);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px) scale(0.97);
  transition: opacity 0.24s ease, transform 0.3s var(--ease-spring);
}

.glass-popover.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.popover-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.popover-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.popover-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.popover-close {
  appearance: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.popover-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.popover-close svg {
  width: 13px;
  height: 13px;
}

/* 12-Key Chromatic Tactile Grid */
.key-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.key-cell {
  appearance: none;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.16s ease,
    box-shadow 0.22s ease;
}

.key-cell:hover {
  background: rgba(255, 255, 255, 0.1);
}

.key-cell:active {
  transform: scale(0.94);
}

.key-cell.is-active {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.3) 0%,
    rgba(var(--glow-rgb), 0.16) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.65);
  color: #ffffff;
  box-shadow: 0 0 20px rgba(var(--glow-rgb), 0.28);
}

.popover-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 16px 0;
}

/* Octave / Register Control */
.octave-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.octave-segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.oct-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.oct-btn.is-active {
  background: rgba(var(--glow-rgb), 0.24);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(var(--glow-rgb), 0.45);
}

/* Voice Grid */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.voice-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 12px 14px;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-primary);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.16s ease;
}

.voice-card:hover {
  background: rgba(255, 255, 255, 0.085);
}

.voice-card:active {
  transform: scale(0.97);
}

.voice-card.is-active {
  background: linear-gradient(
    180deg,
    rgba(var(--glow-rgb), 0.24) 0%,
    rgba(var(--glow-rgb), 0.11) 100%
  );
  border-color: rgba(var(--glow-rgb), 0.6);
  box-shadow: 0 0 18px rgba(var(--glow-rgb), 0.2);
}

.voice-card-name {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}

.voice-card-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
}

/* Toggle Switches */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.toggle-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 27px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: background 0.26s ease, border-color 0.26s ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.28s var(--ease-spring);
}

.switch-input:checked + .switch-track {
  background: rgba(var(--glow-rgb), 0.78);
  border-color: rgba(var(--glow-rgb), 0.9);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(19px);
}

/* Desktop keyboard shortcuts footer inside Sound popover */
.desktop-tips {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .desktop-tips {
    display: block;
  }
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.tips-grid kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ==========================================================================
   Responsive Adaptation — iPad Portrait & iPhone Portrait / Landscape
   ========================================================================== */

/* Tablet Portrait & Medium Widths */
@media (max-width: 900px) {
  .top-bar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    row-gap: 10px;
  }

  .brand-cluster {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  .controls-cluster {
    grid-column: 2 / 3;
    grid-row: 1;
  }

  .mode-segmented {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
  }

  .glass-popover {
    top: calc(max(14px, var(--safe-top)) + 52px);
  }
}

/* iPhone Portrait & Compact Phones */
@media (max-width: 540px) {
  .app-shell {
    padding-top: max(10px, var(--safe-top));
    padding-right: max(10px, var(--safe-right));
    padding-bottom: max(12px, var(--safe-bottom));
    padding-left: max(10px, var(--safe-left));
    gap: 10px;
  }

  .brand-title {
    font-size: 15px;
  }

  .mode-meta {
    font-size: 11px;
  }

  .control-pill {
    height: 36px;
    padding: 0 11px;
    gap: 5px;
    font-size: 12.5px;
  }

  .mic-pill {
    width: 36px;
    padding: 0;
  }

  .sound-label {
    display: none;
  }

  .mode-segmented {
    grid-template-columns: 0.9fr 1.05fr 1.08fr 1.05fr;
  }

  .mode-btn {
    font-size: 10.5px;
    letter-spacing: -0.02em;
    padding: 5px 3px;
  }

  .mode-btn-hebrew {
    font-size: 9.5px;
  }

  .mode-btn-alias {
    font-size: 8.5px;
  }

  .bars-stage {
    gap: 5px;
  }

  .octave-group.is-mid {
    flex: 1.15 1 0%;
  }

  .octave-group.is-wing {
    flex: 0.54 1 0%;
    height: 86%;
  }

  .octave-group-head {
    height: 14px;
  }

  .octave-tag {
    font-size: 9px;
  }

  .octave-bars {
    gap: 3px;
  }

  .octave-group.is-wing .octave-bars {
    gap: 2px;
  }

  .note-bar {
    border-radius: 10px;
  }

  .octave-group.is-wing .note-bar {
    border-radius: 6px;
  }

  .bar-footer {
    padding-bottom: 11px;
    gap: 2px;
  }

  .bar-number {
    font-size: 16px;
  }

  .bar-note {
    font-size: 9.5px;
  }

  .octave-group.is-wing .bar-number {
    font-size: 10px;
  }

  .octave-group.is-wing .bar-note {
    display: none;
  }

  .octave-divider {
    display: none;
  }

  .aug-marker-tag {
    display: none;
  }

  .hint-line {
    font-size: 11.5px;
    white-space: normal;
    text-align: center;
  }

  .gesture-hint {
    width: calc(100% - 36px);
    max-width: 310px;
  }

  /* Bottom-sheet presentation on phones for effortless thumb reach */
  .glass-popover {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: max(12px, var(--safe-bottom));
    width: auto;
    transform: translateY(18px) scale(0.98);
  }

  .glass-popover.is-visible {
    transform: translateY(0) scale(1);
  }
}

/* Compact Phone Landscape (maximize vertical bar area) */
@media (max-height: 480px) and (orientation: landscape) {
  .app-shell {
    padding-top: max(8px, var(--safe-top));
    padding-bottom: max(8px, var(--safe-bottom));
    gap: 8px;
  }

  .top-bar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    gap: 10px;
  }

  .brand-cluster {
    grid-column: 1;
    grid-row: 1;
  }

  .mode-meta {
    display: none;
  }

  .mode-segmented {
    grid-column: 2;
    grid-row: 1;
  }

  .controls-cluster {
    grid-column: 3;
    grid-row: 1;
  }

  .control-pill {
    height: 34px;
    padding: 0 11px;
  }

  .mode-btn {
    padding: 7px 6px;
    font-size: 12px;
  }

  .bar-footer {
    padding-bottom: 10px;
  }
}
