:root {
  --bg: #0b1020;
  --surface: #141b2f;
  --text: #e8eefc;
  --muted: #93a4c7;
  --accent: #2dd4bf;
  --danger: #f87171;
  --inhale-color: #2dd4bf;
  --exhale-color: #0891b2;
  --breath-duration: 2s;
  --app-max: 28rem;
  --circle-size: min(68vw, 17.5rem);
  --pad-x: 1rem;
  --pad-y: 1rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% 20%, color-mix(in srgb, var(--inhale-color) 8%, transparent), transparent),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--pad-y) var(--pad-x) calc(var(--pad-y) + env(safe-area-inset-bottom));
  max-width: var(--app-max);
  margin: 0 auto;
  width: 100%;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-btn {
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: #1c2640;
}

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

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 2vh, 1.25rem);
  min-height: 0;
  padding: clamp(0.5rem, 2vh, 1.5rem) 0;
  user-select: none;
  cursor: pointer;
}

.circle {
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--inhale-color) 40%, transparent), color-mix(in srgb, var(--exhale-color) 25%, transparent));
  box-shadow: 0 0 60px color-mix(in srgb, var(--inhale-color) 35%, transparent);
  transition: transform var(--breath-duration) ease-in-out, background var(--breath-duration) ease-in-out, box-shadow var(--breath-duration) ease-in-out;
  transform: scale(0.72);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.circle-value {
  font-size: clamp(2.4rem, 10vw, 4.2rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.circle-value.timer {
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  font-weight: 500;
}

.circle.inhale {
  transform: scale(1);
  background: radial-gradient(circle, color-mix(in srgb, var(--inhale-color) 55%, transparent), color-mix(in srgb, var(--exhale-color) 30%, transparent));
  box-shadow: 0 0 80px color-mix(in srgb, var(--inhale-color) 45%, transparent);
}

.circle.exhale {
  transform: scale(0.72);
  background: radial-gradient(circle, color-mix(in srgb, var(--exhale-color) 50%, transparent), color-mix(in srgb, var(--inhale-color) 20%, transparent));
  box-shadow: 0 0 50px color-mix(in srgb, var(--exhale-color) 35%, transparent);
}

.circle.hold {
  transform: scale(0.85);
  animation: pulse-hold 2.4s ease-in-out infinite;
}

.circle.idle {
  transform: scale(0.8);
}

@keyframes pulse-hold {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

.phase-label {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 2rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
}

.retention-hint {
  margin: 0;
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  color: var(--muted);
  text-align: center;
  max-width: 18rem;
  line-height: 1.35;
}

.stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: var(--muted);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  min-height: 2.5rem;
  flex-shrink: 0;
}

.speed-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  flex-shrink: 0;
  width: 100%;
}

.speed-btn {
  border: 1px solid #2a3555;
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.55rem 0.5rem;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.speed-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: #3d4f78;
}

.speed-btn.active {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent);
}

.controls {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 0.6rem;
  flex-shrink: 0;
  width: 100%;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.85rem 0.5rem;
  font-size: clamp(0.9rem, 2vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: filter 0.15s ease, transform 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.12);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, #14b8a6, #0891b2);
  color: #041018;
}

.btn.danger {
  background: #2a1820;
  color: var(--danger);
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 15;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(22rem, 88vw);
  background: #11182b;
  border-left: 1px solid #243152;
  padding: 1.1rem 1.15rem calc(1.1rem + env(safe-area-inset-bottom));
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 20;
  overflow-y: auto;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.1rem;
}

.settings-header h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.15rem;
}

.setting-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.setting-label strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
}

.stepper {
  display: grid;
  grid-template-columns: 2.4rem 1fr 2.4rem;
  align-items: center;
  gap: 0.55rem;
}

.stepper-btn {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid #2a3555;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.stepper-btn:hover {
  background: #1c2640;
  border-color: #3d4f78;
}

.stepper-btn:active {
  transform: scale(0.94);
}

.select {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid #2a3555;
  border-radius: 0.7rem;
  padding: 0.7rem 0.8rem;
  font-size: 0.95rem;
}

.music-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
}

.preview-btn {
  border: 1px solid #2a3555;
  background: var(--surface);
  color: var(--text);
  border-radius: 0.7rem;
  padding: 0.7rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.preview-btn:hover:not(:disabled) {
  background: #1c2640;
  border-color: var(--accent);
}

.preview-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.preview-btn.playing {
  border-color: var(--accent);
  color: var(--accent);
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.9rem;
  background: transparent;
  cursor: pointer;
}

.slider:focus {
  outline: none;
}

.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
}

.slider::-webkit-slider-runnable-track {
  height: 0.4rem;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill, 0%),
    #243152 var(--fill, 0%),
    #243152 100%
  );
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.2rem;
  height: 1.2rem;
  margin-top: -0.4rem;
  border-radius: 50%;
  border: 2px solid #0b1020;
  background: linear-gradient(145deg, #5eead4, #14b8a6);
  box-shadow: 0 2px 8px rgba(20, 184, 166, 0.45);
  transition: transform 0.12s ease;
}

.slider:active::-webkit-slider-thumb {
  transform: scale(1.12);
}

.slider::-moz-range-track {
  height: 0.4rem;
  border-radius: 999px;
  background: #243152;
}

.slider::-moz-range-progress {
  height: 0.4rem;
  border-radius: 999px;
  background: var(--accent);
}

.slider::-moz-range-thumb {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  border: 2px solid #0b1020;
  background: linear-gradient(145deg, #5eead4, #14b8a6);
  box-shadow: 0 2px 8px rgba(20, 184, 166, 0.45);
}

/* —— Landscape phones —— */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --circle-size: min(42vh, 11rem);
    --pad-y: 0.5rem;
  }

  .stage {
    padding: 0.25rem 0;
    gap: 0.4rem;
  }

  .phase-label {
    font-size: 1.15rem;
  }

  .stats {
    min-height: 2.25rem;
    font-size: 0.85rem;
  }

  .speed-picker {
    margin: 0.25rem 0 0.5rem;
  }

  .speed-btn,
  .btn {
    padding: 0.45rem 0.4rem;
  }

  .settings-panel {
    width: min(20rem, 70vw);
  }
}

/* —— Tablet / small desktop —— */
@media (min-width: 640px) {
  :root {
    --app-max: 32rem;
    --circle-size: min(42vw, 20rem);
    --pad-x: 1.5rem;
    --pad-y: 1.5rem;
  }

  .controls {
    gap: 0.75rem;
  }

  .btn {
    padding: 0.95rem 0.75rem;
  }

  .settings-panel {
    width: min(24rem, 40vw);
  }
}

/* —— Desktop —— */
@media (min-width: 900px) {
  :root {
    --app-max: 36rem;
    --circle-size: min(38vh, 22rem);
    --pad-x: 2rem;
    --pad-y: 2rem;
  }

  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .app {
    min-height: min(100dvh, 52rem);
    max-height: 100dvh;
  }

  .settings-panel {
    width: min(26rem, 32vw);
    padding: 1.35rem 1.4rem;
  }
}

/* —— Large desktop —— */
@media (min-width: 1200px) {
  :root {
    --app-max: 40rem;
    --circle-size: min(40vh, 24rem);
  }

  .phase-label {
    font-size: 2.1rem;
  }
}
