:root {
  color-scheme: dark;
  --bg: #061322;
  --bg-deep: #030b16;
  --text: #f7f4e9;
  --muted: #9daeb4;
  --soft: #719398;
  --mint: #bbf7dc;
  --mint-strong: #94e7c1;
  --mint-ink: #092a30;
  --ring: rgba(159, 225, 205, 0.48);
  --ring-track: rgba(167, 229, 210, 0.12);
  --orb-scale: 0.78;
  --safe-bottom: max(22px, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg-deep);
  color: var(--text);
  overflow-x: hidden;
}

button, a { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  overflow-x: clip;
  overflow-y: visible;
  padding: 24px clamp(20px, 5vw, 48px) var(--safe-bottom);
  background:
    radial-gradient(circle at 50% 43%, rgba(12, 80, 84, 0.22), transparent 30%),
    radial-gradient(circle at 87% 16%, rgba(55, 107, 109, 0.1), transparent 20%),
    linear-gradient(155deg, #071725 0%, #051120 51%, #030b16 100%);
}

.app-shell::before,
.app-shell::after {
  position: absolute;
  z-index: -2;
  inset: 0;
  content: "";
  pointer-events: none;
}

.app-shell::before {
  opacity: 0.58;
  background-image:
    radial-gradient(circle at 12% 19%, rgba(255,255,255,.85) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 14%, rgba(224,255,245,.7) 0 1px, transparent 1.4px),
    radial-gradient(circle at 92% 39%, rgba(255,255,255,.58) 0 1px, transparent 1.5px),
    radial-gradient(circle at 26% 76%, rgba(224,255,245,.64) 0 1px, transparent 1.3px),
    radial-gradient(circle at 76% 82%, rgba(255,255,255,.5) 0 1px, transparent 1.4px),
    radial-gradient(circle at 45% 31%, rgba(255,255,255,.46) 0 1px, transparent 1.2px);
  background-size: 180px 180px, 220px 220px, 260px 260px, 240px 240px, 300px 300px, 190px 190px;
}

.app-shell::after {
  z-index: -1;
  opacity: .17;
  background: radial-gradient(ellipse at 50% 68%, rgba(153, 250, 215, .58), transparent 26%);
  filter: blur(42px);
}

.ambient { position: absolute; z-index: -1; border-radius: 50%; pointer-events: none; filter: blur(2px); }
.ambient-one { width: 2px; height: 2px; top: 24%; left: 8%; background: #effffb; box-shadow: 0 0 12px 3px rgba(220, 255, 245, .7); }
.ambient-two { width: 3px; height: 3px; top: 20%; right: 9%; background: #effffb; box-shadow: 0 0 16px 4px rgba(220, 255, 245, .48); }

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 660px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.4rem, 4.5vw, 1.85rem);
  letter-spacing: -.03em;
  text-decoration: none;
}

.brand-icon { flex: none; width: 34px; height: 34px; border: 1px solid rgba(191, 237, 222, .3); border-radius: 10px; object-fit: cover; object-position: center; }

.icon-button,
.close-button {
  display: grid;
  place-items: center;
  border: 1px solid rgba(191, 237, 222, .32);
  border-radius: 50%;
  background: rgba(7, 26, 39, .42);
  color: #c1d8d4;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}
.icon-button { width: 42px; height: 42px; }
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.5; }
.icon-button:hover, .icon-button:focus-visible, .close-button:hover, .close-button:focus-visible { border-color: var(--mint); background: rgba(162, 236, 208, .12); }
.icon-button:active, .primary-button:active { transform: scale(.97); }

.practice {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 660px);
  min-height: calc(100svh - 90px);
  margin: 24px auto 0;
  text-align: center;
}

.cycle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--soft);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.cycle-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--mint-strong); box-shadow: 0 0 11px rgba(180, 249, 215, .9); }
.session-timer { color: #c5ddd4; font-variant-numeric: tabular-nums; letter-spacing: .08em; white-space: nowrap; }

.breath-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(90vw, 480px);
  aspect-ratio: 1;
  margin: clamp(24px, 5vh, 52px) auto 4px;
}

.progress-ring { position: absolute; width: 100%; height: 100%; overflow: visible; }
.progress-ring circle { fill: none; }
.ring-track { stroke: var(--ring-track); stroke-width: 1.2; }
.ring-progress { stroke: var(--ring); stroke-linecap: round; stroke-width: 2.3; stroke-dasharray: 1005.31; stroke-dashoffset: calc(1005.31 * (1 - var(--progress, 0))); filter: drop-shadow(0 0 5px rgba(190, 255, 224, .3)); transform-origin: 180px 180px; transform: rotate(-90deg); }
.progress-ring .ring-dot { fill: #70e59e; stroke: #c2ffd5; stroke-width: 1; filter: drop-shadow(0 0 5px rgba(112, 229, 158, .9)); transform-origin: 180px 180px; transform: rotate(calc(var(--progress, 0) * 360deg)); }
html[data-phase="izelpa"] .progress-ring .ring-dot { fill: #64baff; stroke: #c1e5ff; filter: drop-shadow(0 0 5px rgba(100, 186, 255, .9)); }
html[data-phase="pauze"] .progress-ring .ring-dot,
html[data-phase="sagatavosanas"] .progress-ring .ring-dot { fill: transparent; stroke: #dcebe7; stroke-width: 1.5; filter: none; }

.breath-orb {
  position: relative;
  display: grid;
  place-items: center;
  width: 76%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(210, 255, 240, .54);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 34%, rgba(226, 255, 242, .44), transparent 24%),
    radial-gradient(circle at 47% 53%, rgba(48, 132, 132, .52), rgba(6, 49, 60, .93) 63%, rgba(5, 30, 42, .96) 100%);
  box-shadow: 0 0 22px rgba(142, 241, 199, .28), inset 0 0 46px rgba(176, 255, 220, .16), inset 0 -30px 60px rgba(3, 17, 28, .34);
  transform: scale(var(--orb-scale));
  transition: transform var(--phase-duration, 5s) cubic-bezier(.35, .05, .22, 1), box-shadow 2.4s ease;
}

.breath-orb::before, .breath-orb::after { position: absolute; content: ""; border-radius: 50%; pointer-events: none; }
.breath-orb::before { inset: 7%; border: 1px solid rgba(212, 255, 241, .13); }
.breath-orb::after { inset: -10%; background: radial-gradient(circle, transparent 42%, rgba(172, 255, 219, .12) 60%, transparent 67%); animation: orb-pulse 6s ease-in-out infinite; }
.orb-grain { position: absolute; inset: 0; opacity: .72; background-image: radial-gradient(circle, rgba(201, 255, 232, .6) 0 1px, transparent 1.3px); background-size: 16px 16px; mask-image: radial-gradient(circle, black, transparent 72%); }
.orb-content { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; padding: 12px; }
.phase-label { margin: 0 0 2px; color: #f3f6e9; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 5vw, 2.25rem); letter-spacing: -.035em; }
.countdown { margin: 0; color: var(--text); font-family: Georgia, "Times New Roman", serif; font-size: clamp(4rem, 16vw, 6.2rem); font-weight: 400; line-height: .95; letter-spacing: -.08em; }
.phase-cue { max-width: 180px; margin: 16px 0 0; color: rgba(223, 248, 236, .7); font-size: .76rem; line-height: 1.45; }

.controls { display: flex; flex-direction: column; align-items: center; gap: 11px; width: min(100%, 330px); margin-top: auto; }
.primary-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.primary-row .primary-button { flex: 1; width: auto; }
.primary-button {
  width: 100%;
  min-height: 62px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(112deg, #c7f7df 0%, #9ee9c3 100%);
  color: var(--mint-ink);
  box-shadow: 0 14px 32px rgba(117, 232, 181, .16), inset 0 1px 1px rgba(255,255,255,.75);
  cursor: pointer;
  font-size: .96rem;
  font-weight: 750;
  letter-spacing: .01em;
  transition: transform .2s ease, filter .2s ease, box-shadow .2s ease;
}
.primary-button:hover { filter: brightness(1.05); box-shadow: 0 16px 38px rgba(117, 232, 181, .22), inset 0 1px 1px rgba(255,255,255,.75); }
.sound-toggle { flex: 0 0 62px; display: grid; place-items: center; width: 62px; height: 62px; padding: 0; border: 1px solid rgba(191, 237, 222, .35); border-radius: 50%; background: rgba(7, 26, 39, .68); color: var(--mint); cursor: pointer; box-shadow: 0 8px 22px rgba(0, 0, 0, .2), inset 0 1px 1px rgba(255,255,255,.08); transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease; }
.sound-toggle:hover, .sound-toggle:focus-visible { border-color: var(--mint); background: rgba(162, 236, 208, .12); }
.sound-toggle:active { transform: scale(.96); }
.sound-toggle[aria-pressed="false"] { color: #93a9a8; }
.sound-toggle-icon { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.sound-icon-off { display: none; }
.sound-toggle[aria-pressed="false"] .sound-icon-on { display: none; }
.sound-toggle[aria-pressed="false"] .sound-icon-off { display: block; }
.text-button { border: 0; padding: 2px 10px; background: transparent; color: #9ab7b5; cursor: pointer; font-size: .78rem; letter-spacing: .02em; transition: color .2s ease; }
.text-button:hover, .text-button:focus-visible { color: var(--mint); }
.pattern { display: inline-flex; align-items: center; gap: 10px; margin: 26px auto 0; color: #78969a; font-size: .78rem; letter-spacing: .1em; }
.pattern i { width: 3px; height: 3px; border-radius: 50%; background: #57757a; }

.music-section {
  width: min(100%, 470px);
  margin: 25px auto 0;
  padding: 18px 0 4px;
  border-top: 1px solid rgba(191, 237, 222, .14);
}
.music-kicker { margin: 0; color: #c5ddd4; font-family: Georgia, "Times New Roman", serif; font-size: 1.15rem; }
.music-buttons { display: grid; grid-template-columns: 1fr; gap: 8px; }
.music-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 43px;
  padding: 8px 12px;
  border: 1px solid rgba(191, 237, 222, .23);
  border-radius: 999px;
  background: rgba(7, 26, 39, .44);
  color: #d7ebe1;
  font-size: .78rem;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}
.music-button:hover, .music-button:focus-visible { border-color: rgba(187, 247, 220, .72); background: rgba(162, 236, 208, .1); color: var(--mint); }
.music-icon { width: 10px; color: var(--mint-strong); font-size: .8rem; }
.music-player { display: block; width: 100%; height: 40px; margin: 13px auto 0; }
@media (min-width: 500px) {
  .music-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .music-button { gap: 7px; padding-inline: 8px; font-size: .72rem; }
}

:focus-visible { outline: 2px solid var(--mint); outline-offset: 4px; }

.menu-dialog { width: min(450px, calc(100vw - 32px)); max-height: min(88svh, 760px); padding: 22px; overflow: hidden; border: 1px solid rgba(184, 237, 217, .25); border-radius: 24px; background: #0a1d2c; color: var(--text); box-shadow: 0 20px 80px rgba(0, 0, 0, .48); }
.menu-dialog[open] { display: flex; flex-direction: column; }
.menu-dialog::backdrop { background: rgba(1, 7, 14, .72); backdrop-filter: blur(5px); }
.dialog-topline { display: flex; align-items: center; justify-content: space-between; }
.dialog-kicker { margin: 0; color: var(--mint-strong); font-size: .68rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.close-button { width: 32px; height: 32px; border-color: rgba(191, 237, 222, .2); font-size: 1.45rem; line-height: 1; }
.menu-dialog h2 { margin: 18px 0 5px; font-family: Georgia, "Times New Roman", serif; font-size: 2rem; font-weight: 400; letter-spacing: -.04em; }
.menu-description { flex: none; margin: 0 0 14px; color: #a7c0bf; font-size: .8rem; line-height: 1.5; }
.preset-list { display: grid; gap: 8px; min-height: 0; overflow-y: auto; padding: 2px 5px 4px 0; scrollbar-color: rgba(148, 231, 193, .4) transparent; scrollbar-width: thin; }
.preset-button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px; border: 1px solid rgba(191, 237, 222, .14); border-radius: 14px; background: rgba(255, 255, 255, .045); color: var(--text); text-align: left; cursor: pointer; transition: border-color .18s ease, background .18s ease; }
.preset-button:hover, .preset-button:focus-visible { border-color: rgba(187, 247, 220, .58); background: rgba(162, 236, 208, .09); }
.preset-button[aria-pressed="true"] { border-color: rgba(148, 231, 193, .66); background: rgba(148, 231, 193, .1); }
.preset-details { display: grid; gap: 3px; min-width: 0; }
.preset-name { overflow-wrap: anywhere; color: #f1f4e9; font-size: .88rem; font-weight: 600; }
.preset-values { color: #8eaead; font-size: .73rem; letter-spacing: .08em; }
.preset-selected { flex: none; color: var(--mint); font-size: 1rem; }

@keyframes orb-pulse { 0%, 100% { transform: scale(.92); opacity: .34; } 50% { transform: scale(1.04); opacity: .7; } }

@media (min-width: 600px) {
  .app-shell { padding-top: 34px; }
  .practice { margin-top: 30px; }
  .breath-stage { margin-top: 34px; }
  .controls { margin-top: 0; }
}

@media (max-height: 700px) and (max-width: 599px) {
  .app-shell { padding-top: 16px; }
  .practice { margin-top: 14px; }
  .breath-stage { width: min(72vw, 340px); margin-top: 12px; }
  .pattern { margin-top: 13px; }
  .primary-button, .sound-toggle { min-height: 54px; height: 54px; }
  .sound-toggle { flex-basis: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
