*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  height:100dvh;
  display:flex;
  flex-direction:column;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,"PT Sans",sans-serif;
  color:var(--fg);
  background:radial-gradient(1200px 800px at 20% 10%, #1a3357 0%, var(--bg-1) 55%, #060c18 100%);
  overflow:hidden;
  -webkit-tap-highlight-color:transparent;
}
header{
  position:relative;z-index:5;flex:0 0 auto;
  padding:calc(14px + env(safe-area-inset-top,0px)) 20px 14px;
  display:flex;align-items:center;justify-content:space-between;
  gap:12px;font-weight:500;letter-spacing:.04em;
}
header .brand{
  display:inline-flex;align-items:center;
  text-decoration:none;color:inherit;
  border-radius:var(--radius-sm);
  margin:-4px 0;
  min-width:0;
}
header .brand:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:3px;
}
header .brand-logo{
  display:block;
  /* адаптивная высота: компактно на узких экранах, крупнее на десктопе.
     Аспект ~4.8:1, при height 26px ширина ~125px — помещается рядом с правым блоком. */
  height:clamp(20px, 4.4vw, 30px);
  width:auto;
  max-width:55vw;
  object-fit:contain;
  opacity:.92;
}
@media (max-width:380px){
  header .brand-logo{ height:20px; max-width:50vw; }
}
.stage{
  flex:1 1 auto;min-height:0;overflow:hidden;
  display:grid;place-items:center;
  padding:12px 18px;
}
.dial{
  display:flex;flex-direction:column;align-items:center;
  gap:clamp(8px,2.5vmin,24px);
}
.phase{
  font-size:clamp(16px,4vmin,26px);
  letter-spacing:.16em;text-transform:uppercase;
  color:var(--muted);font-weight:600;
  text-align:center;min-height:1.3em;
  transition:color .45s ease;
}
.scene{
  position:relative;
  width:var(--r);height:var(--r);
  display:grid;place-items:center;
  flex-shrink:0;
}
.ring{
  position:absolute;inset:0;border-radius:50%;
  border:1px solid rgba(255,255,255,.06);
}
.ring.r2{transform:scale(1.08);border-color:rgba(255,255,255,.04)}
.ring.r3{transform:scale(1.18);border-color:rgba(255,255,255,.025)}
.prog{
  position:absolute;inset:0;
  width:100%;height:100%;
  transform:rotate(-90deg);
  pointer-events:none;overflow:visible;
}
.prog circle{fill:none}
.prog-track{stroke:rgba(255,255,255,.09);stroke-width:1.4}
.prog-arc{
  color:var(--accent);
  stroke:currentColor;stroke-width:2.4;
  stroke-linecap:round;
  stroke-dasharray:100;
  stroke-dashoffset:100;
  filter:drop-shadow(0 0 5px currentColor);
  transition:color .45s ease;
}
.orb{
  --s:.45;
  width:100%;height:100%;
  border-radius:50%;
  background:
    radial-gradient(circle at 32% 30%, rgba(255,255,255,.55), rgba(255,255,255,0) 55%),
    radial-gradient(circle at 50% 50%, var(--accent) 0%, #2c63a6 65%, #0e2444 100%);
  transform:scale(var(--s));
  transition:transform var(--phase-dur,4s) cubic-bezier(.45,.05,.55,.95),
             background var(--phase-dur,4s) ease;
  box-shadow:
    0 0 80px rgba(127,209,255,.25),
    inset 0 0 60px rgba(255,255,255,.08);
  will-change:transform;
}
.count{
  position:absolute;
  font-size:clamp(52px,15vmin,124px);
  font-weight:200;line-height:1;
  color:#fff;
  text-shadow:0 2px 26px rgba(0,0,0,.55), 0 0 8px rgba(0,0,0,.4);
  font-variant-numeric:tabular-nums;
  pointer-events:none;user-select:none;
}
.meta{
  display:flex;align-items:center;gap:11px;
  font-size:12.5px;color:var(--muted);
  letter-spacing:.13em;text-transform:uppercase;
  font-variant-numeric:tabular-nums;
}
.meta .dot{width:4px;height:4px;border-radius:50%;background:currentColor;opacity:.5}

.controls{
  flex:0 0 auto;
  display:flex;flex-direction:column;align-items:center;gap:10px;
  padding:16px 18px calc(14px + env(safe-area-inset-bottom,0px));
  background:linear-gradient(to top, rgba(8,14,26,.97), rgba(8,14,26,.42) 72%, rgba(8,14,26,0));
}
.ctl{
  width:100%;max-width:430px;
  display:flex;flex-direction:column;gap:3px;
}
.ctl[hidden]{display:none}
.ctl-head{
  display:flex;justify-content:space-between;align-items:center;
  padding:0 5px;min-height:20px;
  font-size:12px;color:var(--muted);
  letter-spacing:.12em;text-transform:uppercase;
}
.ctl-head .name{font-weight:600}
.ctl-head .val b{color:var(--fg);font-weight:700;font-size:13.5px}
.ctl-head .hint{opacity:.6;text-transform:none;letter-spacing:.02em;margin-left:8px}
.unit-toggle{
  display:inline-flex;
  gap:3px;
  background:rgba(127,209,255,.08);
  border:1px solid rgba(127,209,255,.22);
  border-radius:999px;
  padding:2px;
}
.unit-seg{
  min-height:auto;
  background:transparent;
  border:1px solid transparent;
  border-radius:999px;
  padding:3px 11px;
  font-size:11px;font-weight:700;
  letter-spacing:.1em;text-transform:uppercase;
  color:var(--muted);
  transition:background .15s,color .15s,border-color .15s;
}
.unit-seg.active{
  background:rgba(127,209,255,.18);
  border-color:rgba(127,209,255,.4);
  color:var(--accent);
}

input[type=range]{
  -webkit-appearance:none;appearance:none;
  width:100%;height:32px;margin:0;
  background:transparent;cursor:pointer;
}
input[type=range]::-webkit-slider-runnable-track{
  height:8px;border-radius:999px;background:rgba(255,255,255,.16);
}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;appearance:none;
  width:30px;height:30px;margin-top:-11px;border-radius:50%;
  background:var(--accent);border:3px solid #0a1424;
  box-shadow:0 3px 12px rgba(0,0,0,.5);
}
input[type=range]:active::-webkit-slider-thumb{background:#a3e0ff}
input[type=range]::-moz-range-track{
  height:8px;border-radius:999px;background:rgba(255,255,255,.16);
}
input[type=range]::-moz-range-thumb{
  width:30px;height:30px;border-radius:50%;
  background:var(--accent);border:3px solid #0a1424;
  box-shadow:0 3px 12px rgba(0,0,0,.5);
}
input[type=range]:active::-moz-range-thumb{background:#a3e0ff}

.btns{display:flex;gap:10px;width:100%;max-width:430px}
.btns button{flex:1}
button{
  font-family:inherit;
  min-height:48px;
  background:rgba(255,255,255,.07);
  color:var(--fg);
  border:1px solid rgba(255,255,255,.13);
  border-radius:15px;
  padding:0 16px;
  font-size:15px;cursor:pointer;
  transition:background .15s ease, transform .06s ease, border-color .15s ease;
}
button:active{transform:translateY(1px) scale(.99)}
.btns-main button{min-height:52px;font-size:16px;font-weight:600}
.btns-main .primary{flex:1.7}
.btns-toggle button{font-size:14px;color:var(--muted)}
.btns-toggle button[aria-pressed="true"]{
  color:var(--fg);
  background:rgba(127,209,255,.14);
  border-color:rgba(127,209,255,.32);
}
button.primary{background:var(--accent);color:#06203a;border-color:transparent}
@media (hover:hover){
  button:hover{background:rgba(255,255,255,.13);border-color:rgba(255,255,255,.22)}
  button.primary:hover{background:#a3e0ff}
  .unit-seg:not(.active):hover{background:rgba(127,209,255,.12);color:var(--fg)}
}

.pattern-pick{position:relative;flex-shrink:0}
.pattern-btn{
  min-height:38px;
  display:flex;align-items:center;gap:6px;
  padding:0 11px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.12);
  border-radius:11px;
  color:var(--fg);
  font-size:13px;font-weight:600;letter-spacing:.04em;
}
.pattern-btn .caret{width:10px;height:7px;flex-shrink:0}
.pattern-btn .caret path{
  fill:none;stroke:var(--muted);stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round;
}
.pattern-menu{
  position:absolute;top:46px;right:0;z-index:20;
  display:flex;flex-direction:column;gap:2px;
  padding:5px;min-width:100%;
  background:rgba(16,28,48,.97);
  border:1px solid rgba(255,255,255,.13);
  border-radius:13px;
  box-shadow:var(--shadow);
}
.pattern-menu[hidden]{display:none}
.pattern-opt{
  min-height:38px;
  padding:0 14px;
  background:transparent;border:1px solid transparent;
  border-radius:9px;
  color:var(--muted);
  font-size:13px;font-weight:600;letter-spacing:.04em;
  white-space:nowrap;text-align:center;
}
.pattern-opt.active{
  background:rgba(127,209,255,.16);
  border-color:rgba(127,209,255,.34);
  color:var(--fg);
}

.hdr-right{display:flex;align-items:center;gap:7px}
.audio-pick{position:relative;flex-shrink:0}
.audio-btn{
  min-height:auto;width:38px;height:38px;
  padding:0;display:grid;place-items:center;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.12);
  border-radius:11px;
}
.audio-menu{
  position:absolute;top:48px;right:0;z-index:20;
  display:flex;flex-direction:column;gap:3px;
  padding:5px;
  background:rgba(16,28,48,.97);
  border:1px solid rgba(255,255,255,.13);
  border-radius:13px;
  box-shadow:var(--shadow);
}
.audio-menu[hidden]{display:none}
.audio-opt{
  min-height:auto;width:44px;height:38px;
  padding:0;display:grid;place-items:center;
  background:transparent;
  border:1px solid transparent;
  border-radius:9px;
}
.audio-opt.active{
  background:rgba(127,209,255,.16);
  border-color:rgba(127,209,255,.34);
}
.wave-ico{width:25px;height:16px;display:block}
.wave-ico path{
  fill:none;stroke:var(--muted);stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round;
}
.audio-btn .wave-ico path{stroke:var(--accent)}
.audio-opt.active .wave-ico path{stroke:var(--accent)}

/* phase tinting */
body.inhale .orb{background:
  radial-gradient(circle at 32% 30%, rgba(255,255,255,.55), rgba(255,255,255,0) 55%),
  radial-gradient(circle at 50% 50%, var(--inhale) 0%, #2c63a6 65%, #0e2444 100%);}
body.hold .orb{background:
  radial-gradient(circle at 32% 30%, rgba(255,255,255,.55), rgba(255,255,255,0) 55%),
  radial-gradient(circle at 50% 50%, var(--hold) 0%, #5d3aa6 65%, #1a0e44 100%);}
body.exhale .orb{background:
  radial-gradient(circle at 32% 30%, rgba(255,255,255,.55), rgba(255,255,255,0) 55%),
  radial-gradient(circle at 50% 50%, var(--exhale) 0%, #2c9a78 65%, #0e3328 100%);}
body.inhale .phase{color:var(--inhale)}
body.hold   .phase{color:var(--hold)}
body.exhale .phase{color:var(--exhale)}
body.inhale .prog-arc{color:var(--inhale)}
body.hold   .prog-arc{color:var(--hold)}
body.exhale .prog-arc{color:var(--exhale)}

body.mode-timer #baseCtl{display:none}
body.mode-timer .unit-toggle{pointer-events:none;opacity:.55}
body.mode-timer #cycle,
body.mode-timer .meta .dot{display:none}
body.mode-timer .count{font-size:clamp(40px,11vmin,90px);letter-spacing:-.02em}

/* Интервальный таймер: работа/отдых/раунды вместо слайдера База и цели. */
body.mode-interval #baseCtl,
body.mode-interval #targetCtl{display:none}
body.mode-interval .count{font-size:clamp(40px,11vmin,90px);letter-spacing:-.02em}

/* Индивидуальный паттерн: четыре степпера вместо слайдера База */
body.mode-custom #baseCtl{display:none}
.ctl-custom .custom-grid{
  display:grid;grid-template-columns:repeat(4,minmax(0,1fr));
  gap:4px;width:100%;
}
.ctl-custom .custom-grid.grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}
.custom-cell{
  min-width:0;
  display:flex;flex-direction:column;align-items:center;gap:3px;
  padding:4px 2px 5px;
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.09);
  border-radius:10px;
}
.cp-name{
  font-size:9.5px;font-weight:600;letter-spacing:.06em;
  text-transform:uppercase;color:var(--muted);
  text-align:center;line-height:1;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;
}
.stepper{
  display:flex;align-items:center;gap:1px;
  font-variant-numeric:tabular-nums;
}
.step-btn{
  min-height:auto;width:24px;height:26px;
  padding:0;display:grid;place-items:center;
  background:rgba(127,209,255,.1);
  border:1px solid rgba(127,209,255,.24);
  border-radius:7px;
  color:var(--accent);
  font-size:15px;font-weight:600;line-height:1;
  -webkit-user-select:none;user-select:none;
}
.step-btn:disabled{
  opacity:.35;pointer-events:none;
  background:rgba(255,255,255,.05);border-color:rgba(255,255,255,.08);
  color:var(--muted);
}
@media (hover:hover){
  .step-btn:not(:disabled):hover{background:rgba(127,209,255,.18);border-color:rgba(127,209,255,.42)}
}
.step-val{
  min-width:18px;text-align:center;
  font-size:15px;font-weight:600;color:var(--fg);
  letter-spacing:.01em;
}
.step-btn:focus-visible{
  outline:2px solid var(--accent);outline-offset:2px;
}

/* completion overlay */
.done-overlay{
  position:fixed;inset:0;z-index:50;
  display:grid;place-items:center;
  background:rgba(6,12,24,.72);
  backdrop-filter:blur(10px);
  -webkit-backdrop-filter:blur(10px);
  animation:fadeIn .45s ease;
}
.done-overlay[hidden]{display:none}
.done-card{
  text-align:center;
  padding:38px 44px;
  border-radius:22px;
  background:linear-gradient(160deg, rgba(127,209,255,.12), rgba(255,255,255,.04));
  border:1px solid rgba(255,255,255,.12);
  box-shadow:var(--shadow);
  max-width:86vw;
  animation:rise .5s cubic-bezier(.2,.7,.3,1);
}
.done-mark{
  width:66px;height:66px;margin:0 auto 20px;
  border-radius:50%;
  display:grid;place-items:center;
  font-size:32px;color:#06203a;
  background:var(--exhale);
  box-shadow:0 0 44px rgba(158,233,197,.5);
}
.done-title{font-size:24px;font-weight:600;letter-spacing:.02em}
.done-sub{font-size:14px;color:var(--muted);margin-top:8px}
.done-stats{
  font-size:16px;color:var(--fg);margin:20px 0 24px;
  font-variant-numeric:tabular-nums;letter-spacing:.04em;
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
@keyframes rise{from{opacity:0;transform:translateY(16px) scale(.96)}to{opacity:1;transform:none}}

@media (prefers-reduced-motion:reduce){
  .orb{transition:none}
}

/* Phase 6: focus-стили для клавиатурной навигации внутри таймера. */
button:focus-visible,
.pattern-opt:focus-visible,
.audio-opt:focus-visible,
.unit-seg:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
}
input[type=range]:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:6px;
  border-radius:999px;
}
