:root {
  --ink: #182236;
  --muted: #66758a;
  --paper: #f3ead8;
  --panel: #fffaf0;
  --line: rgba(24, 34, 54, 0.14);
  --pass: #28a66f;
  --review: #2f74d0;
  --reject: #d64b45;
  --new: #f5b83d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(115deg, rgba(40, 166, 111, 0.12), transparent 38%),
    linear-gradient(35deg, rgba(214, 75, 69, 0.1), transparent 42%),
    var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.page {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 30px clamp(14px, 3vw, 44px) 42px;
}

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

.eyebrow {
  margin: 0;
  color: #52627a;
  font-size: 15px;
  font-weight: 900;
}

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

h1 {
  margin-bottom: 4px;
  font-size: clamp(42px, 7vw, 86px);
  line-height: 1;
  letter-spacing: 0;
}

.lesson {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
}

.story-panel,
.stage-card,
.try-panel {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 22px 70px rgba(55, 47, 33, 0.12);
}

.story-panel {
  display: flex;
  flex-direction: column;
  min-height: 588px;
  padding: 22px;
}

.step-count {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: #8a6f31;
  font-weight: 1000;
}

.step-count span:first-child {
  font-size: 50px;
  line-height: 1;
}

.step-count i,
.step-count span:last-child {
  font-size: 22px;
  font-style: normal;
}

.story-panel h2 {
  margin: 14px 0 10px;
  font-size: 29px;
  line-height: 1.16;
}

.story-panel p {
  color: #4c5c72;
  font-size: 18px;
  line-height: 1.45;
}

.vote-card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid rgba(24, 34, 54, 0.12);
  border-top: 4px solid var(--ink);
  background: #fffdf6;
}

.vote-card span {
  color: #8a6f31;
  font-size: 13px;
  font-weight: 1000;
}

.vote-card strong {
  display: block;
  margin: 6px 0 0;
  font-size: 21px;
}

.teacher-prompt {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(138, 111, 49, 0.24);
  background: linear-gradient(135deg, #fff7d8, #fffdf6);
}

.teacher-prompt span {
  display: block;
  margin-bottom: 8px;
  color: #8a6f31;
  font-size: 13px;
  font-weight: 1000;
}

.teacher-prompt strong {
  color: #3c3013;
  font-size: 18px;
  line-height: 1.45;
}

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

.controls button,
.preset-buttons button {
  min-height: 52px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fffaf0;
  cursor: pointer;
  font-weight: 950;
}

.controls button:disabled {
  border-color: rgba(24, 34, 54, 0.18);
  background: rgba(24, 34, 54, 0.08);
  color: rgba(24, 34, 54, 0.45);
  cursor: not-allowed;
}

.stage-card {
  padding: 18px;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: #53637a;
  font-size: 15px;
  font-weight: 900;
}

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

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 999px;
}

.swatch.pass {
  background: var(--pass);
}

.swatch.review {
  background: var(--review);
}

.swatch.reject {
  background: var(--reject);
}

.swatch.new {
  background: var(--new);
  border: 2px solid var(--ink);
}

.stage-hint {
  color: #8a6f31;
  font-size: 16px;
  font-weight: 950;
}

.plot {
  display: block;
  width: 100%;
  height: auto;
  background: #fffdf6;
  touch-action: none;
  user-select: none;
}

.axis {
  stroke: rgba(24, 34, 54, 0.54);
  stroke-width: 2;
}

.axis-arrow {
  fill: rgba(24, 34, 54, 0.54);
}

.axis-label {
  fill: #4f5e72;
  font-size: 19px;
  font-weight: 900;
}

.axis-vertical {
  transform: rotate(-90deg);
}

.zone {
  font-size: 22px;
  font-weight: 1000;
}

.zone.pass {
  fill: var(--pass);
}

.zone.review {
  fill: #8b671a;
}

.zone.reject {
  fill: var(--reject);
}

.sample {
  transition: opacity 260ms ease;
}

.sample circle {
  transition: r 180ms ease, opacity 180ms ease;
}

.sample.chosen circle {
  stroke: var(--ink);
  stroke-width: 4;
}

.rank-text {
  fill: #fffaf0;
  font-size: 17px;
  font-weight: 1000;
  text-anchor: middle;
  dominant-baseline: central;
}

.point-caption,
.new-caption {
  fill: #39495f;
  font-size: 15px;
  font-weight: 900;
  text-anchor: middle;
}

.measure-line {
  stroke-width: 1.5;
  stroke-dasharray: 5 8;
  opacity: 0.28;
}

.neighbor-line {
  stroke-width: 4;
  stroke-dasharray: 9 9;
  opacity: 0.8;
}

.range-circle {
  fill: rgba(245, 184, 61, 0.14);
  stroke: rgba(24, 34, 54, 0.28);
  stroke-width: 3;
  stroke-dasharray: 7 8;
}

.new-node {
  cursor: grab;
}

.new-node:active {
  cursor: grabbing;
}

.new-halo {
  fill: rgba(245, 184, 61, 0.26);
}

.new-core {
  fill: var(--new);
  stroke: var(--ink);
  stroke-width: 6;
}

.question {
  fill: var(--ink);
  font-size: 32px;
  font-weight: 1000;
  text-anchor: middle;
  dominant-baseline: central;
}

.bottom-lab {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 190px;
  gap: 12px;
  margin-top: 12px;
}

.lab-card,
.slider-card {
  min-height: 86px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fffdf6;
}

.lab-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.lab-card span,
.slider-card span {
  display: block;
  margin-bottom: 8px;
  color: #5a6a80;
  font-size: 15px;
  font-weight: 900;
}

.lab-card strong {
  font-size: 38px;
  line-height: 1;
}

.result strong {
  font-size: 30px;
}

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

input[type="range"]:disabled {
  opacity: 0.35;
}

.vote-box {
  display: grid;
  gap: 5px;
  margin-top: 6px;
}

.vote-row {
  display: grid;
  grid-template-columns: 64px 1fr 20px;
  gap: 8px;
  align-items: center;
  color: #53637a;
  font-size: 12px;
  font-weight: 950;
}

.vote-row.winner {
  color: var(--ink);
}

.vote-track {
  height: 10px;
  background: rgba(24, 34, 54, 0.1);
  overflow: hidden;
}

.vote-fill {
  height: 100%;
  transition: width 180ms ease-out;
}

.try-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 480px;
  gap: 22px;
  align-items: center;
  margin-top: 22px;
  padding: 24px;
}

.try-panel h2 {
  margin-bottom: 8px;
  font-size: 32px;
}

.try-panel p {
  margin-bottom: 0;
  color: #53637a;
  font-size: 19px;
  line-height: 1.5;
}

.preset-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.preset-buttons button {
  background: #fffdf6;
  color: var(--ink);
}

.preset-buttons button:hover {
  background: var(--ink);
  color: #fffaf0;
}

@media (max-width: 1120px) {
  .lesson,
  .try-panel {
    grid-template-columns: 1fr;
  }

  .story-panel {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .page {
    padding: 18px 12px 32px;
  }

  .stage-card {
    overflow-x: hidden;
  }

  .plot {
    width: 100%;
    min-width: 0;
  }

  .bottom-lab,
  .preset-buttons {
    grid-template-columns: 1fr;
  }

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

@media (min-width: 900px), (orientation: landscape) {
  html,
  body {
    width: 100%;
    height: 100vh;
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
  }

  .page {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: clamp(12px, 1.6vh, 24px) clamp(18px, 3vw, 42px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(10px, 1.5vh, 18px);
  }

  .hero {
    gap: 4px;
    margin-bottom: 0;
  }

  h1 {
    font-size: clamp(42px, 5.2vw, 76px);
    line-height: 0.96;
  }

  .lesson {
    min-height: 0;
    grid-template-columns: minmax(310px, 30vw) minmax(0, 1fr);
    gap: clamp(14px, 2vw, 24px);
  }

  .story-panel,
  .stage-card {
    min-height: 0;
    height: 100%;
  }

  .story-panel {
    overflow: hidden;
    padding: clamp(14px, 1.7vh, 22px);
  }

  .step-count span:first-child {
    font-size: clamp(38px, 5vh, 50px);
  }

  .step-count i,
  .step-count span:last-child {
    font-size: clamp(17px, 2.4vh, 22px);
  }

  .story-panel h2 {
    margin: clamp(8px, 1.2vh, 14px) 0 clamp(6px, 1vh, 10px);
    font-size: clamp(22px, 3.1vh, 29px);
  }

  .story-panel p {
    font-size: clamp(14px, 1.9vh, 18px);
    line-height: 1.35;
  }

  .vote-card {
    margin-top: clamp(8px, 1.2vh, 12px);
    padding: clamp(9px, 1.2vh, 14px);
  }

  .vote-card strong {
    font-size: clamp(16px, 2.4vh, 21px);
  }

  .teacher-prompt {
    padding: clamp(10px, 1.5vh, 16px);
  }

  .teacher-prompt span {
    margin-bottom: 4px;
    font-size: clamp(11px, 1.5vh, 13px);
  }

  .teacher-prompt strong {
    font-size: clamp(14px, 1.9vh, 18px);
    line-height: 1.35;
  }

  .controls {
    gap: 10px;
    margin-top: clamp(8px, 1.2vh, 12px);
  }

  .controls button,
  .preset-buttons button {
    min-height: clamp(40px, 5.8vh, 52px);
  }

  .stage-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: clamp(12px, 1.6vh, 18px);
  }

  .stage-topline {
    margin-bottom: clamp(6px, 1vh, 10px);
  }

  .legend {
    gap: 10px;
    font-size: clamp(12px, 1.55vh, 15px);
  }

  .stage-hint {
    font-size: clamp(12px, 1.65vh, 16px);
  }

  .plot {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .bottom-lab {
    grid-template-columns: minmax(105px, 150px) minmax(0, 1fr) minmax(150px, 190px);
    gap: 10px;
    margin-top: clamp(8px, 1.2vh, 12px);
  }

  .lab-card,
  .slider-card {
    min-height: clamp(58px, 8.5vh, 86px);
    padding: clamp(9px, 1.4vh, 14px) 14px;
  }

  .lab-card span,
  .slider-card span {
    margin-bottom: 4px;
    font-size: clamp(12px, 1.65vh, 15px);
  }

  .lab-card strong {
    font-size: clamp(28px, 4.6vh, 38px);
  }

  .result strong {
    font-size: clamp(23px, 3.8vh, 30px);
  }

  .try-panel {
    margin-top: 0;
    padding: clamp(14px, 1.8vh, 24px);
    grid-template-columns: minmax(0, 1fr) minmax(360px, 42vw);
    gap: clamp(14px, 2vw, 22px);
  }

  .try-panel h2 {
    margin-bottom: 4px;
    font-size: clamp(22px, 3.1vh, 32px);
  }

  .try-panel p {
    font-size: clamp(13px, 1.75vh, 18px);
    line-height: 1.35;
  }

  .preset-buttons {
    gap: 8px;
  }
}

@media (max-width: 899px) and (orientation: portrait) {
  html,
  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .page {
    width: 100%;
    overflow-x: hidden;
  }

  .lesson,
  .story-panel,
  .stage-card,
  .try-panel,
  .vote-card,
  .teacher-prompt,
  .controls,
  .bottom-lab,
  .preset-buttons {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .story-panel,
  .stage-card,
  .try-panel {
    overflow: hidden;
  }

  h1 {
    font-size: clamp(32px, 10vw, 42px);
    line-height: 1.05;
  }

  .story-panel p,
  .teacher-prompt strong,
  .try-panel p {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media (min-width: 900px) and (max-height: 820px) {
  html,
  body {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: hidden;
  }

  .page {
    height: 100vh;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 8px 42px 8px;
    gap: 4px;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  h1 {
    font-size: clamp(34px, 3.8vw, 52px);
  }

  .lesson {
    grid-template-columns: minmax(260px, 31vw) minmax(0, 1fr);
    gap: 10px;
    align-self: stretch;
    min-height: 0;
  }

  .story-panel {
    padding: 10px 12px;
  }

  .step-count span:first-child {
    font-size: 34px;
  }

  .step-count i,
  .step-count span:last-child {
    font-size: 16px;
  }

  .story-panel h2 {
    margin: 5px 0 5px;
    font-size: 21px;
  }

  .story-panel p {
    font-size: 12px;
    line-height: 1.28;
  }

  .vote-card {
    margin-top: 6px;
    padding: 7px 10px;
  }

  .vote-card span {
    font-size: 11px;
  }

  .vote-card strong {
    font-size: 16px;
  }

  .vote-box {
    gap: 3px;
    margin-top: 4px;
  }

  .vote-row {
    grid-template-columns: 52px 1fr 16px;
    gap: 6px;
    font-size: 10px;
  }

  .vote-track {
    height: 7px;
  }

  .teacher-prompt {
    display: none;
  }

  .controls {
    margin-top: 6px;
    gap: 8px;
  }

  .controls button,
  .preset-buttons button {
    min-height: 36px;
  }

  .stage-card {
    position: static;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: 8px 10px;
  }

  .stage-topline {
    position: static;
    margin-bottom: 1px;
    pointer-events: auto;
  }

  .legend {
    font-size: 11px;
  }

  .swatch {
    width: 10px;
    height: 10px;
  }

  .stage-hint {
    font-size: 11px;
  }

  .plot {
    height: 100%;
  }

  .bottom-lab {
    position: static;
    grid-template-columns: 70px minmax(0, 1fr) 108px;
    gap: 6px;
    margin-top: 2px;
  }

  .lab-card,
  .slider-card {
    min-height: 28px;
    padding: 3px 7px;
  }

  .lab-card span,
  .slider-card span {
    margin-bottom: 0;
    font-size: 10px;
  }

  .lab-card strong {
    font-size: 20px;
  }

  .result strong {
    font-size: 17px;
  }

  input[type="range"] {
    height: 16px;
  }

  .try-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 44vw);
    margin-top: 0;
    padding: 8px 14px;
    gap: 10px;
  }

  .try-panel h2 {
    margin-bottom: 2px;
    font-size: 17px;
  }

  .try-panel p {
    font-size: 11px;
    line-height: 1.28;
  }

  .preset-buttons button {
    min-height: 34px;
    font-size: 13px;
  }
}

@media (max-width: 899px) {
  html,
  body {
    width: 100%;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    min-height: 100vh;
  }

  .page {
    display: block;
    width: 100%;
    height: auto;
    padding: 16px 12px 28px;
    overflow-x: hidden;
  }

  .hero {
    margin-bottom: 14px;
  }

  h1 {
    font-size: clamp(31px, 9.5vw, 42px);
    line-height: 1.08;
  }

  .lesson,
  .try-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    width: 100%;
    min-width: 0;
  }

  .story-panel,
  .stage-card,
  .try-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .story-panel {
    padding: 18px;
  }

  .stage-card {
    display: block;
    position: static;
    padding: 12px;
  }

  .stage-topline,
  .bottom-lab {
    position: static;
    inset: auto;
    pointer-events: auto;
  }

  .stage-topline {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .plot {
    display: block;
    width: 100%;
    min-width: 0;
    height: auto;
  }

  .bottom-lab,
  .preset-buttons {
    grid-template-columns: 1fr;
  }

  .lab-card,
  .slider-card {
    min-height: 58px;
  }

  .lab-card {
    align-items: center;
    justify-content: center;
  }

  .try-panel {
    margin-top: 14px;
    padding: 16px;
  }

  .try-panel h2 {
    font-size: 24px;
  }

  .try-panel p,
  .story-panel p,
  .teacher-prompt strong {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
