:root {
  --bg-deep: #0d1117;
  --bg-mid: #161b26;
  --panel: #1a2030;
  --panel-border: #2a3244;
  --text: #e8ecf3;
  --text-dim: #9aa5b8;
  --accent: #6fa8dc;
  --accent-soft: rgba(111, 168, 220, 0.25);
  --radius: 14px;
  --transition-slow: 1.4s ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Start overlay ---------- */

.start-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1b2436, #0d1117 75%);
  z-index: 100;
}

.start-card {
  text-align: center;
  padding: 2rem;
  max-width: 360px;
}

.start-card h1 {
  font-size: 2rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  letter-spacing: 0.02em;
}

.start-card p {
  color: var(--text-dim);
  margin: 0 0 1.75rem;
  line-height: 1.5;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 999px;
  padding: 0.85rem 2.25rem;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.97); }

/* ---------- App shell ---------- */

.app {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg-deep), var(--bg-mid) 60%, var(--bg-deep));
}

.scene-video {
  position: absolute;
  inset: -6%;
  width: 112%;
  height: 112%;
  object-fit: cover;
  opacity: 0;
  will-change: transform, opacity;
  pointer-events: none;
  animation: photo-drift var(--photo-duration, 42s) ease-in-out infinite alternate;
  transition: opacity 1.8s ease, filter 0.6s ease;
}

@keyframes photo-drift {
  0%   { transform: scale(1.04) translate(0, 0); }
  100% { transform: scale(1.14) translate(-2.5%, -1.5%); }
}

@media (prefers-reduced-motion: reduce) {
  .scene-video { animation: none; }
}

.scene-blob {
  position: absolute;
  width: 58vmax;
  height: 58vmax;
  top: var(--blob-top, 20%);
  left: var(--blob-left, 20%);
  border-radius: 50%;
  background: var(--blob-color, var(--accent));
  filter: blur(70px);
  opacity: 0;
  mix-blend-mode: screen;
  will-change: transform, opacity;
  pointer-events: none;
  animation: blob-drift var(--blob-duration, 26s) ease-in-out infinite alternate;
  animation-delay: var(--blob-delay, 0s);
  transition: opacity 1.4s ease;
}

@keyframes blob-drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(5%, -4%) scale(1.15); }
  100% { transform: translate(-4%, 4%) scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
  .scene-blob { animation: none; }
}

.freq-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.freq-canvas[hidden] {
  display: none;
}

.scene-mode-bar {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 5;
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 899px) {
  .scene-mode-bar {
    left: 1.25rem;
    right: 1.25rem;
    justify-content: flex-end;
  }
}

.scene-mode-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(22, 27, 38, 0.7);
  backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.8rem;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.scene-mode-btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.scene-mode-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.scene-mode-btn.is-active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 520px) {
  .scene-mode-btn span { display: none; }
  .scene-mode-btn { padding: 0.6rem; }
}

/* ---------- Drawer toggle (mobile) ---------- */

.drawer-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.drawer-toggle span {
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

@media (min-width: 900px) {
  .drawer-toggle { display: none; }
}

/* ---------- Mixer sidebar / drawer ---------- */

.mixer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(88vw, 440px);
  background: var(--bg-mid);
  border-right: 1px solid var(--panel-border);
  z-index: 15;
  overflow-y: auto;
  padding: 0.55rem 1.1rem 0.55rem;
  transform: translateX(-520px);
  transition: transform 0.28s ease;
}

.mixer.open { transform: translateX(0); }

@media (min-width: 900px) {
  .mixer { transform: translateX(0); }
  .app { padding-left: min(88vw, 440px); }
}

.mixer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  padding-left: 52px;
}

@media (min-width: 900px) {
  .mixer-header { padding-left: 0; }
}

.mixer-header h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.panel {
  margin-bottom: 0.26rem;
}

.panel h2 {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 0.3rem;
  font-weight: 600;
}

/* ---------- Presets ---------- */

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preset-chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 999px;
  padding: 0.32rem 0.85rem;
  font-size: 0.88rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.preset-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.preset-chip.is-locked {
  opacity: 0.5;
}

/* ---------- Layers ---------- */

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.layer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.22rem 0.6rem;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  transition: border-color 0.2s ease;
}

.layer.is-active {
  border-color: var(--layer-color, var(--accent));
}

.layer.is-locked {
  cursor: pointer;
}

.layer.is-locked .layer-slider {
  pointer-events: none;
  opacity: 0.35;
}

.layer.is-locked .layer-value {
  opacity: 0.5;
}

.layer-icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--layer-color, var(--accent)) 22%, transparent);
  color: var(--layer-color, var(--accent));
}

.layer-icon svg { width: 16px; height: 16px; }

.layer-name {
  flex: 0 0 auto;
  width: 5.4rem;
  font-size: 0.92rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-slider {
  flex: 1 1 auto;
  min-width: 0;
}

.layer-value {
  flex: 0 0 auto;
  width: 2.7rem;
  text-align: right;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.layer-env-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.layer-env-btn:hover {
  color: var(--text);
  background: var(--panel-border);
}

.layer-env-btn svg {
  width: 15px;
  height: 15px;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--panel-border);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--layer-color, var(--accent));
  cursor: pointer;
  border: 2px solid var(--bg-mid);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--layer-color, var(--accent));
  cursor: pointer;
  border: 2px solid var(--bg-mid);
}

/* ---------- Save / saved mixes ---------- */

.save-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.save-row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
}

input[type="text"], input[type="number"] {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 10px;
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.btn-secondary:hover { background: var(--accent-soft); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  font-size: 0.8rem;
}

.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.saved-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
}

.saved-list .saved-actions {
  display: flex;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.saved-list button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
}

.saved-list button:hover { color: var(--accent); }
.saved-list .delete-btn:hover { color: #e0793c; }

.empty-hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-style: italic;
}

/* ---------- Sleep timer ---------- */

.timer-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.btn-timer {
  flex: 1 1 auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.4rem 0.35rem;
  font-size: 0.78rem;
}

.btn-timer:hover { border-color: var(--accent); }
.btn-timer.is-active { background: var(--accent-soft); border-color: var(--accent); }

#customMinutes { width: 70px; }

.timer-status {
  font-size: 0.85rem;
  color: var(--text-dim);
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

/* ---------- Get Ambiens (install links) ---------- */

.get-ambiens {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0;
  margin-top: 0.2rem;
}

.get-ambiens-link {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 9px;
  padding: 0.35rem 0.4rem;
  font-size: 0.72rem;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.get-ambiens-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.get-ambiens-link svg {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
}

.get-ambiens-link.is-disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: default;
}

.get-ambiens-link .coming-soon {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
}

#proBadge {
  font-family: inherit;
}

#proBadge.is-pro-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Pro modal ---------- */

.pro-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pro-modal[hidden] {
  display: none;
}

.pro-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.pro-modal-card {
  position: relative;
  background: var(--bg-mid);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 320px;
  width: 90%;
  text-align: left;
}

.pro-modal-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.pro-modal-card p {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0 0 1rem;
}

.pro-modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.2rem;
}

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

.pro-buy-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-bottom: 1rem;
}

.pro-activate-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.pro-activate-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.pro-status {
  font-size: 0.8rem;
  min-height: 1.2em;
  color: var(--text-dim);
}

.pro-status.is-error {
  color: #e0793c;
}

.pro-status.is-success {
  color: #6aa84f;
}
