/* ── Variables ───────────────────────────────── */
:root {
  --bg:        #0d0d16;
  --surface:   #14141f;
  --border:    #1e1e30;
  --accent:    #7c6bff;
  --accent-dim:#3d3580;
  --alpha:     #7c6bff;
  --theta:     #4facde;
  --text:      #e8e6f0;
  --text-muted:#6b6880;
  --radius:    14px;
  --transition:0.2s ease;
}

:root[data-theme="light"] {
  --bg:        #f4f3fa;
  --surface:   #ffffff;
  --border:    #dddaf0;
  --accent:    #6155e0;
  --accent-dim:#c2bef7;
  --alpha:     #6155e0;
  --theta:     #2f90c8;
  --text:      #1a1830;
  --text-muted:#8e8aaa;
}

/* ── Reset ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── App shell ───────────────────────────────── */
.app {
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.4rem;
  padding: 2rem 0;
  position: relative;
}

/* ── Header row (theme + info) ───────────────── */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

/* ── Wordmark ────────────────────────────────── */
.wordmark {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.wordmark-text {
  font-size: 1.15rem;
  font-weight: 300;
  letter-spacing: 0.18em;
  color: var(--text);
  user-select: none;
}

/* Theme btn inside wordmark: borderless, icon-only */
.wordmark .theme-btn {
  border-color: transparent;
  background: none;
  width: 28px;
  height: 28px;
  color: var(--text-muted);
}

.wordmark .theme-btn:hover {
  border-color: transparent;
  background: none;
  color: var(--accent);
}

.info-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), color var(--transition),
              background var(--transition);
}

.info-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(124, 107, 255, 0.08);
}

/* ── Modal body text ─────────────────────────── */
.modal-body {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.modal-body strong { color: var(--text); font-weight: 600; }

.modal-cite {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.65;
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.modal-cite-inline {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.8;
}

/* ── Theme toggle ────────────────────────────── */
.theme-btn {
  position: static;
  align-self: center;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), color var(--transition),
              background var(--transition);
}

.theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(124, 107, 255, 0.08);
}

.theme-btn .icon-sun  { display: none; }
.theme-btn .icon-moon { display: block; }

:root[data-theme="light"] .theme-btn .icon-sun  { display: block; }
:root[data-theme="light"] .theme-btn .icon-moon { display: none; }

.tagline {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.tip {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: rgba(124, 107, 255, 0.06);
  border: 1px solid rgba(124, 107, 255, 0.15);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  width: 100%;
  line-height: 1.4;
}

/* ── Band groups (BWE panel) ─────────────────── */
.band-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.band-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.band-label.alpha { color: var(--alpha); }
.band-label.theta { color: var(--theta); }

/* ── Technique pills ─────────────────────────── */
.technique-pills {
  display: flex;
  gap: 0.3rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 2rem;
  padding: 0.25rem;
  width: 100%;
}

.technique-pill {
  flex: 1;
  padding: 0.4rem 0;
  font-size: 0.78rem;
  font-weight: 500;
  border: none;
  border-radius: 1.5rem;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  letter-spacing: 0.01em;
}

.technique-pill.active {
  background: var(--accent-dim);
  color: var(--text);
}

/* ── Presets ─────────────────────────────────── */
.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
}

.preset {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
  text-align: left;
}

.preset-icon {
  display: flex;
  flex-shrink: 0;
  color: var(--text-muted);
}

.preset-icon svg {
  width: 18px;
  height: 18px;
}

.preset.active[data-band="alpha"] .preset-icon { color: var(--alpha); }
.preset.active[data-band="theta"] .preset-icon { color: var(--theta); }

.preset:hover {
  border-color: var(--accent-dim);
}

.preset.active[data-band="alpha"] {
  border-color: var(--alpha);
  background: rgba(124, 107, 255, 0.08);
  box-shadow: 0 0 18px rgba(124, 107, 255, 0.15);
}

.preset.active[data-band="theta"] {
  border-color: var(--theta);
  background: rgba(79, 172, 222, 0.08);
  box-shadow: 0 0 18px rgba(79, 172, 222, 0.15);
}

.preset-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.preset-name {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.preset-hz {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.preset.active .preset-hz                        { color: var(--accent); }
.preset.active[data-band="theta"] .preset-hz     { color: var(--theta); }

/* ── Preset situational sub-label ───────────── */
.preset-context {
  font-size: 0.63rem;
  color: var(--text-muted);
  opacity: 0.65;
  line-height: 1.2;
  font-style: italic;
}

/* ── Band descriptions ───────────────────────── */
.band-hint {
  display: flex;
  gap: 0.6rem;
  font-size: 0.70rem;
}

.band-hint-alpha { color: var(--alpha); opacity: 0.75; }
.band-hint-sep   { color: var(--text-muted); }
.band-hint-theta { color: var(--theta); opacity: 0.75; }

/* ── Panels ──────────────────────────────────── */
#panel-bwe {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.2rem;
  width: 100%;
}


/* ── Play area ───────────────────────────────── */
.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.timer {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  transition: color var(--transition);
}

.timer.running { color: var(--accent); }
.timer.ending  { color: #e05c5c; }

.timer-options {
  display: flex;
  gap: 0.35rem;
}

.timer-opt {
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.timer-opt:hover { border-color: var(--accent-dim); color: var(--text); }

.timer-opt.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Rescue (5m): background fill when active to distinguish it from other selections */
.timer-opt.timer-opt-rescue.active {
  background: rgba(124, 107, 255, 0.15);
}

/* ── Visualiser ──────────────────────────────── */
.viz-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 200px;
  height: 200px;
}

#viz-canvas {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#viz-canvas.active { opacity: 1; }

/* ── Play button ─────────────────────────────── */
.play-btn {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), box-shadow var(--transition),
              transform var(--transition);
}

.play-btn svg {
  width: 32px;
  height: 32px;
}

.play-btn:hover {
  background: rgba(124, 107, 255, 0.1);
  box-shadow: 0 0 28px rgba(124, 107, 255, 0.3);
}

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

.play-btn.playing {
  background: rgba(124, 107, 255, 0.15);
  box-shadow: 0 0 36px rgba(124, 107, 255, 0.4);
  animation: breathe 10s ease-in-out infinite;
}

.play-btn.playing[data-band="theta"] {
  border-color: var(--theta);
  color: var(--theta);
  background: rgba(79, 172, 222, 0.12);
  animation: breathe-theta 10s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% {
    transform: scale(0.7);
    box-shadow: 0 0 18px rgba(124, 107, 255, 0.2);
  }
  50% {
    transform: scale(1.0);
    box-shadow: 0 0 48px rgba(124, 107, 255, 0.55);
  }
}

@keyframes breathe-theta {
  0%, 100% {
    transform: scale(0.7);
    box-shadow: 0 0 18px rgba(79, 172, 222, 0.2);
  }
  50% {
    transform: scale(1.0);
    box-shadow: 0 0 48px rgba(79, 172, 222, 0.5);
  }
}

/* ── Music section ───────────────────────────── */
.music-section {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  width: 100%;
}

.music-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.music-styles {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: center;
}

.style-opt {
  padding: 0.25rem 0.65rem;
  font-size: 0.72rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.style-opt:hover { border-color: var(--accent-dim); color: var(--text); }

.style-opt.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Music on/off toggle ─────────────────────── */
.music-toggle {
  flex-shrink: 0;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  padding: 0;
}

.music-toggle[aria-pressed="false"] {
  background: var(--border);
}

.music-toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
}

.music-toggle[aria-pressed="true"] .music-toggle-knob {
  transform: translateX(14px);
}

.music-section.music-off .music-label,
.music-section.music-off .music-slider,
.music-section.music-off .music-styles {
  opacity: 0.35;
  pointer-events: none;
}

.music-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.music-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: box-shadow var(--transition);
}

.music-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 10px var(--accent);
}

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

/* ── Notice ──────────────────────────────────── */
.notice {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  transition: opacity var(--transition);
}

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

/* ── Headphone routing warning ───────────────── */
.headphone-warn {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: #c9922a;
  background: rgba(201, 146, 42, 0.09);
  border: 1px solid rgba(201, 146, 42, 0.28);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  width: 100%;
  line-height: 1.4;
}

.headphone-warn.hidden { display: none; }

:root[data-theme="light"] .headphone-warn {
  color: #8a5e00;
  background: rgba(201, 146, 42, 0.10);
  border-color: rgba(201, 146, 42, 0.35);
}

/* ── Footer ──────────────────────────────────── */
.footer {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.5;
  letter-spacing: 0.04em;
  text-align: center;
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition), opacity var(--transition);
}

.footer-link:hover {
  border-bottom-color: var(--text-muted);
  opacity: 1;
}

.footer-btn {
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 0;
  font: inherit;
  font-size: 0.68rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color var(--transition), opacity var(--transition);
}

.footer-btn:hover {
  border-bottom-color: var(--text-muted);
  opacity: 1;
}

/* ── Smooth-start toggle ─────────────────────── */
.smooth-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.smooth-btn {
  flex-shrink: 0;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  padding: 0;
}

.smooth-btn[aria-pressed="false"] { background: var(--border); }

.smooth-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
}

.smooth-btn[aria-pressed="true"] .smooth-knob { transform: translateX(14px); }

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

/* ── Modals (shared) ─────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

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

.modal {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(340px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal.modal-wide { width: min(480px, 92vw); }

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

.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.2rem 0.4rem;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.modal-close:hover { color: var(--text); background: var(--border); }

.modal-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition);
}

.modal-btn:hover { opacity: 0.88; box-shadow: 0 0 18px rgba(124, 107, 255, 0.35); }

.modal-btn-link {
  display: block;
  text-align: center;
  text-decoration: none;
}

.modal-link-btn {
  background: none;
  border: none;
  width: 100%;
  padding: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: color var(--transition);
}

.modal-link-btn:hover { color: var(--text); }

/* ── SUDS modal ──────────────────────────────── */
.suds-display {
  text-align: center;
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.suds-unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
}

.suds-slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.suds-input {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.suds-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: box-shadow var(--transition);
}

.suds-input::-webkit-slider-thumb:hover { box-shadow: 0 0 12px var(--accent); }

.suds-input::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.suds-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ── History modal ───────────────────────────── */
.history-chart-wrap {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}

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

.history-table-wrap { overflow-x: auto; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
  min-width: 340px;
}

.history-table th {
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.history-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.history-table tr:last-child td { border-bottom: none; }

.history-delta-pos { color: #4caf7d; }
.history-delta-neg { color: #e05c5c; }

.history-empty {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem 0;
}

.history-empty.hidden { display: none; }
