:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #f1f5f3;
  --ink: #202426;
  --muted: #647077;
  --line: #dce3df;
  --teal: #0f8b8d;
  --teal-dark: #096568;
  --green: #287d4f;
  --amber: #a46412;
  --red: #b8323c;
  --violet: #6257a5;
  --shadow: 0 18px 48px rgba(32, 36, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--teal);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 139, 141, 0.22);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 36px;
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 74px;
}

.hero > div:last-child {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 850;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  font-size: 0.95rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.hero p,
.panel-heading span,
.input-label,
.small-control label,
.step-item p,
.answer-band p {
  color: var(--muted);
}

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

.solver-card {
  margin-top: 18px;
  padding: 18px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 8px;
}

.mode-tabs button {
  font-weight: 750;
  overflow-wrap: anywhere;
}

.mode-tabs button.active {
  border-color: var(--teal);
  background: #eaf7f7;
  color: var(--teal-dark);
}

.input-label {
  display: block;
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 0.86rem;
  font-weight: 750;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  font-family:
    "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

textarea {
  min-height: 104px;
  resize: vertical;
  padding: 14px;
  font-size: 1.02rem;
  line-height: 1.5;
}

input {
  min-height: 40px;
  padding: 0 11px;
}

.example-picker {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  max-width: 360px;
}

#exampleSelect {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line, #cdd7d6);
  background: var(--surface, #fff);
  color: var(--teal-dark);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#exampleSelect:focus-visible {
  outline: 2px solid var(--teal-dark);
  outline-offset: 1px;
}

#flipAllButton {
  padding: 0 12px;
  color: var(--teal-dark);
  white-space: normal;
}

.control-strip {
  margin-top: 14px;
}

.small-control {
  display: grid;
  gap: 5px;
  max-width: 220px;
}

.small-control label {
  font-size: 0.8rem;
  font-weight: 750;
}

.logic-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
  align-items: end;
}

.compare-control {
  max-width: none;
}

.values-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.value-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  font-weight: 750;
}

.value-toggle .state {
  min-width: 42px;
  border-radius: 999px;
  padding: 3px 8px;
  color: #ffffff;
  font-size: 0.76rem;
  text-align: center;
}

.value-toggle[data-value="true"] {
  border-color: rgba(40, 125, 79, 0.42);
  background: #f0fbf5;
}

.value-toggle[data-value="true"] .state {
  background: var(--green);
}

.value-toggle[data-value="false"] {
  border-color: rgba(184, 50, 60, 0.36);
  background: #fff7f7;
}

.value-toggle[data-value="false"] .state {
  background: var(--red);
}

.empty-state {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.error-box {
  margin-top: 12px;
  border-left: 4px solid var(--red);
  background: #fff4f4;
  color: var(--red);
  padding: 10px 12px;
  font-size: 0.92rem;
}

.error-box > strong {
  display: block;
  overflow-wrap: anywhere;
}

.input-assist {
  margin-top: 10px;
  border: 1px solid rgba(184, 50, 60, 0.2);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  color: var(--ink);
}

.input-assist span {
  display: block;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.input-assist p {
  margin-top: 5px;
  color: var(--muted);
}

.input-assist ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.input-assist li + li {
  margin-top: 3px;
}

.assist-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.assist-examples button {
  min-height: 32px;
  border-color: rgba(15, 139, 141, 0.24);
  padding: 5px 9px;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.answer-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  border-radius: 8px;
  background: #eaf7f7;
  padding: 16px;
}

.answer-band span {
  display: block;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.answer-band strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: clamp(1.45rem, 3vw, 2.3rem);
  line-height: 1.12;
}

.summary-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(15, 139, 141, 0.22);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 12px;
}

.summary-pill span {
  color: var(--teal-dark);
}

.insight-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 0;
}

.metric-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
  font-size: 0.82rem;
}

.metric-row strong,
.variable-count strong {
  color: var(--ink);
}

.tree-frame {
  height: 390px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(#e8eeeb 1px, transparent 1px),
    linear-gradient(90deg, #e8eeeb 1px, transparent 1px);
  background-color: #fbfcfb;
  background-size: 30px 30px;
  overflow: auto;
}

#treeSvg {
  display: block;
  width: 100%;
  min-width: 720px;
  height: 100%;
}

.tree-edge {
  stroke: #9aa9a4;
  stroke-width: 2;
}

.tree-node circle,
.tree-node rect {
  fill: var(--teal);
  filter: drop-shadow(0 8px 12px rgba(32, 36, 38, 0.14));
}

.tree-node.logic circle,
.tree-node.logic rect {
  fill: var(--violet);
}

.tree-node.number circle,
.tree-node.number rect {
  fill: var(--green);
}

.tree-node.symbol circle,
.tree-node.symbol rect {
  fill: var(--ink);
}

.tree-node.function circle,
.tree-node.function rect {
  fill: var(--amber);
}

.tree-node.statistics circle,
.tree-node.statistics rect {
  fill: var(--teal-dark);
}

.tree-node.matrix circle,
.tree-node.matrix rect {
  fill: var(--violet);
}

.tree-node.equation circle,
.tree-node.equation rect {
  fill: var(--red);
}

.tree-node text {
  fill: #ffffff;
  font-size: 13px;
  font-weight: 850;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

#outputPanel {
  min-height: 390px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  overflow: auto;
}

.graph-card {
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--line);
}

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

.graph-header strong {
  overflow-wrap: anywhere;
  font-family:
    "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.graph-header span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 10px;
}

.graph-legend span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.graph-card svg {
  display: block;
  width: 100%;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#e8eeeb 1px, transparent 1px),
    linear-gradient(90deg, #e8eeeb 1px, transparent 1px);
  background-color: #fbfcfb;
  background-size: 40px 40px;
}

.graph-card rect {
  fill: transparent;
}

.graph-axis {
  stroke: #9aa9a4;
  stroke-width: 1.5;
}

.graph-line {
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.graph-line-accent {
  stroke: var(--violet);
  stroke-dasharray: 8 7;
}

.graph-line-muted {
  stroke: #7f8f89;
  stroke-dasharray: 5 6;
  stroke-width: 2.4;
}

.graph-area {
  fill: rgba(98, 87, 165, 0.24);
  stroke: none;
}

.graph-point {
  fill: var(--violet);
  stroke: #ffffff;
  stroke-width: 2;
}

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

.artifact-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 13px 16px;
}

.artifact-row span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.artifact-row strong {
  overflow-wrap: anywhere;
  font-family:
    "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.table-wrap {
  max-height: 390px;
  overflow: auto;
}

.extra-table {
  border-top: 1px solid var(--line);
}

.extra-table h3 {
  margin: 0;
  padding: 12px 16px 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

table {
  width: 100%;
  min-width: 360px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
}

td.true {
  color: var(--green);
  font-weight: 850;
}

td.false {
  color: var(--red);
  font-weight: 850;
}

.steps-panel {
  margin-top: 14px;
}

.steps-list {
  display: grid;
  gap: 0;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.step-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.step-index {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--teal-dark);
  font-weight: 850;
}

.step-item code {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 6px 0;
  overflow-wrap: anywhere;
  border-radius: 8px;
  background: #f7f8f7;
  padding: 6px 8px;
  font-family:
    "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .insight-grid,
  .logic-controls {
    grid-template-columns: 1fr;
  }

  .summary-pill {
    align-self: flex-start;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 14px;
  }

  .hero {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    font-size: 0.9rem;
  }

  .solver-card {
    padding: 12px;
  }

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

  .answer-band {
    display: grid;
  }

  .artifact-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .tree-frame,
  #outputPanel {
    height: 340px;
    min-height: 340px;
  }
}
