/* ── Design Tokens ── */
:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface2:     #21262d;
  --border:       #30363d;
  --accent:       #58a6ff;
  --yellow:       #e3b341;
  --green:        #3fb950;
  --purple:       #bc8cff;
  --orange:       #f0883e;
  --cyan:         #39c5cf;
  --red:          #f85149;
  --io:           #8b949e;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --font-code:    'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui:      'Inter', 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

/* ── Navigation Bar ── */
#nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 100;
}

#nav .nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s;
}
#nav .nav-btn:hover { background: var(--border); }

#slide-counter {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 60px;
  text-align: center;
}

#slide-dots {
  display: flex;
  gap: 6px;
  flex: 1;
}

.slide-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  padding: 0;
}
.slide-dot.active { background: var(--accent); transform: scale(1.4); }

#slide-title-nav {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Slide Container ── */
#slides-viewport {
  position: fixed;
  top: 48px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

#slides {
  display: flex;
  flex-direction: row;
  height: 100%;
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Title Slide (slide 0) ── */
.slide-title {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 40px;
  background: var(--bg);
}

.slide-title h1 {
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 12px;
}

.slide-title .subtitle {
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  color: var(--text-muted);
  margin-bottom: 40px;
}

.agenda {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  max-width: 900px;
  width: 100%;
}

.agenda li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.agenda .badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Summary Slide ── */
.slide-summary,
.slide-basics {
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.slide-summary h2,
.slide-basics h2 {
  font-size: 2rem;
  margin-bottom: 28px;
  color: var(--accent);
}

.takeaways {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 760px;
  width: 100%;
}

.takeaways li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Concept Grid (basics slides) ── */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 920px;
  width: 100%;
}

.concept-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.concept-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 8px 8px 6px 6px;
  padding: 16px 18px;
}

.concept-card h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.concept-tag {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.concept-card p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}

.concept-card code {
  font-family: var(--font-code);
  font-size: 0.85em;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ── Example Slide ── */
.slide-example {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.slide-header {
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.slide-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.slide-header p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.slide-body {
  display: grid;
  grid-template-columns: minmax(380px, 480px) 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* ── Code Panel ── */
.code-panel {
  position: relative;
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.code-panel pre {
  flex: 1;
  overflow: auto;
  margin: 0 !important;
  padding: 16px 12px 16px 44px !important;
  background: var(--bg) !important;
  font-size: 12.5px !important;
  line-height: 1.7 !important;
  tab-size: 2;
}

.code-panel pre code {
  font-family: var(--font-code) !important;
  display: block;
}

/* Each source line wrapped in a span for precise highlight tracking */
.code-line {
  display: block;
  position: relative;
}

.line-highlight {
  position: absolute;
  left: 0; right: 0;
  background: rgba(88, 166, 255, 0.12);
  border-left: 3px solid var(--accent);
  pointer-events: none;
  transition: top 0.18s ease, height 0.18s ease, opacity 0.15s;
  opacity: 0;
  top: 0;
  height: 0;
  z-index: 0;
}

.line-highlight.visible { opacity: 1; }

/* ── Diagram Panel ── */
.diagram-panel {
  display: grid;
  grid-template-rows: 1fr auto 1fr auto;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 8px;
  overflow: hidden;
  min-height: 0;
}

/* ── Event Loop bar (between exec row and queues) ── */
.event-loop-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.event-loop-bar::before,
.event-loop-bar::after {
  content: '';
  position: absolute;
  top: 50%;
  height: 1px;
  width: calc(50% - 90px);
  background: linear-gradient(90deg, transparent, var(--border));
}
.event-loop-bar::before { left: 0; }
.event-loop-bar::after  { right: 0; transform: scaleX(-1); }

.event-loop-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
  z-index: 1;
}

.el-ring {
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  display: inline-block;
  transition: color 0.2s;
}

.el-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  transition: color 0.2s;
}

/* Active "ping": ring spins + glows, expanding pulse behind it */
.event-loop-icon.pinging {
  border-color: var(--accent);
  background: rgba(88,166,255,0.12);
  box-shadow: 0 0 22px rgba(88,166,255,0.7);
  animation: el-pop 0.6s ease;
}
.event-loop-icon.pinging .el-ring {
  color: var(--accent);
  animation: el-spin 0.6s ease;
}
.event-loop-icon.pinging .el-label { color: var(--accent); }

@keyframes el-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.event-loop-icon.pinging::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 20px;
  border: 2px solid var(--accent);
  animation: el-ping 0.6s ease-out;
}

@keyframes el-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes el-ping {
  0%   { transform: scale(1);   opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Top row: Call Stack + Web APIs side by side (fill remaining width) */
.exec-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-height: 0;
}

/* Bottom row: the queues, horizontal, ordered by event-loop priority */
.queues-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  min-height: 0;
}

.queue-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.queue-col.io-col {
  border-color: #3d3d3d;
  background: #0f1117;
  opacity: 0.85;
}

.queue-col-header {
  padding: 6px 8px 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.queue-col-header h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-col-header .queue-subtitle {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Queue header accent colors */
.queue-col[data-queue="callstack"] .queue-col-header h3 { color: var(--accent); }
.queue-col[data-queue="webapis"]   .queue-col-header h3 { color: var(--orange); }
.queue-col[data-queue="microtask"] .queue-col-header h3 { color: var(--green); }
.queue-col[data-queue="ui"]        .queue-col-header h3 { color: var(--cyan); }
.queue-col[data-queue="task"]      .queue-col-header h3 { color: var(--yellow); }
.queue-col[data-queue="render"]    .queue-col-header h3 { color: var(--purple); }
.queue-col[data-queue="io"]        .queue-col-header h3 { color: var(--io); }

.queue-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 4px;
  gap: 3px;
  overflow-y: auto;
  min-height: 0;
}

/* Call Stack grows from the bottom up (LIFO visual) */
.queue-col[data-queue="callstack"] .queue-items {
  justify-content: flex-end;
}

/* ── Queue Item ── */
.queue-item {
  border-radius: 5px;
  border: 1px solid;
  padding: 4px 6px;
  font-size: 10px;
  font-family: var(--font-code);
  line-height: 1.3;
  word-break: break-all;
  animation: slide-in 0.2s ease;
  position: relative;
}

.queue-item[data-type="callstack"] { border-color: var(--accent);  background: rgba(88,166,255,0.08); color: var(--accent); }
.queue-item[data-type="webapis"]   { border-color: var(--orange); background: rgba(240,136,62,0.08); color: var(--orange); }
.queue-item[data-type="microtask"] { border-color: var(--green);  background: rgba(63,185,80,0.08);  color: var(--green); }
.queue-item[data-type="ui"]        { border-color: var(--cyan);   background: rgba(57,197,207,0.08); color: var(--cyan); }
.queue-item[data-type="task"]      { border-color: var(--yellow); background: rgba(227,179,65,0.08); color: var(--yellow); }
.queue-item[data-type="render"]    { border-color: var(--purple); background: rgba(188,140,255,0.08);color: var(--purple); }
.queue-item[data-type="io"]        { border-color: var(--io);     background: rgba(139,148,158,0.08);color: var(--io); }

.queue-item.executing {
  background: rgba(248, 81, 73, 0.15) !important;
  border-color: var(--red) !important;
  color: #ff8080 !important;
}

.queue-item.blocked {
  background: rgba(248,81,73,0.06) !important;
  border-color: #444 !important;
  color: var(--text-muted) !important;
  font-style: italic;
}

.queue-item.warning {
  background: rgba(227,179,65,0.12) !important;
  border-color: var(--yellow) !important;
  color: var(--yellow) !important;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* A floating clone that travels from a queue to the call stack (or between
   columns). Rendered on <body> with position:fixed, above everything. */
.flying-ghost {
  z-index: 9999;
  pointer-events: none;
  animation: none !important;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  border-radius: 5px;
  border: 1px solid;
  padding: 4px 6px;
  font-size: 10px;
  font-family: var(--font-code);
  line-height: 1.3;
  box-sizing: border-box;
}

/* starvation warning badge */
.starvation-badge {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--red);
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── Output Panel ── */
.output-panel {
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  background: var(--bg);
  flex-shrink: 0;
  max-height: 90px;
  overflow-y: auto;
}

.output-panel h4 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.output-line {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--green);
  line-height: 1.5;
  animation: slide-in 0.15s ease;
}

.output-line::before {
  content: '> ';
  color: var(--text-muted);
}

/* ── Controls Strip ── */
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-ui);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-run  { border-color: var(--accent); color: var(--accent); }
.btn-run:hover  { background: rgba(88,166,255,0.1); }
.btn-step { border-color: var(--green); color: var(--green); }
.btn-step:hover { background: rgba(63,185,80,0.1); }
.btn-back { border-color: var(--purple); color: var(--purple); }
.btn-back:hover { background: rgba(188,140,255,0.1); }

.step-counter {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.step-description {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  min-width: 0;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}

/* ── Prism overrides ── */
pre[class*="language-"] {
  border-radius: 0 !important;
  border: none !important;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ── Responsive: narrow screens ── */
@media (max-width: 860px) {
  .slide-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .code-panel { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ── Whole-page paint flash (render phase made visible) ── */
#paint-flash {
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  opacity: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#paint-flash::before {
  /* a sweep of light moving across the page */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 0%,
    rgba(188, 140, 255, 0.0) 35%,
    rgba(188, 140, 255, 0.28) 50%,
    rgba(188, 140, 255, 0.0) 65%,
    transparent 100%
  );
  background-size: 250% 100%;
  background-position: 150% 0;
}

#paint-flash::after {
  /* a soft purple border glow framing the whole viewport */
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--purple), inset 0 0 60px rgba(188,140,255,0.35);
}

#paint-flash .paint-flash-label {
  margin-top: 60px;
  background: var(--purple);
  color: #1a1030;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.04em;
  padding: 8px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 24px rgba(188,140,255,0.6);
  transform: translateY(-12px);
  opacity: 0;
}

#paint-flash.active {
  animation: paint-flash-fade 0.6s ease-out;
}
#paint-flash.active::before {
  animation: paint-sweep 0.6s ease-out;
}
#paint-flash.active .paint-flash-label {
  animation: paint-label-pop 0.6s ease-out;
}

@keyframes paint-flash-fade {
  0%   { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes paint-sweep {
  0%   { background-position: 150% 0; }
  100% { background-position: -150% 0; }
}

@keyframes paint-label-pop {
  0%   { opacity: 0; transform: translateY(-12px) scale(0.9); }
  25%  { opacity: 1; transform: translateY(0) scale(1); }
  75%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-8px) scale(0.98); }
}
