:root {
  --bg: #101214;
  --surface: #181b1f;
  --surface-2: #20242a;
  --line: #353b43;
  --text: #f4f6f8;
  --muted: #aeb6c0;
  --green: #5ee0a0;
  --blue: #68b9ff;
  --yellow: #ffd166;
  --red: #ff7474;
  --ink: #0e1114;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  line-height: 1.6;
}

a { color: var(--blue); }

button,
input { font: inherit; }

.page {
  width: min(1100px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.topbar a {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.topbar span { color: var(--muted); }

.lesson-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding-bottom: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: .8rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  max-width: 760px;
  margin-bottom: 10px;
  font-size: clamp(2rem, 4vw, 3.7rem);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.45rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
  letter-spacing: 0;
}

p { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.band {
  min-width: 0;
  padding: 26px 0;
  border-top: 1px solid var(--line);
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, .95fr);
  gap: 28px;
  align-items: start;
}

.concept-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.concept-list li {
  padding: 12px 0 12px 16px;
  border-left: 3px solid var(--blue);
  color: var(--muted);
}

.concept-list strong { color: var(--text); }

.lab {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.lab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border-bottom: 1px solid var(--line);
}

.lab-head h2 { margin: 0; font-size: 1.08rem; }

.lab-head output {
  color: var(--yellow);
  font-family: Consolas, "Courier New", monospace;
  font-weight: 800;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.controls input {
  width: 118px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #555e69;
  border-radius: 6px;
  outline: none;
  background: #111418;
  color: var(--text);
}

.controls input:focus { border-color: var(--blue); }

.controls button {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #2a3037;
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
}

.controls button:hover { border-color: var(--blue); }
.controls .primary { background: var(--green); color: var(--ink); }
.controls .danger { background: var(--red); color: var(--ink); }
.controls .inspect { background: var(--yellow); color: var(--ink); }

.visual-stage {
  min-height: 230px;
  padding: 26px 18px;
  overflow-x: auto;
  background-color: #12161a;
  background-image:
    linear-gradient(#242a30 1px, transparent 1px),
    linear-gradient(90deg, #242a30 1px, transparent 1px);
  background-size: 28px 28px;
}

.structure-track {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: max-content;
  min-height: 175px;
}

.structure-track.stack {
  flex-direction: column;
  min-width: 100%;
}

.node-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stack .node-wrap { flex-direction: column; }

.node {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 152px;
  min-width: 152px;
  min-height: 126px;
  overflow: visible;
  border: 2px solid var(--blue);
  border-radius: 6px;
  background: #192838;
  color: var(--text);
}

.stack .node { border-color: var(--red); background: #342124; }
.queue .node { border-color: var(--green); background: #183027; }
.deque .node { border-color: var(--yellow); background: #332c18; }
.single .node { border-color: var(--blue); }
.double .node { border-color: var(--yellow); background: #302a19; }

.node .cell-id {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, .15);
  background: rgba(0, 0, 0, .22);
  color: var(--muted);
  font: .7rem/1.35 Consolas, "Courier New", monospace;
}

.node .cell-value {
  display: grid;
  place-items: center;
  padding: 10px 8px;
}

.node .cell-value span {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.node .cell-value strong {
  max-width: 132px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 1.2rem;
}

.node .cell-links {
  display: grid;
  grid-template-columns: repeat(var(--link-count, 1), minmax(0, 1fr));
  border-top: 1px solid rgba(255, 255, 255, .15);
  background: rgba(0, 0, 0, .16);
}

.node .cell-links span {
  padding: 6px 7px;
  color: #c7d7e8;
  font: .68rem/1.3 Consolas, "Courier New", monospace;
  text-align: center;
}

.node .cell-links span + span { border-left: 1px solid rgba(255, 255, 255, .15); }

.node small {
  position: absolute;
  top: -24px;
  width: max-content;
  color: var(--muted);
  font-size: .68rem;
  text-transform: uppercase;
}

.stack .node small {
  top: 50%;
  left: calc(100% + 10px);
  transform: translateY(-50%);
}

.arrow {
  min-width: 26px;
  color: var(--green);
  font-size: 1.4rem;
  font-weight: 900;
  text-align: center;
}

.stack .arrow { color: var(--red); }

.node.enter-from-top { animation: enterFromTop .55s ease both; }
.node.enter-from-left { animation: enterFromLeft .55s ease both; }
.node.enter-from-right { animation: enterFromRight .55s ease both; }

@keyframes enterFromTop {
  from { opacity: 0; transform: translateY(-46px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes enterFromLeft {
  from { opacity: 0; transform: translateX(-70px) scale(.92); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes enterFromRight {
  from { opacity: 0; transform: translateX(70px) scale(.92); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.empty-state {
  display: grid;
  place-items: center;
  min-width: 260px;
  min-height: 120px;
  border: 1px dashed #4d5661;
  border-radius: 6px;
  color: var(--muted);
}

.movement-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.movement-column {
  min-height: 112px;
  padding: 12px 14px;
}

.movement-column + .movement-column { border-left: 1px solid var(--line); }

.movement-column h3 {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
}

.movement-slot {
  min-height: 54px;
  color: var(--muted);
  font-size: .82rem;
}

.movement-cell {
  display: grid;
  gap: 2px;
  min-height: 54px;
  padding: 7px 9px;
  border: 1px solid var(--green);
  border-radius: 5px;
  background: #183027;
  color: var(--text);
  animation: movementArrive .55s ease both;
}

.movement-cell.removed {
  border-color: #68717b;
  background: #22262b;
  color: #8f98a3;
  filter: saturate(.35);
  opacity: .72;
}

.movement-cell code { color: inherit; }

.remaining-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.remaining-cells code {
  padding: 4px 6px;
  border: 1px solid #4d5661;
  border-radius: 4px;
  color: var(--text);
}

@keyframes movementArrive {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: .72; transform: translateY(0); }
}

.lab-status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--line);
}

.lab-status > div { padding: 14px 16px; }
.lab-status > div + div { border-left: 1px solid var(--line); }
.lab-status strong { display: block; margin-bottom: 3px; font-size: .75rem; text-transform: uppercase; }
.lab-status span { color: var(--muted); }

.history {
  margin: 0;
  padding: 12px 16px 16px 34px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.history li { padding: 3px 0; }

.code-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0f12;
}

.code-title {
  display: flex;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

pre {
  margin: 0;
  padding: 18px;
  overflow: auto;
  color: #dce9f8;
  font: .92rem/1.65 Consolas, "Courier New", monospace;
}

.note {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 3px solid var(--yellow);
  background: #211f17;
  color: var(--muted);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: var(--surface);
}

.comparison-table th,
.comparison-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.comparison-table th {
  background: var(--surface-2);
  color: var(--text);
}

.comparison-table td { color: var(--muted); }

.comparison-table tr:last-child td { border-bottom: 0; }

.memory-diagram {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: max-content;
  padding: 26px 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12161a;
}

.memory-cell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 118px;
  min-width: 118px;
  min-height: 112px;
  overflow: hidden;
  border: 2px solid var(--blue);
  border-radius: 6px;
  background: #192838;
}

.memory-cell.dynamic { border-color: var(--yellow); background: #302a19; }

.memory-cell .cell-address,
.memory-cell .cell-pointer {
  padding: 5px 8px;
  background: rgba(0, 0, 0, .24);
  color: var(--muted);
  font: .7rem/1.35 Consolas, "Courier New", monospace;
}

.memory-cell .cell-data {
  display: grid;
  place-items: center;
  padding: 10px 8px;
  color: var(--text);
  font-weight: 900;
}

.memory-arrow {
  display: grid;
  place-items: center;
  min-width: 28px;
  color: var(--green);
  font-size: 1.45rem;
  font-weight: 900;
}

.definition-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.definition-item {
  padding: 15px 0 15px 16px;
  border-left: 3px solid var(--green);
}

.definition-item h3 { margin-bottom: 4px; }
.definition-item p { margin-bottom: 0; }

.representation-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.representation-title h3,
.representation-title p { margin-bottom: 0; }

.array-strip {
  display: flex;
  align-items: stretch;
  min-width: max-content;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #12161a;
}

.array-slot {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 132px;
  min-width: 132px;
  min-height: 112px;
  border-right: 1px solid #53606d;
  background: #192838;
}

.array-slot:last-child { border-right: 0; }
.array-slot.empty { background: #191d21; }

.array-slot .slot-index,
.array-slot .slot-capacity {
  padding: 6px 8px;
  color: var(--muted);
  font: .7rem/1.35 Consolas, "Courier New", monospace;
}

.array-slot .slot-index { border-bottom: 1px solid rgba(255, 255, 255, .14); }
.array-slot .slot-capacity { border-top: 1px solid rgba(255, 255, 255, .14); }
.array-slot .slot-value { display: grid; place-items: center; padding: 12px 8px; font-weight: 900; }
.array-slot.empty .slot-value { color: #707985; font-weight: 700; }

.scroll-frame {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 8px;
}

.fact-check {
  padding: 15px 17px;
  border: 1px solid #456a5a;
  border-radius: 7px;
  background: #15251e;
  color: var(--muted);
}

.fact-check strong { color: var(--green); }

.sources {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources li {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.sources li:last-child { border-bottom: 0; }
.sources a { font-weight: 800; text-decoration: none; }

.sort-lab {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sort-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.sort-toolbar button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #2a3037;
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
}

.sort-toolbar button.active { border-color: var(--green); background: var(--green); color: var(--ink); }
.sort-toolbar button.command { background: var(--yellow); color: var(--ink); }

.sort-stage {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 10px;
  min-height: 280px;
  padding: 28px 18px;
  overflow-x: auto;
  background-color: #12161a;
  background-image:
    linear-gradient(#242a30 1px, transparent 1px),
    linear-gradient(90deg, #242a30 1px, transparent 1px);
  background-size: 28px 28px;
}

.sort-cell {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 84px;
  min-width: 84px;
  height: calc(72px + var(--bar-height));
  min-height: 112px;
  border: 2px solid var(--blue);
  border-radius: 6px 6px 3px 3px;
  background: #192838;
  transition: height .28s ease, background .28s ease, border-color .28s ease, transform .28s ease;
}

.sort-cell.active { border-color: var(--red); background: #382226; transform: translateY(-8px); }
.sort-cell.sorted { border-color: var(--green); background: #183027; }
.sort-cell.sorted.active { border-color: var(--red); background: #382226; transform: translateY(-8px); }
.sort-cell .sort-index { padding: 5px; border-bottom: 1px solid rgba(255,255,255,.14); color: var(--muted); font: .7rem Consolas, monospace; text-align: center; }
.sort-cell .sort-value { display: grid; place-items: center; font-size: 1.3rem; font-weight: 900; }

.sort-status {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.sort-status strong { color: var(--yellow); }
.sort-status span { color: var(--muted); }

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.lesson-nav a {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.lesson-nav a:hover { border-color: var(--green); }

@media (max-width: 780px) {
  .page { overflow-x: clip; padding-inline: 14px; }
  .topbar > *,
  .lesson-header > *,
  .two-col > * { min-width: 0; }
  .lesson-header,
  .two-col { grid-template-columns: 1fr; }
  .lesson-header { align-items: start; }
  .lab-status { grid-template-columns: 1fr; }
  .lab-status > div + div { border-top: 1px solid var(--line); border-left: 0; }
  .controls input { width: 100%; }
  .controls button { flex: 1 1 130px; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { text-align: center; }
  .definition-grid { grid-template-columns: 1fr; }
  .movement-board { grid-template-columns: 1fr; }
  .movement-column + .movement-column { border-top: 1px solid var(--line); border-left: 0; }
  .comparison-table { font-size: .88rem; }
  .comparison-table th,
  .comparison-table td { padding: 9px; }
  .sort-toolbar button { flex: 1 1 130px; }
  .sort-stage { justify-content: flex-start; }
  .sort-status { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .node.enter-from-top,
  .node.enter-from-left,
  .node.enter-from-right,
  .movement-cell { animation: none; }
}
