:root {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-elevated: #1b2640;
  --border: #263452;
  --primary: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.16);
  --accent: #f59e0b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --safe: #10b981;
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 86px;
}

/* HEADER */
.app-header {
  background: rgba(19, 28, 49, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 12px 16px;
}
.header-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 1.6rem; }
.brand h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.status-badge { font-size: 0.72rem; color: var(--safe); display: block; font-weight: 500; }

.header-actions { display: flex; gap: 8px; align-items: center; }
.pro-pill {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 6px 11px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}
.pro-pill.unlocked {
  background: rgba(16, 185, 129, 0.15);
  color: var(--safe);
  border-color: rgba(16, 185, 129, 0.4);
}
.sos-pill {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

/* TREND BANNER */
.trend-banner {
  background: #1e293b;
  border-bottom: 1px solid var(--accent);
  padding: 14px 16px;
}
.trend-content { max-width: 600px; margin: 0 auto; }
.trend-content strong { color: var(--accent); font-size: 0.92rem; }
.trend-content p { font-size: 0.84rem; color: #cbd5e1; margin: 4px 0 10px; }
.trend-actions { display: flex; gap: 12px; align-items: center; }

/* MAIN LAYOUT */
.app-main { max-width: 600px; margin: 0 auto; padding: 16px; }
.tab-view { display: none; animation: fadeIn 0.2s ease; }
.tab-view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* CARDS & TYPOGRAPHY */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.center-card { text-align: center; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; color: var(--text); }
h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.muted { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 14px; }
.eyebrow { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; color: var(--primary); text-transform: uppercase; }

/* CONTRACT PROGRESS CARD */
.contract-stats { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.contract-stats h2 { font-size: 2rem; line-height: 1; color: var(--primary); margin: 0; }
.sub-label { font-size: 0.78rem; color: var(--text-muted); }
.contract-right { text-align: right; display: flex; flex-direction: column; gap: 4px; }
.pct-tag { font-size: 0.85rem; font-weight: 700; color: var(--safe); }
.streak-tag { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.progress-track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--safe)); transition: width 0.4s ease; }
.contract-editor { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.grid-2 label { font-size: 0.78rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }

/* MOOD SELECTOR */
.mood-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.mood-btn {
  background: var(--surface-elevated);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.mood-btn .emoji { font-size: 1.65rem; }
.mood-btn .label { font-size: 0.68rem; color: var(--text-muted); font-weight: 600; }
.mood-btn:active, .mood-btn.selected { border-color: var(--primary); background: var(--primary-glow); transform: scale(1.05); }
.inline-toast { margin-top: 10px; text-align: center; font-size: 0.82rem; color: var(--safe); font-weight: 600; }

/* CHART & INSIGHTS */
.insight-pill { font-size: 0.72rem; background: var(--bg); color: var(--primary); padding: 4px 9px; border-radius: 99px; border: 1px solid var(--border); }
.chart-box { background: var(--bg); border-radius: 10px; padding: 10px; margin: 10px 0; }
#mood-chart { width: 100%; height: 110px; display: block; }

/* QUICK JUMP CARDS */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.q-icon { font-size: 1.5rem; margin-bottom: 4px; }
.quick-card strong { font-size: 0.92rem; }
.quick-card small { font-size: 0.76rem; color: var(--text-muted); }

/* BUTTONS & INPUTS */
.btn {
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.85; }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; width: auto; }
.btn-primary { background: var(--primary); color: #06121e; }
.btn-accent { background: var(--accent); color: #1a1000; }
.btn-warn { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface-elevated); color: var(--text); border: 1px solid var(--border); margin-bottom: 10px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.4); }
.btn-link { background: none; border: none; color: var(--primary); font-size: 0.82rem; font-weight: 600; cursor: pointer; text-decoration: underline; }

input[type="text"], input[type="date"], input[type="time"], textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; margin-bottom: 12px; }

/* SUB-NAV FOR TOOLKIT */
.sub-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.sub-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.sub-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }
.sub-view { display: none; }
.sub-view.active { display: block; }
.pro-tag { font-size: 0.62rem; background: var(--accent); color: #000; padding: 2px 5px; border-radius: 4px; font-weight: 800; vertical-align: middle; }

/* BREATHING */
.breath-stage { height: 240px; display: flex; align-items: center; justify-content: center; position: relative; }
.breath-ring {
  position: absolute;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 1px dashed var(--border);
}
.breath-circle {
  width: 125px;
  height: 125px;
  border-radius: 50%;
  background: var(--primary-glow);
  border: 3px solid var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 4s ease-in-out;
}
.breath-circle.inhale { transform: scale(1.48); }
.breath-circle.exhale { transform: scale(1); }
#breath-text { font-weight: 700; font-size: 1rem; color: var(--primary); }
#breath-timer { font-size: 0.72rem; color: var(--text-muted); }

/* GROUNDING & REFRAME */
.sos-step { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.sos-step h4 { font-size: 0.9rem; color: var(--primary); margin-bottom: 8px; }
.sos-inputs { display: flex; flex-direction: column; gap: 6px; }
.sos-result { background: rgba(16, 185, 129, 0.12); border: 1px solid var(--safe); padding: 16px; border-radius: 10px; text-align: center; margin-top: 12px; }

.reframe-step { display: none; }
.reframe-step.active { display: block; }
.reframe-step label { display: block; font-weight: 700; font-size: 0.9rem; color: var(--primary); margin-bottom: 8px; }
.distortion-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.distortion-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  text-align: left;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.distortion-btn small { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.76rem; }
.distortion-btn.selected { border-color: var(--primary); background: var(--primary-glow); }

/* SANCTUARY & SLEEP */
.sanctuary-visual { background: #060a14; border-radius: 10px; overflow: hidden; margin-bottom: 12px; border: 1px solid var(--border); }
#wave-canvas { width: 100%; height: 110px; display: block; }
.sound-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sound-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.sound-btn span { font-weight: 700; font-size: 0.92rem; display: block; }
.sound-btn small { color: var(--text-muted); font-size: 0.78rem; }
.sound-btn.active { border-color: var(--primary); background: var(--primary-glow); }
.audio-controls label { font-size: 0.82rem; color: var(--text-muted); display: block; margin-bottom: 10px; }
.audio-controls input[type="range"] { width: 100%; margin-top: 6px; }

.preset-row { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.preset-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.sleep-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.sleep-inputs label { font-size: 0.78rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.sleep-window {
  background: var(--bg);
  border-left: 4px solid var(--safe);
  padding: 12px;
  border-radius: 8px;
  margin-top: 10px;
}
.sleep-window.nap { border-left-color: var(--accent); }
.sleep-window h4 { font-size: 0.92rem; color: var(--safe); margin-bottom: 2px; }
.sleep-window.nap h4 { color: var(--accent); }
.sleep-window p { font-size: 0.82rem; color: var(--text-muted); }

/* LISTS */
.compact-list { list-style: none; margin-top: 10px; }
.compact-list li {
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.86rem;
  border-left: 3px solid var(--primary);
}
.compact-list .date { display: block; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 2px; }

/* PRO GATE OVERLAY */
.pro-locked { position: relative; }
.pro-lock-banner {
  background: rgba(11, 17, 32, 0.92);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.pro-lock-banner span { font-size: 0.82rem; color: #fde68a; }

/* HELP TAB */
.help-hero { border-left: 4px solid var(--danger); }
.help-links { display: flex; flex-direction: column; gap: 8px; }
.help-btn {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 12px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
}
.help-card.featured .help-btn { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.crisis-callout {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 14px;
  border-radius: 10px;
  font-size: 0.84rem;
  color: #fde68a;
}

/* PRO UPSELL & MODAL */
.pro-upsell-card { border-color: rgba(245, 158, 11, 0.45); background: linear-gradient(180deg, #1b2438 0%, #131c31 100%); }
.badge-free { font-size: 0.72rem; background: var(--bg); padding: 4px 8px; border-radius: 6px; color: var(--text-muted); }
.feature-checklist { list-style: none; margin: 12px 0; font-size: 0.85rem; color: #cbd5e1; display: flex; flex-direction: column; gap: 6px; }
.license-input-row { display: flex; gap: 8px; margin-bottom: 10px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.82);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 16px;
  max-width: 440px;
  width: 100%;
  padding: 22px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}
.modal-cta-group { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 14px; }

/* BOTTOM NAVIGATION */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(19, 28, 49, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.nav-icon { font-size: 1.25rem; }
.nav-label { font-size: 0.72rem; font-weight: 700; }
.nav-item.active { color: var(--primary); }

.hidden { display: none !important; }

/* LICENSE GATE & INSTALL BANNER */
.license-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 999;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}
.license-gate[hidden] { display: none !important; }

.lc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 440px;
  width: 100%;
  padding: 24px 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.55);
}
.lc-logo { font-size: 2.2rem; display: block; margin-bottom: 8px; }
.lc-header { margin-bottom: 14px; }
.lc-divider {
  text-align: center;
  border-bottom: 1px solid var(--border);
  line-height: 0.1em;
  margin: 20px 0 16px;
}
.lc-divider span {
  background: var(--surface);
  padding: 0 10px;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.lc-form label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.lc-form input { margin-bottom: 10px; }
.lc-error { color: var(--danger); font-size: 0.82rem; margin-bottom: 10px; font-weight: 600; }
.lc-email-tag { color: var(--safe); font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; }
.lc-install-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin: 14px 0;
}
.lc-steps { font-size: 0.84rem; color: #cbd5e1; line-height: 1.5; }
.lc-wide { width: 100%; margin-top: 8px; }
.lc-tip { font-size: 0.8rem; color: #fde68a; background: rgba(245, 158, 11, 0.1); padding: 10px; border-radius: 8px; margin-top: 12px; }
.lc-footer { text-align: center; margin-top: 16px; font-size: 0.8rem; }
.lc-footer a { color: var(--text-muted); text-decoration: underline; }

.install-banner {
  background: #172554;
  border-bottom: 1px solid var(--primary);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}