:root {
  /* --- Tatami Dawn palette -------------------------------------------------
     Inspired by wabi-sabi / zendo interiors: warm cream, tatami sand, moss,
     terracotta. All muted — nothing saturated. Reads like morning light on
     rice paper. */

  --bg-top:       #F5EEE1;  /* soft warm cream */
  --bg-mid:       #EFE5D1;
  --bg-bottom:    #E4D7BE;  /* tatami / sand */
  --bg-card:      rgba(255, 251, 243, 0.55);
  --bg-card-hov:  rgba(255, 251, 243, 0.85);

  --ink:          #2B2620;  /* warm charcoal — soft, not harsh */
  --ink-dim:      #6D5F53;  /* warm taupe */
  --ink-faint:    #A99B8C;
  --ink-ghost:    #C5B7A6;
  --ink-on-accent:#F5EEE1;

  --accent-warm:  #C97E58;  /* terracotta */
  --accent-cool:  #4A6B5A;  /* forest moss */
  --accent-sage:  #8FA893;
  --line:         rgba(43, 38, 32, 0.08);
  --line-strong:  rgba(43, 38, 32, 0.14);

  /* Goal palettes — all muted earth tones */
  --calm-a:   #A8C4B2;  /* sage */
  --calm-b:   #6B9487;
  --focus-a:  #8AA3B8;  /* dusty slate */
  --focus-b:  #4E6B80;
  --sleep-a:  #A899B8;  /* dusk plum */
  --sleep-b:  #685A7B;
  --energy-a: #E0A878;  /* warm amber */
  --energy-b: #B56A4A;  /* terracotta */

  /* Orb phase colors — dramatic warm/cool contrast */
  --orb-inhale-1: #FBCBA7;  /* peach highlight */
  --orb-inhale-2: #F5A584;  /* coral */
  --orb-inhale-3: #E08560;  /* burnt coral edge */
  --orb-inhale-glow: rgba(236, 145, 106, 0.45);

  --orb-exhale-1: #D4E5D6;  /* mist sage highlight */
  --orb-exhale-2: #A8C4B2;  /* sage */
  --orb-exhale-3: #6B9487;  /* deeper sage edge */
  --orb-exhale-glow: rgba(107, 148, 135, 0.32);

  --radius: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --breath-ease: cubic-bezier(0.45, 0, 0.55, 1);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse at 50% 0%, #F8F1E4 0%, var(--bg-top) 30%, var(--bg-mid) 70%, var(--bg-bottom) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

/* Subtle paper-grain texture — just enough to keep the background from
   looking flat/digital. Very low contrast so it doesn't read as noise. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle at 25% 20%, rgba(43, 38, 32, 0.025) 1px, transparent 1px),
                    radial-gradient(circle at 75% 60%, rgba(43, 38, 32, 0.02) 1px, transparent 1px);
  background-size: 7px 7px, 11px 11px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

#app {
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  animation: fadeIn 400ms var(--ease);
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Home */
.home-header {
  text-align: center;
  margin: 24px 0 28px;
}

.brand {
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

.brand::after {
  content: '';
  display: block;
  width: 28px;
  height: 1px;
  background: var(--accent-warm);
  margin: 12px auto 0;
  opacity: 0.8;
}

.brand-breath { color: var(--ink); }
.brand-orb    { color: var(--accent-warm); font-weight: 400; }

/* Smaller brand mark at the top of the session screen for continuity */
.session-brand {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin: 0 0 18px;
  opacity: 0.75;
}

.tagline {
  color: var(--ink-dim);
  font-size: 15px;
  margin: 14px 0 0;
  line-height: 1.5;
  font-weight: 300;
}

.goals {
  display: flex;
  gap: 8px;
  justify-content: safe center;
  overflow-x: auto;
  padding: 4px 20px 12px;
  margin: 0 -20px 16px;
  scrollbar-width: none;
}

.goals::-webkit-scrollbar { display: none; }

.goal-chip {
  background: rgba(43, 38, 32, 0.04);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 240ms var(--ease);
  flex-shrink: 0;
}

.goal-chip:hover {
  background: rgba(43, 38, 32, 0.07);
  color: var(--ink);
}

.goal-chip.active {
  background: var(--ink);
  color: var(--ink-on-accent);
  border-color: var(--ink);
}

.technique-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.technique-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all 220ms var(--ease);
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.technique-card:hover,
.technique-card:focus-visible {
  background: var(--bg-card-hov);
  border-color: rgba(201, 126, 88, 0.28);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px -12px rgba(43, 38, 32, 0.1);
  outline: none;
}

.technique-card:active { transform: translateY(0); }

.technique-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 2px 8px -2px rgba(43, 38, 32, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.technique-icon.calm   { background: linear-gradient(135deg, var(--calm-a), var(--calm-b)); }
.technique-icon.focus  { background: linear-gradient(135deg, var(--focus-a), var(--focus-b)); }
.technique-icon.sleep  { background: linear-gradient(135deg, var(--sleep-a), var(--sleep-b)); }
.technique-icon.energy { background: linear-gradient(135deg, var(--energy-a), var(--energy-b)); }

.technique-body { flex: 1; min-width: 0; }

.technique-name {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 4px;
  color: var(--ink);
}

.technique-desc {
  font-size: 13px;
  color: var(--ink-dim);
  margin: 0;
  line-height: 1.45;
}

.technique-pattern {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
  margin-top: 4px;
  letter-spacing: 0.06em;
}

.technique-chevron {
  color: var(--ink-ghost);
  font-size: 22px;
  line-height: 1;
}

.home-footer {
  margin-top: 28px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.08em;
}

/* Session */
#session {
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.top-left {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 16px;
  z-index: 10;
}

.icon-btn {
  background: rgba(43, 38, 32, 0.05);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 220ms var(--ease);
  padding: 0;
}

.icon-btn:hover { background: rgba(43, 38, 32, 0.09); }

.icon-btn[aria-pressed='false'] .on,
.icon-btn[aria-pressed='true'] .off { display: none; }

.session-top {
  text-align: center;
  margin-top: 28px;
  transition: opacity 600ms var(--ease);
}

.session-title {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

.session-subtitle {
  font-size: 13px;
  color: var(--ink-dim);
  margin: 6px 0 0;
  font-weight: 400;
}

.orb-wrap {
  position: relative;
  width: min(78vw, 340px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 20px 0;
}

/* --- Orb: two stacked layers (warm + cool) crossfaded via opacity ---------
   Hue-rotate couldn't give us the color-family change we wanted. Stacking
   two independent gradients and fading between them is cleaner and gives
   a real "warm → cool" shift that's unmistakable. */

.orb {
  position: relative;
  width: 55%;
  aspect-ratio: 1;
  border-radius: 50%;
  transition: transform var(--orb-duration, 5s) var(--breath-ease);
  will-change: transform;
}

.orb-layer {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transition: opacity var(--orb-duration, 5s) var(--breath-ease),
              box-shadow var(--orb-duration, 5s) ease-in-out;
  pointer-events: none;
}

.orb-warm {
  background: radial-gradient(circle at 32% 28%,
    var(--orb-inhale-1) 0%,
    var(--orb-inhale-2) 55%,
    var(--orb-inhale-3) 100%);
  box-shadow:
    0 0 70px var(--orb-inhale-glow),
    inset 0 0 40px rgba(255, 240, 220, 0.4);
  opacity: 1; /* default: at rest, warm layer visible */
}

.orb-cool {
  background: radial-gradient(circle at 32% 28%,
    var(--orb-exhale-1) 0%,
    var(--orb-exhale-2) 55%,
    var(--orb-exhale-3) 100%);
  box-shadow:
    0 0 50px var(--orb-exhale-glow),
    inset 0 0 35px rgba(230, 245, 235, 0.4);
  opacity: 0;
}

.orb-inner {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 70%);
  opacity: 0.55;
  pointer-events: none;
}

.orb-glow {
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(236, 145, 106, 0.14), transparent 65%);
  animation: pulse-bg 8s ease-in-out infinite;
  pointer-events: none;
  transition: background var(--orb-duration, 5s) ease-in-out;
}

@keyframes pulse-bg {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.85; }
}

/* Phase classes control scale + which layer is visible */
.orb.inhale {
  transform: scale(1.55);
}
.orb.inhale .orb-warm { opacity: 1; }
.orb.inhale .orb-cool { opacity: 0; }

.orb.hold-in {
  transform: scale(1.55);
}
.orb.hold-in .orb-warm { opacity: 1; }
.orb.hold-in .orb-cool { opacity: 0; }

.orb.exhale {
  transform: scale(0.85);
}
.orb.exhale .orb-warm { opacity: 0; }
.orb.exhale .orb-cool { opacity: 1; }

.orb.hold-out {
  transform: scale(0.85);
}
.orb.hold-out .orb-warm { opacity: 0; }
.orb.hold-out .orb-cool { opacity: 1; }

/* Background glow shifts warm ↔ cool too — :has() lets us style the earlier
   sibling .orb-glow based on the later .orb's phase class. */
.orb-wrap:has(.orb.exhale) .orb-glow,
.orb-wrap:has(.orb.hold-out) .orb-glow {
  background: radial-gradient(circle, rgba(107, 148, 135, 0.12), transparent 65%);
}

.cue-stack {
  text-align: center;
  transition: opacity 600ms var(--ease);
  min-height: 60px;
}

.phase-label {
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

.phase-count {
  font-size: 44px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  color: var(--accent-warm);
  line-height: 1;
  min-height: 44px;
  transition: opacity 600ms var(--ease), font-size 600ms var(--ease);
}

.session-bottom {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  transition: opacity 600ms var(--ease);
}

.session-meta {
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.session-meta .dot {
  margin: 0 8px;
  color: var(--ink-faint);
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.primary-btn {
  background: var(--ink);
  color: var(--ink-on-accent);
  border: none;
  padding: 14px 32px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 200ms var(--ease), background 200ms var(--ease);
  min-width: 140px;
  justify-content: center;
  box-shadow: 0 6px 16px -6px rgba(43, 38, 32, 0.3);
}

.primary-btn:hover { background: #3A3329; }
.primary-btn:active { transform: scale(0.97); }

.primary-btn .pause-icon { display: none; }

body.playing .primary-btn .play-icon { display: none; }
body.playing .primary-btn .pause-icon { display: inline; }

.duration-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-dim);
}

.duration-row select {
  background: rgba(255, 251, 243, 0.6);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* Zen mode — fade chrome when running */
body.playing.zen .session-top,
body.playing.zen .session-bottom,
body.playing.zen .phase-count {
  opacity: 0.15;
}

body.playing.zen .phase-count {
  font-size: 22px;
}

body.playing.zen .session-top:hover,
body.playing.zen .session-bottom:hover,
body.playing.zen .session-top:focus-within,
body.playing.zen .session-bottom:focus-within {
  opacity: 1;
}

/* Afterglow — post-session stats */
.afterglow {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(245, 184, 149, 0.18), rgba(245, 238, 225, 0.96) 70%);
  z-index: 20;
  animation: afterglow-in 900ms var(--ease);
  padding: 40px 24px;
  text-align: center;
}

.afterglow[hidden] { display: none; }

@keyframes afterglow-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.afterglow-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  max-width: 420px;
}

.afterglow-title {
  font-size: 24px;
  font-weight: 300;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

.afterglow-title::after {
  content: '';
  display: block;
  width: 28px;
  height: 1px;
  background: var(--accent-warm);
  margin: 14px auto 0;
  opacity: 0.8;
}

.afterglow-subtitle {
  color: var(--ink-dim);
  font-size: 14px;
  font-weight: 400;
  margin: -8px 0 0;
}

.afterglow-stats {
  display: flex;
  gap: 28px;
  justify-content: center;
}

.afterglow-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
}

.afterglow-stats .stat .num {
  font-size: 36px;
  font-weight: 200;
  color: var(--accent-warm);
  line-height: 1;
}

.afterglow-stats .stat .unit {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 10px;
}

.afterglow-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.afterglow .ghost-btn {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 200ms var(--ease);
}

.afterglow .ghost-btn:hover {
  background: rgba(43, 38, 32, 0.05);
  border-color: rgba(43, 38, 32, 0.22);
}

@media (max-width: 380px) {
  .brand { font-size: 24px; }
  .phase-label { font-size: 18px; }
  .phase-count { font-size: 36px; }
  .primary-btn { min-width: 120px; padding: 12px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb-glow { animation: none; }
  .orb { transition: none; }
  .orb-layer { transition: opacity 600ms ease-in-out; }
  .orb.inhale, .orb.exhale, .orb.hold-in, .orb.hold-out { transform: none; }
  .afterglow { animation: none; }
}

/* iOS meta theme-color won't auto-update; PWA status bar inherits from here */
@supports (-webkit-touch-callout: none) {
  body {
    background-attachment: fixed;
  }
}
