:root {
  color-scheme: dark;
  --bg: #10130f;
  --panel: rgba(247, 244, 232, 0.08);
  --panel-strong: rgba(247, 244, 232, 0.14);
  --line: rgba(247, 244, 232, 0.18);
  --text: #f8f3e4;
  --muted: #b8b09e;
  --ink: #10130f;
  --teal: #76e0ba;
  --coral: #ff896f;
  --gold: #ffd36b;
  --violet: #bba8ff;
  --phase-color: var(--teal);
  --phase-soft: rgba(118, 224, 186, 0.18);
  --phase-progress: 0%;
  --breath-scale: 0.72;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(155deg, rgba(118, 224, 186, 0.16), transparent 32%),
    linear-gradient(330deg, rgba(255, 137, 111, 0.13), transparent 38%),
    linear-gradient(180deg, #20231d 0%, var(--bg) 58%, #090a08 100%);
  color: var(--text);
  min-height: 100svh;
}

button,
output {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  align-items: center;
  display: grid;
  min-height: 100svh;
  padding: 16px;
  place-items: center;
}

.timer {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.035)),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 430px;
  overflow: hidden;
  padding: clamp(18px, 5vw, 28px);
  position: relative;
  width: min(100%, 430px);
}

.timer::before {
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral), var(--violet));
  content: "";
  height: 3px;
  inset: 0 0 auto;
  position: absolute;
}

.topbar {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2.45rem, 12vw, 4.25rem);
  letter-spacing: 0;
  line-height: 0.88;
  margin: 0;
  max-width: 7ch;
}

.session-clock {
  background: rgba(247, 244, 232, 0.1);
  border: 1px solid rgba(247, 244, 232, 0.16);
  border-radius: 999px;
  color: var(--text);
  display: inline-grid;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  min-width: 76px;
  padding: 8px 12px;
  place-items: center;
}

.stage {
  align-items: center;
  aspect-ratio: 1;
  display: grid;
  isolation: isolate;
  justify-items: center;
  margin: 2px auto 0;
  position: relative;
  width: min(74vw, 302px);
}

.session-ring {
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.34));
  grid-area: 1 / 1;
  height: 100%;
  overflow: visible;
  transform: rotate(-90deg);
  width: 100%;
}

.ring-track {
  fill: rgba(255, 255, 255, 0.025);
  stroke: rgba(247, 244, 232, 0.15);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke: var(--phase-color);
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  stroke-linecap: round;
  stroke-width: 8;
  transition: stroke 180ms ease;
}

.ring-tick {
  fill: rgba(247, 244, 232, 0.38);
}

.tick-two {
  fill: var(--gold);
}

.tick-three {
  fill: var(--coral);
}

.tick-four {
  fill: var(--violet);
}

.breath-orb {
  align-content: center;
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 35% 29%, rgba(255, 255, 255, 0.32), transparent 22%),
    radial-gradient(circle at 68% 72%, rgba(255, 137, 111, 0.2), transparent 30%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05)),
    var(--phase-soft);
  border: 1px solid rgba(247, 244, 232, 0.22);
  border-radius: 50%;
  box-shadow:
    0 0 0 16px rgba(247, 244, 232, 0.035),
    0 0 66px var(--phase-soft),
    inset 0 1px 18px rgba(255, 255, 255, 0.09);
  display: grid;
  grid-area: 1 / 1;
  justify-items: center;
  min-width: 0;
  padding: 28px;
  text-align: center;
  transform: scale(var(--breath-scale));
  transition:
    transform 120ms linear,
    background 180ms ease,
    box-shadow 180ms ease;
  width: 72%;
  z-index: 1;
}

.phase,
.cue {
  color: rgba(248, 243, 228, 0.7);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.phase-time {
  color: var(--text);
  font-size: clamp(3rem, 14vw, 4.5rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 0.9;
  margin: 10px 0;
}

.phase-meter {
  background: rgba(247, 244, 232, 0.1);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.phase-meter span {
  background: linear-gradient(90deg, var(--phase-color), rgba(247, 244, 232, 0.78));
  border-radius: inherit;
  display: block;
  height: 100%;
  transition: width 120ms linear;
  width: var(--phase-progress);
}

.control-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

legend {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 7px;
  text-transform: uppercase;
}

.segmented {
  background: rgba(247, 244, 232, 0.08);
  border: 1px solid rgba(247, 244, 232, 0.13);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.79rem;
  font-weight: 800;
  min-height: 34px;
  padding: 6px 5px;
  transition:
    background 160ms ease,
    color 160ms ease;
}

.segmented button[aria-pressed="true"] {
  background: rgba(247, 244, 232, 0.9);
  color: var(--ink);
}

.phase-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--phase-count, 3), minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.phase-list li {
  background: rgba(247, 244, 232, 0.07);
  border: 1px solid rgba(247, 244, 232, 0.12);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 9px 7px;
  text-align: center;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.phase-list li.is-active {
  background: var(--phase-soft);
  border-color: color-mix(in srgb, var(--phase-color) 62%, transparent);
  color: var(--text);
}

.phase-list span {
  font-size: 0.72rem;
  font-weight: 780;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.phase-list strong {
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 44px 1fr 84px;
}

.actions button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  min-height: 46px;
  transition:
    transform 140ms ease,
    background 160ms ease,
    color 160ms ease;
}

.actions button:active {
  transform: translateY(1px);
}

.primary {
  background: var(--text);
  color: var(--ink);
}

.reset,
.sound {
  background: rgba(247, 244, 232, 0.1);
  color: var(--text);
}

.sound[aria-pressed="true"] {
  background: var(--phase-color);
  color: var(--ink);
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

@media (max-width: 390px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .session-clock {
    justify-self: start;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-template-columns: 44px minmax(0, 1fr) 76px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
