/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #07071a;
  --primary:      #7c6bff;
  --secondary:    #a89cff;
  --accent:       #ff9fce;
  --text:         #e8e4ff;
  --text-dim:     rgba(232, 228, 255, 0.55);
  --surface:      rgba(255, 255, 255, 0.06);
  --surface-hi:   rgba(255, 255, 255, 0.12);
  --radius-pill:  100px;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Raleway', 'Segoe UI', system-ui, sans-serif;
  font-weight: 300;
  line-height: 1.6;
}

/* ── Views ─────────────────────────────────────────────────────────────── */
.view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease;
}
.view.hidden { opacity: 0; pointer-events: none; }

canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
}

/* ── Login animations ──────────────────────────────────────────────────── */
@keyframes loginFadeInUp {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Animate in, hold, then gently fade out and drift up */
@keyframes welcomeTextLifecycle {
  0%   { opacity: 0; transform: translateY(28px); }
  12%  { opacity: 1; transform: translateY(0); }
  65%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-content {
  position: relative;
  z-index: 1;
  text-align: center;
  width: min(420px, calc(100vw - 2rem));
  padding: clamp(1.5rem, 5vw, 2.5rem);
  background: rgba(7, 7, 26, 0.5);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 1.5rem;
}

.brand-title {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0.04em;
  margin-bottom: 1.25rem;
  animation: welcomeTextLifecycle 5.5s ease forwards;
}
.brand-title span { color: var(--primary); font-style: italic; }

.tagline {
  color: var(--text-dim);
  font-size: clamp(0.9rem, 2.5vw, 1.05rem);
  margin-bottom: 2.75rem;
  animation: welcomeTextLifecycle 5.5s 0.15s ease forwards;
}

.btn-github {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 0.85rem 2rem;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  font-weight: 400;
  text-decoration: none;
  backdrop-filter: blur(12px);
  transition: background 0.25s, border-color 0.25s, box-shadow 0.25s, transform 0.2s;
  opacity: 0;
  animation: loginFadeInUp 0.7s 0.8s ease forwards;
}
.btn-github svg { width: 1.2rem; height: 1.2rem; flex-shrink: 0; }
.btn-github:hover {
  background: var(--surface-hi);
  border-color: var(--primary);
  box-shadow: 0 6px 28px rgba(124, 107, 255, 0.3);
  transform: translateY(-2px);
}

.btn-guest {
  display: inline-block;
  margin-top: 0.9rem;
  padding: 0.55rem 1.5rem;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.10);
  background: transparent;
  transition: color 0.2s, border-color 0.2s;
  opacity: 0;
  animation: loginFadeInUp 0.7s 1.0s ease forwards;
}
.btn-guest:hover { color: var(--text); border-color: rgba(255,255,255,0.28); }

.login-note {
  margin-top: 1.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0;
  animation: loginFadeInUp 0.7s 1.1s ease forwards;
}

/* ── Setup ─────────────────────────────────────────────────────────────── */
.setup-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 580px;
  padding: 1.5rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.setup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user-info { display: flex; align-items: center; gap: 0.75rem; }
#user-avatar {
  border-radius: 50%;
  border: 2px solid var(--primary);
  width: 36px; height: 36px;
}

.setup-heading {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: clamp(2.2rem, 5vw, 3rem);
  font-weight: 400;
  line-height: 1.2;
}
.setup-heading span { color: var(--primary); font-style: italic; }

.form-group { position: relative; }

textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 1rem;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 300;
  padding: 1.1rem 1.25rem;
  resize: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 107, 255, 0.15);
}
textarea::placeholder { color: var(--text-dim); }

.char-counter {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

.duration-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.7rem;
}
.duration-options { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.duration-btn {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-dim);
  padding: 0.45rem 1.1rem;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.duration-btn:hover { background: var(--surface-hi); color: var(--text); }
.duration-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}

/* ── Mood buttons ──────────────────────────────────────────────────────── */
.mood-group { display: flex; flex-direction: column; gap: 0.5rem; }

.mood-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.mood-btn {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-pill);
  color: rgba(232, 228, 255, 0.55);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 300;
  padding: 0.32rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.mood-btn:hover {
  border-color: rgba(124, 107, 255, 0.5);
  color: var(--text);
}
.mood-btn.active {
  background: rgba(124, 107, 255, 0.18);
  border-color: var(--primary);
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(124, 107, 255, 0.12);
}

/* ── Shared buttons ────────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border: none;
  color: #fff;
  padding: 0.9rem 2.25rem;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  align-self: flex-start;
  transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
}
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(124, 107, 255, 0.4);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: color 0.2s;
}
.btn-link:hover { color: var(--text); }

/* ── Loading ───────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.loading-ring {
  width: 22px; height: 22px;
  border: 2px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ─────────────────────────────────────────────────────────────── */
.error-msg {
  color: #ff8fa3;
  font-size: 0.88rem;
  padding: 0.9rem 1.1rem;
  background: rgba(255, 100, 130, 0.1);
  border: 1px solid rgba(255, 100, 130, 0.25);
  border-radius: 0.75rem;
}

/* ── Meditation ────────────────────────────────────────────────────────── */
#view-meditation { background: var(--bg); }

.meditation-ui {
  position: relative;
  z-index: 1;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2rem;
  pointer-events: none;
}

.meditation-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: auto;
}
.med-title {
  font-family: 'Crimson Text', Georgia, serif;
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-dim);
  max-width: 55%;
}
.meditation-timer {
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.timer-sep { margin: 0 0.2rem; opacity: 0.45; }

.phase-text-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(3rem, 8vw, 6rem) clamp(1rem, 4vw, 2rem) clamp(1rem, 3vw, 2rem);
}
.phase-text {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: clamp(1.05rem, 3.5vw, 1.45rem);
  font-style: italic;
  line-height: 1.85;
  text-align: center;
  width: min(580px, calc(100vw - 2rem));
  color: var(--text);
  /* glass pill backdrop */
  background: rgba(7, 7, 26, 0.52);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 1.25rem;
  padding: clamp(1.25rem, 4vw, 1.75rem) clamp(1.25rem, 5vw, 2.25rem);
  /* animate: fade up in, fade down out */
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 1.1s ease, transform 1.1s ease;
}
.phase-text.visible {
  opacity: 1;
  transform: translateY(0);
}

.meditation-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
}
.phase-name {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}
.btn-end {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-dim);
  padding: 0.45rem 1.4rem;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-end:hover { border-color: rgba(255, 255, 255, 0.4); color: var(--text); }

.footer-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.btn-download:hover { border-color: var(--primary); color: var(--text); background: rgba(124,107,255,0.12); }

/* ── Download modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: modalFadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  position: relative;
  background: rgba(18, 15, 40, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 1.25rem;
  padding: 2.25rem 2rem 1.75rem;
  width: min(400px, calc(100vw - 2rem));
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  animation: modalSlideUp 0.25s ease;
}
@keyframes modalSlideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: none; border: none;
  color: var(--text-dim); font-size: 1.1rem;
  cursor: pointer; line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}
.modal-close:hover { color: var(--text); background: rgba(255,255,255,0.08); }

.modal-heading {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1.5rem; font-weight: 400;
  margin: 0 0 0.4rem;
}
.modal-sub {
  font-size: 0.85rem; color: var(--text-dim);
  margin: 0 0 1.5rem;
}

.modal-formats {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.fmt-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.fmt-btn:hover:not(:disabled) {
  background: var(--surface-hi);
  border-color: var(--primary);
  transform: translateX(3px);
}
.fmt-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.fmt-name { font-weight: 500; font-size: 0.95rem; letter-spacing: 0.04em; }
.fmt-info { font-size: 0.78rem; color: var(--text-dim); }

.modal-status {
  margin-top: 1.1rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
}
.modal-status.hidden { display: none; }

/* ── Complete ──────────────────────────────────────────────────────────── */
.complete-content {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 480px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.4rem;
}
.complete-star {
  font-size: 2.8rem;
  color: var(--primary);
  animation: star-pulse 2.5s ease-in-out infinite;
}
@keyframes star-pulse {
  0%, 100% { text-shadow: 0 0 20px var(--primary); }
  50% { text-shadow: 0 0 50px var(--primary), 0 0 90px var(--primary); }
}
.complete-content h1 {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 400;
}
.complete-stats { color: var(--text-dim); font-size: 0.9rem; }
.affirmation {
  font-family: 'Crimson Text', Georgia, serif;
  font-style: italic;
  font-size: 1.25rem;
  line-height: 1.75;
  color: var(--text-dim);
  border-left: 2px solid var(--primary);
  padding-left: 1.1rem;
  text-align: left;
  max-width: 380px;
}

/* ── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
