:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #5e6a62;
  --line: #d9dfd8;
  --green: #2f6f4e;
  --green-dark: #1e4f37;
  --blue: #2d5f9a;
  --rust: #a85d32;
  --amber: #c58b26;
  --soft-green: #e8f1e8;
  --soft-blue: #e8eff8;
  --danger: #a63f3f;
  --ok: #1f7a4b;
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.topbar h1,
.workspace-head h2,
.sidebar h2,
.source-dialog h2 {
  margin: 0;
}

.topbar h1 {
  max-width: 880px;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.download-link,
.primary-button,
.secondary-button,
.ghost-button,
.tab-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  white-space: nowrap;
}

.download-link:hover,
.ghost-button:hover,
.secondary-button:hover,
.icon-button:hover {
  border-color: var(--green);
}

.problem-tabs {
  display: flex;
  width: fit-content;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.tab-button {
  min-width: 150px;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
}

.tab-button:last-child {
  border-right: 0;
}

.tab-button.active {
  background: var(--green);
  color: #ffffff;
}

.main-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 430px;
  gap: 16px;
  align-items: start;
}

.main-grid > *,
.split > *,
.topbar > * {
  min-width: 0;
}

.sidebar,
.lesson-panel,
.workspace-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  max-width: 100%;
  overflow-wrap: break-word;
}

.sidebar,
.workspace-panel {
  position: sticky;
  top: 18px;
}

.sidebar {
  padding: 14px;
}

.sidebar-section + .sidebar-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.sidebar h2,
.workspace-head h2 {
  font-size: 17px;
}

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

.step-list button {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
}

.step-list button.active {
  border-color: var(--green);
  background: var(--soft-green);
}

.step-number {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e5ebe4;
  color: var(--green-dark);
  font-weight: 700;
}

.source-box p {
  margin: 8px 0 12px;
  color: var(--muted);
  line-height: 1.45;
}

.ghost-button,
.secondary-button,
.primary-button {
  min-height: 38px;
  padding: 0 12px;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.lesson-panel {
  min-height: 620px;
  padding: 22px;
}

.lesson-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-weight: 700;
}

.lesson-panel h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.lesson-lead {
  margin: 12px 0 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.content-band {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.content-band h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
  gap: 16px;
  align-items: start;
}

.definition-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.definition-list div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.definition-list dt {
  margin-bottom: 4px;
  color: var(--green-dark);
  font-weight: 700;
}

.definition-list dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.equation-list,
.prompt-list,
.solver-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.equation-list li,
.prompt-list li,
.solver-list li {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  line-height: 1.45;
}

.formula {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
}

.note-panel {
  padding: 14px;
  border-left: 4px solid var(--amber);
  background: #fff8e8;
  border-radius: 6px;
  color: #513c13;
  line-height: 1.5;
}

.corner-table,
.constraint-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
}

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

.corner-table th,
.constraint-table th {
  background: #edf3ed;
  color: var(--green-dark);
}

.corner-table tr:last-child td,
.constraint-table tr:last-child td {
  border-bottom: 0;
}

.best-row {
  background: #f0f7ed;
  font-weight: 700;
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.step-count {
  color: var(--muted);
  font-size: 14px;
}

.workspace-panel {
  padding: 14px;
}

.workspace-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.graph-wrap {
  width: 100%;
  aspect-ratio: 1.28;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
}

.graph-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.axis-label,
.grid-label {
  fill: #4f5b54;
  font-size: 13px;
}

.point-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.graph-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin-top: 10px;
}

.legend-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.legend-line {
  width: 20px;
  height: 3px;
  border-radius: 999px;
}

.point-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.point-controls input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.slider-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.check-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.metric-row strong {
  white-space: nowrap;
}

.constraint-checks {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.constraint-check {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 7px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.check-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 50%;
  background: var(--danger);
}

.check-dot.ok {
  background: var(--ok);
}

.answer-check {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.answer-check label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.answer-check input {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.feedback {
  margin-top: 12px;
  padding: 12px;
  border-radius: 6px;
  background: var(--soft-blue);
  color: #17375d;
  line-height: 1.45;
}

.feedback.ok {
  background: var(--soft-green);
  color: var(--green-dark);
}

.source-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: min(780px, calc(100vh - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
}

.source-dialog::backdrop {
  background: rgb(23 32 27 / 0.42);
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 36px;
  height: 36px;
}

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

.reference-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
}

.reference-item figure {
  margin: 0;
}

.reference-item img {
  display: block;
  width: 100%;
  height: 280px;
  object-fit: contain;
  background: #eef1ee;
}

.reference-item figcaption {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.rotate-180 {
  transform: rotate(180deg);
}

@media (max-width: 1180px) {
  .main-grid {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workspace-panel {
    position: static;
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    max-width: 100vw;
  }

  .app-shell {
    width: 100vw;
    max-width: 100vw;
    padding: 10px;
  }

  .topbar,
  .problem-tabs,
  .main-grid,
  .sidebar,
  .lesson-panel,
  .workspace-panel {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
  }

  .topbar,
  .nav-row {
    align-items: stretch;
    flex-direction: column;
  }

  .download-link,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .problem-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .tab-button {
    min-width: 0;
    white-space: normal;
  }

  .main-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .lesson-panel h2 {
    font-size: 23px;
  }

  .answer-check,
  .reference-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .app-shell {
    display: grid;
    justify-items: start;
  }

  .topbar,
  .problem-tabs,
  .main-grid,
  .sidebar,
  .lesson-panel,
  .workspace-panel {
    width: min(100%, 370px);
    max-width: 370px;
  }

  .problem-tabs {
    grid-template-columns: 1fr;
  }

  .tab-button {
    min-height: 40px;
  }
}
