/* ===================================================
   MEDITATION APP — style.css
   =================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --color-bg-1: #1a1a2e;
  --color-bg-2: #16213e;
  --color-bg-3: #0f3460;
  --color-bg-4: #533483;

  --color-accent:  #b39ddb;
  --color-active:  #ce93d8;
  --color-active-hover: #d9a8e4;

  --color-text:       rgba(255, 255, 255, 0.90);
  --color-text-muted: rgba(255, 255, 255, 0.55);
  --color-text-dim:   rgba(255, 255, 255, 0.35);

  --glass-bg:     rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-blur:   blur(14px);

  --transition-std:  0.4s ease-in-out;
  --transition-slow: 0.6s ease-in-out;

  --font-primary: 'Roboto', sans-serif;

  --radius-pill: 999px;
  --radius-card: 24px;
  --radius-btn:  12px;

  --phase-duration: 4s;
}

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

/* ---------- Base / Background ---------- */
html, body {
  height: 100%;
  font-family: var(--font-primary);
  color: var(--color-text);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background: linear-gradient(
    -45deg,
    var(--color-bg-1),
    var(--color-bg-2),
    var(--color-bg-3),
    var(--color-bg-4)
  );
  background-size: 400% 400%;
  animation: gradientShift 20s ease infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Particle Canvas ---------- */
#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ---------- App Wrapper & Card ---------- */
#app-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  min-height: 100vh;
}

#app-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: clamp(1.75rem, 4vw, 2.75rem) clamp(1.5rem, 4vw, 2.5rem);
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

/* ---------- Header ---------- */
#app-header {
  text-align: center;
}

.app-title {
  font-size: clamp(1.75rem, 5vw, 2.4rem);
  font-weight: 300;
  letter-spacing: 0.18em;
  color: var(--color-text);
  text-transform: uppercase;
}

.app-subtitle {
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--color-text-muted);
  letter-spacing: 0.12em;
  margin-top: 0.25rem;
}

/* ---------- Notices ---------- */
#notices {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notice {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--color-accent);
  text-align: center;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgba(179, 157, 219, 0.25);
  border-radius: 8px;
  background: rgba(179, 157, 219, 0.06);
  line-height: 1.5;
}

.notice--action {
  border-color: rgba(206, 147, 216, 0.35);
  background: rgba(206, 147, 216, 0.08);
}

.notice-btn {
  background: none;
  border: none;
  color: var(--color-active);
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  transition: color var(--transition-std);
}

.notice-btn:hover,
.notice-btn:focus-visible {
  color: var(--color-active-hover);
  outline: 2px solid var(--color-active);
  outline-offset: 3px;
  border-radius: 4px;
  text-decoration: none;
}

/* ---------- Breathing Section ---------- */
#breathing-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

#breathing-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(179, 157, 219, 0.18), rgba(179, 157, 219, 0.04));
  border: 2px solid rgba(179, 157, 219, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Completely static — no transitions, no shadow, no scaling ever */
}

/* Inner orb — this is what animates */
#breathing-inner {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(206, 147, 216, 0.55), rgba(179, 157, 219, 0.15));
  border: 1px solid rgba(206, 147, 216, 0.35);
  /* Resting: small */
  transform: scale(0.45);
  transition: transform 4s ease-in-out;
}

/* Inhale — inner orb expands smoothly */
#breathing-ring[data-breathe="in"] #breathing-inner {
  transform: scale(1.72);
}

/* Hold after inhale — stay expanded, instant */
#breathing-ring[data-breathe="hold-in"] #breathing-inner {
  transform: scale(1.72);
  transition-duration: 0s;
}

/* Exhale — inner orb contracts smoothly */
#breathing-ring[data-breathe="out"] #breathing-inner {
  transform: scale(0.45);
}

/* Hold after exhale / rest — inner orb stays contracted, instant */

#breathing-ring[data-breathe="hold-out"] #breathing-inner {
  transform: scale(0.45);
  transition-duration: 0s;
}

.breathing-label {
  font-size: 0.8rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  text-transform: uppercase;
  transition: opacity var(--transition-std);
}

/* ---------- Timer ---------- */
#timer-display {
  font-family: 'Roboto Mono', monospace;
  font-size: clamp(2.8rem, 10vw, 4rem);
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--color-text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: opacity var(--transition-std);
}

/* ---------- On-Screen Cue ---------- */
.onscreen-cue {
  min-height: 1.4em;
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--color-accent);
  text-align: center;
  font-style: italic;
  letter-spacing: 0.04em;
  line-height: 1.5;
  transition: opacity 0.5s ease-in-out;
}

/* ---------- Soundscape Selector ---------- */
#soundscape-nav {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: nowrap;
  width: 100%;
}

.soundscape-btn {
  border-radius: var(--radius-pill);
  padding: 0.38rem 0;
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 400;
  flex: 1;
  text-align: center;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition:
    background var(--transition-std),
    color var(--transition-std),
    border-color var(--transition-std),
    transform 0.15s ease;
}

.soundscape-btn:hover,
.soundscape-btn:focus-visible {
  background: rgba(206, 147, 216, 0.12);
  color: var(--color-text);
  border-color: rgba(206, 147, 216, 0.45);
  outline: none;
}

.soundscape-btn[aria-pressed="true"] {
  background: var(--color-active);
  color: #fff;
  border-color: var(--color-active);
  font-weight: 500;
}

.soundscape-btn:active { transform: scale(0.95); }
.soundscape-btn:focus-visible { outline: 2px solid var(--color-active); outline-offset: 3px; }

/* ---------- Duration Selector ---------- */
#duration-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.duration-btn {
  border-radius: var(--radius-pill);
  padding: 0.35rem 1rem;
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition:
    background var(--transition-std),
    color var(--transition-std),
    border-color var(--transition-std),
    transform 0.15s ease;
}

.duration-btn:hover,
.duration-btn:focus-visible {
  background: rgba(206, 147, 216, 0.12);
  color: var(--color-text);
  border-color: rgba(206, 147, 216, 0.45);
  outline: none;
}

.duration-btn[aria-pressed="true"] {
  background: var(--color-active);
  color: #fff;
  border-color: var(--color-active);
  font-weight: 500;
}

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

.duration-btn:focus-visible {
  outline: 2px solid var(--color-active);
  outline-offset: 3px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-primary);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-btn);
  padding: 0.65rem 1.6rem;
  transition:
    background var(--transition-std),
    color var(--transition-std),
    transform 0.15s ease,
    box-shadow var(--transition-std);
}

.btn:focus-visible {
  outline: 2px solid var(--color-active);
  outline-offset: 3px;
}

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

.btn--primary {
  background: rgba(206, 147, 216, 0.22);
  color: var(--color-text);
  border: 1px solid rgba(206, 147, 216, 0.4);
}

.btn--primary:hover {
  background: rgba(206, 147, 216, 0.35);
  box-shadow: 0 4px 16px rgba(206, 147, 216, 0.2);
}

.btn--secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-muted);
  border: 1px solid var(--glass-border);
  font-size: 0.8rem;
  padding: 0.55rem 1.2rem;
}

.btn--secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
}

.btn--icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.btn--icon:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Controls Row ---------- */
#controls {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- Audio Controls ---------- */
#audio-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  justify-content: center;
}

#volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--color-active) 0%,
    var(--color-active) 40%,
    rgba(255, 255, 255, 0.15) 40%,
    rgba(255, 255, 255, 0.15) 100%
  );
  outline: none;
  cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-active);
  cursor: pointer;
  transition: transform 0.15s ease;
}

#volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

#volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-active);
  cursor: pointer;
  border: none;
}

#volume-slider:focus-visible {
  outline: 2px solid var(--color-active);
  outline-offset: 4px;
  border-radius: 4px;
}

.volume-label {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  min-width: 2.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}


/* ---------- Breathing Voice Toggle ---------- */
#breathing-voice-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.btn--toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.4rem;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 400;
  cursor: pointer;
  transition:
    background var(--transition-std),
    color var(--transition-std),
    border-color var(--transition-std),
    box-shadow var(--transition-std);
}

.btn--toggle:hover {
  background: rgba(206, 147, 216, 0.1);
  color: var(--color-text);
  border-color: rgba(206, 147, 216, 0.4);
}

.btn--toggle[aria-pressed="true"] {
  background: rgba(206, 147, 216, 0.18);
  border-color: var(--color-active);
  color: var(--color-active);
  box-shadow: 0 0 12px rgba(206, 147, 216, 0.25);
}

.btn--toggle[aria-pressed="true"] .toggle-label::after {
  content: ' On';
  font-weight: 500;
}

.btn--toggle[aria-pressed="false"] .toggle-label::after {
  content: ' Off';
}

.btn--toggle:focus-visible {
  outline: 2px solid var(--color-active);
  outline-offset: 3px;
}

/* ---------- Completion Screen ---------- */
#completion-screen {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.completion-icon {
  font-size: 2.2rem;
  animation: fadeInUp 0.6s ease-in-out;
}

.completion-title {
  font-size: 1.4rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: var(--color-text);
}

.completion-subtitle {
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: 28ch;
}

/* ---------- Keyframe Animations ---------- */
@keyframes gradientShift {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0%   50%; }
}


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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- State-Driven Visibility ----------
   html[data-state] drives which elements are shown.
   CSS display:none is applied here; JS adds/removes `hidden`
   as a belt-and-suspenders backup.
   ----------------------------------------------- */

/* === IDLE: show start + duration nav, hide everything session-specific === */
html[data-state="idle"] #pause-btn,
html[data-state="idle"] #resume-btn,
html[data-state="idle"] #end-btn,
html[data-state="idle"] #breathing-section,
html[data-state="idle"] #completion-screen {
  display: none !important;
}

/* === ACTIVE: show pause + end, hide start + duration + completion === */
html[data-state="active"] #start-btn,
html[data-state="active"] #resume-btn,
html[data-state="active"] #duration-nav,
html[data-state="active"] #completion-screen {
  display: none !important;
}

html[data-state="active"] #breathing-section {
  display: flex;
  animation: fadeIn 0.6s ease-in-out;
}

/* === PAUSED: show resume + end, hide start/pause/duration/completion === */
html[data-state="paused"] #start-btn,
html[data-state="paused"] #pause-btn,
html[data-state="paused"] #duration-nav,
html[data-state="paused"] #completion-screen {
  display: none !important;
}

html[data-state="paused"] #breathing-section {
  display: flex;
  opacity: 0.45;
}

/* === COMPLETE: show completion screen only, hide controls/timer/breathing === */
html[data-state="complete"] #controls,
html[data-state="complete"] #duration-nav,
html[data-state="complete"] #breathing-section,
html[data-state="complete"] #timer-display,
html[data-state="complete"] #audio-controls,
html[data-state="complete"] .onscreen-cue {
  display: none !important;
}

html[data-state="complete"] #completion-screen {
  display: flex !important;
  animation: fadeInUp 0.7s ease-in-out;
}

/* ---------- Scrollbar Styling ---------- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(179, 157, 219, 0.3);
  border-radius: 3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 400px) {
  #duration-nav {
    gap: 0.4rem;
  }
  .duration-btn {
    padding: 0.3rem 0.75rem;
    font-size: 0.72rem;
  }
  #app-card {
    gap: 1rem;
  }
}

@media (min-width: 600px) {
  #duration-nav {
    flex-wrap: nowrap;
  }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  body {
    animation: none;
    background: var(--color-bg-1);
  }
}
