/* ============================================================
   Pointers Explained
   Same dark family palette. Big visual focus on memory cells
   and arrows between them.
   ============================================================ */

:root {
  --bg:        #0f1115;
  --surface:   #181b22;
  --surface-2: #1f242d;
  --border:    #2a2e38;
  --text:      #e6e8ee;
  --muted:     #8a93a6;
  --accent:    #6ea8ff;

  /* Per-variable colors. Reusable across scenarios. */
  --c-var-a:    #4ade80;   /* age, x, etc. */
  --c-var-b:    #facc15;   /* second variable when needed */
  --c-var-c:    #fb923c;
  --c-ptr:      #c084fc;   /* pointers always purple */
  --c-ptr2:     #ec4899;   /* second-level pointer */
  --c-null:     #f87171;
  --c-active:   #38bdf8;
  --c-changed:  #f59e0b;

  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
em { color: var(--accent); font-style: normal; }

/* ---------- Hero ---------- */
.hero { border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #11141b 0%, var(--bg) 100%); }
.hero-inner { max-width: 1100px; margin: 0 auto; padding: 48px 32px 32px; }
.hero h1 { font-size: 2.1rem; margin: 0 0 12px; }
.lede { font-size: 1rem; color: var(--muted); max-width: 820px; }
.toc { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 8px; font-family: var(--mono); font-size: 0.82rem; }
.toc a { background: var(--surface); padding: 5px 10px; border-radius: 5px; border: 1px solid var(--border); }

/* ---------- Section frame ---------- */
.scenario { max-width: 1100px; margin: 0 auto; padding: 40px 32px; border-bottom: 1px solid var(--border); }
.scenario-header h2 { margin: 0 0 10px; font-size: 1.45rem; }
.scenario-header p { color: var(--muted); max-width: 820px; margin: 0; }
.scenario-body { margin-top: 24px; }

.viz { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 22px; min-height: 340px; }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.controls button { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: var(--mono); font-size: 1rem; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.controls button:hover:not(:disabled) { background: #262b35; border-color: var(--accent); }
.controls button:disabled { opacity: 0.35; cursor: not-allowed; }
.step-indicator { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 0.85rem; }

.step-status {
  margin-top: 14px;
  font-size: 0.93rem;
  padding: 12px 14px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  min-height: 60px;
}

/* ---------- Code panel ---------- */
.code-panel {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.9rem;
  margin-bottom: 18px;
  overflow-x: auto;
}
.code-panel pre { margin: 0; }
.code-line { display: block; padding: 2px 6px; border-radius: 3px; color: var(--muted); }
.code-line.run    { color: var(--text); }
.code-line.active { color: var(--accent); background: rgba(110, 168, 255, 0.12); border-left: 2px solid var(--accent); padding-left: 4px; }
.code-line .comment  { color: var(--muted); font-style: italic; }
.code-line .keyword  { color: var(--accent); }
.code-line .literal  { color: var(--c-var-a); }
.code-line .var      { color: var(--c-var-b); }
.code-line .ptr      { color: var(--c-ptr); }
.code-line .ampersand,
.code-line .star     { color: var(--c-ptr); font-weight: 700; }

/* ---------- Memory strip ---------- */
.mem-section { margin-bottom: 22px; }
.mem-section-h {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
  padding-left: 4px;
}

.mem-strip {
  position: relative;
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow: visible;
}
.mem-cells {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}

.cell {
  flex-shrink: 0;
  width: 110px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: #14181f;
  font-family: var(--mono);
  text-align: center;
  position: relative;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}
.cell.empty { background: repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 6px, transparent 6px 12px); }
.cell.has-var { background: #14181f; }

.cell .cell-name {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 4px 2px;
  letter-spacing: 0.02em;
  color: var(--muted);
  border-bottom: 1px dashed transparent;
  min-height: 22px;
}
.cell .cell-value {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 4px;
  letter-spacing: 0.02em;
  color: var(--text);
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell .cell-addr {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 4px;
  border-top: 1px dashed var(--border);
  letter-spacing: 0.04em;
}

/* Per-variable colors via data-color */
.cell[data-color="a"]    { border-color: var(--c-var-a); }
.cell[data-color="a"]    .cell-name, .cell[data-color="a"] .cell-value    { color: var(--c-var-a); }
.cell[data-color="b"]    { border-color: var(--c-var-b); }
.cell[data-color="b"]    .cell-name, .cell[data-color="b"] .cell-value    { color: var(--c-var-b); }
.cell[data-color="c"]    { border-color: var(--c-var-c); }
.cell[data-color="c"]    .cell-name, .cell[data-color="c"] .cell-value    { color: var(--c-var-c); }
.cell[data-color="ptr"]  { border-color: var(--c-ptr); background: rgba(192, 132, 252, 0.06); }
.cell[data-color="ptr"]  .cell-name, .cell[data-color="ptr"] .cell-value  { color: var(--c-ptr); }
.cell[data-color="ptr2"] { border-color: var(--c-ptr2); background: rgba(236, 72, 153, 0.06); }
.cell[data-color="ptr2"] .cell-name, .cell[data-color="ptr2"] .cell-value { color: var(--c-ptr2); }
.cell[data-color="null"] { border-color: var(--c-null); background: rgba(248, 113, 113, 0.08); }
.cell[data-color="null"] .cell-name, .cell[data-color="null"] .cell-value { color: var(--c-null); }

/* Highlighting states */
.cell.highlight {
  outline: 3px solid var(--c-active);
  outline-offset: 2px;
}
.cell.changed {
  animation: cellChanged 0.6s ease-out;
}
.cell.crash {
  animation: cellCrash 0.5s ease-out;
  border-color: var(--c-null) !important;
}
@keyframes cellChanged {
  0%   { background: rgba(245, 158, 11, 0.4); transform: scale(1.05); }
  100% { background: #14181f; transform: scale(1); }
}
@keyframes cellCrash {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
}

/* Arrow overlay (SVG sits above the cells) */
.mem-strip svg.arrow-overlay {
  position: absolute;
  top: 0;
  left: 14px;   /* match .mem-strip padding-left so the SVG aligns with the cells container */
  width: calc(100% - 28px);
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.arrow-line {
  fill: none;
  stroke: var(--c-ptr);
  stroke-width: 2;
  stroke-dasharray: 4, 4;
  opacity: 0.85;
}
.arrow-line.solid { stroke-dasharray: none; }
.arrow-line.ptr2  { stroke: var(--c-ptr2); }
.arrow-line.flash { animation: arrowFlash 0.6s ease-out; }
@keyframes arrowFlash {
  0%   { stroke-width: 5; opacity: 1; }
  100% { stroke-width: 2; opacity: 0.85; }
}
.arrow-head { fill: var(--c-ptr); }
.arrow-head.ptr2 { fill: var(--c-ptr2); }

/* Caption above cells */
.viz .caption {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 14px;
  padding: 8px 12px;
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.viz .caption.tip {
  border-left: 3px solid var(--accent);
  color: var(--text);
}
.viz .caption strong { color: var(--accent); }

/* Output / "what the program prints" */
.output {
  background: #050709;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.92rem;
  margin-top: 14px;
}
.output .out-h {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.output .out-text { color: var(--c-var-a); }

/* Side-by-side comparison panels (used in section 6) */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
@media (max-width: 760px) { .compare-grid { grid-template-columns: 1fr; } }
.compare-card {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.compare-card h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-family: var(--mono);
}
.compare-card h4.decl { color: var(--c-ptr); }
.compare-card h4.expr { color: var(--c-active); }

/* Function call section 8: stack frame box */
.frame-box {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 14px;
}
.frame-h {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

/* Crash banner */
.crash-banner {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--c-null);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 14px;
  color: var(--c-null);
  font-family: var(--mono);
  font-weight: 700;
  text-align: center;
}

footer { text-align: center; padding: 30px 20px 60px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); margin-top: 20px; }
footer p { max-width: 820px; margin: 0 auto 10px; }
footer .back-link { font-family: var(--mono); }
