/**
 * Resonance Body Map - Main Styles
 * Layout, components, and base styling
 */

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Keyboard focus ring — visible only for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--status-listening);
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

html,
body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: var(--font-body);
  font-weight: var(--weight-regular);
  color: var(--text-mid);
  letter-spacing: var(--tracking-body);
  line-height: 1.6;
  
  /* Allow touch for buttons, prevent zoom */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  
  /* Smooth font rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== APP CONTAINER ===== */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + var(--space-md)) calc(var(--safe-right) + var(--space-md)) calc(var(--safe-bottom) + var(--space-md)) calc(var(--safe-left) + var(--space-md));
  overflow: hidden;
}

/* ===== AMBIENT BACKGROUND ===== */
.ambient-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-bg);
  overflow: hidden;
}

.ambient-bg::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(ellipse at 50% 0%, rgba(60, 40, 100, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 100%, rgba(40, 30, 80, 0.06) 0%, transparent 40%),
    var(--bg-deep);
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.5;
  will-change: transform;
}

.orb-1 {
  width: 350px;
  height: 350px;
  background: rgba(80, 50, 120, 0.12);
  top: -150px;
  left: -100px;
  animation: floatOrb1 25s var(--ease-in-out-gentle) infinite;
}

.orb-2 {
  width: 280px;
  height: 280px;
  background: rgba(50, 70, 130, 0.1);
  bottom: -80px;
  right: -100px;
  animation: floatOrb2 30s var(--ease-in-out-gentle) infinite;
  animation-delay: -10s;
}

.orb-3 {
  width: 200px;
  height: 200px;
  background: rgba(100, 60, 100, 0.08);
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: floatOrb3 20s var(--ease-in-out-gentle) infinite;
  animation-delay: -5s;
}

.vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-shadow: inset 0 0 150px 50px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* ===== TITLE ===== */
.app-title {
  font-family: var(--font-display);
  font-size: var(--font-title);
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-title);
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.7;
  margin-bottom: var(--space-md);
  z-index: var(--z-ui);
  transition: opacity var(--duration-smooth) var(--ease-out-smooth);
}

/* ===== FULLSCREEN BUTTON ===== */
.btn-fullscreen {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-md));
  right: calc(var(--safe-right) + var(--space-md));
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  z-index: var(--z-ui);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: 
    background var(--duration-fast) var(--ease-out-fast),
    border-color var(--duration-fast) var(--ease-out-fast),
    color var(--duration-fast) var(--ease-out-fast),
    opacity var(--duration-smooth) var(--ease-out-smooth);
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-fullscreen:hover,
.btn-fullscreen:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-mid);
  outline: none;
}

.btn-fullscreen:active {
  transform: scale(0.95);
}

/* Icon visibility */
.btn-fullscreen .icon-expand {
  display: block;
}

.btn-fullscreen .icon-compress {
  display: none;
}

/* Fullscreen active state */
.fullscreen-active .btn-fullscreen .icon-expand {
  display: none;
}

.fullscreen-active .btn-fullscreen .icon-compress {
  display: block;
}

/* Fullscreen mode: hide title and settings */
.fullscreen-active .app-title {
  opacity: 0;
  pointer-events: none;
}

.fullscreen-active #settingsBtn {
  opacity: 0;
  pointer-events: none;
}

/* Fullscreen mode: reposition fullscreen button */
.fullscreen-active .btn-fullscreen {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

/* ===== iPHONE SIMULATED FULLSCREEN ===== */
/* Stretch content to fill viewport when address bar is hidden */
.iphone-fullscreen,
.iphone-fullscreen body {
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
}

.iphone-fullscreen .app-container {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* Fullscreen toast notification */
.fullscreen-toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 30, 40, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.8);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
  max-width: min(300px, calc(100vw - var(--safe-left) - var(--safe-right) - 32px));
}

.fullscreen-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.fullscreen-toast strong {
  color: rgba(255, 255, 255, 0.95);
}

.light-theme .fullscreen-toast {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.7);
}

.light-theme .fullscreen-toast strong {
  color: rgba(0, 0, 0, 0.9);
}

/* Light theme fullscreen button */
.light-theme .btn-fullscreen {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-dim);
}

.light-theme .btn-fullscreen:hover,
.light-theme .btn-fullscreen:focus {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.12);
  color: var(--text-mid);
}

/* ===== BODY CONTAINER ===== */
.body-container {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-body);
  min-height: 0;
  overflow: hidden;
}

.body-wrapper {
  position: relative;
  width: 95%;
  height: 100%;
  max-height: 68dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.body-wrapper svg {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ===== BODY SVG STYLING ===== */
.body-layer {
  opacity: 1;
  transition: opacity var(--duration-smooth) var(--ease-out-smooth);
}

.body-outline {
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
  fill: none;
}

/* ===== ENERGY SPINE ===== */
.energy-spine-layer {
  pointer-events: none;
}

.energy-spine-line {
  transition: opacity 0.3s ease-out, stroke-width 0.3s ease-out;
}

.energy-spine-node {
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

/* Spine line flow animation when active */
.energy-spine-line.flowing {
  stroke-dasharray: 6 10;
  animation: spineFlow 1.2s linear infinite;
}

@keyframes spineFlow {
  to {
    stroke-dashoffset: -32;
  }
}

.skeletal-layer {
  opacity: 0.4;
}

.organs-layer .organ {
  transition: 
    fill var(--duration-fast) var(--ease-out-fast),
    fill-opacity var(--duration-fast) var(--ease-out-fast),
    stroke var(--duration-fast) var(--ease-out-fast);
  will-change: fill-opacity;
}

.energy-layer {
  pointer-events: none;
}

/* Ellipses start hidden; setRegionIntensity / idle breathing drive them.
   (The layer itself must stay visible, or no glow shows while listening.) */
.energy-layer ellipse,
.energy-spine-node {
  transform-box: fill-box;
}

.energy-layer ellipse {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out-fast);
  will-change: opacity;
}

/* Region-specific glow classes */
.region-active[data-region="root"] {
  --region-color: var(--color-root);
  --region-glow: var(--color-root-glow);
}

/* ===== SVG LABELS ===== */
.labels-layer {
  pointer-events: none;
}

.label-chakra,
.label-organ {
  transition: opacity var(--duration-smooth) var(--ease-out-smooth);
}

/* Hide labels when region is very active (glow too bright) */
.body-wrapper.high-activity .labels-layer {
  opacity: 0.3;
}

/* Optional: hide labels entirely */
.body-wrapper.hide-labels .labels-layer {
  display: none;
}

.region-active[data-region="sacral"] {
  --region-color: var(--color-sacral);
  --region-glow: var(--color-sacral-glow);
}

.region-active[data-region="solar"] {
  --region-color: var(--color-solar);
  --region-glow: var(--color-solar-glow);
}

.region-active[data-region="heart"] {
  --region-color: var(--color-heart);
  --region-glow: var(--color-heart-glow);
}

.region-active[data-region="throat"] {
  --region-color: var(--color-throat);
  --region-glow: var(--color-throat-glow);
}

.region-active[data-region="thirdeye"] {
  --region-color: var(--color-thirdeye);
  --region-glow: var(--color-thirdeye-glow);
}

.region-active[data-region="crown"] {
  --region-color: var(--color-crown);
  --region-glow: var(--color-crown-glow);
}

/* ===== SPECTRUM ARC ===== */
#spectrum-arc {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 500ms ease-out;
}

.spectrum-arc-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== HARMONIC LINES ===== */
#harmonic-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.harmonic-line {
  transition: opacity 300ms ease-out, stroke-width 200ms ease-out;
  fill: none;
}

/* ===== RESONANCE BLOOM ===== */
#resonance-rings {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

.resonance-bloom {
  fill: none;
  /* Smooth, gentle appearance */
  stroke-linecap: round;
}

/* ===== PARTICLES ===== */
.particles-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-particles);
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform, opacity;
}

/* ===== FREQUENCY DISPLAY ===== */
.frequency-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: var(--z-ui);
  /* Fixed height - ALWAYS reserves same space regardless of content visibility */
  height: 80px;
  min-height: 80px;
  flex-shrink: 0;
}

.freq-value {
  font-family: var(--font-display);
  font-size: var(--font-frequency);
  font-weight: var(--weight-light);
  color: var(--text-bright);
  letter-spacing: 0.05em;
  line-height: 1;
  /* Use visibility + opacity to always reserve space */
  visibility: hidden;
  opacity: 0;
  transition: 
    opacity var(--duration-smooth) var(--ease-out-smooth),
    visibility 0s var(--duration-smooth),
    color var(--duration-fast) var(--ease-out-fast),
    text-shadow var(--duration-fast) var(--ease-out-fast);
}

.freq-value.visible {
  visibility: visible;
  opacity: 1;
  transition: 
    opacity var(--duration-smooth) var(--ease-out-smooth),
    visibility 0s 0s,
    color var(--duration-fast) var(--ease-out-fast),
    text-shadow var(--duration-fast) var(--ease-out-fast);
}

.freq-number {
  display: inline;
}

.freq-unit {
  font-size: var(--font-frequency-unit);
  margin-left: var(--space-xs);
  opacity: 0.6;
}

/* Musical Note Display */
.freq-note {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: var(--weight-light);
  color: var(--text-bright);
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: var(--space-xs);
  /* Use visibility + opacity to always reserve space */
  visibility: hidden;
  opacity: 0;
  /* Fixed height so it always reserves space even when empty */
  min-height: 1.8rem;
  transition: 
    opacity var(--duration-smooth) var(--ease-out-smooth),
    visibility 0s var(--duration-smooth),
    color var(--duration-fast) var(--ease-out-fast),
    text-shadow var(--duration-fast) var(--ease-out-fast);
}

.freq-note.visible {
  visibility: visible;
  opacity: 1;
  transition: 
    opacity var(--duration-smooth) var(--ease-out-smooth),
    visibility 0s 0s,
    color var(--duration-fast) var(--ease-out-fast),
    text-shadow var(--duration-fast) var(--ease-out-fast);
}

/* Adjust Hz display when note is shown */
.freq-note.visible + .freq-value {
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.freq-region {
  font-family: var(--font-body);
  font-size: var(--font-label);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: var(--space-sm);
  opacity: 0;
  transition: opacity var(--duration-smooth) var(--ease-out-smooth);
}

.freq-region.visible {
  opacity: 0.6;
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  z-index: var(--z-ui);
  /* Ensure controls are always visible */
  flex-shrink: 0;
  padding-bottom: var(--space-sm);
}

/* Status Indicator */
.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--status-idle);
  transition: 
    background var(--duration-smooth) var(--ease-out-smooth),
    box-shadow var(--duration-smooth) var(--ease-out-smooth);
}

.status-indicator.listening {
  background: var(--status-listening);
  box-shadow: 
    0 0 10px var(--status-listening),
    0 0 20px rgba(0, 255, 136, 0.5);
  animation: statusPulse 2s var(--ease-in-out-gentle) infinite;
}

.status-indicator.error {
  background: var(--status-error);
  box-shadow: 0 0 10px var(--status-error);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  font-family: var(--font-body);
  font-size: var(--font-button);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-button);
  text-transform: uppercase;
  color: var(--text-mid);
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-pill);
  /* iOS touch compatibility */
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 10;
  cursor: pointer;
  transition: 
    background var(--duration-fast) var(--ease-out-fast),
    border-color var(--duration-fast) var(--ease-out-fast),
    color var(--duration-fast) var(--ease-out-fast),
    box-shadow var(--duration-fast) var(--ease-out-fast),
    transform var(--duration-fast) var(--ease-out-fast);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn:hover,
.btn:focus {
  background: var(--ui-surface-hover);
  border-color: var(--ui-border-hover);
  color: var(--text-bright);
  outline: none;
}

.btn:active {
  transform: scale(0.98);
}

/* iOS active states (touchend doesn't always trigger :active) */
.btn.btn-pressed {
  transform: scale(0.96);
  background: var(--ui-surface-active);
}

/* Better touch target for mobile */
@media (pointer: coarse) {
  .btn {
    min-height: 48px;
    min-width: 48px;
  }
  
  .btn-large {
    min-height: 56px;
    padding: var(--space-lg) var(--space-2xl);
  }
}

.btn.active {
  background: var(--ui-surface-active);
  border-color: var(--ui-border-active);
  color: var(--text-bright);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.btn-primary {
  background: rgba(255, 255, 255, 0.08);
}

.btn-primary.active {
  background: rgba(0, 255, 136, 0.15);
  border-color: rgba(0, 255, 136, 0.3);
}

.btn-large {
  padding: var(--space-lg) var(--space-2xl);
  font-size: 0.85rem;
}

.btn-icon {
  padding: var(--space-md);
  border-radius: 50%;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn-text {
  display: inline-block;
}

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: var(--z-overlay);
  padding: var(--space-lg);
  padding-top: calc(var(--safe-top) + var(--space-lg));
  padding-bottom: calc(var(--safe-bottom) + var(--space-lg));
  padding-left: calc(var(--safe-left) + var(--space-lg));
  padding-right: calc(var(--safe-right) + var(--space-lg));
  /* iOS touch handling and scrolling */
  touch-action: manipulation;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  transition: 
    opacity var(--duration-slow) var(--ease-out-smooth),
    visibility var(--duration-slow);
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 360px;
  padding: var(--space-2xl);
  background: rgba(15, 15, 25, 0.9);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-lg);
  animation: overlayEnter var(--duration-slow) var(--ease-out-smooth);
  /* Ensure buttons inside are tappable */
  pointer-events: auto;
  touch-action: manipulation;
}

.overlay-icon {
  color: var(--text-dim);
  margin-bottom: var(--space-lg);
  opacity: 0.7;
}

.overlay-icon.error-icon {
  color: var(--status-error);
}

.overlay-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-label);
  color: var(--text-bright);
  margin-bottom: var(--space-lg);
}

.overlay-text {
  font-size: var(--font-body-text);
  line-height: 1.8;
  color: var(--text-mid);
  margin-bottom: var(--space-md);
}

.overlay-subtext {
  font-size: var(--font-small);
  color: var(--text-dim);
  margin-bottom: var(--space-xl);
  opacity: 0.7;
}

/* Primary CTA button in overlays - extra touch-friendly for iOS */
.overlay .btn-primary {
  position: relative;
  z-index: 10;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  /* Larger tap target on mobile */
  min-height: 56px;
  min-width: 220px;
  font-size: 0.9rem;
}

/* Visual feedback for touch on iOS */
.overlay .btn-primary:active,
.overlay .btn-primary.btn-pressed {
  transform: scale(0.96);
  opacity: 0.9;
  background: var(--ui-surface-active);
}

/* iPhone specific - smaller screens need special handling */
@media (max-width: 430px) {
  .overlay {
    padding: var(--space-md);
    padding-top: calc(var(--safe-top) + var(--space-md));
    padding-bottom: calc(var(--safe-bottom) + var(--space-md));
  }
  
  .overlay-content {
    max-width: 95vw;
    padding: var(--space-lg) var(--space-md);
    margin: auto;
  }
  
  .overlay-title {
    font-size: 1.4rem;
  }
  
  .overlay-text {
    font-size: 0.85rem;
    line-height: 1.6;
  }
  
  .overlay-subtext {
    font-size: 0.7rem;
    margin-bottom: var(--space-lg);
  }
  
  .overlay .btn-primary {
    min-height: 54px;
    min-width: 90%;
    width: 90%;
    font-size: 0.85rem;
    padding: var(--space-md) var(--space-lg);
  }
  
  /* Ensure button is visible and tappable */
  .overlay .btn-large {
    margin-top: var(--space-md);
  }
}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 375px) {
  .overlay-content {
    padding: var(--space-md);
  }
  
  .overlay-icon svg {
    width: 50px;
    height: 50px;
  }
  
  .overlay-title {
    font-size: 1.2rem;
    margin-bottom: var(--space-md);
  }
  
  .overlay-text {
    font-size: 0.8rem;
    margin-bottom: var(--space-sm);
  }
  
  .body-wrapper {
    max-height: 65dvh;
  }
  
  .app-title {
    font-size: 0.7rem;
  }
}

/* Tall phones (iPhone Pro Max, Samsung Ultra, etc.) — extra vertical space available */
@media (max-width: 430px) and (min-height: 800px) {
  .body-wrapper {
    max-height: 72dvh;
  }
}

/* iPhone controls visibility fix */
@media (max-width: 430px) {
  .app-container {
    padding-top: calc(var(--safe-top) + var(--space-xs));
    padding-bottom: calc(var(--safe-bottom) + var(--space-xs));
    gap: 0;
  }
  
  .controls {
    gap: var(--space-sm);
    padding-bottom: var(--space-xs);
  }
  
  /* Maximize body size on mobile phones */
  .body-container {
    flex: 1;
    min-height: 0;
    max-width: 100%;
  }
  
  .body-wrapper {
    width: 100%;
    max-height: 70dvh;
  }
  
  /* Compact frequency display */
  .frequency-display {
    height: 50px;
    min-height: 50px;
  }
  
  .freq-note {
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    margin-bottom: 2px;
    min-height: 1.4rem;
  }
  
  .freq-value {
    font-size: clamp(1.4rem, 5vw, 2rem);
  }
  
  .freq-note.visible + .freq-value {
    font-size: clamp(1.1rem, 4vw, 1.5rem);
  }
  
  .freq-region {
    font-size: 0.6rem;
    margin-top: var(--space-xs);
  }
  
  /* Make title minimal */
  .app-title {
    font-size: 0.75rem;
    margin-bottom: 0;
  }
  
  /* Smaller buttons on mobile */
  .btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.65rem;
    min-height: 40px;
  }
  
  .btn-icon {
    padding: var(--space-sm);
    width: 40px;
    height: 40px;
  }
  
  .btn-icon svg {
    width: 16px;
    height: 16px;
  }
  
  .status-indicator {
    width: 8px;
    height: 8px;
  }
}

/* iPhone with notch - extra safe area handling */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 430px) {
    .app-container {
      padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-lg));
    }
    
    .controls {
      margin-bottom: 0;
    }
  }
}

/* ===== SETTINGS PANEL ===== */
.settings-content {
  max-width: 400px;
  width: 100%;
  max-height: 80dvh;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-bottom) + var(--space-md));
}

@supports (height: 1dvh) {
  .settings-content {
    max-height: 80dvh;
  }
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
}

.settings-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-label);
  color: var(--text-bright);
}

.btn-close {
  padding: var(--space-sm);
}

.settings-group {
  margin-bottom: var(--space-xl);
}

.settings-label {
  display: block;
  font-size: var(--font-small);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: var(--space-md);
}

/* Slider */
.slider-container {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--ui-border);
  border-radius: var(--radius-pill);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--text-mid);
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out-fast);
}

/* Larger touch targets on touch devices */
@media (pointer: coarse) {
  .slider::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }
  .slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
}

.slider::-webkit-slider-thumb:hover {
  background: var(--text-bright);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--text-mid);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.slider-value {
  font-size: var(--font-small);
  color: var(--text-mid);
  min-width: 50px;
  text-align: right;
}

/* Toggle */
.toggle-container {
  display: flex;
  align-items: center;
}

.toggle {
  /* Keep checkbox accessible but hidden visually */
  position: absolute;
  opacity: 0;
  width: 50px;
  height: 30px;
  cursor: pointer;
  z-index: 2;
  /* iOS touch handling */
  -webkit-appearance: none;
  touch-action: manipulation;
}

.toggle-label {
  position: relative;
  width: 50px;
  height: 26px;
  background: var(--ui-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out-fast);
  /* iOS touch handling */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.toggle-label::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--text-mid);
  border-radius: 50%;
  transition: transform var(--duration-fast) var(--ease-out-fast);
}

.toggle:checked + .toggle-label {
  background: rgba(0, 255, 136, 0.3);
}

.toggle:checked + .toggle-label::after {
  transform: translateX(24px);
  background: var(--status-listening);
}

/* Make toggle easier to tap on mobile */
@media (pointer: coarse) {
  .toggle {
    width: 60px;
    height: 36px;
  }
}

.settings-footer {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--ui-border);
}

.settings-info {
  font-size: var(--font-small);
  color: var(--text-dim);
  text-align: center;
  line-height: 1.8;
}

.settings-note {
  opacity: 0.6;
}

/* ===== RESPONSIVE ===== */
@media (max-height: 700px) {
  .body-wrapper {
    max-height: 60dvh;
  }
  
  .frequency-display {
    height: 55px;
    min-height: 55px;
  }
  
  .overlay-content {
    padding: var(--space-lg);
  }
  
  .app-title {
    margin-bottom: var(--space-xs);
  }
}

/* iPad and tablets in portrait */
@media (min-width: 768px) {
  .body-container {
    max-width: 600px;
  }
  
  .body-wrapper {
    width: 100%;
    max-height: 78dvh;
  }
}

/* iPad Pro and larger tablets */
@media (min-width: 1024px) {
  .body-container {
    max-width: 700px;
  }
  
  .body-wrapper {
    max-height: 80dvh;
  }
}

/* iPad portrait specific - maximize body size */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .app-container {
    padding-top: calc(var(--safe-top) + var(--space-md));
    padding-bottom: calc(var(--safe-bottom) + var(--space-md));
  }
  
  .body-container {
    max-width: 90vw;
  }
  
  .body-wrapper {
    width: 100%;
    max-height: 65dvh;
  }
  
  .frequency-display {
    height: 75px;
    min-height: 75px;
  }
  
  .controls {
    margin-top: var(--space-sm);
  }
}

/* ===== HARMONIC CASCADE & CYMATICS OVERLAYS ===== */
.harmonic-cascade-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  mix-blend-mode: screen;
}

.cymatics-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: screen;
  opacity: 0.7;
}

/* Toggle control styling */
.cascade-toggle,
.cymatics-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Cymatics position toggle */
.cymatics-position-toggle {
  display: flex;
  gap: 0.5rem;
}

.cymatics-position-toggle button {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--ui-border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.cymatics-position-toggle button:hover {
  border-color: var(--ui-border-hover);
  color: var(--text-mid);
}

.cymatics-position-toggle button.active {
  background: rgba(0, 255, 136, 0.15);
  border-color: rgba(0, 255, 136, 0.3);
  color: var(--text-bright);
}

/* ===== PRINT ===== */
@media print {
  .controls,
  .overlay,
  .ambient-bg,
  .harmonic-cascade-canvas,
  .cymatics-overlay-canvas {
    display: none;
  }
}


/* ===== RECORD BUTTON ===== */
.btn-record {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.btn-record.hidden {
  display: none;
}

.record-dot {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #cc4444;
  transition: background 0.3s ease, box-shadow 0.3s ease, border-radius 0.3s ease;
}

.btn-record.recording {
  background: rgba(255, 50, 50, 0.2);
  border-color: rgba(255, 68, 68, 0.6);
  box-shadow: 0 0 16px rgba(255, 68, 68, 0.35);
}

.btn-record.recording .record-dot {
  border-radius: 3px;
  background: #ff2222;
  box-shadow: 0 0 10px rgba(255, 34, 34, 0.8);
  animation: recordPulse 1s ease-in-out infinite;
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

@media (max-width: 430px) {
  .btn-record {
    width: 36px;
    height: 36px;
  }
  .record-dot {
    width: 10px;
    height: 10px;
  }
}

/* ===== SESSION TIMER ===== */
.session-timer {
  font-family: var(--font-display);
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  font-weight: var(--weight-light);
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-align: center;
  z-index: var(--z-ui);
  transition: opacity 0.4s ease;
  flex-shrink: 0;
  padding-bottom: var(--space-xs);
}

/* ===== SESSION SUMMARY OVERLAY ===== */
.session-summary-overlay {
  z-index: calc(var(--z-overlay) + 1);
}

.session-summary-content {
  max-width: 420px;
  width: 100%;
  text-align: left;
}

.summary-duration {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-mid);
  margin-bottom: var(--space-lg);
  text-align: center;
}

.summary-bars {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.summary-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.summary-bar-id {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 110px;
}

.summary-chakra-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.summary-bar-label {
  font-size: var(--font-small);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.summary-bar-note {
  font-size: 0.65rem;
  color: var(--text-dim);
  opacity: 0.5;
}

.summary-bar-track {
  flex: 1;
  height: 8px;
  background: var(--ui-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.summary-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.summary-bar-value {
  font-size: var(--font-small);
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}

.summary-sparkline-wrap {
  margin-bottom: var(--space-lg);
}

.summary-spark-label {
  font-size: var(--font-small);
  color: var(--text-dim);
  margin-bottom: var(--space-xs);
  text-align: center;
}

.summary-sparkline {
  width: 100%;
  height: 100px;
  display: block;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.summary-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.summary-export-btn {
  font-size: var(--font-small) !important;
  padding: var(--space-sm) var(--space-md) !important;
}

/* ===== FREQUENCY REFERENCE OVERLAY ===== */
.freq-reference-overlay {
  position: fixed;
  top: calc(var(--safe-top) + 60px);
  left: calc(var(--safe-left) + var(--space-md));
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: var(--z-ui);
  pointer-events: none;
  animation: overlayEnter 0.3s ease;
}

.freq-ref-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(15, 15, 25, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 6px;
  padding: 3px 8px;
}

.freq-ref-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.freq-ref-label {
  min-width: 60px;
  color: var(--text-mid);
}

.freq-ref-range {
  opacity: 0.7;
  min-width: 80px;
}

.freq-ref-note {
  opacity: 0.5;
}

/* ===== TUNER DISPLAY ===== */
.tuner-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: var(--z-ui);
  flex-shrink: 0;
  padding: var(--space-xs) 0;
}

.tuner-note {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: var(--weight-light);
  color: var(--text-bright);
  letter-spacing: 0.08em;
}

.tuner-cents-bar {
  position: relative;
  width: 160px;
  height: 6px;
  background: var(--ui-border);
  border-radius: var(--radius-pill);
  margin: var(--space-xs) 0;
}

.tuner-cents-center {
  position: absolute;
  top: -2px;
  left: 50%;
  width: 2px;
  height: 10px;
  background: var(--text-dim);
  transform: translateX(-50%);
}

.tuner-cents-marker {
  position: absolute;
  top: -3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #00ff88;
  transform: translateX(-50%);
  transition: left 0.15s ease, background 0.2s ease;
  left: 50%;
}

.tuner-cents-value {
  font-size: var(--font-small);
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* ===== SCREENSHOT BUTTON ===== */
.btn-screenshot {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-md));
  right: calc(var(--safe-right) + var(--space-md) + 44px);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  z-index: var(--z-ui);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition:
    background var(--duration-fast) var(--ease-out-fast),
    border-color var(--duration-fast) var(--ease-out-fast),
    color var(--duration-fast) var(--ease-out-fast);
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-screenshot:hover,
.btn-screenshot:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-mid);
  outline: none;
}

.btn-screenshot:active {
  transform: scale(0.95);
}

.light-theme .btn-screenshot {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-dim);
}

.light-theme .btn-screenshot:hover,
.light-theme .btn-screenshot:focus {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.12);
  color: var(--text-mid);
}

/* Light theme overrides for new features */
.light-theme .freq-ref-row {
  background: rgba(245, 242, 237, 0.7);
}

.light-theme .session-summary-content {
  background: rgba(245, 242, 237, 0.95);
}


/* ===== LANDSCAPE MODE SUPPORT ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .app-container {
    flex-direction: row;
    flex-wrap: wrap;
    padding: var(--space-sm) calc(var(--safe-right) + var(--space-md)) var(--space-sm) calc(var(--safe-left) + var(--space-md));
    padding-top: calc(var(--safe-top) + var(--space-sm));
    padding-bottom: calc(var(--safe-bottom) + var(--space-sm));
    justify-content: center;
    align-items: center;
  }

  .app-title {
    position: absolute;
    top: var(--safe-top, 0px);
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 0.7rem;
  }

  .body-container {
    flex: 0 0 auto;
    width: 50vw;
    max-width: none;
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--space-md));
  }

  .body-wrapper {
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 40px);
  }

  .frequency-display {
    position: absolute;
    right: calc(var(--safe-right) + var(--space-lg));
    top: 50%;
    transform: translateY(-50%);
    height: auto;
    min-height: auto;
  }

  .controls {
    position: absolute;
    bottom: calc(var(--safe-bottom) + var(--space-sm));
    left: 50%;
    transform: translateX(-50%);
  }

  .session-timer {
    position: absolute;
    right: calc(var(--safe-right) + var(--space-lg));
    top: calc(var(--safe-top) + var(--space-lg));
  }
  
  /* Settings panel in landscape */
  .settings-content {
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--space-xl));
  }
  
  .overlay-content {
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--space-xl));
    overflow-y: auto;
  }
}

/* Landscape on taller phones (500-700px height) */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 700px) {
  .app-container {
    padding-left: calc(var(--safe-left) + var(--space-md));
    padding-right: calc(var(--safe-right) + var(--space-md));
  }
  
  .body-wrapper {
    max-height: 80dvh;
  }
}

/* Desktop landscape — wider screens */
@media (orientation: landscape) and (min-width: 1024px) {
  .body-container {
    max-width: 45vw;
  }

  .body-wrapper {
    max-height: 82dvh;
  }
}

/* ===== DESKTOP HOVER STATES ===== */
@media (hover: hover) {
  .btn-primary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
  }

  .btn-primary.active:hover {
    background: rgba(0, 255, 136, 0.2);
    border-color: rgba(0, 255, 136, 0.4);
    box-shadow: 0 0 25px rgba(0, 255, 136, 0.15);
  }

  .btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
  }
}

/* ===== FONT SCALING ON VERY LARGE SCREENS ===== */
@media (min-width: 1440px) {
  .frequency-display {
    height: 100px;
    min-height: 100px;
  }

  .freq-value {
    font-size: clamp(2.5rem, 4vw, 4rem);
  }

  .freq-note {
    font-size: clamp(2rem, 3.5vw, 3rem);
  }

  .freq-region {
    font-size: 0.9rem;
  }

  .app-title {
    font-size: clamp(1rem, 1.5vw, 1.4rem);
  }

  .btn {
    font-size: 0.85rem;
    padding: var(--space-lg) var(--space-2xl);
  }

  .session-timer {
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
  }

  .tuner-note {
    font-size: clamp(1.6rem, 2vw, 2.2rem);
  }

  .tuner-cents-bar {
    width: 220px;
  }
}

@media (min-width: 2000px) {
  .freq-value {
    font-size: 4.5rem;
  }

  .freq-note {
    font-size: 3.5rem;
  }

  .body-container {
    max-width: 800px;
  }
}

/* ===== WELCOME OVERLAY DISMISS ON BACKGROUND TAP ===== */
/* The welcome overlay already has pointer-events, just needs cursor */
.welcome-overlay {
  cursor: pointer;
}

.welcome-overlay .overlay-content {
  cursor: default;
}


/* ===== COLOR THEME & VIZ PRESET SELECTORS ===== */
#colorThemeSelector,
#vizPresetSelector {
  flex-wrap: wrap;
}

#colorThemeSelector button,
#vizPresetSelector button {
  flex: 0 0 auto;
  min-width: 50px;
}


/* ===== INSTRUMENT GUIDE ===== */
.instrument-guide-overlay {
  z-index: calc(var(--z-overlay) + 1);
}

.instrument-guide-content {
  max-width: 460px;
  width: 100%;
  max-height: 85dvh;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
}

@supports (height: 1dvh) {
  .instrument-guide-content {
    max-height: 85dvh;
  }
}

.guide-region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-lg);
}

.guide-region-chip {
  font-size: 0.65rem;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: var(--radius-pill);
  opacity: 0.8;
}

.guide-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.guide-row {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--ui-border);
}

.guide-name {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-bright);
  margin-bottom: 2px;
}

.guide-freq {
  font-size: var(--font-small);
  color: var(--text-mid);
}

.guide-regions {
  font-size: var(--font-small);
  color: var(--status-listening);
  opacity: 0.8;
  margin: 2px 0;
}

.guide-desc {
  font-size: var(--font-small);
  color: var(--text-dim);
  line-height: 1.4;
}


/* ===== ACTIVE REGION LABEL (Accessibility) ===== */
.freq-active-label {
  /* Visually hidden — screen-reader only; freqRegion already shows the label */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
