/* ============================================================
   Breath Pacer — tool styles
   Color research: blue/green calms heart rate (J Environmental
   Psychology 2010). Apple Watch Breathe uses teal-green #61bea2.
   Color breathing therapy: inhale cool (teal/green = healing),
   exhale warm (coral/peach = release). Calm app: analogous
   blue-green. Muted pastels, not saturated neon.
   ============================================================ */

/* --- @property: register color vars so CSS can interpolate them --- */
@property --orb-color-inner { syntax: '<color>'; inherits: true; initial-value: #8cc8b8; }
@property --orb-color-mid   { syntax: '<color>'; inherits: true; initial-value: #5ca898; }
@property --orb-color-outer { syntax: '<color>'; inherits: true; initial-value: #3a8878; }
@property --orb-glow-1      { syntax: '<color>'; inherits: true; initial-value: rgba(140,200,184,0.35); }
@property --orb-glow-2      { syntax: '<color>'; inherits: true; initial-value: rgba(92,168,152,0.12); }
@property --orb-glow-3      { syntax: '<color>'; inherits: true; initial-value: rgba(58,136,120,0.04); }
@property --arc-color        { syntax: '<color>'; inherits: true; initial-value: rgba(140,200,184,0.25); }
@property --bp-ambient       { syntax: '<color>'; inherits: true; initial-value: rgba(80,160,140,0.07); }

/* --- Full-page immersion: the entire page is the breathing room --- */
.breath-pacer-page {
  --bp-frame-width: 720px;
  background: linear-gradient(175deg, #0c1820 0%, #081418 50%, #0b1620 100%);
  min-height: 100svh;
}

/* Shell, header, footer adapt to dark */
.breath-pacer-page .page-shell {
  background: transparent;
}

.breath-pacer-page .site-header {
  background: transparent;
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.breath-pacer-page .site-brand {
  color: rgba(255, 255, 255, 0.70);
}

.breath-pacer-page .site-brand:hover {
  color: rgba(255, 255, 255, 0.90);
}

.breath-pacer-page .section-tool-page {
  background: transparent;
}

.breath-pacer-page .tool-frame {
  max-width: var(--bp-frame-width);
}

.breath-pacer-page .tool-header-block {
  max-width: none;
}

/* Remove tool-shell card frame for seamless immersion */
.breath-pacer-page .tool-shell {
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.breath-pacer-page .page-title {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1;
  color: rgba(255, 255, 255, 0.90);
}

.breath-pacer-page .page-subtitle {
  max-width: 40ch;
  color: rgba(255, 255, 255, 0.50);
}

.breath-pacer-page .page-meta {
  margin: 0;
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.30);
}

/* Footer goes dark too */
.breath-pacer-page .site-footer {
  background: transparent;
  border-top-color: rgba(255, 255, 255, 0.06);
}

.breath-pacer-page .footer-title,
.breath-pacer-page .footer-copy {
  color: rgba(255, 255, 255, 0.50);
}

.breath-pacer-page .site-nav--footer a {
  color: rgba(255, 255, 255, 0.40);
}

.breath-pacer-page .site-nav--footer a:hover {
  color: rgba(255, 255, 255, 0.70);
}

.bp-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.bp-header-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* --- Language toggle --- */
.bp-lang-toggle {
  display: flex;
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  margin-top: 4px;
}

.bp-lang-btn {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-height: 0;
  line-height: 1.4;
}

.bp-lang-btn[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.80);
}

.bp-lang-btn:hover:not([aria-pressed="true"]) {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.60);
}

.bp-lang-btn:active:not([aria-pressed="true"]) {
  background: rgba(255, 255, 255, 0.12);
}

/* ============================================================
   Dark UI — deep dusk sky that the orb illuminates
   Background: saturated dark teal-navy, not cold grey-black.
   The radial ambient gradient shifts per phase so the WHOLE
   background breathes with the orb.
   ============================================================ */
.breath-pacer-ui {
  /* No separate panel background — the page IS the background.
     Only the ambient glow around the orb creates subtle depth. */
  background:
    radial-gradient(ellipse 80% 60% at 50% 36%,
      var(--bp-ambient, rgba(80, 160, 140, 0.07)) 0%,
      transparent 60%);
  padding: 52px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  overflow: hidden;
  transition:
    background 1.2s ease,
    --orb-color-inner 1.5s ease,
    --orb-color-mid 1.5s ease,
    --orb-color-outer 1.5s ease,
    --orb-glow-1 1.5s ease,
    --orb-glow-2 1.5s ease,
    --orb-glow-3 1.5s ease,
    --arc-color 1.5s ease,
    --bp-ambient 1.5s ease;

  /* ── Idle phase: soft teal invitation ── */
  --orb-color-inner: #8cc8b8;
  --orb-color-mid: #5ca898;
  --orb-color-outer: #3a8878;
  --orb-glow-1: rgba(140, 200, 184, 0.35);
  --orb-glow-2: rgba(92, 168, 152, 0.12);
  --orb-glow-3: rgba(58, 136, 120, 0.04);
  --orb-scale: 0.8;
  --arc-color: rgba(140, 200, 184, 0.25);
  --bp-ambient: rgba(80, 160, 140, 0.07);
}

/* ── Inhale: teal-green (healing, fresh air entering)
     Research: green = healing/balance, teal = calming.
     Apple Watch Breathe uses #61bea2. ── */
.breath-pacer-ui[data-phase="inhale"] {
  --orb-color-inner: #a0e8d0;
  --orb-color-mid: #60c8a8;
  --orb-color-outer: #38a888;
  --orb-glow-1: rgba(160, 232, 208, 0.50);
  --orb-glow-2: rgba(96, 200, 168, 0.18);
  --orb-glow-3: rgba(56, 168, 136, 0.06);
  --arc-color: rgba(120, 216, 188, 0.70);
  --bp-ambient: rgba(80, 200, 160, 0.12);
}

/* ── Hold-in: warm gold (steady, sunlit, held warmth)
     Color therapy: gold = stability, inner warmth.
     Like holding sunlight in your chest. ── */
.breath-pacer-ui[data-phase="hold_in"] {
  --orb-color-inner: #f2dca0;
  --orb-color-mid: #d8b868;
  --orb-color-outer: #c0a048;
  --orb-glow-1: rgba(242, 220, 160, 0.45);
  --orb-glow-2: rgba(216, 184, 104, 0.16);
  --orb-glow-3: rgba(192, 160, 72, 0.05);
  --arc-color: rgba(235, 210, 140, 0.70);
  --bp-ambient: rgba(216, 184, 104, 0.10);
}

/* ── Exhale: soft peach-coral (warm release, letting go)
     Color breathing: exhale warm/orange — complementary
     to the cool inhale. Like a sunset sigh. ── */
.breath-pacer-ui[data-phase="exhale"] {
  --orb-color-inner: #f2c0b0;
  --orb-color-mid: #d89880;
  --orb-color-outer: #c07860;
  --orb-glow-1: rgba(242, 192, 176, 0.45);
  --orb-glow-2: rgba(216, 152, 128, 0.16);
  --orb-glow-3: rgba(192, 120, 96, 0.05);
  --arc-color: rgba(235, 175, 155, 0.70);
  --bp-ambient: rgba(216, 152, 128, 0.10);
}

/* ── Hold-out: soft lavender (quiet stillness, rest)
     Color therapy: purple = introspection, calm between.
     The emptiness before the next breath. ── */
.breath-pacer-ui[data-phase="hold_out"] {
  --orb-color-inner: #c8b8e0;
  --orb-color-mid: #a898c8;
  --orb-color-outer: #8878b0;
  --orb-glow-1: rgba(200, 184, 224, 0.42);
  --orb-glow-2: rgba(168, 152, 200, 0.15);
  --orb-glow-3: rgba(136, 120, 176, 0.05);
  --arc-color: rgba(188, 172, 212, 0.70);
  --bp-ambient: rgba(168, 152, 200, 0.10);
}

/* ── Done: warm completion glow ── */
.breath-pacer-ui[data-phase="done"] {
  --orb-color-inner: #f0e8c8;
  --orb-color-mid: #d8d0a8;
  --orb-color-outer: #b8b088;
  --orb-glow-1: rgba(240, 232, 200, 0.50);
  --orb-glow-2: rgba(216, 208, 168, 0.18);
  --orb-glow-3: rgba(184, 176, 136, 0.06);
  --arc-color: rgba(230, 220, 180, 0.50);
  --bp-ambient: rgba(216, 208, 168, 0.10);
}

/* ============================================================
   Orb stage
   ============================================================ */
.bp-orb-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(260px, 56vw, 380px);
  height: clamp(260px, 56vw, 380px);
  cursor: pointer;
}

/* SVG arc — delicate timing ring */
.bp-arc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  overflow: visible;
}

.bp-arc-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.04);
  stroke-width: 2.5;
}

.bp-arc-progress {
  fill: none;
  stroke: var(--arc-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 816.81;
  stroke-dashoffset: 816.81;
  transition: stroke 1s ease;
}

/* Orb — container for layered breathing sphere.
   Layers (back to front):
   1. Glow: far-extending light spill
   2. Rings: 3 overlapping translucent circles (staggered drift → alive)
   3. Core: main sphere with specular highlight + organic shape wobble */
.bp-orb {
  position: relative;
  width: clamp(150px, 42vw, 220px);
  height: clamp(150px, 42vw, 220px);
  will-change: transform;
  z-index: 1;
}

/* Core — the visible sphere with 3D specular highlight */
.bp-orb-core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at var(--highlight-x, 36%) var(--highlight-y, 32%),
      rgba(255, 255, 255, 0.35) 0%,
      rgba(255, 255, 255, 0.06) 30%,
      transparent 50%),
    radial-gradient(circle at 50% 50%,
      var(--orb-color-inner) 0%,
      var(--orb-color-mid) 45%,
      var(--orb-color-outer) 78%,
      transparent 100%);
  animation: organic-shape 5s ease-in-out infinite;
}

/* Overlapping rings — staggered drift creates "alive" feel.
   mix-blend-mode: screen makes overlaps glow luminously. */
.bp-orb-ring {
  position: absolute;
  border-radius: 50%;
  mix-blend-mode: screen;
  pointer-events: none;
}

.bp-orb-ring--1 {
  inset: -3%;
  background: radial-gradient(circle, var(--orb-color-inner) 10%, transparent 68%);
  opacity: 0.30;
  animation: ring-drift-1 7s ease-in-out infinite;
}

.bp-orb-ring--2 {
  inset: -6%;
  background: radial-gradient(circle, var(--orb-color-mid) 8%, transparent 62%);
  opacity: 0.22;
  animation: ring-drift-2 9s ease-in-out infinite;
}

.bp-orb-ring--3 {
  inset: -10%;
  background: radial-gradient(circle, var(--orb-color-outer) 5%, transparent 55%);
  opacity: 0.15;
  animation: ring-drift-3 11s ease-in-out infinite;
}

/* Glow — 3-layer radial for realistic light spill */
.bp-orb-glow {
  position: absolute;
  top: -65%; right: -65%; bottom: -65%; left: -65%;
  border-radius: 50%;
  background:
    radial-gradient(circle,
      var(--orb-glow-1) 0%,
      var(--orb-glow-2) 28%,
      var(--orb-glow-3) 50%,
      transparent 68%);
  pointer-events: none;
  transition: top 1.5s ease, right 1.5s ease, bottom 1.5s ease, left 1.5s ease;
}

/* Hold phase: slow glow bloom to reinforce the stillness visually */
.breath-pacer-ui[data-phase="hold_in"] .bp-orb-glow,
.breath-pacer-ui[data-phase="hold_out"] .bp-orb-glow {
  top: -75%; right: -75%; bottom: -75%; left: -75%;
  transition: top 1.5s ease, right 1.5s ease, bottom 1.5s ease, left 1.5s ease;
}

/* --- Keyframes for organic life --- */
@keyframes organic-shape {
  0%   { border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
  25%  { border-radius: 46% 54% 47% 53% / 53% 47% 54% 46%; }
  50%  { border-radius: 54% 46% 55% 45% / 45% 55% 46% 54%; }
  75%  { border-radius: 47% 53% 45% 55% / 55% 45% 53% 47%; }
  100% { border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
}

@keyframes ring-drift-1 {
  0%, 100% { transform: translate(0, 0); }
  33%  { transform: translate(3%, -2%); }
  66%  { transform: translate(-2%, 3%); }
}

@keyframes ring-drift-2 {
  0%, 100% { transform: translate(0, 0); }
  33%  { transform: translate(-3%, -3%); }
  66%  { transform: translate(4%, 1%); }
}

@keyframes ring-drift-3 {
  0%, 100% { transform: translate(0, 0); }
  33%  { transform: translate(2%, 4%); }
  66%  { transform: translate(-3%, -2%); }
}

/* Phase label */
.bp-phase-label {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
  z-index: 2;
}

.bp-phase-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.08em;
  transition: color 0.5s ease;
}

.bp-phase-countdown {
  font-size: 1.35rem;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.55);
  font-variant-numeric: tabular-nums;
  min-height: 1.8rem;
  line-height: 1.2;
  transition: color 0.5s ease;
}

/* Prevent double-tap zoom on mobile for all app buttons */
.breath-pacer-ui button,
.breath-pacer-ui input[type="range"] {
  touch-action: manipulation;
}

/* ============================================================
   Controls — quiet, subordinate to the orb
   ============================================================ */
.bp-controls {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.bp-pattern-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.bp-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 14px;
  cursor: pointer;
  /* Touch target — was 21–27px tall on mobile (failed WCAG 2.5.5).
     32px desktop / 44px mobile via the responsive block below. */
  min-height: 32px;
  line-height: 1.4;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bp-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
}

.bp-chip:active {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.80);
}

.bp-chip--active {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.75);
}

.bp-chip[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Custom sliders */
.bp-custom-panel {
  display: none;
  width: 100%;
  grid-template-columns: 1fr;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 16px 20px;
}

.bp-custom-panel:not([hidden]) {
  display: grid;
}

.bp-slider-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.bp-slider-label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}

.bp-slider {
  width: 100%;
  cursor: pointer;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
}

.bp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
}

.bp-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
}

.bp-slider::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.bp-slider::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.bp-slider-val {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.50);
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}

/* Action row */
.bp-action-row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.bp-action-btn {
  min-height: 0;
  padding: 10px 32px;
  font-size: 0.9rem;
}

.breath-pacer-ui .button-primary {
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.80);
  border-color: rgba(255, 255, 255, 0.16);
}

.breath-pacer-ui .button-primary:hover {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.95);
  border-color: rgba(255, 255, 255, 0.28);
}

.breath-pacer-ui .button-secondary {
  background: transparent;
  color: rgba(255, 255, 255, 0.42);
  border-color: rgba(255, 255, 255, 0.10);
}

.breath-pacer-ui .button-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.65);
  border-color: rgba(255, 255, 255, 0.18);
}

.bp-audio-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s;
  flex-shrink: 0;
  min-height: 0;
  padding: 0;
}

.bp-audio-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.bp-audio-hint {
  display: none;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.55);
  opacity: 0;
  transition: opacity 0.3s;
}

.bp-audio-hint:not([hidden]) {
  display: inline;
}

.bp-audio-btn:active {
  background: rgba(255, 255, 255, 0.14);
  transform: scale(0.94);
}

/* Focus indicators for keyboard navigation */
.bp-chip:focus-visible,
.bp-limit-btn:focus-visible,
.bp-lang-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 2px;
}

.bp-audio-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.40);
  outline-offset: 3px;
}

.bp-action-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 3px;
}

.bp-stats {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.48);
  display: flex;
  gap: 8px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.bp-limit-label {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.48);
  white-space: nowrap;
}

/* Cycle-limit chip row (replaces native select) */
.bp-limit-row {
  display: flex;
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
}

.bp-limit-btn {
  background: transparent;
  border: none;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.50);
  cursor: pointer;
  min-height: 0;
  line-height: 1.3;
  transition: background 0.15s, color 0.15s;
  font-variant-numeric: tabular-nums;
}

.bp-limit-btn:last-child {
  border-right: none;
}

.bp-limit-btn--active {
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.65);
}

.bp-limit-btn:hover:not(.bp-limit-btn--active) {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.45);
}

.bp-limit-btn:active:not(.bp-limit-btn--active) {
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.55);
}

.bp-stats-sep {
  opacity: 0.4;
}

/* ============================================================
   prefers-reduced-motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .bp-orb {
    transform: scale(0.8) !important;
  }
  .bp-orb-core {
    animation: none !important;
  }
  .bp-orb-ring {
    animation: none !important;
    opacity: 0 !important;
  }
  .breath-pacer-ui {
    transition: none !important;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .breath-pacer-ui {
    padding: 40px 20px 32px;
    gap: 28px;
  }
}

@media (max-width: 480px) {
  .breath-pacer-page .page-title {
    font-size: clamp(1.6rem, 7vw, 2rem);
  }

  .bp-header-row {
    flex-direction: column;
    gap: 12px;
  }

  .breath-pacer-ui {
    padding: 32px 16px 24px;
    gap: 22px;
  }

  .bp-orb-stage {
    width: clamp(240px, 80vw, 280px);
    height: clamp(240px, 80vw, 280px);
  }

  .bp-chip {
    font-size: 0.76rem;
    padding: 10px 12px;
    min-height: 44px;
  }

  .bp-action-row {
    width: 100%;
  }

  .bp-action-btn {
    flex: 1;
    text-align: center;
  }

  .bp-slider-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .bp-slider {
    grid-column: 1 / -1;
  }
}
