/* -------------------------------------------------------------
 * Custom Design System & CSS Variables - "Mundfein"
 * ------------------------------------------------------------- */
:root {
  /* Harmonious Color Palette (Sleek Dark Mode) */
  --bg-color: #070a13;
  --bg-surface: rgba(15, 23, 42, 0.65);
  --bg-surface-solid: #0f172a;
  
  --color-primary: #3b82f6;      /* Royal Indigo */
  --color-primary-rgb: 59, 130, 246;
  --color-cyan: #06b6d4;         /* Nasal Breathe Light Blue */
  --color-cyan-rgb: 6, 182, 212;
  --color-pink: #ec4899;         /* Warning Pink */
  --color-pink-rgb: 236, 72, 153;
  --color-purple: #8b5cf6;       /* Accent Purple */
  --color-purple-rgb: 139, 92, 246;
  
  --text-primary: #f8fafc;       /* Slate 50 */
  --text-secondary: #94a3b8;     /* Slate 400 */
  --text-muted: #64748b;         /* Slate 500 */
  
  --border-light: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(59, 130, 246, 0.15);
  
  /* Font Stacks */
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Layout Constants */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: calc(64px + var(--safe-area-top));
  --nav-height: calc(68px + var(--safe-area-bottom));
}

/* -------------------------------------------------------------
 * Base Reset & Box Sizing
 * ------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available; /* Fixed stretch bug on iOS Safari */
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* HTML scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* -------------------------------------------------------------
 * Vibrant Background Orbs
 * ------------------------------------------------------------- */
.glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  z-index: -1;
  pointer-events: none;
  opacity: 0.28;
  mix-blend-mode: screen;
}
.orb-1 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, var(--color-primary) 0%, rgba(59,130,246,0) 70%);
  top: -100px;
  right: -50px;
}
.orb-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--color-purple) 0%, rgba(139,92,246,0) 70%);
  bottom: 10%;
  left: -150px;
}
.orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, var(--color-cyan) 0%, rgba(6,182,212,0) 70%);
  top: 40%;
  right: -100px;
}

/* -------------------------------------------------------------
 * App Shell Layout
 * ------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: -webkit-fill-available;
  position: relative;
}

/* Top App Header */
.app-header {
  height: var(--header-height);
  padding: var(--safe-area-top) 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  background-color: rgba(7, 10, 19, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-logo {
  display: flex;
  align-items: center;
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Wake Lock / Connection Indicator Badge */
.wake-lock-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.3s ease;
}
.wake-lock-indicator.active {
  background: rgba(6, 182, 212, 0.1);
  border-color: rgba(6, 182, 212, 0.3);
  color: #cffafe;
}
.wake-lock-indicator.active .indicator-dot {
  background-color: var(--color-cyan);
  box-shadow: 0 0 8px var(--color-cyan);
}
.indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-muted);
  transition: all 0.3s ease;
}

/* Main Content Area */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px calc(24px + var(--nav-height));
  position: relative;
}

/* Bottom Tab Navigation Bar */
.app-nav {
  height: var(--nav-height);
  padding-bottom: var(--safe-area-bottom);
  background-color: rgba(7, 10, 19, 0.85);
  border-top: 1px solid var(--border-light);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  justify-content: space-around;
  align-items: center;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 12px;
  flex: 1;
  max-width: 90px;
}

.nav-item svg {
  opacity: 0.65;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.nav-label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.nav-item.active {
  color: var(--color-cyan);
}

.nav-item.active svg {
  opacity: 1;
  transform: translateY(-2px);
  stroke: var(--color-cyan);
  filter: drop-shadow(0 0 6px rgba(6, 182, 212, 0.5));
}

/* -------------------------------------------------------------
 * App Views (State transitions)
 * ------------------------------------------------------------- */
.app-view {
  display: none;
  animation: viewFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.app-view.active {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@keyframes viewFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.view-title {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.view-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* -------------------------------------------------------------
 * Premium UI Components (Glassmorphism Cards, Buttons, Badges)
 * ------------------------------------------------------------- */
.glass-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.badge {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.badge-indigo {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  color: #e0e7ff;
}

.header-badges {
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge-streak {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fef3c7;
}

/* Quick Toggles */
.quick-toggles {
  margin-top: 4px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  transition: background 0.2s;
}

.toggle-label:active {
  background: rgba(255, 255, 255, 0.08);
}

.toggle-checkbox {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 34px;
  transition: .4s;
  flex-shrink: 0;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  transition: .4s;
}

.toggle-checkbox:checked + .toggle-slider {
  background-color: var(--color-purple);
}

.toggle-checkbox:checked + .toggle-slider:before {
  transform: translateX(20px);
  background-color: #fff;
}

.toggle-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

#app-status-badge.calibrating {
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.4);
  color: #f5f3ff;
  animation: pulseGrad 1.5s infinite alternate;
}

#app-status-badge.active {
  background: rgba(6, 182, 212, 0.2);
  border-color: rgba(6, 182, 212, 0.4);
  color: #ecfeff;
}

#app-status-badge.warning {
  background: rgba(236, 72, 153, 0.25);
  border-color: rgba(236, 72, 153, 0.5);
  color: #fdf2f8;
  animation: pulseBorderPink 1s infinite alternate;
}

@keyframes pulseBorderPink {
  from { border-color: rgba(236, 72, 153, 0.4); }
  to { border-color: rgba(236, 72, 153, 0.9); }
}

/* Button UI Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 28px;
  border-radius: 16px;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  outline: none;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-cyan) 0%, var(--color-primary) 100%);
  color: white;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.35);
}

.btn-primary:active {
  transform: scale(0.98);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.2);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.35);
  color: #ffe4e6;
}

.btn-danger:active {
  background: rgba(244, 63, 94, 0.3);
}

.btn-sm {
  padding: 10px 18px;
  font-size: 0.88rem;
  border-radius: 12px;
  width: auto;
}

/* -------------------------------------------------------------
 * 1. HOME VIEW - Breathing Visualizer Core
 * ------------------------------------------------------------- */
.visualizer-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
}

.breathing-circle-outer {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.01);
  border: 2px dashed rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.5s ease;
}

/* Outer Pulsing Glow Orbit */
.breathing-circle-outer::before {
  content: '';
  position: absolute;
  top: -12px;
  left: -12px;
  right: -12px;
  bottom: -12px;
  border-radius: 50%;
  border: 2px solid var(--color-cyan);
  opacity: 0.15;
  animation: pulseOuterOrb 3.5s infinite linear;
}

@keyframes pulseOuterOrb {
  0% { transform: scale(1); opacity: 0.2; }
  50% { transform: scale(1.08); opacity: 0.08; }
  100% { transform: scale(1); opacity: 0.2; }
}

.breathing-circle-middle {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.03);
  border: 1px solid rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.breathing-circle-inner {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(30,41,59,0.9) 0%, rgba(15,23,42,0.95) 100%);
  border: 2px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.05),
              0 10px 30px rgba(0, 0, 0, 0.5);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.breathing-circle-inner.calibrating {
  border-color: var(--color-purple);
  box-shadow: 0 0 25px rgba(139, 92, 246, 0.4);
}

.breathing-circle-inner.active {
  border-color: var(--color-cyan);
  box-shadow: 0 0 30px rgba(6, 182, 212, 0.5);
  animation: quietBreathing 4s infinite ease-in-out;
}

.breathing-circle-inner.warning {
  border-color: var(--color-pink);
  box-shadow: 0 0 35px rgba(236, 72, 153, 0.7);
  animation: urgentWarning 0.6s infinite alternate;
}

@keyframes quietBreathing {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes urgentWarning {
  from { transform: scale(0.98); }
  to { transform: scale(1.04); }
}

.visualizer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.mic-icon {
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: flex;
}
.breathing-circle-inner.active .mic-icon {
  color: var(--color-cyan);
}
.breathing-circle-inner.warning .mic-icon {
  color: var(--color-pink);
}

.volume-label {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.2;
}

.state-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Canvas Audio Spectrogram */
.canvas-panel {
  padding: 12px 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--color-pink);
}

.live-indicator::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--color-pink);
  box-shadow: 0 0 6px var(--color-pink);
  animation: pulseGrad 0.8s infinite alternate;
}

@keyframes pulseGrad {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

#waveform-canvas {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  display: block;
}

/* Live Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
}

.text-cyan { color: var(--color-cyan); }
.text-pink { color: var(--color-pink); }
.text-purple { color: var(--color-purple); }

/* Control Button Animations */
#btn-session-control.btn-active {
  background: linear-gradient(135deg, var(--color-pink) 0%, #b91c1c 100%);
  box-shadow: 0 4px 20px rgba(236, 72, 153, 0.35);
}

/* -------------------------------------------------------------
 * 2. HISTORY VIEW - Custom Sleep Statistics
 * ------------------------------------------------------------- */
.summary-card {
  padding: 24px;
}

.summary-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.summary-score {
  font-family: var(--font-heading);
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--color-cyan) 0%, var(--color-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.summary-metrics {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.metric-value {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1rem;
}

/* Chart Canvas styling */
.chart-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-container {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  padding: 8px;
}

#history-canvas {
  width: 100%;
  display: block;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 4px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.bg-cyan { background-color: var(--color-cyan); }
.bg-pink { background-color: var(--color-pink); }

/* Empty State Styling */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-light);
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.empty-state h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 600;
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 250px;
}

/* Sleep logs list */
.section-heading {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:active {
  background: rgba(255, 255, 255, 0.06);
  transform: scale(0.99);
}

.history-item.selected {
  border-color: rgba(6, 182, 212, 0.4);
  background: rgba(6, 182, 212, 0.05);
}

.item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-date {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
}

.item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
}

.item-score-badge {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
}

.score-excellent {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.score-warning {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.3);
}

/* -------------------------------------------------------------
 * 3. LEARN VIEW - Science Cards
 * ------------------------------------------------------------- */
.learn-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.learn-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
}

.bg-cyan-soft { background: rgba(6, 182, 212, 0.12); }
.bg-purple-soft { background: rgba(139, 92, 246, 0.12); }
.bg-pink-soft { background: rgba(236, 72, 153, 0.12); }
.bg-indigo-soft { background: rgba(99, 102, 241, 0.12); }

.card-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
}

.card-excerpt {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.card-excerpt b {
  color: var(--text-primary);
}

/* -------------------------------------------------------------
 * 4. SETTINGS VIEW - Premium Layout
 * ------------------------------------------------------------- */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.group-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-cyan);
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.label-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

.label-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

/* Form inputs & select dropdown */
.select-wrapper {
  position: relative;
  width: 100%;
}

.form-input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 12px 16px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.form-input:focus {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-secondary);
  pointer-events: none;
}

/* Custom styled sliders */
.slider-control {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slider {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
  border: none;
  transition: transform 0.1s ease;
}

.slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
  border: none;
  transition: transform 0.1s ease;
}

.slider-value {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-cyan);
  min-width: 48px;
  text-align: right;
}

.setting-item-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.setting-item-row.justify-between {
  justify-content: space-between;
  align-items: center;
}

.setting-label-only {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 70%;
}

/* -------------------------------------------------------------
 * 5. CALIBRATION MODAL OVERLAY (Multi-step UI)
 * ------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(7, 10, 19, 0.85);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 20px;
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-card {
  max-width: 380px;
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalScaleUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalScaleUp {
  from {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  padding: 4px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.calibration-step {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.calibration-step.active {
  display: flex;
}

.step-icon {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-light);
  width: 90px;
  height: 90px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.step-icon svg {
  filter: drop-shadow(0 0 10px currentColor);
}

.step-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
}

.step-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
  max-width: 300px;
}

/* Calibration progress elements */
.cal-progress-container {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 8px;
}

.cal-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-cyan) 0%, var(--color-purple) 100%);
  transition: width 0.1s linear;
}

.cal-timer {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 2.2rem;
  color: var(--color-cyan);
  line-height: 1;
}

.cal-status-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.modal-footer {
  width: 100%;
}

/* -------------------------------------------------------------
 * Responsive Media Queries for tablet & small screens
 * ------------------------------------------------------------- */
/* -------------------------------------------------------------
 * Debug Panel
 * ------------------------------------------------------------- */
.debug-panel {
  padding: 14px 16px;
  border-color: rgba(99, 102, 241, 0.2);
}

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.debug-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 10px 12px;
}

.debug-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.debug-value {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-cyan);
  font-variant-numeric: tabular-nums;
}

.debug-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  text-align: center;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.debug-panel.hidden .debug-grid,
.debug-panel.hidden .debug-hint {
  display: none;
}

/* Apnea warning banner */
.apnea-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  margin-top: 12px;
  box-shadow: 0 8px 32px 0 rgba(239, 68, 68, 0.15);
  animation: apneaPulse 2s infinite ease-in-out;
}

.apnea-banner .alert-icon {
  font-size: 1.8rem;
  animation: alarmWiggle 0.5s infinite alternate ease-in-out;
}

.apnea-banner .alert-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.apnea-banner .alert-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 800;
  color: #f87171;
  margin: 0;
  letter-spacing: 0.5px;
}

.apnea-banner .alert-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 0;
}

@keyframes apneaPulse {
  0% {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.35);
    box-shadow: 0 8px 32px 0 rgba(239, 68, 68, 0.15);
  }
  50% {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 8px 32px 0 rgba(239, 68, 68, 0.3);
  }
  100% {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.35);
    box-shadow: 0 8px 32px 0 rgba(239, 68, 68, 0.15);
  }
}

@keyframes alarmWiggle {
  0% { transform: rotate(-8deg); }
  100% { transform: rotate(8deg); }
}

@media (min-width: 600px) {
  .app-container {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.8);
    position: relative;
    background-color: var(--bg-color);
  }
  
  .app-nav {
    max-width: 480px;
    margin: 0 auto;
  }
  
  .app-header {
    max-width: 480px;
    margin: 0 auto;
    left: 0;
    right: 0;
  }
}

/* -------------------------------------------------------------
 * 6. OLED TRUE BLACK NIGHT MODE & PWA BANNERS
 * ------------------------------------------------------------- */
body.oled-mode {
  --bg-color: #000000;
  --bg-secondary: #000000;
  background-color: #000000 !important;
}

body.oled-mode .glow-orb {
  display: none !important;
}

body.oled-mode .app-container {
  background-color: #000000 !important;
  border-color: #111111;
}

body.oled-mode .glass-card {
  background: rgba(10, 10, 10, 0.95);
  border-color: #222222;
  box-shadow: none;
}

body.oled-mode .app-header,
body.oled-mode .app-nav {
  background: rgba(0, 0, 0, 0.95);
  border-color: #1a1a1a;
}

/* iOS PWA Install Banner */
.ios-install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 14px;
}

.ios-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
}

.ios-icon {
  font-size: 1.4rem;
}

.btn-close-sm {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
}

/* User Account Badge & Modal Tabs */
.user-account-badge {
  transition: all 0.2s ease;
  user-select: none;
}
.user-account-badge:hover {
  background: rgba(255, 255, 255, 0.12) !important;
  border-color: var(--color-cyan) !important;
}

.account-tabs {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}

.account-tabs .tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.account-tabs .tab-btn.active {
  background: var(--color-cyan);
  color: #0B0F19;
}

