:root {
  color-scheme: light dark;
  --bg: #edf5ff;
  --bg-2: #f8fbff;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --ink: #102033;
  --muted: #5c6d80;
  --line: rgba(99, 122, 151, 0.26);
  --primary: #2563eb;
  --primary-dark: #1948ad;
  --primary-soft: #dbeafe;
  --teal: #0f766e;
  --teal-soft: #ccfbf1;
  --tomato: #dc4f3f;
  --tomato-dark: #98291f;
  --tomato-soft: #ffe2d8;
  --gold: #d19016;
  --gold-soft: #fff2c8;
  --pink: #d9468f;
  --success: #15803d;
  --danger: #c02626;
  --shadow: 0 22px 60px rgba(31, 59, 92, 0.16);
  --shadow-small: 0 10px 26px rgba(31, 59, 92, 0.14);
  --radius: 8px;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #101827;
  --bg-2: #172338;
  --glass: rgba(28, 40, 60, 0.76);
  --glass-strong: rgba(32, 45, 68, 0.92);
  --ink: #edf5ff;
  --muted: #aab9cc;
  --line: rgba(214, 226, 241, 0.22);
  --primary: #72a7ff;
  --primary-dark: #a8c7ff;
  --primary-soft: rgba(37, 99, 235, 0.22);
  --teal: #3dd6c6;
  --teal-soft: rgba(15, 118, 110, 0.24);
  --tomato: #ff836f;
  --tomato-dark: #ffd0c7;
  --tomato-soft: rgba(220, 79, 63, 0.25);
  --gold: #ffd166;
  --gold-soft: rgba(209, 144, 22, 0.26);
  --pink: #ff8cc7;
  --success: #7be59b;
  --danger: #ff9b9b;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  --shadow-small: 0 10px 28px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(37, 99, 235, 0.16), transparent 26%),
    radial-gradient(circle at 82% 8%, rgba(217, 70, 143, 0.14), transparent 23%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

body,
button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  color: inherit;
}

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

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary), transparent 58%);
  outline-offset: 2px;
}

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

.app-shell {
  min-height: 100vh;
  padding: 16px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.35);
}

.app-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  display: grid;
  grid-template-rows: 1fr 3px 1fr;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.26)),
    conic-gradient(from -90deg, var(--tomato) 0 180deg, #ffd28a 180deg 360deg);
  color: #fff;
  font-weight: 900;
  box-shadow: var(--shadow-small);
}

.brand-mark i {
  width: 32px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.eyebrow {
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin-top: 3px;
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button,
.text-button,
.segmented button,
.prediction-options button,
.choice-row button {
  min-height: 38px;
  border-radius: 8px;
  border-color: var(--line);
  background: var(--glass-strong);
  color: var(--ink);
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.icon-button {
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
}

.icon-button.wide {
  min-width: 82px;
}

.icon-button:hover,
.text-button:hover,
.segmented button:hover,
.prediction-options button:hover,
.choice-row button:hover,
.preset-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-small);
}

.icon-button.active,
.icon-button[aria-pressed="true"],
.segmented .active,
.prediction-options .selected,
.choice-row .selected {
  border-color: color-mix(in srgb, var(--primary), transparent 20%);
  background: var(--primary);
  color: #fff;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.course-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(540px, 1fr) minmax(300px, 360px);
  gap: 14px;
  align-items: start;
}

.left-rail,
.right-rail,
.stage {
  min-height: 0;
  max-height: calc(100vh - 178px);
  overflow: auto;
}

.left-rail,
.right-rail {
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
}

.panel-section,
.flow-card,
.model-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass-strong);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.26) inset;
}

.panel-section {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.section-title,
.model-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title span,
.model-title span {
  font-size: 15px;
  font-weight: 900;
}

.model-title small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.fraction-readout {
  height: 96px;
  display: grid;
  grid-template-rows: 1fr 4px 1fr;
  place-items: center;
  border: 2px solid color-mix(in srgb, var(--tomato), transparent 40%);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.76), rgba(255, 255, 255, 0.16)),
    var(--tomato-soft);
  color: var(--tomato-dark);
  font-weight: 900;
}

[data-theme="dark"] .fraction-readout {
  background: var(--tomato-soft);
}

.fraction-readout span {
  font-size: 30px;
  line-height: 1;
}

.fraction-readout i {
  width: 76px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.range-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.range-field input {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 34px;
  accent-color: var(--primary);
}

.range-field output {
  color: var(--ink);
}

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

.preset-list {
  display: grid;
  gap: 8px;
}

.preset-card {
  min-height: 64px;
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.preset-card strong {
  font-size: 15px;
}

.preset-card span,
.teacher-prompt,
.status-line,
.flow-card p,
.transfer-grid p,
.choice-row + em {
  color: var(--muted);
  line-height: 1.45;
}

.preset-card.active {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.teacher-prompt {
  font-size: 14px;
}

body.hide-teacher .teacher-only {
  display: none;
}

.stage {
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
}

.stage-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}

.stage-top h2 {
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.22;
  letter-spacing: 0;
}

.formula-chip {
  min-width: 180px;
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--gold), transparent 30%);
  border-radius: 8px;
  background: var(--gold-soft);
  color: color-mix(in srgb, var(--gold), #2b1600 46%);
  font-weight: 900;
  text-align: center;
}

.flow-card {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(240px, 1fr);
  gap: 10px;
  align-items: center;
}

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

.prediction-box textarea {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 54px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--glass-strong), transparent 8%);
  color: var(--ink);
  line-height: 1.45;
}

.prediction-box .status-line {
  grid-column: 1 / -1;
}

.model-stage {
  min-height: 540px;
  display: grid;
  grid-template-columns: minmax(250px, 0.95fr) minmax(220px, 0.68fr);
  grid-template-rows: minmax(260px, 1fr) minmax(160px, 0.52fr);
  gap: 12px;
}

.model-card {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  position: relative;
}

.pizza-card {
  grid-row: 1 / -1;
}

.numberline-card {
  grid-column: 2;
  grid-row: 1;
}

.strip-card {
  grid-column: 2;
  grid-row: 2;
}

.pizza-svg,
.numberline-svg {
  width: 100%;
  height: 100%;
  min-height: 210px;
  display: block;
  touch-action: none;
}

.slice-top {
  transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease;
}

.slice-top.selected {
  filter: drop-shadow(0 8px 10px rgba(220, 79, 63, 0.25));
}

.drag-knob,
.line-marker {
  cursor: grab;
}

.dragging .drag-knob,
.dragging .line-marker {
  cursor: grabbing;
}

.strip-model {
  min-height: 110px;
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 6px 2px 0;
}

.strip-track {
  height: 78px;
  display: grid;
  grid-template-columns: repeat(var(--pieces), minmax(0, 1fr));
  border: 3px solid color-mix(in srgb, var(--ink), transparent 10%);
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--glass-strong), #fff 20%);
  box-shadow: 0 12px 0 color-mix(in srgb, var(--ink), transparent 86%);
  transform: perspective(600px) rotateX(5deg);
}

.strip-piece {
  display: grid;
  place-items: center;
  min-width: 0;
  border-right: 1px solid color-mix(in srgb, var(--ink), transparent 70%);
  color: color-mix(in srgb, var(--ink), transparent 45%);
  font-size: 12px;
  font-weight: 900;
}

.strip-piece:last-child {
  border-right: 0;
}

.strip-piece.filled {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.32), transparent),
    var(--teal);
  color: #fff;
}

.strip-caption {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.trace-strip {
  min-height: 46px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass-strong);
}

.trace-strip > span {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted);
}

.trace-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.trace-list b {
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  white-space: nowrap;
}

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

.diff-grid article {
  min-height: 78px;
  padding: 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  display: grid;
  gap: 6px;
}

.diff-grid article:last-child {
  background: var(--teal-soft);
}

.diff-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.diff-grid strong {
  font-size: 14px;
  line-height: 1.35;
}

.diff-pulse {
  animation: pulseCard 680ms ease;
}

.observation-list {
  max-height: 118px;
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.observation-list li {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--glass-strong), transparent 8%);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.logic-card {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 12px;
  border-radius: 8px;
  background: var(--gold-soft);
  color: color-mix(in srgb, var(--gold), #2b1600 48%);
  font-weight: 900;
  line-height: 1.45;
}

.logic-card.locked {
  background: color-mix(in srgb, var(--glass-strong), transparent 5%);
  color: var(--muted);
  font-weight: 700;
}

.mini-formula {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--primary-dark);
  font-weight: 900;
  text-align: center;
}

.transfer-grid,
.quiz-list {
  display: grid;
  gap: 10px;
}

.transfer-grid article,
.quiz-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--glass-strong), transparent 7%);
}

.choice-row,
.quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.quiz-options button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  font-weight: 800;
}

.quiz-options button.correct {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success), transparent 82%);
}

.quiz-options button.wrong {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger), transparent 82%);
}

.quiz-feedback {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.learning-card {
  max-height: 260px;
  min-height: 172px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--glass-strong), #fff 8%);
  color: var(--ink);
  line-height: 1.45;
}

.flow-nav {
  min-height: 64px;
  display: grid;
  grid-template-columns: repeat(7, minmax(72px, 1fr));
  gap: 8px;
  padding: 10px;
}

.flow-nav button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--glass-strong);
  color: var(--muted);
  font-weight: 900;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.flow-nav button.active {
  background: var(--primary);
  color: #fff;
}

.flow-nav button:hover {
  transform: translateY(-1px);
}

body.view-pizza [data-model="strip"],
body.view-pizza [data-model="line"],
body.view-line [data-model="pizza"],
body.view-line [data-model="strip"] {
  display: none;
}

body.view-pizza .model-stage,
body.view-line .model-stage {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(430px, 1fr);
}

body.view-pizza .pizza-card,
body.view-line .numberline-card {
  grid-column: 1;
  grid-row: 1;
}

body.view-compare .pizza-card {
  grid-row: 1;
}

body.view-compare .strip-card {
  display: none;
}

body.view-compare .model-stage {
  grid-template-rows: minmax(260px, 1fr);
}

.hidden-step {
  opacity: 0.42;
}

@keyframes pulseCard {
  0% { transform: scale(1); }
  45% { transform: scale(1.02); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary), transparent 72%); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

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

  .right-rail {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

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

  .course-grid,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .stage {
    order: 1;
  }

  .left-rail {
    order: 2;
  }

  .right-rail {
    order: 3;
  }

  .stage-top,
  .flow-card,
  .model-stage {
    grid-template-columns: 1fr;
  }

  .model-stage {
    grid-template-rows: auto auto auto;
  }

  .pizza-card,
  .numberline-card,
  .strip-card {
    grid-column: 1;
    grid-row: auto;
    min-height: 270px;
  }

  .strip-card {
    min-height: 190px;
  }

  .prediction-options,
  .flow-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .flow-nav button:last-child {
    grid-column: 1 / -1;
  }

  .stage-top h2 {
    font-size: 20px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .left-rail,
  .stage,
  .flow-nav,
  .transfer-panel,
  .quiz-panel {
    display: none;
  }

  .app-shell,
  .course-grid,
  .right-rail {
    display: block;
    padding: 0;
  }

  .card-panel {
    box-shadow: none;
    border: 0;
  }
}
