/* ============ Tide · נשימה מודרכת ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-1: #04080f;
  --bg-2: #061425;
  --bg-3: #0a1f3d;
  --aqua-1: #22d3ee;
  --aqua-2: #67e8f9;
  --aqua-3: #a5f3fc;
  --deep:  #1e3a8a;
  --gold:  #fbbf24;
  --text:  #ecf6ff;
  --muted: rgba(236,246,255,.58);
  --faint: rgba(236,246,255,.32);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

html, body {
  background: var(--bg-1);
  color: var(--text);
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ============ AMBIENT BACKGROUND (mesh-gradient + waves) ============ */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background: var(--bg-1);
}
.ambient-bg::before {
  content: '';
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(40% 50% at 20% 30%, rgba(34,211,238,.18), transparent 60%),
    radial-gradient(50% 60% at 80% 70%, rgba(30,58,138,.40), transparent 60%),
    radial-gradient(60% 70% at 50% 100%, rgba(103,232,249,.10), transparent 70%);
  filter: blur(40px);
  animation: bg-shift 20s ease-in-out infinite;
}
@keyframes bg-shift {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%      { transform: translate(-3%, 3%) scale(1.05); }
}
.ambient-bg .grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 80px 80px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
  opacity: .8;
}

/* Floating particles */
.particle {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: rgba(165,243,252,.5);
  box-shadow: 0 0 8px rgba(34,211,238,.5);
  animation: rise linear infinite;
  pointer-events: none;
}
@keyframes rise {
  0%   { transform: translateY(110vh) scale(.4); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: .6; }
  100% { transform: translateY(-10vh) scale(1.1); opacity: 0; }
}

/* ============ TOP BAR ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(54px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.brand .mark {
  width: 24px; height: 24px;
  background: linear-gradient(135deg, var(--aqua-1), var(--aqua-3));
  border-radius: 50%;
  position: relative;
  box-shadow: 0 0 14px rgba(34,211,238,.55);
}
.brand .mark::after {
  content: '';
  position: absolute;
  inset: 6px;
  background: var(--bg-1);
  border-radius: 50%;
}
.streak-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .5px;
}
.streak-pill .flame { color: var(--gold); }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 18px;
  backdrop-filter: blur(10px);
  transition: background .2s, border-color .2s, transform .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.15); }
.icon-btn:active { transform: scale(.92); }

/* ============ MAIN STAGE ============ */
main {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 22px;
  padding-top: calc(54px + var(--safe-top));
  padding-bottom: calc(40px + var(--safe-bot));
  position: relative;
}

/* ============ THE ORB ============ */
.orb-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
}

.orb {
  position: relative;
  width: 280px; height: 280px;
  display: grid; place-items: center;
  --scale-min: 0.55;
  --scale-max: 1.0;
  --orb-color: var(--aqua-1);
  transform: scale(var(--scale-min));
  transition: transform 1s cubic-bezier(.45,.05,.5,.95), filter .8s ease;
  z-index: 1;
}
/* Idle pulse */
.orb.idle {
  animation: idle-pulse 4.5s ease-in-out infinite;
  transition: none;
}
@keyframes idle-pulse {
  0%, 100% { transform: scale(0.78); }
  50%      { transform: scale(0.92); }
}
.orb.inhale { transform: scale(var(--scale-max)); }
.orb.exhale { transform: scale(var(--scale-min)); }
.orb.hold-in { transform: scale(var(--scale-max)); }
.orb.hold-out { transform: scale(var(--scale-min)); }

/* Halo */
.orb::before {
  content: '';
  position: absolute;
  inset: -50px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--orb-color) 0%, transparent 60%);
  opacity: .35;
  filter: blur(20px);
  animation: halo-pulse 6s ease-in-out infinite;
}
@keyframes halo-pulse {
  0%, 100% { transform: scale(1); opacity: .25; }
  50%      { transform: scale(1.08); opacity: .45; }
}

/* Outer ring */
.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(165,243,252,.20);
  background: radial-gradient(circle at 30% 25%, rgba(165,243,252,.08), transparent 60%);
}

/* Inner sphere */
.orb-core {
  width: 70%; height: 70%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.40), transparent 50%),
    radial-gradient(circle at 70% 75%, rgba(34,211,238,.30), transparent 60%),
    linear-gradient(135deg, var(--aqua-1) 0%, var(--deep) 80%);
  box-shadow:
    inset 0 -30px 60px rgba(0,0,0,.35),
    inset 0 20px 40px rgba(255,255,255,.12),
    0 30px 80px rgba(34,211,238,.35);
  position: relative;
  display: grid;
  place-items: center;
}

/* SVG progress ring around the orb */
.orb-progress {
  position: absolute;
  inset: -22px;
  pointer-events: none;
}
.orb-progress svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.orb-progress .track { fill: none; stroke: rgba(255,255,255,.06); stroke-width: 2; }
.orb-progress .fill {
  fill: none;
  stroke: var(--orb-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px var(--orb-color));
  transition: stroke-dashoffset .25s linear, stroke .8s ease;
}

/* Phase text inside orb */
.orb-phase {
  text-align: center;
  pointer-events: none;
  z-index: 2;
}
.orb-phase .label {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: rgba(255,255,255,.95);
  text-shadow: 0 2px 16px rgba(0,0,0,.35);
  opacity: .9;
}
.orb-phase .count {
  font-size: 64px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  letter-spacing: -0.04em;
  color: rgba(255,255,255,.95);
  text-shadow: 0 4px 24px rgba(0,0,0,.4);
}

/* ============ TOP TEXT (above orb) ============ */
.session-info {
  position: absolute;
  top: 90px;
  left: 0; right: 0;
  text-align: center;
  z-index: 5;
  pointer-events: none;
}
.session-info .preset-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.session-info .pattern {
  font-size: 14px;
  color: var(--faint);
  letter-spacing: -0.01em;
}

/* ============ CONTROLS (below orb) ============ */
.controls {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.session-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
}
.session-stats .stat {
  text-align: center;
  padding: 12px 8px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px;
  backdrop-filter: blur(10px);
}
.session-stats .stat .value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.session-stats .stat .label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--faint);
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  margin-top: 6px;
}

/* Big primary button */
.btn-primary {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--aqua-1), var(--aqua-2));
  border: none;
  border-radius: 999px;
  color: var(--bg-1);
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 16px 40px -8px rgba(34,211,238,.55);
  transition: transform .15s, box-shadow .25s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary.danger {
  background: linear-gradient(135deg, #ff5470, #ff8a9a);
  color: #fff;
  box-shadow: 0 16px 40px -8px rgba(255,84,112,.5);
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: background .2s, border-color .2s, transform .15s;
}
.btn-secondary:hover { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.18); }
.btn-secondary:active { transform: scale(.98); }

/* Preset cards */
.preset-row {
  display: flex;
  gap: 8px;
  width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.preset-row::-webkit-scrollbar { display: none; }

.preset-chip {
  flex-shrink: 0;
  padding: 9px 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .25s cubic-bezier(.2,.9,.3,1);
  white-space: nowrap;
}
.preset-chip:hover { background: rgba(255,255,255,.07); color: var(--text); }
.preset-chip.active {
  background: rgba(34,211,238,.15);
  border-color: rgba(34,211,238,.5);
  color: var(--aqua-2);
  box-shadow: 0 8px 20px -6px rgba(34,211,238,.4);
}

/* ============ SESSION COMPLETE OVERLAY ============ */
.complete-card {
  position: relative;
  z-index: 10;
  background: rgba(20,30,50,.7);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 24px;
  padding: 28px 26px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  margin: auto;
  animation: fade-up .5s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.complete-card .check {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--aqua-1), var(--aqua-2));
  display: grid; place-items: center;
  font-size: 28px;
  color: var(--bg-1);
  box-shadow: 0 0 30px rgba(34,211,238,.5);
}
.complete-card h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.complete-card p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 18px;
}
.complete-card .summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(255,255,255,.03);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 18px;
}
.complete-card .summary .item .v {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.complete-card .summary .item .k {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--faint);
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  margin-top: 2px;
}
.complete-card .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(4,8,15,.78);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: grid;
  place-items: end center;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: rgba(20,30,50,.92);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255,255,255,.10);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 24px 22px calc(28px + var(--safe-bot));
  width: 100%;
  max-width: 480px;
  margin-bottom: 0;
  animation: sheet-up .35s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-card .handle {
  width: 38px; height: 4px;
  background: rgba(255,255,255,.18);
  border-radius: 2px;
  margin: -8px auto 16px;
}
.modal-card h3 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.modal-card .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.modal-card .row:last-child { border-bottom: 0; }
.modal-card .row strong { font-weight: 600; font-size: 14px; }
.modal-card .row .desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.modal-card .pill-options { display: flex; gap: 6px; flex-wrap: wrap; }
.modal-card .pill-options button {
  padding: 7px 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  color: var(--muted);
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.modal-card .pill-options button.active {
  background: rgba(34,211,238,.15);
  border-color: rgba(34,211,238,.4);
  color: var(--aqua-2);
}

/* Toggle */
.toggle {
  width: 44px; height: 24px;
  border-radius: 999px;
  background: rgba(255,255,255,.10);
  position: relative;
  cursor: pointer;
  transition: background .2s;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text);
  top: 3px; left: 3px;
  transition: transform .2s;
}
.toggle.on { background: var(--aqua-1); }
.toggle.on::after { transform: translateX(20px); }
[dir="rtl"] .toggle::after { left: auto; right: 3px; }
[dir="rtl"] .toggle.on::after { transform: translateX(-20px); }

/* ============ STATS GRID ============ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stats-grid .stat-card {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 16px;
  padding: 16px;
}
.stats-grid .stat-card .v {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stats-grid .stat-card .k {
  font-size: 11px;
  color: var(--faint);
  margin-top: 4px;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Heatmap */
.heatmap {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 4px;
  margin-top: 14px;
}
.heatmap .cell {
  aspect-ratio: 1;
  background: rgba(255,255,255,.04);
  border-radius: 4px;
}
.heatmap .cell.l1 { background: rgba(34,211,238,.20); }
.heatmap .cell.l2 { background: rgba(34,211,238,.40); }
.heatmap .cell.l3 { background: rgba(34,211,238,.60); }
.heatmap .cell.l4 { background: rgba(34,211,238,.85); box-shadow: 0 0 8px rgba(34,211,238,.4); }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,30,50,.92);
  border: 1px solid rgba(255,255,255,.16);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(10px);
  animation: toast-in .25s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.hidden { display: none !important; }

/* Install button */
.install-btn {
  background: linear-gradient(135deg, var(--aqua-1), var(--aqua-2));
  color: var(--bg-1);
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(34,211,238,.4);
}

/* Vibration helper feedback */
.tap-flash {
  position: fixed;
  inset: 0;
  background: var(--aqua-1);
  opacity: 0;
  pointer-events: none;
  z-index: 999;
}
.tap-flash.flash { animation: flash .4s ease-out; }
@keyframes flash {
  from { opacity: .15; }
  to { opacity: 0; }
}
