/* ============================================
   Bilateral — EMDR Bilateral Stimulation
   Design philosophy: The science says LESS.
   Working memory taxation requires the dot to
   be the only attentional demand. Empty space
   is therapeutic. Darkness is intentional.
   ============================================ */

:root {
  --bg: #06060A;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-solid: #111116;
  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(245, 166, 35, 0.25);

  --amber: #F5A623;
  --amber-50: rgba(245, 166, 35, 0.5);
  --amber-20: rgba(245, 166, 35, 0.2);
  --amber-08: rgba(245, 166, 35, 0.08);
  --amber-04: rgba(245, 166, 35, 0.04);

  --text: #E0D8CE;
  --text-dim: #7A746C;
  --text-faint: #3A3630;

  --teal: #4ECDC4;
  --red-subtle: rgba(220, 80, 60, 0.12);

  --dot-color: var(--amber);
  --dot-size: 22px;

  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============================================
   THE CANVAS — Full viewport. The dot's world.
   ============================================ */

#canvas {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  /* Subtle vignette — draws eyes to center */
  background:
    radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.4) 100%),
    var(--bg);
}

/* ---- The Dot ---- */
#dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--dot-size);
  height: var(--dot-size);
  will-change: left;
  z-index: 2;
  pointer-events: none;
}

.dot-core {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--dot-color);
  box-shadow:
    0 0 6px 2px var(--dot-color),
    0 0 15px 5px color-mix(in srgb, var(--dot-color) 50%, transparent),
    0 0 40px 10px color-mix(in srgb, var(--dot-color) 20%, transparent),
    0 0 80px 20px color-mix(in srgb, var(--dot-color) 8%, transparent);
  transition: transform 0.3s var(--ease);
}

/* Idle breathing */
#dot.idle .dot-core {
  animation: dot-breathe 4s ease-in-out infinite;
}

@keyframes dot-breathe {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* ---- Rest Screen ---- */
#rest-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fade-in 0.8s ease;
}

.breath-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid var(--amber-20);
  animation: breathe-ring 8s ease-in-out infinite;
  margin-bottom: 32px;
  position: relative;
}

.breath-ring::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--amber-04);
  animation: breathe-fill 8s ease-in-out infinite;
}

@keyframes breathe-ring {
  0%, 100% { transform: scale(0.7); border-color: var(--amber-20); }
  50% { transform: scale(1.1); border-color: var(--amber-50); }
}

@keyframes breathe-fill {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 0.6; transform: scale(1); }
}

.rest-prompt {
  font-size: 22px;
  font-weight: 300;
  color: var(--teal);
  letter-spacing: 0.02em;
  animation: fade-in 1s ease 0.3s both;
}

.rest-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 8px;
  animation: fade-in 1s ease 0.6s both;
}

/* ---- Complete Screen ---- */
#complete-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fade-in 0.8s ease;
}

.complete-title {
  font-size: 24px;
  font-weight: 300;
  color: var(--teal);
  margin-bottom: 8px;
}

.complete-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

/* ---- Intro ---- */
#intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(6, 6, 10, 0.92);
  animation: fade-in 0.5s ease;
}

.intro-text {
  font-size: 18px;
  font-weight: 300;
  color: var(--text);
  text-align: center;
  line-height: 1.7;
  margin-bottom: 28px;
  max-width: 320px;
}

/* ============================================
   CONTROLS — Floating bar at bottom
   ============================================ */

#controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  transition: opacity 0.6s ease;
}

body.immersed #controls {
  opacity: 0.08;
  pointer-events: none;
}

body.immersed #controls:hover,
body.immersed.touch-reveal #controls {
  opacity: 1;
  pointer-events: auto;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(12, 12, 18, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 6px 12px;
  max-width: 520px;
}

.ctrl-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* Transport buttons */
.btn-start {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--amber);
  color: #0A0A0A;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.btn-start:hover {
  background: #FFB93A;
  transform: scale(1.06);
  box-shadow: 0 0 20px var(--amber-20);
}

.btn-start:active { transform: scale(0.96); }

.btn-stop {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

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

/* Mode pills */
.mode-pill {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.mode-pill:hover {
  color: var(--text-dim);
  background: var(--surface);
}

.mode-pill.active {
  color: var(--amber);
  border-color: var(--amber-20);
  background: var(--amber-04);
}

.mode-pill.active svg { stroke: var(--amber); }

/* Speed inline */
.speed-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 90px;
}

.speed-label {
  font-size: 11px;
  color: var(--amber);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
}

/* Icon buttons */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.btn-icon:hover { color: var(--text-dim); background: var(--surface); }
.btn-icon.open { color: var(--amber); }

/* Set progress bar */
#set-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  animation: fade-in 0.3s ease;
}

#set-dots { display: flex; gap: 5px; }

.sdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.3s var(--ease);
}

.sdot.done {
  background: var(--amber);
  border-color: var(--amber);
  box-shadow: 0 0 6px var(--amber-20);
}

.sdot.now {
  border-color: var(--amber);
  background: var(--amber-50);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 3px var(--amber-08); }
  50% { box-shadow: 0 0 10px var(--amber-20); }
}

.timer-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
}

/* ============================================
   DRAWERS — Slide-up panels for settings/info
   ============================================ */

.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface-solid);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  transform: translateY(0);
  animation: slide-up 0.3s var(--ease);
  overscroll-behavior: contain;
}

.drawer.hidden {
  display: none !important;
}

@keyframes slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto;
  cursor: pointer;
}

.drawer-body {
  padding: 0 20px 28px;
}

.drawer-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 18px;
}

.setting-section {
  margin-bottom: 22px;
}

.setting-section h4 {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.s-note {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  margin-bottom: 10px;
}

.s-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.s-row > span:first-child {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 72px;
  flex-shrink: 0;
}

.s-val {
  font-size: 11px;
  color: var(--amber);
  font-weight: 500;
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ---- Sliders ---- */
.slider-mini, .slider-sm {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  flex: 1;
}

.slider-mini::-webkit-slider-thumb, .slider-sm::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 6px var(--amber-08);
}

.slider-mini::-moz-range-thumb, .slider-sm::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  cursor: pointer;
}

/* ---- Chips ---- */
.chip-row { display: flex; gap: 6px; margin-bottom: 12px; }

.chip {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.chip:hover { border-color: var(--text-faint); color: var(--text); }

.chip.active {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-04);
}

/* ---- Swatches ---- */
.swatch-row { display: flex; gap: 8px; }

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--sw);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.swatch:hover { transform: scale(1.15); }

.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--sw);
}

/* ---- Toggle ---- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 4px;
}

.toggle-row input { display: none; }

.toggle-track {
  width: 32px;
  height: 18px;
  background: rgba(255,255,255,0.06);
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
}

.toggle-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-faint);
  top: 3px;
  left: 3px;
  transition: all 0.2s var(--ease);
}

.toggle-row input:checked + .toggle-track {
  background: var(--amber-20);
}

.toggle-row input:checked + .toggle-track .toggle-thumb {
  transform: translateX(14px);
  background: var(--amber);
}

/* ---- Guide / Safety ---- */
.guide-list {
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.guide-list li {
  counter-increment: step;
  padding-left: 30px;
  position: relative;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}

.guide-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--amber-04);
  color: var(--amber);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-list li strong { color: var(--text); font-weight: 500; }

.theory-box {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 16px;
}

.theory-box h4 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 10px;
}

.theory-box p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 8px;
}

.theory-box p:last-child { margin-bottom: 0; }

.theory-box strong { color: var(--text); font-weight: 500; }
.theory-box em { color: var(--amber); font-style: normal; font-weight: 500; }

.theory-note {
  margin-top: 12px !important;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-style: italic !important;
  color: var(--text-faint) !important;
}

.safety-box {
  padding: 14px;
  border: 1px solid var(--red-subtle);
  border-radius: 10px;
  background: rgba(220, 80, 60, 0.03);
  margin-bottom: 20px;
}

.safety-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}

.safety-box p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 6px;
}

.crisis {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--red-subtle);
  font-size: 12px;
  color: var(--text-dim);
}

.crisis a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.crisis a:hover { color: var(--amber); }

.footer-info {
  text-align: center;
  padding-top: 8px;
}

.footer-info p {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.footer-info a {
  color: var(--text-dim);
  text-decoration: none;
}

.footer-info a:hover { color: var(--amber); }

/* ---- Buttons ---- */
.btn-warm {
  padding: 10px 28px;
  border-radius: 24px;
  border: none;
  background: var(--amber);
  color: #0A0A0A;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.btn-warm:hover { background: #FFB93A; transform: translateY(-1px); }

.btn-ghost {
  padding: 8px 22px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

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

/* ---- Animations ---- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 500px) {
  .ctrl-row { padding: 5px 8px; gap: 4px; }
  .ctrl-divider { margin: 0 2px; }
  .speed-inline { min-width: 70px; }
  .btn-start { width: 38px; height: 38px; }
  .mode-pill, .btn-icon, .btn-stop { width: 30px; height: 30px; }
}

@media (min-width: 768px) {
  .ctrl-row { padding: 8px 16px; gap: 8px; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

::selection {
  background: var(--amber-08);
  color: var(--text);
}

/* Scrollbar for drawers */
.drawer::-webkit-scrollbar { width: 4px; }
.drawer::-webkit-scrollbar-track { background: transparent; }
.drawer::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
