/* CTO Mind Map — interactive knowledge graph product */
:root {
  --bg: #05060a;
  --bg-elev: rgba(14, 16, 24, 0.82);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text: #f2f3f7;
  --muted: #9aa0b4;
  --faint: #6b728a;
  --accent: #8b7cff;
  --accent-2: #4ecdc4;
  --accent-3: #ff8f6b;
  --glow: rgba(139, 124, 255, 0.5);
  --today: #f0c674;
  --learned: #4ecdc4;
  --pending: #4a5068;
  --selected: #a78bfa;
  --radius: 20px;
  --radius-sm: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --touch: 48px;
  --hud-z: 30;
  --sheet-z: 80;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
body {
  position: fixed;
  inset: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Do NOT set touch-action:none on body — it blocks sheet scroll on iOS.
     Graph stage owns touch-action:none; sheet/HUD allow pan-y / manipulation. */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; touch-action: manipulation; }
.glass-chip, .today-chip, .related-chip, .btn, .sources-details summary {
  touch-action: manipulation;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ---------- Ambient ---------- */
.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(90px); opacity: 0.45;
  animation: orbDrift 22s ease-in-out infinite alternate;
}
.orb-a {
  width: 42vw; height: 42vw; top: -12%; left: -10%;
  background: radial-gradient(circle, #5b4fd6 0%, transparent 70%);
}
.orb-b {
  width: 36vw; height: 36vw; bottom: -8%; right: -12%;
  background: radial-gradient(circle, #1a8a7e 0%, transparent 70%);
  opacity: 0.32; animation-delay: -7s; animation-duration: 28s;
}
.orb-c {
  width: 28vw; height: 28vw; top: 45%; left: 40%;
  background: radial-gradient(circle, #a86b3a 0%, transparent 70%);
  opacity: 0.18; animation-delay: -14s; animation-duration: 32s;
}
@keyframes orbDrift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(4%, -3%) scale(1.08); }
}
.particles { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.55; }

/* ---------- Graph stage (hero) ---------- */
.graph-stage {
  position: fixed; inset: 0; z-index: 1;
  touch-action: none;
  overscroll-behavior: none;
  /* Prevent iOS rubber-band / double-tap zoom on the canvas area */
  -webkit-user-select: none;
  user-select: none;
}
body.sheet-open .graph-stage {
  pointer-events: none;
}
body.sheet-open .today-chip,
body.sheet-open .hud-top,
body.sheet-open .hud-legend,
body.sheet-open .hud-hint {
  pointer-events: none;
  opacity: 0.35;
}
body.sheet-open .sheet-backdrop {
  /* Stay inert for the ghost-click window; JS also guards closes */
  touch-action: manipulation;
}
#graph-canvas {
  width: 100%; height: 100%; display: block;
  cursor: grab;
  touch-action: none;
}
#graph-canvas:active { cursor: grabbing; }

.graph-tooltip {
  position: absolute; z-index: 5; max-width: min(280px, 78vw);
  padding: 12px 14px; border-radius: 14px; pointer-events: none;
  background: rgba(10, 12, 20, 0.92);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  font-size: 12px; line-height: 1.45;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  animation: tipIn 0.18s ease;
}
.graph-tooltip strong {
  display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600;
}
.graph-tooltip .tip-domain {
  display: inline-block; margin-bottom: 6px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: #c4bcff;
}
.graph-tooltip .tip-state {
  margin-top: 8px; font-size: 11px; font-weight: 600;
  color: var(--today);
}
@keyframes tipIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- HUD ---------- */
.glass-chip {
  background: rgba(12, 14, 22, 0.72);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
}

.hud-top {
  position: fixed; z-index: var(--hud-z);
  top: calc(12px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; pointer-events: none;
}
.hud-top > * { pointer-events: auto; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 10px 10px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 22px var(--glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text span { font-size: 10px; color: var(--muted); }

.hud-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
}
.pill {
  display: inline-flex; align-items: center; min-height: 26px;
  padding: 0 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.pill-day {
  background: rgba(240,198,116,0.16);
  border: 1px solid rgba(240,198,116,0.35);
  color: var(--today);
}
.hud-progress { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }

.hud-legend {
  position: fixed; z-index: var(--hud-z);
  bottom: calc(18px + var(--safe-b));
  left: calc(12px + var(--safe-l));
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 10px 14px;
  font-size: 11px; color: var(--muted);
  pointer-events: none;
}
.hud-legend .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
}
.dot.today { background: var(--today); box-shadow: 0 0 10px var(--today); }
.dot.learned { background: var(--learned); box-shadow: 0 0 8px var(--learned); }
.dot.pending { background: var(--pending); }
.dot.selected { background: var(--selected); box-shadow: 0 0 10px var(--selected); }

.hud-hint {
  position: fixed; z-index: var(--hud-z);
  bottom: calc(18px + var(--safe-b));
  right: calc(14px + var(--safe-r));
  margin: 0; font-size: 11px; color: var(--faint);
  pointer-events: none; opacity: 0.7;
}

/* Today floating chip */
.today-chip {
  position: fixed; z-index: var(--hud-z);
  top: calc(72px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  display: flex; align-items: center; gap: 10px;
  max-width: min(260px, calc(100vw - 24px));
  padding: 10px 14px 10px 12px;
  border-radius: 999px;
  background: rgba(12, 14, 22, 0.78);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(240,198,116,0.4);
  box-shadow: 0 0 0 1px rgba(240,198,116,0.08), 0 12px 40px rgba(240,198,116,0.18), 0 8px 28px rgba(0,0,0,0.4);
  min-height: var(--touch);
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: left;
}
.today-chip:hover, .today-chip:focus-visible {
  transform: scale(1.03);
  box-shadow: 0 0 0 1px rgba(240,198,116,0.2), 0 16px 48px rgba(240,198,116,0.28), 0 8px 28px rgba(0,0,0,0.45);
}
.today-chip:active { transform: scale(0.97); }
.today-chip-glow {
  position: absolute; inset: -2px; border-radius: inherit;
  background: linear-gradient(135deg, rgba(240,198,116,0.35), transparent 55%);
  opacity: 0.5; pointer-events: none; animation: chipPulse 2.4s ease-in-out infinite;
}
@keyframes chipPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.7; }
}
.today-chip-dot {
  position: relative; width: 10px; height: 10px; border-radius: 50%;
  background: var(--today); box-shadow: 0 0 12px var(--today);
  flex-shrink: 0; animation: todayBlink 1.8s ease-in-out infinite;
}
@keyframes todayBlink {
  0%, 100% { box-shadow: 0 0 8px var(--today); transform: scale(1); }
  50% { box-shadow: 0 0 18px var(--today); transform: scale(1.15); }
}
.today-chip-label {
  position: relative; font-size: 10px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--today);
  flex-shrink: 0;
}
.today-chip-title {
  position: relative; font-size: 12px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 140px;
}

/* ---------- Sheet (lesson panel) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: var(--sheet-z);
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: none;
}
.sheet:not([hidden]) { pointer-events: auto; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; animation: fadeIn 0.28s ease forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

.sheet-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(90dvh, 920px);
  max-height: min(90dvh, 920px);
  overflow: hidden;
  overscroll-behavior: contain;
  padding: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg-elev);
  backdrop-filter: blur(28px); -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  box-shadow: 0 -20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
  animation: sheetUp 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.sheet-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0 18px 12px;
}
.sheet-footer {
  flex: 0 0 auto;
  padding: 10px 18px calc(16px + var(--safe-b));
  border-top: 1px solid rgba(255,255,255,0.06);
  background: linear-gradient(180deg, rgba(14,16,24,0.55), rgba(14,16,24,0.95));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.sheet-footer:empty { display: none; padding: 0; border: none; }
.sheet-footer .lesson-actions { margin: 0; padding: 0; }
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}
.sheet.closing .sheet-panel { animation: sheetDown 0.28s ease forwards; }
.sheet.closing .sheet-backdrop { animation: fadeOut 0.28s ease forwards; }
@keyframes sheetDown { to { transform: translateY(100%); } }
@keyframes fadeOut { to { opacity: 0; } }

.sheet-handle {
  flex: 0 0 auto;
  width: 40px; height: 4px; border-radius: 999px;
  background: rgba(255,255,255,0.28);
  margin: 10px auto 8px;
  touch-action: manipulation;
}
.sheet-close {
  position: absolute; top: 8px; right: 8px;
  width: var(--touch); height: var(--touch); border-radius: 14px;
  font-size: 26px; line-height: 1; color: var(--muted);
  background: rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
  touch-action: manipulation;
}
.sheet-close:hover { color: var(--text); background: rgba(255,255,255,0.1); }

.sheet-body { padding-top: 4px; padding-bottom: 8px; max-width: 560px; margin: 0 auto; }

/* Desktop: right slide-over */
@media (min-width: 768px) {
  .sheet { align-items: stretch; justify-content: flex-end; }
  .sheet-panel {
    width: min(440px, 42vw);
    max-height: none; height: 100%;
    border-radius: 0;
    border-bottom: none;
    border-right: none;
    padding: 0;
    animation: sheetRight 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .sheet.closing .sheet-panel { animation: sheetRightOut 0.28s ease forwards; }
  @keyframes sheetRight {
    from { transform: translateX(100%); }
    to { transform: none; }
  }
  @keyframes sheetRightOut { to { transform: translateX(100%); } }
  .sheet-handle { display: none; }
  .sheet-close { top: 18px; right: 18px; }
  .sheet-scroll { padding: 28px 28px 12px; }
  .sheet-footer { padding: 12px 28px calc(24px + var(--safe-b)); }
  .hud-legend { bottom: calc(22px + var(--safe-b)); }
  .today-chip-title { max-width: 180px; }
}

/* ---------- Lesson content inside sheet ---------- */
.kicker {
  margin: 0 0 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
}
.muted { color: var(--muted); font-size: 13px; }
.eyebrow-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.lesson-title {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(1.45rem, 4.5vw, 1.95rem);
  line-height: 1.18; letter-spacing: -0.02em; margin: 0 0 14px;
}
.domain-chip {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: rgba(139,124,255,0.15); color: #c4bcff;
  border: 1px solid rgba(139,124,255,0.28);
}
.builds-on {
  margin: 0 0 16px; font-size: 12px; color: var(--muted); line-height: 1.4;
}

.lesson-block { margin-bottom: 22px; }
.lesson-block h2 {
  margin: 0 0 8px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint);
}
.lesson-block p { margin: 0; color: #d8dae4; font-size: 15px; }
.cue-text {
  font-family: var(--serif); font-size: clamp(1.1rem, 3.2vw, 1.3rem);
  line-height: 1.35; color: var(--text) !important;
}
.analogy-text { font-style: italic; color: #c8cad6 !important; }

.why-block {
  padding: 14px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(139,124,255,0.12), rgba(78,205,196,0.08));
  border: 1px solid rgba(139,124,255,0.22);
}
.try-block {
  padding: 16px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(240,198,116,0.12), rgba(255,143,107,0.08));
  border: 1px solid rgba(240,198,116,0.28);
}
.try-text {
  font-size: 15px; font-weight: 500; color: var(--text) !important; line-height: 1.5;
}

.visual-stage {
  border-radius: var(--radius-sm); overflow: hidden;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--glass-border);
  padding: 12px 8px 8px;
}
.visual-stage svg {
  width: 100%; height: auto; display: block;
  max-width: 100%;
}

.sources-details {
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.02);
  padding: 0 14px; margin-bottom: 22px;
}
.sources-details summary {
  min-height: 44px; display: flex; align-items: center;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  list-style: none;
}
.sources-details summary::-webkit-details-marker { display: none; }
.sources-details[open] summary {
  color: var(--text); border-bottom: 1px solid var(--glass-border); margin-bottom: 10px;
}
.sources-list { list-style: none; margin: 0; padding: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.sources-list li a, .sources-list li .source-x {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border);
  color: var(--text); font-size: 13px; line-height: 1.4; min-height: 44px;
  transition: border-color 0.2s, background 0.2s;
}
.sources-list li a:hover {
  border-color: rgba(78,205,196,0.4); background: rgba(78,205,196,0.06); text-decoration: none;
}
.source-badge {
  flex-shrink: 0; font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 3px 6px; border-radius: 6px;
  background: rgba(255,255,255,0.08); color: var(--muted); margin-top: 2px;
}
.source-badge.x { background: rgba(29,155,240,0.2); color: #7ec8f8; }
.source-badge.web { background: rgba(78,205,196,0.15); color: var(--accent-2); }

.related-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.related-chip {
  min-height: 40px; padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border);
  color: var(--muted); transition: all 0.2s;
}
.related-chip:hover, .related-chip:active {
  border-color: var(--accent); color: var(--text);
  background: rgba(139,124,255,0.15);
}

.lesson-actions { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; margin-bottom: 8px; }
.btn {
  min-height: var(--touch); padding: 12px 20px; border-radius: 14px;
  font-size: 14px; font-weight: 600; transition: transform 0.15s, box-shadow 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #8b7cff, #5b8def);
  color: #fff; box-shadow: 0 8px 28px rgba(139,124,255,0.35);
}
.btn-primary.done {
  background: linear-gradient(135deg, #2a9d8f, #4ecdc4);
  box-shadow: 0 8px 28px rgba(78,205,196,0.3);
}
.btn-ghost {
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border); color: var(--text);
}

/* Locked / teaser state */
.teaser-card { text-align: left; padding-top: 8px; }
.teaser-card .lock-badge {
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: 14px; padding: 6px 12px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: rgba(240,198,116,0.12); border: 1px solid rgba(240,198,116,0.28);
  color: var(--today);
}
.teaser-card .lock-icon {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--today); box-shadow: 0 0 10px var(--today);
  animation: todayBlink 1.8s ease-in-out infinite;
}
.teaser-summary {
  font-size: 15px; color: #d0d2dc; line-height: 1.55; margin: 14px 0 0;
}
.teaser-unlock {
  margin-top: 20px; padding: 16px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.03);
  border: 1px dashed rgba(255,255,255,0.12);
  font-size: 13px; color: var(--muted); line-height: 1.5;
}
.teaser-connections {
  margin-top: 18px;
}
.teaser-connections h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint);
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .orb, .today-chip-glow, .today-chip-dot, .teaser-card .lock-icon { animation: none; }
  .sheet-panel, .sheet-backdrop { animation-duration: 0.01ms !important; }
}

/* ---------- Mobile compact HUD (<480px) ---------- */
@media (max-width: 479.98px) {
  .brand {
    padding: 8px 10px 8px 8px;
    gap: 8px;
  }
  .brand-mark { width: 26px; height: 26px; border-radius: 8px; }
  .brand-text strong { font-size: 12px; }
  .brand-text span { display: none; } /* hide subtitle on narrow */

  .hud-meta {
    padding: 6px 10px;
    gap: 6px;
    font-size: 11px;
  }
  .pill { min-height: 24px; padding: 0 8px; font-size: 10px; }

  .hud-legend,
  .hud-hint {
    display: none; /* collapse clutter — graph speaks for itself */
  }

  .today-chip {
    top: auto;
    bottom: calc(16px + var(--safe-b));
    left: calc(12px + var(--safe-l));
    right: calc(12px + var(--safe-r));
    max-width: none;
    width: auto;
    justify-content: flex-start;
    padding: 10px 14px;
    min-height: 48px;
  }
  .today-chip-title {
    max-width: none;
    flex: 1 1 auto;
  }

  .hud-top {
    top: calc(10px + var(--safe-t));
    left: calc(10px + var(--safe-l));
    right: calc(10px + var(--safe-r));
  }

  /* Slightly taller sheet on phones */
  .sheet-panel {
    height: min(92dvh, 100%);
    max-height: min(92dvh, 100%);
  }
}

/* Narrow visual SVG readability */
@media (max-width: 420px) {
  .visual-stage {
    padding: 10px 4px 6px;
  }
}
