:root {
  --bg: #020617;
  --bg-soft: #02081b;
  --panel: #020617;
  --card: #02081d;
  --card-soft: #020b28;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.2);
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --danger: #f97373;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 999px;
  --shadow-soft: 0 18px 60px rgba(15, 23, 42, 0.9);
  --border-soft: 1px solid rgba(148, 163, 184, 0.12);
  --phase-color: #38bdf8;
  --phase-shadow: rgba(56, 189, 248, 0.4);
  --bg-gradient: radial-gradient(circle at top, #0b1120 0, #020617 50%, #000 100%);
  --progress: 0;
}

:root[data-theme="dark"] {
  --bg: #020617;
  --bg-soft: #02081b;
  --panel: #0b1224;
  --card: #0b1120;
  --card-soft: #0f172a;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.2);
  --accent-strong: #0ea5e9;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --bg-gradient: radial-gradient(circle at top, #0b1120 0, #020617 50%, #000 100%);
}

:root[data-theme="light"] {
  --bg: #f8fafc;
  --bg-soft: #e5e7eb;
  --panel: #ffffff;
  --card: #f8fafc;
  --card-soft: #f1f5f9;
  --accent: #0ea5e9;
  --accent-soft: rgba(14, 165, 233, 0.16);
  --accent-strong: #0284c7;
  --text: #0f172a;
  --text-soft: #475569;
  --bg-gradient: radial-gradient(circle at top, #e2f3ff 0, #f8fafc 50%, #eef2ff 100%);
  --shadow-soft: 0 12px 30px rgba(15, 23, 42, 0.2);
  --border-soft: 1px solid rgba(148, 163, 184, 0.3);
}

:root[data-theme="sky"] {
  --bg: #0b1120;
  --bg-soft: #0a162b;
  --panel: #0b1b33;
  --card: #0b1f3d;
  --card-soft: #0f274a;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.28);
  --accent-strong: #22d3ee;
  --text: #e2e8f0;
  --text-soft: #cbd5e1;
  --bg-gradient: radial-gradient(circle at top, #0f1f3a 0, #0b1120 50%, #020617 100%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 1080px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  position: relative;
}

/* subtle animated aurora background */
.app::before {
  content: "";
  position: fixed;
  inset: -40%;
  background: radial-gradient(circle at 20% 0, rgba(56, 189, 248, 0.18), transparent 60%),
    radial-gradient(circle at 80% 100%, rgba(56, 189, 248, 0.15), transparent 60%);
  opacity: 0.6;
  filter: blur(40px);
  z-index: -1;
  animation: auroraMove 22s ease-in-out infinite alternate;
}

@keyframes auroraMove {
  0% {
    transform: translate3d(-12px, 10px, 0) scale(1.02);
  }
  100% {
    transform: translate3d(12px, -20px, 0) scale(1.04);
  }
}

/* HEADER */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: var(--border-soft);
  backdrop-filter: blur(20px);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 20%, #e0f2fe, #38bdf8, #0f172a);
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.brand-text h1 {
  font-size: 18px;
  margin: 0;
}

.brand-text p {
  font-size: 11px;
  margin: 0;
  color: var(--text-soft);
}

.app-profile-switcher {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.app-header-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: var(--border-soft);
  cursor: pointer;
}

.header-profile-mini {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-profile-mini-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.header-profile-mini-avatar-inner {
  width: 100%;
  height: 100%;
}

.header-profile-mini-sticker {
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: 0.9rem;
}

.header-profile-mini-name {
  font-weight: 600;
}

.label-small {
  font-size: 11px;
  color: var(--text-soft);
}

.profile-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#profileSelect {
  padding: 4px 10px;
  border-radius: 999px;
  border: var(--border-soft);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}

.profile-tagline {
  font-size: 11px;
  color: var(--text-soft);
}

/* NAV */

.app-nav {
  position: sticky;
  bottom: 0;
  inset-inline: 0;
  display: flex;
  justify-content: space-around;
  padding: 0.4rem 0.6rem env(safe-area-inset-bottom);
  background: var(--panel);
  backdrop-filter: blur(16px);
  border-top: var(--border-soft);
}

.nav-btn {
  flex: 1;
  margin: 0 0.3rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.4rem 0.6rem;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.9rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav-btn--active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent);
}

/* MAIN LAYOUT */

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 1rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.view {
  display: none;
}

.view.view--active,
.view-active {
  display: block;
}

.section-title {
  font-size: 16px;
  margin: 0 0 6px;
}

/* COACH LAYOUT */

.coach-layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .coach-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    align-items: center;
  }
}

.card {
  background: linear-gradient(145deg, var(--card), var(--card-soft));
  border-radius: var(--radius-lg);
  border: var(--border-soft);
  padding: 12px 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.9);
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 10px;
}

.field-label {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text-soft);
}

.field-select,
.field-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 999px;
  border: var(--border-soft);
  background: #020617;
  color: var(--text);
  font-size: 13px;
}

.field-input::-webkit-inner-spin-button,
.field-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.small {
  font-size: 12px;
}

.text-muted {
  color: var(--text-soft);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chip {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-soft);
  background: rgba(15, 23, 42, 0.8);
}

.chip-primary {
  border-color: rgba(56, 189, 248, 0.8);
  color: #cffafe;
}

.chip-toggle {
  cursor: pointer;
  background: transparent;
}

.chip-toggle.chip-active {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.9);
  color: #e0f2fe;
}

/* METRICS */

.coach-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.metric-label {
  font-size: 11px;
  color: var(--text-soft);
}

.metric-value {
  display: block;
  font-size: 14px;
}

/* BUTTONS */

.btn {
  border-radius: 999px;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(120deg, #38bdf8, #0ea5e9);
  color: #0b1120;
  font-weight: 600;
}

.btn-soft {
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.5);
  color: var(--text-soft);
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: var(--text-soft);
  padding: 4px 10px;
  font-size: 12px;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* TOGGLE */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-soft);
}

.toggle input {
  display: none;
}

.toggle-indicator {
  width: 30px;
  height: 16px;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  position: relative;
  transition: background 0.2s ease, border 0.2s ease;
}

.toggle-indicator::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e5e7eb;
  position: absolute;
  top: 1px;
  left: 1px;
  transition: transform 0.2s ease;
}

.toggle input:checked + .toggle-indicator {
  background: rgba(56, 189, 248, 0.4);
  border-color: rgba(56, 189, 248, 0.9);
}

.toggle input:checked + .toggle-indicator::after {
  transform: translateX(14px);
}

.toggle-label {
  user-select: none;
}

/* COACH CONTROLS */

.coach-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.card-tips {
  margin-top: 8px;
}

/* BREATH VISUAL */

.coach-right {
  display: flex;
}

.breath-visual-card {
  width: 100%;
}

.breath-circle-wrapper {
  margin-top: 8px;
  position: relative;
  width: 100%;
  max-width: 320px;
  margin-inline: auto;
  aspect-ratio: 1;
}

.breath-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 6px solid rgba(148, 163, 184, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 0 40px var(--phase-shadow);
  transition: box-shadow 0.6s ease, border-color 0.6s ease,
    transform 0.6s ease;
  overflow: hidden;
}

.breath-circle::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: conic-gradient(
    var(--phase-color) calc(var(--progress) * 1%),
    rgba(15, 23, 42, 0.8) 0%
  );
  transition: background 0.25s linear;
}

.breath-circle::after {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  background: radial-gradient(
      circle at 30% 20%,
      rgba(255, 255, 255, 0.05),
      transparent 30%
    ),
    radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.04), transparent 40%);
  pointer-events: none;
}

.breath-circle[data-phase="inhale"] {
  transform: scale(1.04);
}

.breath-circle[data-phase="exhale"] {
  transform: scale(0.98);
}

.breath-circle[data-phase="hold"] {
  transform: scale(1.01);
}

.breath-circle[data-session-type="energize"] {
  box-shadow: 0 0 50px rgba(248, 113, 38, 0.35);
}

.breath-circle[data-session-type="sleep"] {
  box-shadow: 0 0 40px rgba(99, 102, 241, 0.35);
}

.breath-core {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  transition: background 0.25s ease, transform 0.25s ease, border-color 0.3s ease;
  color: #e5e7eb;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.breath-core:hover,
.breath-core:focus-visible {
  transform: scale(1.02);
}

.breath-core-label {
  font-size: 1.25rem;
  font-weight: 600;
}

.breath-core-sub {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 4px;
}

.breath-core.is-running {
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.breath-core.is-paused {
  background: rgba(148, 163, 184, 0.25);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

/* Helper row */

.breath-helper-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
}

.helper-label {
  display: block;
  color: var(--text-soft);
}

.helper-value {
  font-weight: 500;
}

.breath-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.session-meta {
  margin-top: 10px;
  background: var(--card);
  border-radius: var(--radius-lg);
  border: var(--border-soft);
}

.session-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px;
}

.session-cycles-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.session-cycles-value {
  font-weight: 700;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.dot-inhale {
  background: #22c55e;
}

.dot-hold {
  background: #fbbf24;
}

.dot-exhale {
  background: #38bdf8;
}

.coach-info {
  display: grid;
  gap: 0.35rem;
  align-self: start;
}

.coach-tech-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.coach-tech-pattern {
  font-size: 0.95rem;
  color: #cbd5e1;
}

.coach-tech-summary,
.coach-tech-why {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.4;
}

/* LIBRARY */

.library-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.library-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.library-card-title h3 {
  font-size: 14px;
  margin: 0;
}

.library-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
  gap: 12px;
  align-items: start;
}

.library-detail {
  min-height: 320px;
}

.library-detail h3 {
  margin-top: 0;
  margin-bottom: 8px;
}

.library-detail ul {
  padding-left: 18px;
  margin: 6px 0;
  color: var(--text);
}

.library-detail .detail-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-soft);
}

.library-detail .detail-meta span {
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 8px;
  border-radius: 10px;
}

.library-card-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.library-item {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(31, 41, 55, 0.9);
  cursor: pointer;
}

/* PROFILE */

.profile-layout {
  display: grid;
  grid-template-columns: 1.2fr 1.1fr;
  gap: 12px;
}

.profile-card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 16px;
  padding: 1rem;
  display: grid;
  gap: 1rem;
  border: var(--border-soft);
}

.avatar-preview {
  display: flex;
  justify-content: center;
  align-items: center;
}

.avatar-shape {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  background: radial-gradient(circle at top, var(--accent-soft), var(--card));
}

.avatar-inner {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.5);
}

.avatar-sticker {
  position: absolute;
  bottom: -6px;
  right: -6px;
  font-size: 1.2rem;
}

.avatar-shape[data-shape="circle"] .avatar-inner {
  border-radius: 50%;
}

.avatar-shape[data-shape="diamond"] .avatar-inner {
  transform: rotate(45deg);
  border-radius: 16px;
}

.avatar-shape[data-shape="hex"] .avatar-inner {
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

.avatar-controls {
  display: grid;
  gap: 0.85rem;
}

.avatar-control-group label {
  font-size: 0.95rem;
  color: var(--text);
}

.avatar-color-row,
.avatar-shape-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.avatar-sticker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.avatar-sticker-btn {
  border: var(--border-soft);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease;
}

.avatar-sticker-btn:hover,
.avatar-sticker-btn.active {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.avatar-color-swatch,
.avatar-accent-swatch {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
}

.avatar-color-swatch[data-color="teal"] {
  background: #14b8a6;
}

.avatar-color-swatch[data-color="blue"] {
  background: #3b82f6;
}

.avatar-color-swatch[data-color="purple"] {
  background: #a855f7;
}

.avatar-color-swatch[data-color="amber"] {
  background: #f59e0b;
}

.avatar-accent-swatch[data-accent="yellow"] {
  background: #facc15;
}

.avatar-accent-swatch[data-accent="pink"] {
  background: #ec4899;
}

.avatar-accent-swatch[data-accent="lime"] {
  background: #84cc16;
}

.avatar-accent-swatch[data-accent="sky"] {
  background: #0ea5e9;
}

.avatar-shape-btn {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: transparent;
  color: #e5e7eb;
  cursor: pointer;
}

.avatar-shape-btn.avatar-shape-btn--active,
.avatar-color-swatch.is-active,
.avatar-accent-swatch.is-active {
  border-color: #38bdf8;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-soft);
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
}

.streak-bar {
  margin-top: 6px;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.6);
  overflow: hidden;
}

.streak-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #38bdf8);
  transition: width 0.3s ease;
}

/* Badges */

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.badge-card {
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: radial-gradient(circle at 0 0, rgba(56, 189, 248, 0.16), rgba(15, 23, 42, 0.96));
  padding: 8px 10px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0.5;
}

.badge-card.unlocked {
  opacity: 1;
  border-color: rgba(56, 189, 248, 0.9);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.7);
}

.theme-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-pill {
  border: var(--border-soft);
  background: var(--card);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.theme-pill--active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.badge-title {
  font-weight: 600;
}

.badge-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.badge-chip {
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(15, 23, 42, 0.8);
}

/* Textarea */

.field-textarea {
  width: 100%;
  margin-top: 6px;
  border-radius: 12px;
  border: var(--border-soft);
  background: #020617;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  resize: vertical;
}

/* FOOTER */

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(15, 23, 42, 0.9);
  font-size: 10px;
  color: var(--text-soft);
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  color: #e5e7eb;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* RESPONSIVE */

@media (max-width: 840px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .app-profile-switcher {
    align-items: flex-start;
  }

  .coach-layout,
  .profile-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .app-footer {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .library-layout {
    grid-template-columns: 1fr;
  }
}
