:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --ink: #1b2430;
  --muted: #627081;
  --line: #d8e0e7;
  --accent: #1e7d68;
  --accent-2: #c66a2e;
  --danger: #b23b4a;
  --shadow: 0 12px 30px rgba(27, 36, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.35;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.status-pill {
  min-width: 86px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(360px, 1fr);
  gap: 18px;
  min-width: 0;
}

.editor-pane,
.visual-pane,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.editor-pane,
.visual-pane {
  min-height: 650px;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.mini-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.active-dot {
  background: var(--accent);
}

.visited-dot {
  background: #77b8a7;
}

.sample-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

select {
  min-height: 38px;
  max-width: 160px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: white;
  color: var(--ink);
  font: inherit;
}

.algorithm-info {
  min-height: 48px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.code-editor {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  width: 100%;
  min-height: 472px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  direction: ltr;
}

.line-gutter {
  min-height: 472px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  padding: 16px 0 16px 0;
  background: #f1f5f8;
  color: #8a98a8;
  direction: ltr;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.65;
  text-align: right;
  user-select: none;
}

.line-number {
  position: relative;
  display: block;
  width: 100%;
  height: 23.1px;
  min-height: 0;
  padding: 0 10px 0 6px;
  border: 0;
  border-right: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 400;
  line-height: 23.1px;
  text-align: right;
  cursor: pointer;
}

.line-number:hover {
  background: #e5edf2;
  filter: none;
}

.line-number-breakpoint::before {
  position: absolute;
  left: 7px;
  top: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  content: "";
}

.line-number-current {
  border-right-color: var(--accent);
  background: #dcefe9;
  color: var(--accent);
  font-weight: 700;
}

.line-number-current.line-number-breakpoint {
  background: #f8e5e8;
}

textarea {
  display: block;
  width: 100%;
  min-height: 472px;
  resize: vertical;
  border: 0;
  padding: 16px;
  direction: ltr;
  text-align: left;
  color: #16202a;
  background: transparent;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.65;
  outline: none;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 8px 12px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.96);
}

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

.ghost-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.compact-btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.speed-control {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.speed-control select {
  max-width: none;
}

.learning-toggle {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.learning-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  border: 1px solid #aab8c4;
  border-radius: 11px;
  background: #dbe2e8;
  transition: background 150ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(27, 36, 48, 0.25);
  content: "";
  transition: transform 150ms ease;
}

.learning-toggle input:checked + .toggle-track {
  border-color: var(--accent);
  background: var(--accent);
}

.learning-toggle input:checked + .toggle-track::after {
  transform: translateX(-16px);
}

.learning-toggle input:focus-visible + .toggle-track {
  outline: 2px solid #78adce;
  outline-offset: 2px;
}

.flow-stage {
  height: calc(100% - 54px);
  min-height: 594px;
  overflow: auto;
  background:
    linear-gradient(#edf2f7 1px, transparent 1px),
    linear-gradient(90deg, #edf2f7 1px, transparent 1px);
  background-size: 28px 28px;
}

#flowSvg {
  display: block;
  min-width: 760px;
  min-height: 640px;
}

.node-rect {
  fill: #ffffff;
  stroke: #9fb0bf;
  stroke-width: 1.4;
}

.node-diamond {
  fill: #fffaf3;
  stroke: var(--accent-2);
  stroke-width: 1.5;
}

.node-visited .node-rect {
  fill: #eef8f5;
  stroke: #77b8a7;
}

.node-visited .node-diamond {
  fill: #fff2e5;
  stroke: #d69057;
}

.node-active .node-rect,
.node-active .node-diamond {
  stroke: var(--accent);
  stroke-width: 3;
}

.node-text {
  fill: #1b2430;
  direction: ltr;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.edge {
  fill: none;
  stroke: #7e8d9c;
  stroke-width: 1.4;
  marker-end: url(#arrow);
}

.edge-taken {
  stroke: var(--accent);
  stroke-width: 3;
  marker-end: url(#arrowTaken);
}

.edge-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.edge-label-taken {
  fill: var(--accent);
}

.inspector {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel {
  min-height: 160px;
  padding: 16px;
}

.history-panel {
  max-height: 360px;
  overflow: hidden;
}

.diagnostics-panel {
  min-height: 140px;
}

.challenge-panel {
  min-height: 140px;
}

.challenge-score {
  min-width: 44px;
  padding: 3px 7px;
  border-radius: 4px;
  background: #eef3f6;
  color: var(--muted);
  direction: ltr;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

.challenge-view {
  display: grid;
  gap: 8px;
}

.challenge-active {
  color: var(--ink);
}

.challenge-line {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.challenge-expression {
  overflow-x: auto;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f7fafb;
  direction: ltr;
  text-align: left;
  white-space: nowrap;
}

.challenge-values {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.challenge-values span {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  direction: ltr;
}

.challenge-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.challenge-feedback {
  padding: 10px;
  border-right: 4px solid var(--accent);
  background: #eef8f5;
}

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

.challenge-wrong {
  border-right-color: var(--accent-2);
  background: #fff7ed;
}

.panel h2 {
  margin-bottom: 12px;
}

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

.panel-heading h2 {
  margin-bottom: 0;
}

.vars-view {
  display: grid;
  gap: 8px;
}

.var-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  direction: ltr;
  font-family: Consolas, "Courier New", monospace;
}

.var-row-changed {
  border-color: #77b8a7;
  background: #eef8f5;
  box-shadow: inset 3px 0 0 var(--accent);
}

.var-value-wrap {
  display: inline-flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.var-change {
  color: var(--accent);
  font-family: Tahoma, Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.arrays-panel {
  min-height: 150px;
}

.arrays-heading {
  align-items: flex-start;
  margin-bottom: 10px;
}

.array-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 9px;
  color: var(--muted);
  font-size: 10px;
}

.array-legend span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.array-key {
  width: 10px;
  height: 10px;
  border: 1px solid #9fb0bf;
  border-radius: 2px;
  background: white;
}

.range-key {
  background: #eef4f7;
}

.access-key {
  border: 2px solid #367c9e;
}

.change-key {
  border-color: var(--accent);
  background: #dcefe9;
}

.arrays-view {
  display: grid;
  gap: 14px;
}

.array-visualizer {
  min-width: 0;
}

.array-name {
  margin-bottom: 7px;
  direction: ltr;
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}

.array-track {
  display: flex;
  gap: 5px;
  max-width: 100%;
  overflow-x: auto;
  padding: 3px 1px 7px;
  direction: ltr;
}

.array-column {
  display: grid;
  grid-template-rows: 20px 44px 18px;
  flex: 0 0 52px;
  width: 52px;
  text-align: center;
}

.array-pointers {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
}

.array-pointers span {
  padding: 1px 3px;
  border-radius: 3px;
  background: #e5edf2;
  color: #456070;
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
}

.array-cell {
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #9fb0bf;
  border-radius: 5px;
  background: white;
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.array-cell-in-range {
  background: #eef4f7;
}

.array-cell-accessed {
  border: 2px solid #367c9e;
  box-shadow: inset 0 0 0 1px white;
}

.array-cell-mid {
  border-color: #6a4b9a;
  box-shadow: inset 0 0 0 1px white, 0 0 0 2px #d9ccec;
}

.array-cell-changed {
  border-color: var(--accent);
  background: #dcefe9;
  color: #135747;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px white, 0 0 0 2px #a7d4c7;
}

.array-index {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  line-height: 18px;
}

.empty,
.explain,
.complexity {
  color: var(--muted);
  line-height: 1.8;
}

.step-trace {
  display: grid;
  gap: 9px;
}

.trace-title {
  color: var(--ink);
  font-size: 13px;
}

.trace-expression {
  display: block;
  overflow-x: auto;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafb;
  direction: ltr;
  color: #253746;
  text-align: left;
  white-space: nowrap;
}

.trace-values {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.trace-values span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 1px solid #cbd7df;
  border-radius: 4px;
  background: white;
  direction: ltr;
  color: var(--ink);
  font-size: 11px;
}

.trace-values code {
  color: #456070;
}

.trace-values b {
  color: var(--muted);
}

.trace-empty {
  color: var(--muted);
  font-size: 11px;
}

.trace-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-right: 3px solid #6f8798;
  background: #f4f7f9;
  color: var(--muted);
}

.trace-result strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  direction: ltr;
  text-align: left;
}

.trace-result-true {
  border-right-color: var(--accent);
  background: #eef8f5;
}

.trace-result-false {
  border-right-color: var(--accent-2);
  background: #fff7ed;
}

.step-trace p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

pre {
  min-height: 76px;
  max-height: 160px;
  overflow: auto;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  direction: ltr;
  text-align: left;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.complexity strong {
  color: var(--ink);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

.metric-item {
  display: grid;
  place-items: center;
  min-height: 54px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafb;
  text-align: center;
}

.metric-item strong {
  color: var(--accent);
  font-size: 17px;
  line-height: 1;
}

.metric-item span {
  color: var(--muted);
  font-size: 10px;
}

.analysis-summary {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.analysis-summary small {
  display: block;
  padding: 7px 9px;
  border-right: 3px solid #4e7ea8;
  background: #f3f8fb;
  color: #4b6170;
  font-size: 11px;
}

.analysis-summary details {
  margin-top: 3px;
}

.analysis-summary summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
}

.history-view {
  max-height: 292px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  direction: rtl;
  font-size: 12px;
}

.history-table th,
.history-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.history-table th {
  position: sticky;
  top: 0;
  background: #f3f7f9;
  color: var(--muted);
  text-align: right;
  font-weight: 700;
}

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

.history-code,
.history-vars {
  direction: ltr;
  text-align: left;
  font-family: Consolas, "Courier New", monospace;
}

.history-code {
  min-width: 120px;
}

.history-vars {
  color: var(--muted);
  white-space: nowrap;
}

.diagnostics-view {
  display: grid;
  gap: 8px;
}

.diagnostic-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-right-width: 4px;
  border-radius: 7px;
  background: #fbfcfe;
  font-size: 13px;
  line-height: 1.6;
}

.diagnostic-line {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.diagnostic-error {
  border-right-color: var(--danger);
  background: #fff7f8;
}

.diagnostic-warning {
  border-right-color: var(--accent-2);
  background: #fffaf3;
}

.diagnostic-info {
  border-right-color: #4e7ea8;
  background: #f6faff;
}

.error {
  color: var(--danger);
}

@media (max-width: 1160px) {
  .app-shell,
  .workspace {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  h1 {
    font-size: 20px;
  }

  .app-shell {
    padding: 12px;
  }

  .inspector {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  textarea {
    min-height: 380px;
  }

  .code-editor,
  .line-gutter {
    min-height: 380px;
  }
}
