:root {
  --bg-deep: #050814;
  --bg-surface: rgba(15, 22, 41, 0.84);
  --bg-surface-solid: rgba(5, 8, 20, 0.92);
  --bg-raised: rgba(26, 31, 53, 0.72);
  --glass-border: rgba(217, 168, 255, 0.16);
  --text-primary: #ffffff;
  --text-secondary: #d9d7e6;
  --text-muted: #89849d;
  --accent-base: #d9a8ff;
  --accent-base-dim: rgba(217, 168, 255, 0.14);
  --accent-identity: #8be7ff;
  --accent-identity-dim: rgba(139, 231, 255, 0.13);
  --accent-identity-glow: rgba(139, 231, 255, 0.38);
  --accent-purple: #7c3aed;
  --accent-pink: #ec4899;
  --error: #f87171;
  --error-dim: rgba(248, 113, 113, 0.12);
  --success: #8be7ff;
  --success-dim: rgba(139, 231, 255, 0.12);
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-2xl: 18px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Figtree', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  background-image:
    radial-gradient(circle at 20% 0%, rgba(124, 58, 237, 0.26), transparent 30rem),
    radial-gradient(circle at 85% 90%, rgba(236, 72, 153, 0.14), transparent 30rem),
    linear-gradient(180deg, #0f1629 0%, var(--bg-deep) 100%);
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  background: var(--bg-surface-solid);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-mark {
  width: 34px;
  height: 34px;
  font-size: 0;
  color: var(--accent-base);
  opacity: 0.85;
  filter: drop-shadow(0 0 14px rgba(217, 168, 255, 0.38));
}

.logo-mark::before {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  background: currentColor;
  -webkit-mask: url('/brand-mark.svg') center / contain no-repeat;
  mask: url('/brand-mark.svg') center / contain no-repeat;
}

.app-header h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.app-header h1 span {
  color: var(--text-secondary);
  font-weight: 400;
}

@media (max-width: 768px) {
  .app-header {
    height: 64px;
    gap: 12px;
    padding: 0 18px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .logo-mark {
    width: 34px;
    height: 34px;
  }

  .app-header h1 {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 17px;
    line-height: 1;
    letter-spacing: 0.18em;
  }

  .app-header h1 span {
    display: block;
    font-weight: 400;
  }
}

@media (max-width: 380px) {
  .logo-mark {
    width: 34px;
    height: 34px;
  }

  .app-header h1 {
    font-size: 17px;
    letter-spacing: 0.18em;
  }
}

/* ── Page layout ── */
.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Identity header card ─────────────────────────────────────────────
   Avatar + name + identity reminder pulled from the user's Blueprint
   "I AM" statement. This is the first thing a user sees when they open
   Settings — a deliberate cue back to who they said they are.
   Uses a subtle radial highlight so the card feels like a presence card,
   not a generic profile row. */
.identity-card {
  background: var(--bg-surface-solid);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  padding: 1.25rem 1.125rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.identity-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.identity-avatar-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(148, 148, 168, 0.35);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.identity-avatar-link:hover,
.identity-avatar-link:focus-visible {
  color: var(--text-secondary);
  text-decoration-color: var(--text-secondary);
  outline: none;
}

.identity-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 0% 0%, var(--accent-identity-dim) 0%, transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(217, 168, 255, 0.1) 0%, transparent 55%);
  pointer-events: none;
}

.identity-avatar {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 2px solid var(--accent-identity);
  box-shadow: 0 0 18px var(--accent-identity-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.identity-meta {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.identity-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.identity-label {
  margin-top: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-identity);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.identity-statement {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.4;
  /* Allow up to 2 lines so a longer "I am ___" statement isn't cut off
     mid-thought. The whole point of this card is the reminder. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

/* Title rendering — when the coach has distilled a 2–4 label Title from
   the I am statements, we swap the italic statement style for a confident
   label-style render. Each label gets its own span so we can style the
   separator without baking a literal "|" character into the markup. */
.identity-statement.identity-title {
  font-style: normal;
  color: var(--accent-identity);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
}

.identity-title-sep {
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.55;
}

.identity-title-label { white-space: nowrap; }

.identity-cta {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent-base);
  text-decoration: none;
}

.identity-cta:hover { opacity: 0.85; }

/* ── Tab strip ─────────────────────────────────────────────────────────
   Three tabs (Profile, App, Voice) with a green underline on the active
   tab. Mirrors the inspiration screenshot. */
.tab-strip {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--glass-border);
  margin-top: 0.25rem;
}

.tab-btn {
  flex: 0 0 auto;
  padding: 0.75rem 1.25rem 0.6rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--accent-identity);
  font-weight: 600;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: -1px;
  height: 2px;
  background: var(--accent-identity);
  border-radius: 2px 2px 0 0;
  box-shadow: 0 0 8px var(--accent-identity-glow);
}

/* ── Tab panels ── */
.tab-panel {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
}

.tab-panel.active { display: flex; }

/* ── Section card ── */
.section-card {
  background: var(--bg-surface-solid);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  overflow: hidden;
}

.section-header {
  padding: 0.875rem 1.125rem 0.625rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
}

.section-body {
  padding: 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Field ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: 0.65rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

#voiceSampleText {
  min-height: calc((0.9375rem * 1.5 * 3) + 1.3rem + 2px);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent-base);
  box-shadow: 0 0 0 3px var(--accent-base-dim);
}

.field input::placeholder,
.field textarea::placeholder { color: var(--text-muted); }

.field input[readonly] {
  opacity: 0.55;
  cursor: default;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239494a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  cursor: pointer;
}

.field select option {
  background: #1e1e22;
  color: var(--text-primary);
}

/* ── Buttons ── */
.btn {
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: var(--r-md);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: #fff;
}

.btn-primary:hover:not(:disabled) { opacity: 0.94; filter: brightness(1.08); }

.btn-danger {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--error);
}

.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.16); }

.btn-feedback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  background: var(--accent-identity-dim);
  border: 1px solid rgba(139, 231, 255, 0.28);
  color: var(--accent-identity);
}

.btn-feedback:hover {
  background: rgba(139, 231, 255, 0.18);
  border-color: rgba(139, 231, 255, 0.45);
}

.btn-feedback svg { flex-shrink: 0; }

/* ── Banner ── */
.banner {
  display: none;
  border-radius: var(--r-md);
  padding: 0.6rem 0.875rem;
  font-size: 0.8125rem;
}

.banner.visible { display: block; }

.banner--error {
  background: var(--error-dim);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--error);
}

.banner--success {
  background: var(--success-dim);
  border: 1px solid rgba(139, 231, 255, 0.2);
  color: var(--success);
}

/* ── Input + inline button row ── */
.input-btn-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.input-btn-row input { flex: 1; }

.btn-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  font-size: 1rem;
}

.btn-icon:hover:not(:disabled) {
  border-color: var(--accent-base);
  color: var(--accent-base);
  background: var(--accent-base-dim);
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-icon.playing {
  color: var(--accent-base);
  border-color: var(--accent-base);
}

/* ── Important date row ── */
.date-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
}

.date-row input[type="text"] { min-width: 0; }
.date-row input[type="date"] {
  width: 155px;
  flex-shrink: 0;
}

.btn-remove {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.15s;
}

.btn-remove:hover { background: var(--error-dim); }

/* ── Toggle switch (push notifications) ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.toggle-info { flex: 1; min-width: 0; }
.toggle-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.toggle-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}
.toggle-switch {
  position: relative;
  width: 50px;
  height: 30px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}
.toggle-switch[aria-checked="true"] {
  background: var(--accent-base);
  border-color: var(--accent-base);
}
.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.toggle-switch[aria-checked="true"] .toggle-knob {
  transform: translateX(20px);
  background: #fff;
}
.toggle-switch.is-blocked {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
}
.toggle-switch.is-blocked .toggle-knob { background: var(--error); }
.toggle-switch:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Voice picker (inlined from voice-config) ─────────────────────────
   Compact grid version sized for the Settings tab. The full-page picker
   at /voice-config.html is still used during onboarding; this is a
   trimmed, embedded variant for users who already finished onboarding. */
.voice-status-pill {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  padding: 4px 10px;
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
  margin-left: 0.5rem;
  vertical-align: middle;
}
.voice-status-pill.enabled {
  background: var(--accent-identity-dim);
  color: var(--accent-identity);
  border-color: rgba(139, 231, 255, 0.3);
}
.voice-status-pill.disabled {
  background: var(--error-dim);
  color: var(--error);
  border-color: rgba(248, 113, 113, 0.3);
}

.voice-warning {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 0.875rem;
  border-radius: var(--r-md);
  background: var(--error-dim);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--error);
  font-size: 0.8125rem;
  line-height: 1.45;
}
.voice-warning code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  background: rgba(248, 113, 113, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}

.voice-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 0.75rem 0.875rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}

.voice-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--voice-accent, transparent);
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.voice-card:hover {
  border-color: var(--voice-accent, rgba(255,255,255,0.15));
  background: rgba(255, 255, 255, 0.05);
}
.voice-card:hover::before { opacity: 0.85; }

.voice-card.selected {
  border-color: var(--voice-accent, var(--accent-identity));
  background: var(--voice-accent-dim, var(--accent-identity-dim));
}
.voice-card.selected::before { opacity: 1; }

.voice-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.voice-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}
.voice-card.selected .voice-name {
  color: var(--voice-accent, var(--accent-identity));
}

.voice-badge {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
}
.voice-card.selected .voice-badge {
  background: var(--voice-accent-dim, var(--accent-identity-dim));
  border-color: var(--voice-accent, rgba(139, 231, 255, 0.3));
  color: var(--voice-accent, var(--accent-identity));
}

.voice-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.voice-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
}

.voice-play-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.voice-play-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}
.voice-play-btn.loading {
  border-color: var(--accent-base);
  color: var(--accent-base);
  animation: voiceBtnSpin 1.2s linear infinite;
}
.voice-play-btn.playing {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--error);
}

.voice-active-tag {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-identity);
  font-family: 'JetBrains Mono', monospace;
}
.voice-card.selected .voice-active-tag { display: inline-flex; }

@keyframes voiceBtnSpin {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* On narrow screens drop voice grid to 1 column */
@media (max-width: 380px) {
  .voice-grid { grid-template-columns: 1fr; }
}

.app-version {
  position: fixed;
  z-index: 150;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 0.5rem);
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: auto;
  margin: 0;
  font-size: 0.65rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  opacity: 0.5;
  user-select: none;
  pointer-events: none;
}

/* Unsaved rhythm changes — modal (App tab) */
.rhythm-unsaved-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(5, 5, 8, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.rhythm-unsaved-overlay[hidden] { display: none !important; }
.rhythm-unsaved-card {
  width: 100%;
  max-width: 400px;
  border-radius: var(--r-xl);
  border: 1px solid var(--glass-border);
  background: var(--bg-surface-solid);
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}
.rhythm-unsaved-card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem 0;
  color: var(--text-primary);
}
.rhythm-unsaved-card p {
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-secondary);
  margin: 0 0 1.25rem 0;
}
.rhythm-unsaved-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.rhythm-unsaved-actions .btn {
  width: 100%;
  justify-content: center;
}
.rhythm-unsaved-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.rhythm-unsaved-row .btn { flex: 1; min-width: 120px; }
