:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: rgba(231, 240, 255, 0.72);
  --quiet: rgba(231, 240, 255, 0.52);
  --glass: rgba(8, 14, 30, 0.54);
  --glass-strong: rgba(10, 20, 40, 0.76);
  --line: rgba(213, 232, 255, 0.2);
  --aqua: #8be7ff;
  --rose: #ffb7d5;
  --gold: #f7d98b;
  --focus: #b9f3ff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 44%, rgba(139, 231, 255, 0.18), transparent 28rem),
    radial-gradient(circle at 18% 20%, rgba(255, 183, 213, 0.13), transparent 20rem),
    linear-gradient(145deg, #05060d 0%, #0a1020 42%, #160f25 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#breathCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

.practice-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem);
  gap: clamp(1rem, 3vw, 3rem);
  align-items: end;
  min-height: 100vh;
  padding: clamp(1.25rem, 4vw, 3.5rem);
}

.breath-stage {
  align-self: center;
  max-width: 56rem;
  text-shadow: 0 0 34px rgba(142, 230, 255, 0.25);
}

.session-kicker,
.phase-caption {
  margin: 0;
  color: var(--muted);
}

.session-kicker {
  font-size: clamp(0.62rem, 1vw, 0.78rem);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

h1 {
  max-width: 12ch;
  margin: 0.65rem 0 0;
  font-size: clamp(1.2rem, 3vw, 2.45rem);
  font-weight: 650;
  line-height: 0.93;
  letter-spacing: 0;
}

.heading-row {
  position: relative;
  max-width: 100%;
}

.heading-row h1 {
  min-width: 0;
}

.phase-title-line {
  display: block;
  width: max-content;
  max-width: 100%;
}

.phase-title-line-help {
  position: relative;
  display: block;
  width: max-content;
  max-width: 100%;
}

.help-toggle {
  position: absolute;
  top: 0.28em;
  left: calc(100% + clamp(0.5rem, 1vw, 0.85rem));
  z-index: 2;
  display: inline-grid;
  place-items: center;
  width: clamp(1.85rem, 0.42em, 2.7rem);
  height: clamp(1.85rem, 0.42em, 2.7rem);
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  font-size: clamp(0.86rem, 0.18em, 1.1rem);
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 22px rgba(139, 231, 255, 0.18);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.help-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 231, 255, 0.62);
  background: rgba(139, 231, 255, 0.14);
}

body.help-open .help-toggle {
  border-color: rgba(139, 231, 255, 0.7);
  background: rgba(139, 231, 255, 0.2);
}

.help-popover {
  display: none;
  max-width: min(17rem, 100%);
  margin-top: 0.85rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(213, 232, 255, 0.12);
  border-radius: 8px;
  color: rgba(247, 251, 255, 0.9);
  background: rgba(8, 14, 30, 0.2);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
  cursor: pointer;
}

body.help-open .help-popover {
  display: block;
}

.help-popover p {
  margin: 0;
  font-size: clamp(0.72rem, 0.9vw, 0.78rem);
  line-height: 1.48;
}

.phase-time {
  margin-top: clamp(0.75rem, 2vw, 1.25rem);
  color: var(--aqua);
  font-size: clamp(1.5rem, 3.2vw, 2.7rem);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.phase-caption {
  max-width: 36rem;
  margin-top: 0.55rem;
  font-size: clamp(0.78rem, 1.1vw, 0.9rem);
  line-height: 1.45;
}

.progress-track {
  width: min(18rem, 100%);
  height: 0.5rem;
  margin-top: clamp(1.5rem, 4vw, 2.5rem);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--aqua), var(--rose), var(--gold));
  box-shadow: 0 0 24px rgba(139, 231, 255, 0.58);
  transition: width 180ms linear;
}

.control-panel {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--glass), var(--glass-strong));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(24px);
}

.control-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 3rem 3rem;
  gap: 0.65rem;
}

.settings-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.settings-chevron {
  display: none;
  font-size: 1.05rem;
  line-height: 1;
  transition: transform 160ms ease;
}

body.settings-open .settings-chevron {
  transform: rotate(180deg);
}

.action-button {
  min-height: 2.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.95rem;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.action-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.38);
  background: rgba(255, 255, 255, 0.13);
}

.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  min-width: 3rem;
  padding: 0;
}

.share-button-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.action-button:focus-visible,
.settings-toggle:focus-visible,
.help-toggle:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.action-button-primary {
  border-color: rgba(139, 231, 255, 0.48);
  color: #ffffff;
  background: linear-gradient(135deg, #087996, #149fc0);
  box-shadow:
    0 0 26px rgba(139, 231, 255, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 16, 24, 0.42);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.settings-body {
  display: none;
  gap: 1rem;
}

body.settings-open .settings-body {
  display: grid;
}

.setting,
.volume-setting {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.setting {
  position: relative;
}

.setting input,
.setting select {
  width: 100%;
  min-height: 2.7rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.setting input {
  padding: 0 2.5rem 0 0.75rem;
}

.setting select {
  padding: 0 0.75rem;
  color-scheme: dark;
}

.setting select option {
  color: #f7fbff;
  background: #111a31;
}

.setting select option:checked {
  color: #04121d;
  background: #8be7ff;
}

.setting small {
  position: absolute;
  right: 0.7rem;
  bottom: 0.82rem;
  color: var(--quiet);
  pointer-events: none;
}

.volume-setting input {
  width: 100%;
  accent-color: var(--aqua);
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .practice-shell {
    grid-template-columns: 1fr;
    align-content: space-between;
    min-height: 100svh;
    gap: 0.8rem;
  }

  .breath-stage {
    padding-top: 2.5vh;
  }

  h1 {
    max-width: 12ch;
    font-size: clamp(1.55rem, 6vw, 2.6rem);
  }

  .help-toggle {
    width: clamp(1.75rem, 0.46em, 2.3rem);
    height: clamp(1.75rem, 0.46em, 2.3rem);
  }

  .help-popover {
    max-width: min(100%, 24rem);
    margin-top: 0.65rem;
    padding: 0.8rem 0.85rem;
  }

  .phase-time {
    font-size: clamp(1.25rem, 4.4vw, 2.2rem);
  }

  .phase-caption {
    font-size: clamp(0.78rem, 3vw, 0.95rem);
  }

  .progress-track {
    width: min(34rem, 100%);
    margin-top: 1.1rem;
  }

  .control-panel {
    width: 100%;
    gap: 0.75rem;
    padding: 0.8rem;
  }

  .control-actions {
    grid-template-columns: minmax(3.8rem, 1fr) minmax(3.8rem, 1fr) 2.75rem 2.75rem;
    gap: 0.42rem;
  }

  .action-button,
  .settings-toggle {
    min-height: 2.55rem;
    font-size: 0.84rem;
  }

  .settings-toggle {
    gap: 0.28rem;
  }

  .settings-chevron {
    display: inline-block;
    font-size: 0.92rem;
  }

  .share-button {
    width: 2.75rem;
    min-width: 2.75rem;
  }

}

@media (max-width: 480px) {
  .practice-shell {
    padding: 0.8rem;
  }

  h1 {
    font-size: clamp(1.35rem, 5.4vw, 2rem);
  }

  .help-toggle {
    width: clamp(1.65rem, 0.5em, 2.1rem);
    height: clamp(1.65rem, 0.5em, 2.1rem);
  }

  .help-popover p {
    font-size: 0.84rem;
  }

  .session-kicker {
    font-size: 0.62rem;
  }

  .phase-time {
    margin-top: 0.45rem;
  }

  .phase-caption {
    margin-top: 0.25rem;
  }

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