:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-hover: #f1f3f6;
  --surface-sunken: #eef0f3;
  --border: #e4e7ec;
  --text-primary: #101828;
  --text-secondary: #667085;
  --text-tertiary: #98a2b3;
  --accent: #4338ca;
  --accent-contrast: #ffffff;
  --accent-inhale: #4338ca;
  --accent-hold: #b45309;
  --accent-exhale: #0f766e;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, 0.18);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e12;
  --surface: #15171d;
  --surface-hover: #1b1e26;
  --surface-sunken: #101318;
  --border: #262a33;
  --text-primary: #f0f2f5;
  --text-secondary: #94a0b2;
  --text-tertiary: #667085;
  --accent: #8b7ff5;
  --accent-contrast: #101018;
  --accent-inhale: #8b7ff5;
  --accent-hold: #e0a458;
  --accent-exhale: #4fc3b0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.25s ease, color 0.25s ease;
}

button { font-family: inherit; }

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text-primary);
}
.brand-mark {
  color: var(--accent);
  display: flex;
}
.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}
.nav-link {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}
.nav-link:hover { color: var(--text-primary); }
.nav-link-active { color: var(--accent); }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--surface-hover); }
.icon-btn:active { transform: scale(0.93); }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

/* ---------- Page layout ---------- */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 20px 64px;
}

.intro {
  max-width: 620px;
  margin-bottom: 28px;
}
.intro h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.intro p {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ---------- Situations ---------- */
.situation-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 48px;
}
@media (min-width: 640px) {
  .situation-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .situation-grid { grid-template-columns: repeat(3, 1fr); }
}

.situation-card {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 14px;
  row-gap: 2px;
  align-items: center;
  text-align: left;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.situation-card:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  transform: translateY(-2px);
}
.situation-card:active { transform: translateY(0) scale(0.98); }

.situation-icon {
  grid-row: 1 / 3;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-sunken);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.situation-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.situation-blurb {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.situation-technique {
  grid-column: 1 / 3;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

/* ---------- Library section ---------- */
.library-section {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.section-heading {
  margin: 32px 0 20px;
}
.section-heading h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.section-heading p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

/* ---------- Filter chips ---------- */
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 7px 15px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filter-chip:hover { background: var(--surface-hover); }
.filter-chip.active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--bg);
}

/* ---------- Card grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 640px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .card-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1180px) {
  .card-grid { grid-template-columns: repeat(5, 1fr); }
}

.tech-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.tech-card:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  transform: translateY(-2px);
}
.tech-card:active { transform: translateY(0) scale(0.98); }
.tech-card.hidden { display: none; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.card-index {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
}
.card-level {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 100px;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  white-space: nowrap;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.rhythm-svg { display: block; width: 100%; height: 22px; }
.bar-inhale { fill: var(--accent-inhale); }
.bar-hold { fill: var(--accent-hold); }
.bar-exhale { fill: var(--accent-exhale); }

.card-legend {
  display: flex;
  gap: 10px;
  font-size: 10.5px;
  color: var(--text-tertiary);
  font-weight: 600;
}
.card-legend span { display: inline-flex; align-items: center; gap: 4px; }
.card-legend i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.card-legend .i-inhale { background: var(--accent-inhale); }
.card-legend .i-hold { background: var(--accent-hold); }
.card-legend .i-exhale { background: var(--accent-exhale); }

.card-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin: 0;
}

.card-suggested {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  margin: -4px 0 0;
}

/* ---------- Guidance section ---------- */
.guidance {
  margin-top: 52px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.guidance h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin: 0 0 18px;
}
.guidance-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
@media (min-width: 800px) {
  .guidance-grid { grid-template-columns: repeat(4, 1fr); }
}
.guidance-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.guidance-index {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
}
.guidance-item p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ---------- Session dialog ---------- */
.session-dialog {
  border: none;
  padding: 0;
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  width: min(420px, 100vw);
  max-width: 100vw;
  box-shadow: var(--shadow-lg);
  position: fixed;
  margin: auto;
  inset: 0;
}
.session-dialog::backdrop {
  background: rgba(10, 12, 16, 0.5);
  backdrop-filter: blur(3px);
}

.session-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 24px 26px;
  animation: dialog-in 0.28s cubic-bezier(.2,.8,.2,1);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.dialog-close:hover { background: var(--surface-hover); color: var(--text-primary); }

.session-header {
  text-align: center;
  margin-top: 8px;
  max-width: 320px;
}
.level-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 100px;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.session-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.session-header p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.context-banner {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  max-width: 320px;
  text-align: left;
}
.context-situation {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}
.context-banner p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.breath-stage {
  position: relative;
  width: 240px;
  height: 240px;
  margin: 26px auto 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ring-bg, .ring-progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.ring-bg { z-index: 1; }
.ring-progress { z-index: 2; }
.ring-bg circle {
  fill: none;
  stroke: var(--surface-sunken);
  stroke-width: 5;
}
.ring-progress circle {
  fill: none;
  stroke: var(--accent-inhale);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 804.2;
  stroke-dashoffset: 804.2;
  transition: stroke-dashoffset 0.2s linear, stroke 0.3s ease;
}

.ring-marker {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}
#ringMarker {
  fill: var(--accent-inhale);
  transition: fill 0.3s ease, opacity 0.3s ease;
}

.ambient-glow {
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-inhale) 0%, transparent 68%);
  opacity: 0.16;
  filter: blur(28px);
  z-index: 0;
  transform: scale(1);
  transition: background 1s ease;
  animation: ambient-pulse 6s ease-in-out infinite;
}
@keyframes ambient-pulse {
  0%, 100% { transform: scale(1); opacity: 0.13; }
  50% { transform: scale(1.06); opacity: 0.2; }
}

.breath-halo {
  position: absolute;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: var(--accent-inhale);
  filter: blur(20px);
  opacity: 0.55;
  z-index: 3;
  transform: scale(0.6);
  transition: transform 4s cubic-bezier(.45,0,.35,1), background 0.6s ease;
}

.ripple-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-inhale);
  z-index: 3;
  pointer-events: none;
  animation: ripple-expand 1.3s ease-out forwards;
}
@keyframes ripple-expand {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(2); opacity: 0; }
}

.goal-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 130px;
  height: 130px;
  margin: -65px 0 0 -65px;
  border-radius: 50%;
  background: var(--accent-exhale);
  filter: blur(16px);
  z-index: 3;
  pointer-events: none;
  animation: goal-burst-pulse 1s ease-out forwards;
}
@keyframes goal-burst-pulse {
  0% { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}

.breath-circle {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: var(--accent-inhale);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.6);
  transition: transform 4s cubic-bezier(.45,0,.35,1), background 0.6s ease;
  will-change: transform;
  z-index: 4;
}
.breath-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--accent-contrast);
}
#phaseLabel {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#phaseCount {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .breath-circle { transition: background 0.6s ease, box-shadow 0.6s ease; transform: scale(0.82) !important; }
  .breath-halo { transition: background 0.6s ease; transform: scale(0.82) !important; }
  .ring-progress circle { transition: stroke 0.3s ease; }
  .ambient-glow { animation: none; }
  .ring-marker, .ripple-ring { display: none; }
  .goal-burst { animation: none; opacity: 0.35; }
}

.session-info {
  display: flex;
  gap: 28px;
  margin: 18px 0 4px;
}
.info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: color 0.25s ease;
}
.info-item.goal-reached {
  color: var(--accent-exhale);
}
.info-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 700;
}
.info-item.goal-reached .info-label {
  color: var(--accent-exhale);
}
.info-item span:last-child {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pattern-strip {
  display: flex;
  gap: 6px;
  margin: 16px 0 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.pattern-chip {
  padding: 6px 11px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease;
}
.pattern-chip.active {
  background: var(--text-primary);
  color: var(--bg);
  transform: scale(1.06);
}

.toggle-btn {
  margin-top: 20px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 100px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.toggle-btn:hover { opacity: 0.92; }
.toggle-btn:active { transform: scale(0.98); }
.icon-pause { display: none; }
.toggle-btn.running .icon-play { display: none; }
.toggle-btn.running .icon-pause { display: block; }

/* ---------- Responsive dialog sizing ---------- */
@media (max-width: 560px) {
  .session-dialog[open] {
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    justify-content: center;
    animation: sheet-in 0.3s cubic-bezier(.2,.8,.2,1);
  }
  @keyframes sheet-in {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .toggle-btn { margin-top: auto; }
}

@media (min-width: 561px) {
  .session-dialog { border-radius: var(--radius-lg); }
}

/* ---------- How it works page ---------- */
.page-narrow {
  max-width: 680px;
}
.info-block {
  padding: 24px 0;
  border-top: 1px solid var(--border);
}
.info-block-index {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
}
.info-block h2 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
.info-block p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.disclaimer {
  margin: 32px 0 28px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.disclaimer strong {
  color: var(--text-primary);
}

.back-link {
  display: inline-block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 40px;
}
.back-link:hover { text-decoration: underline; }
