:root {
  --bg-paper: #faf7f2;
  --bg-surface: #fffdf9;
  --bg-muted: #f2ece1;
  --bg-accent-soft: #fff2e6;
  --bg-ok-soft: #edf7f1;
  --bg-warn-soft: #fff8e6;
  --bg-err-soft: #fff1ec;

  --ink-primary: #1c2126;
  --ink-secondary: #495057;
  --ink-muted: #666e76;

  --copper: #c85a17;
  --copper-deep: #9e420b;
  --brass: #b8862d;
  --slate-blue: #2c5282;
  --ok-green: #236b48;
  --warn-amber: #9c6500;
  --err-rust: #a33319;

  --border-warm: #e2d9cb;
  --border-strong: #c8bca8;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  overflow-x: clip;
  background-color: var(--bg-paper);
  color: var(--ink-primary);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

a {
  color: var(--slate-blue);
}

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

.app-shell {
  max-width: 780px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

/* Masthead */
.masthead {
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink-primary);
  margin-bottom: 18px;
}

.masthead-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  text-decoration: none;
  font-weight: 600;
  color: var(--ink-primary);
}

.back-link:hover {
  border-color: var(--ink-primary);
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 4px 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
  font-weight: 600;
}

.nature-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 10px;
  background: var(--bg-accent-soft);
  border: 1px solid #e7b897;
  border-radius: 6px;
  color: var(--copper-deep);
  font-size: 0.94rem;
  font-weight: 700;
}

.problem-title {
  margin: 0;
  font-size: 1.48rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
}

.home-lead {
  margin: 10px 0 0;
  color: var(--ink-secondary);
}

/* Home grid */
.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 700px) {
  .home-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-warm);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(28, 33, 38, 0.04);
}

.home-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-meta-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.tag-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 0.88rem;
  font-weight: 700;
}

.tag-badge.is-selfmade {
  background: var(--bg-accent-soft);
  color: var(--copper-deep);
  border: 1px solid #e7b897;
}

.tag-badge.is-hebei {
  background: #edf3fa;
  color: var(--slate-blue);
  border: 1px solid #b9cde4;
}

.tag-badge.is-neutral {
  background: var(--bg-muted);
  color: var(--ink-secondary);
}

.home-card-title {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
}

.home-card-desc {
  margin: 0;
  color: var(--ink-secondary);
}

.home-meta-box {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  font-size: 0.94rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-progress-line {
  font-weight: 700;
  color: var(--ink-primary);
}

.home-cta {
  margin-top: auto;
  text-align: center;
  text-decoration: none;
}

.home-footer-actions {
  margin-top: 16px;
}

.footer-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Main problem stack */
.main-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.section-heading {
  margin: 0 0 10px;
  font-size: 1.12rem;
  color: var(--ink-primary);
}

/* Lab card & SVG stage */
.lab-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  border: 1.5px solid var(--ink-primary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-muted);
}

.view-tab {
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink-primary);
}

.view-tab.is-active {
  background: var(--ink-primary);
  color: #fffdf9;
}

.motion-btn {
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
}

.svg-stage {
  background: #f6f1e8;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-md);
  padding: 8px;
  overflow: hidden;
}

.lab-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* SVG styling */
.wire-live {
  fill: none;
  stroke: #c85a17;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wire-open {
  fill: none;
  stroke: #8e969e;
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.sch-wire-live {
  fill: none;
  stroke: #1c2126;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sch-wire-open {
  fill: none;
  stroke: #9aa2aa;
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.sch-open-dot {
  fill: #fffdf9;
  stroke: #7a828a;
  stroke-width: 2;
}

.svg-coil-label {
  font-size: 10.5px;
  font-weight: 700;
  fill: #1c2126;
}

.svg-term {
  font-size: 11px;
  font-weight: 700;
  fill: #2c5282;
}

.svg-micro-note {
  font-size: 9.8px;
  fill: #495057;
}

.svg-water-note {
  font-size: 9.5px;
  fill: #35586c;
  font-weight: 600;
}

.svg-badge-light {
  font-size: 12px;
  font-weight: 700;
  fill: #fffdf9;
}

.svg-badge-sub {
  font-size: 9.5px;
  fill: #e7dfd2;
}

.svg-plus,
.svg-minus {
  font-size: 13px;
  font-weight: 700;
  fill: #1c2126;
}

.sch-source-label {
  font-size: 11px;
  font-weight: 700;
  fill: #1c2126;
}

.sch-res-name {
  font-size: 11px;
  font-weight: 700;
  fill: #1c2126;
}

.sch-res-val {
  font-size: 10px;
  fill: #495057;
}

.sch-val-badge {
  font-size: 10.5px;
  font-weight: 700;
  fill: #c85a17;
}

.cell-num {
  font-size: 10.5px;
  font-weight: 700;
  fill: #fffdf9;
}

.cell-minus {
  font-size: 10px;
  font-weight: 700;
  fill: #e9e2d8;
}

@keyframes steamFloat {
  0% {
    transform: translateY(3px);
  }
  50% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(3px);
  }
}

.steam-wisp {
  animation: steamFloat 3.2s ease-in-out infinite;
}

.steam-wisp.is-static {
  animation: none;
}

.diagram-caption {
  margin: 10px 0 0;
  font-size: 0.94rem;
  color: var(--ink-secondary);
}

.thermal-disclaimer {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: var(--bg-muted);
  border-left: 3px solid var(--copper);
  border-radius: 4px;
  font-size: 0.94rem;
  color: var(--ink-secondary);
}

/* Controls */
.control-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-warm);
}

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

.control-title {
  font-weight: 700;
}

.control-state-pill {
  padding: 3px 10px;
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.94rem;
}

/* Tactile Rotary Switch */
.rotary-switch {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-muted);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
}

.rotary-switch .dial-station[data-mode="only_r1"] {
  grid-column: 1;
  grid-row: 1;
}

.rotary-switch .dial-station[data-mode="series"] {
  grid-column: 2;
  grid-row: 1;
}

.rotary-switch .dial-station[data-mode="parallel"] {
  grid-column: 3;
  grid-row: 1;
}

.rotary-switch .dial-center-wrap {
  grid-column: 1 / -1;
  grid-row: 2;
}

.dial-station {
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-weight: 700;
  cursor: pointer;
}

.dial-station.is-active {
  background: var(--ink-primary);
  color: #fffdf9;
  border-color: var(--ink-primary);
  box-shadow: 0 2px 0 var(--copper);
}

.dial-knob {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4d555e, #23282d);
  border: 3px solid #b8862d;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);
}

.dial-needle {
  position: absolute;
  left: 50%;
  top: 7px;
  width: 4px;
  height: 27px;
  margin-left: -2px;
  border-radius: 2px;
  background: #ff8c42;
  transform-origin: 2px 27px;
  transition: transform 0.2s ease;
}

.dial-cap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: #d4af37;
}

/* Flashlight controls */
.flashlight-control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.switch-toggle-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--ink-primary);
  font-weight: 700;
  cursor: pointer;
}

.switch-toggle-btn.is-closed {
  background: var(--ink-primary);
  color: #fffdf9;
}

.switch-toggle-btn.is-open {
  background: var(--bg-surface);
  color: var(--err-rust);
  border-color: var(--err-rust);
}

.slider-wrap {
  padding: 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}

.slider-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.rheostat-slider,
.sim-slider {
  width: 100%;
  min-height: 44px;
  accent-color: var(--copper);
  cursor: pointer;
}

.slider-marker-row {
  position: relative;
  height: 24px;
  margin-top: -4px;
}

.normal-tick {
  position: absolute;
  transform: translateX(-18%);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--copper-deep);
  white-space: normal;
  max-width: 9rem;
}

.slider-nudge-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.btn-nudge {
  min-height: 44px;
  padding: 8px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-weight: 600;
  cursor: pointer;
}

/* Exploration & Meters */
.exploration-region {
  margin-top: 14px;
}

.exploration-note {
  margin-bottom: 10px;
  font-size: 0.96rem;
  color: var(--ink-secondary);
}

.lock-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  border: 1.5px dashed var(--border-strong);
}

.scope-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scope-card,
.exploration-panel.is-unlocked {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #faf6ee;
  border: 1.5px solid #dec9ad;
}

.scope-title {
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--copper-deep);
}

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

.meter-cell {
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-sm);
}

.meter-label {
  display: block;
  font-size: 0.88rem;
  color: var(--ink-secondary);
}

.meter-value {
  font-size: 1.04rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.power-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.bar-label-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.94rem;
  font-weight: 600;
  margin-bottom: 3px;
}

.bar-track {
  height: 12px;
  background: #e6dfd2;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #df7a35, #c85a17);
}

.bar-fill.is-energy {
  background: linear-gradient(90deg, #2c5282, #c85a17);
}

.integral-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-warm);
}

.integral-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.95rem;
}

.integral-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
}

.integral-note,
.exploration-explain {
  margin: 6px 0 0;
  font-size: 0.94rem;
  color: var(--ink-secondary);
}

.energy-flow-bar {
  display: flex;
  min-height: 36px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  margin: 8px 0;
  font-size: 0.85rem;
  font-weight: 700;
}

.ef-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
}

.ef-bulb {
  background: #ffe094;
  color: #3a2700;
}

.ef-rheo {
  background: #f2b788;
  color: #4a2003;
}

.ef-int {
  background: #d9dfe6;
  color: #1c2126;
}

/* Givens & Stem */
.givens-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

@media (min-width: 520px) {
  .givens-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.given-chip {
  padding: 8px 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-sm);
}

.given-key {
  display: block;
  font-size: 0.88rem;
  color: var(--ink-secondary);
}

.given-val {
  font-size: 1rem;
}

.stem-details {
  border-top: 1px solid var(--border-warm);
  padding-top: 10px;
}

.stem-summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 700;
  cursor: pointer;
}

.stem-body {
  margin: 6px 0 8px;
}

.stem-subquestions {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Step Cards */
.steps-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.steps-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-card {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.step-card.is-locked {
  background: var(--bg-muted);
  border-style: dashed;
}

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

.step-header h3 {
  margin: 0;
  font-size: 1.12rem;
}

.step-status-badge {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

.step-status-badge.is-pending {
  background: var(--bg-muted);
  color: var(--ink-primary);
}

.step-status-badge.is-ok {
  background: var(--bg-ok-soft);
  color: var(--ok-green);
}

.step-status-badge.is-warn {
  background: var(--bg-warn-soft);
  color: var(--warn-amber);
}

.step-status-badge.is-err {
  background: var(--bg-err-soft);
  color: var(--err-rust);
}

.step-status-badge.is-locked {
  background: #e6dfd2;
  color: var(--ink-secondary);
}

.step-prompt {
  margin: 0 0 12px;
}

.step-lock-notice,
.hints-locked-note {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-warm);
  color: var(--ink-secondary);
  font-size: 0.95rem;
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

@media (min-width: 520px) {
  .fields-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.field-group,
.formula-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.formula-group {
  margin-bottom: 14px;
}

.field-label {
  font-size: 0.95rem;
  font-weight: 700;
}

.field-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: 100%;
}

.field-row .answer-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.field-unit {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  font-weight: 700;
}

.page-footer a,
.source-link-line,
.source-link-line a {
  overflow-wrap: anywhere;
}

.answer-input,
.formula-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--ink-primary);
}

.answer-input:focus,
.formula-input:focus {
  outline: 2px solid var(--slate-blue);
  outline-offset: 1px;
  border-color: var(--slate-blue);
}

/* Action Buttons (>= 44px touch targets, clear non-disabled Reset contrast!) */
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 18px;
  border: 1.5px solid var(--ink-primary);
  border-radius: var(--radius-sm);
  background: var(--ink-primary);
  color: #fffdf9;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:hover {
  background: #2f373f;
}

.btn-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border: 1.5px solid var(--copper);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--copper-deep);
  font-weight: 700;
  cursor: pointer;
}

.btn-reset:hover {
  background: var(--bg-accent-soft);
}

.btn-secondary-sm,
.btn-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--slate-blue);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--slate-blue);
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary-sm:hover,
.btn-hint:hover {
  background: #edf3fa;
}

/* Feedback & Hints */
.feedback-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid;
}

.feedback-box.is-success {
  background: var(--bg-ok-soft);
  border-color: #93c4a9;
}

.feedback-box.is-warn {
  background: var(--bg-warn-soft);
  border-color: #dec079;
}

.feedback-box.is-error {
  background: var(--bg-err-soft);
  border-color: #e4a896;
}

.feedback-headline {
  font-weight: 700;
  margin-bottom: 6px;
}

.feedback-list,
.diag-list {
  margin: 6px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.diag-item {
  color: var(--err-rust);
  font-weight: 600;
}

.hints-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hints-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hints-title {
  font-weight: 700;
}

.hint-done-note {
  font-size: 0.92rem;
  color: var(--ok-green);
  font-weight: 600;
}

.hint-item {
  padding: 10px 12px;
  background: var(--bg-surface);
  border-left: 3px solid var(--slate-blue);
  border-radius: 6px;
}

/* Footer */
.page-footer {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1.5px solid var(--border-warm);
  font-size: 0.94rem;
  color: var(--ink-secondary);
}

.page-footer p {
  margin: 0 0 8px;
}

.local-note {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  .steam-wisp {
    animation: none;
  }
  .dial-needle {
    transition: none;
  }
}
