/* ============================================================
   AI Engineer Course — styles.css
   Roadmap.sh-style vertical flowchart — dark theme
   ============================================================ */

/* ── CSS Custom Properties ────────────────────────────────── */
:root {
  --bg:            hsl(220, 15%,  6%);
  --bg-secondary:  hsl(220, 15%, 10%);
  --bg-node:       hsl(220, 15%, 12%);
  --bg-node-hover: hsl(220, 15%, 16%);
  --text:          hsl(0,   0%,  92%);
  --text-muted:    hsl(0,   0%,  55%);
  --accent:        hsl(250, 90%, 65%);
  --accent-glow:   hsla(250, 90%, 65%, 0.15);
  --green:         hsl(150, 80%, 50%);
  --orange:        hsl(30,  90%, 60%);
  --topic-bg:      hsl(220, 20%, 14%);
  --subtopic-bg:   hsl(220, 15%, 10%);

  --ease-snappy:   cubic-bezier(0.33, 1, 0.68, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ── Text Selection ──────────────────────────────────────── */
::selection {
  background: var(--accent-glow);
  color: var(--text);
}

/* ── Film Grain ─────────────────────────────────────────── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
  animation: grain-shift 0.5s steps(1) infinite;
}

@keyframes grain-shift {
  0%   { transform: translate(0,   0); }
  10%  { transform: translate(-2%, -3%); }
  20%  { transform: translate(3%,  1%); }
  30%  { transform: translate(-1%,  3%); }
  40%  { transform: translate(2%,  -1%); }
  50%  { transform: translate(-3%,  2%); }
  60%  { transform: translate(1%,  -2%); }
  70%  { transform: translate(-2%,  1%); }
  80%  { transform: translate(3%,  -3%); }
  90%  { transform: translate(-1%,  2%); }
  100% { transform: translate(2%,   0%); }
}

/* ── Scroll Progress Bar ─────────────────────────────────── */
#scroll-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 9999;
  pointer-events: none;
  transform-origin: left center;
  transition: width 0.05s linear;
}

/* ── Navigation ─────────────────────────────────────────── */
.course-nav {
  position: fixed;
  top: 2px; /* below progress bar */
  left: 0;
  right: 0;
  z-index: 500;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(14, 16, 20, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: opacity 0.2s ease;
}

.nav-logo:hover {
  opacity: 0.8;
}

.nav-logo-icon {
  font-size: 18px;
  color: var(--accent);
  line-height: 1;
}

.nav-powered {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.nav-powered strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── Hero ────────────────────────────────────────────────── */
.hero {
  height: 180px;
  margin-top: 54px; /* nav height + progress bar */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg,
    hsl(220, 20%, 9%) 0%,
    var(--bg) 100%
  );
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  position: relative;
  overflow: hidden;
}

/* Subtle radial glow behind hero text */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 600px 200px at 50% 100%, hsla(250, 90%, 65%, 0.07), transparent);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
}

.hero-title {
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 8px;
}

.hero-sub {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── Flow Wrapper (scrollable page area) ─────────────────── */
.flow-wrapper {
  padding: 48px 24px 120px;
  display: flex;
  justify-content: center;
  min-height: calc(100vh - 234px);
}

/* ── Flow Container (positioned by JS) ──────────────────── */
#flow-container {
  position: relative;
  /* width/height set by JS from node bounds */
  overflow: visible;
  margin: 0 auto;
}

/* ── SVG Edge Lines ──────────────────────────────────────── */
#flow-edges {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

#flow-edges line,
#flow-edges path {
  stroke: hsl(220, 15%, 25%);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
}

/* ── Node Layer ─────────────────────────────────────────── */
#flow-nodes {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ── Base Node ───────────────────────────────────────────── */
.flow-node {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.35;
  word-break: break-word;
  transition:
    transform 0.2s var(--ease-snappy),
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease;
}

/* ── type: topic ─────────────────────────────────────────── */
.flow-node[data-type="topic"] {
  min-width: 200px;
  background: var(--topic-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  justify-content: flex-start;
  text-align: left;
}

.flow-node[data-type="topic"]:hover {
  background: var(--bg-node-hover);
  transform: translateY(-1px);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(139, 92, 246, 0.25),
    0 0 16px rgba(139, 92, 246, 0.1);
}

/* ── type: subtopic ──────────────────────────────────────── */
.flow-node[data-type="subtopic"] {
  min-width: 150px;
  background: var(--subtopic-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.flow-node[data-type="subtopic"]:hover {
  background: var(--bg-node);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ── type: title ─────────────────────────────────────────── */
.flow-node[data-type="title"] {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  justify-content: center;
}

.flow-node[data-type="title"]:hover {
  color: var(--accent);
}

/* ── type: label ─────────────────────────────────────────── */
.flow-node[data-type="label"] {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: default;
  pointer-events: none;
  justify-content: center;
}

/* ── type: button ────────────────────────────────────────── */
.flow-node[data-type="button"] {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  justify-content: center;
  letter-spacing: 0.01em;
  transition:
    transform 0.2s var(--ease-snappy),
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.flow-node[data-type="button"]:hover {
  background: hsl(250, 90%, 70%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px hsla(250, 90%, 65%, 0.4);
}

/* ── type: section ───────────────────────────────────────── */
.flow-node[data-type="section"] {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  pointer-events: none;
  cursor: default;
  z-index: 0 !important;
}

/* ── type: paragraph ─────────────────────────────────────── */
.flow-node[data-type="paragraph"] {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  background: transparent;
  border: none;
  cursor: default;
  justify-content: flex-start;
  align-items: flex-start;
  text-align: left;
  padding: 4px 0;
  pointer-events: none;
}

/* white / non-transparent paragraph nodes */
.flow-node[data-type="paragraph"].node-has-bg {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 12px 14px;
  pointer-events: auto;
  color: var(--text-muted);
}

/* ── Node z-index stacking ───────────────────────────────── */
.flow-node[data-type="section"] { z-index: 0; }
.flow-node[data-type="paragraph"] { z-index: 1; }
.flow-node[data-type="label"] { z-index: 2; }
.flow-node[data-type="title"] { z-index: 3; }
.flow-node[data-type="subtopic"] { z-index: 4; }
.flow-node[data-type="topic"] { z-index: 5; }
.flow-node[data-type="button"] { z-index: 6; }

/* ── Detail Panel Backdrop ───────────────────────────────── */
#panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#panel-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Detail Panel ────────────────────────────────────────── */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(600px, 90vw);
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg-secondary);
  z-index: 200;
  overflow-y: auto;
  padding: 48px;
  transform: translateX(100%);
  transition: transform 0.45s var(--ease-snappy);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#detail-panel::-webkit-scrollbar {
  width: 4px;
}

#detail-panel::-webkit-scrollbar-track {
  background: transparent;
}

#detail-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

#detail-panel.open {
  transform: translateX(0);
}

/* ── Panel Close Button ──────────────────────────────────── */
.panel-close {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.2s var(--ease-snappy);
  flex-shrink: 0;
}

.panel-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  transform: rotate(90deg);
}

/* ── Panel Content ───────────────────────────────────────── */
.panel-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 16px;
  display: block;
}

#detail-panel h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 20px;
}

#detail-panel p {
  font-size: 15px;
  line-height: 1.7;
  color: rgba(235, 235, 235, 0.8);
  margin-bottom: 16px;
}

#detail-panel h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 28px;
  margin-bottom: 10px;
}

#detail-panel ul,
#detail-panel ol {
  padding-left: 20px;
  color: rgba(235, 235, 235, 0.8);
  font-size: 15px;
  line-height: 1.7;
}

#detail-panel li {
  margin-bottom: 6px;
}

#detail-panel pre {
  background-color: var(--bg);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#detail-panel pre::-webkit-scrollbar {
  height: 4px;
}

#detail-panel pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

#detail-panel pre code,
#detail-panel code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  background: none;
  padding: 0;
  border: none;
  border-radius: 0;
}

#detail-panel p code,
#detail-panel li code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  background-color: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--accent);
}

.panel-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
  margin: 28px 0;
}

/* ── Topics.js injected panel elements ───────────────────── */

/* Close button injected by topics.js */
.detail-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.2s ease, color 0.2s ease;
}

.detail-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.detail-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 12px;
  display: block;
}

.detail-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 20px;
  color: var(--text);
}

.detail-content {
  font-size: 15px;
  line-height: 1.7;
  color: rgba(235, 235, 235, 0.8);
}

.detail-done-btn {
  display: inline-block;
  margin-top: 28px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.detail-done-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.detail-done-btn.is-done {
  background: rgba(80, 200, 120, 0.12);
  border-color: rgba(80, 200, 120, 0.3);
  color: var(--green);
}

/* ── Responsive ──────────────────────────────────────────── */

/* Tablet: slight padding reduction */
@media (max-width: 1100px) {
  .flow-wrapper {
    padding: 32px 16px 100px;
    justify-content: flex-start;
  }
}

/* Mobile: scale-down the entire flow canvas */
@media (max-width: 768px) {
  .course-nav {
    padding: 0 16px;
  }

  .hero {
    height: 140px;
  }

  .hero-title {
    font-size: 22px;
  }

  .flow-wrapper {
    padding: 24px 0 80px;
    overflow-x: auto;
    justify-content: flex-start;
  }

  /* Scale the flow container down and adjust height to match */
  #flow-container {
    transform: scale(0.5);
    transform-origin: top left;
    /* The outer wrapper handles scroll; the container shrinks to half */
  }

  /* Panel takes full width on mobile */
  #detail-panel {
    width: 100vw;
    padding: 32px 20px;
  }
}

/* Very small screens */
@media (max-width: 400px) {
  #flow-container {
    transform: scale(0.38);
    transform-origin: top left;
  }
}

/* ─── View Toggle ─── */
.view-toggle {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 16px 0 8px;
  position: sticky;
  top: 56px;
  z-index: 90;
  background: linear-gradient(to bottom, var(--bg) 60%, transparent);
  padding-bottom: 24px;
}

.view-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-btn:hover {
  border-color: rgba(255,255,255,0.2);
  color: var(--text);
}

.view-btn.active {
  background: rgba(255,255,255,0.08);
  border-color: var(--accent);
  color: var(--text);
}

.view-btn svg {
  opacity: 0.7;
}
.view-btn.active svg {
  opacity: 1;
}

/* ─── Grid View ─── */
.grid-wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.grid-section {
  margin-bottom: 56px;
}

.grid-section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.grid-section-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  font-family: 'Inter', sans-serif;
  letter-spacing: 0.05em;
}

.grid-section-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.grid-topics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.grid-card {
  background: var(--bg-node, hsl(220, 15%, 12%));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.grid-card:hover {
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.grid-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.grid-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.grid-card-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.grid-card.completed {
  border-color: var(--green, hsl(150, 80%, 50%));
}

.grid-card.completed::after {
  content: '✓';
  position: absolute;
  top: 12px;
  right: 14px;
  color: var(--green, hsl(150, 80%, 50%));
  font-size: 14px;
  font-weight: 700;
}

/* Source links styling for detail panel */
.source-links {
  list-style: none;
  padding: 0;
}

.source-links li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.source-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.2s;
}

.source-links a:hover {
  color: #fff;
  text-decoration: underline;
}

/* Actionable examples styling */
.examples-list li {
  padding: 6px 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

@media (max-width: 768px) {
  .grid-topics {
    grid-template-columns: 1fr;
  }
  .view-toggle {
    top: 48px;
  }
}


/* ── SS+ Grade Fixes (2026-02-26) ────────────────────────── */

/* Hide redundant category tag — section header already shows it */
.grid-card-tag {
  display: none !important;
}

/* Prevent section headers from hiding under sticky nav */
.grid-section {
  scroll-margin-top: 140px;
  padding-top: 20px;
}

.grid-section-header {
  scroll-margin-top: 140px;
  position: sticky;
  top: 100px;
  z-index: 80;
  background: var(--bg);
  padding-top: 16px;
  padding-bottom: 12px;
}
