:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --ink: #1d252c;
  --muted: #65717b;
  --line: #d9ded9;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --accent: #0f766e;
  --accent-strong: #0b4f4a;
  --primitive: #2563eb;
  --reference: #d97706;
  --heap: #059669;
  --shadow: 0 12px 28px rgba(29, 37, 44, 0.08);
  --shadow-strong: 0 18px 48px rgba(29, 37, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app {
  margin: 0 auto;
  max-width: 1440px;
  padding: 28px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 22px;
}

.topline {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.language-toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  padding: 3px;
}

.language-option {
  border: 0;
  border-radius: 5px;
  min-height: 32px;
  padding: 0 10px;
}

.language-option.active {
  background: var(--accent);
  color: white;
}

.eyebrow {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(36px, 4vw, 56px);
  line-height: 1.04;
  margin-bottom: 14px;
  max-width: 1180px;
}

.lede {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
  margin-bottom: 0;
  max-width: 980px;
}

.legend {
  align-items: center;
  background: #f8fbfa;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: flex-end;
  padding: 10px 20px;
}

.legend span {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 14px;
  gap: 9px;
  white-space: nowrap;
}

.dot {
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.dot.primitive {
  background: var(--primitive);
}

.dot.reference {
  background: var(--reference);
}

.dot.heap {
  background: var(--heap);
}

.workspace {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: 300px minmax(0, 1fr);
}

.scenario-panel,
.simulator,
.code-panel,
.memory-column,
.memory-table-panel,
.explanation {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scenario-panel {
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 16px;
  position: sticky;
  top: 20px;
}

.scenario-panel-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.scenario-panel h2 {
  font-size: 18px;
  margin-bottom: 0;
}

#scenarioProgress {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.scenario-list {
  display: grid;
  gap: 14px;
}

.scenario-group {
  display: grid;
  gap: 7px;
}

.scenario-group-title {
  color: var(--accent-strong);
  font-size: 11px;
  letter-spacing: 0;
  margin: 0;
  text-transform: uppercase;
}

.scenario-card {
  align-items: start;
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.scenario-card strong {
  font-size: 13px;
}

.scenario-card.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.scenario-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.scenario-card.active span {
  color: rgba(255, 255, 255, 0.82);
}

.simulator {
  box-shadow: var(--shadow-strong);
  overflow: hidden;
}

.simulator-header {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 20px;
}

.simulator-header h2 {
  font-size: 26px;
  margin-bottom: 0;
}

.controls {
  display: flex;
  gap: 8px;
}

.progress {
  background: #e8ece8;
  height: 8px;
}

#progressBar {
  background: var(--accent);
  height: 100%;
  transition: width 180ms ease;
  width: 0;
}

.content-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(300px, 0.85fr) minmax(360px, 1.15fr);
  padding: 20px;
}

.panel-heading {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-heading h3 {
  font-size: 15px;
  margin-bottom: 0;
}

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.code-panel,
.memory-column,
.memory-table-panel,
.explanation {
  box-shadow: none;
  padding: 16px;
}

pre {
  background: #111827;
  border-radius: 8px;
  color: #e5e7eb;
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  overflow: auto;
  padding: 16px;
}

.code-line {
  display: block;
  min-height: 24px;
  padding: 0 8px;
}

.code-line.active {
  background: rgba(20, 184, 166, 0.23);
  border-left: 3px solid #2dd4bf;
}

.memory-stage {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr);
}

.memory-table-panel {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
}

.memory-table {
  border-collapse: collapse;
  font-size: 12px;
  min-width: 620px;
  width: 100%;
}

.memory-table th,
.memory-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.memory-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.memory-table td {
  color: var(--ink);
}

.memory-table tbody tr:nth-child(even) {
  background: #f8faf8;
}

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

.memory-table .value {
  justify-self: start;
}

.table-empty {
  color: var(--muted);
  text-align: center;
}

.stack-frames,
.heap-objects {
  display: grid;
  gap: 12px;
}

.frame,
.heap-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.frame {
  border-left: 4px solid var(--accent);
}

.heap-card {
  border-left: 4px solid var(--heap);
}

.frame-title,
.heap-title {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
}

.heap-title {
  color: #047857;
}

.binding,
.property-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(217, 222, 217, 0.9);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(54px, 0.6fr) minmax(0, 1fr);
  min-height: 38px;
  padding: 8px;
}

.binding + .binding,
.property-row + .property-row {
  margin-top: 8px;
}

.name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;
}

.value {
  align-items: center;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-self: end;
  min-width: 0;
}

.pill {
  border-radius: 999px;
  color: white;
  display: inline-flex;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 6px 8px;
}

.pill.primitive {
  background: #3b82f6;
}

.pill.reference {
  background: var(--reference);
}

.pill.heap {
  background: var(--heap);
}

.arrow {
  color: var(--reference);
  font-size: 15px;
  font-weight: 900;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.explanation {
  background: #fcf8ea;
  border-color: #eadb9f;
  margin: 0 20px 20px;
}

.explanation-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.explanation h3 {
  font-size: 18px;
  margin-bottom: 0;
}

.explanation p {
  color: #5f5030;
  line-height: 1.55;
  margin-bottom: 0;
}

.change-badge {
  background: #fff3c4;
  border: 1px solid #e8cc62;
  border-radius: 999px;
  color: #5f5030;
  flex: none;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.change-badge[data-change="mutate"] {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

.change-badge[data-change="reassign"] {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.change-badge[data-change="copy"] {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.change-badge[data-change="call"],
.change-badge[data-change="return"],
.change-badge[data-change="closure"] {
  background: #f0fdfa;
  border-color: #99f6e4;
  color: #0f766e;
}

.learning-guide {
  margin-top: 24px;
}

.section-heading {
  margin-bottom: 18px;
  max-width: 900px;
}

.section-heading h2 {
  font-size: 30px;
  margin-bottom: 10px;
}

.section-heading p {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 0;
}

.learning-tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
}

.learning-tab {
  border: 0;
  border-radius: 6px;
  min-height: 36px;
}

.learning-tab.active {
  background: var(--accent);
  color: white;
}

.tab-panel[hidden] {
  display: none;
}

.model-basics {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.model-basics h3 {
  font-size: 17px;
  margin-bottom: 14px;
}

.model-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.model-grid article {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.model-grid h4 {
  font-size: 15px;
  margin: 0 0 8px;
}

.model-grid p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 10px;
}

.model-grid ul {
  margin: 0;
  padding-left: 18px;
}

.model-grid li {
  line-height: 1.45;
  margin: 5px 0;
}

.scenario-lesson {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
}

.lesson-card,
.scenario-notes,
.references {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.lesson-card {
  padding: 18px;
}

.featured-lesson {
  min-height: 100%;
}

.lesson-card h3,
.scenario-notes h3,
.references h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

.lesson-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 12px;
}

.lesson-card ul,
.references ul {
  margin: 0;
  padding-left: 18px;
}

.lesson-card li,
.references li {
  line-height: 1.5;
  margin: 6px 0;
}

.scenario-notes,
.references {
  padding: 18px;
}

.references {
  margin-top: 0;
}

.notes-list {
  display: grid;
  gap: 10px;
}

.notes-list div {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding-top: 10px;
}

.notes-list strong {
  font-size: 14px;
}

.notes-list span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.references a {
  color: var(--accent-strong);
  font-weight: 700;
}

@media (max-width: 1000px) {
  .intro,
  .workspace,
  .content-grid,
  .memory-stage,
  .model-grid,
  .scenario-lesson {
    grid-template-columns: 1fr;
  }

  .scenario-panel {
    max-height: none;
    position: static;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 16px;
  }

  .topline {
    align-items: flex-start;
    flex-direction: column;
  }

  .scenario-list {
    grid-template-columns: 1fr;
  }

  .learning-tabs,
  .explanation-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .learning-tab {
    width: 100%;
  }

  .legend {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
  }

  .simulator-header,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .controls button {
    width: 100%;
  }

  .content-grid {
    padding: 14px;
  }

  .explanation {
    margin: 0 14px 14px;
  }
}
