:root {
  --bg: #eef1ed;
  --panel: #ffffff;
  --panel-strong: #f8faf7;
  --ink: #17211b;
  --muted: #667168;
  --line: #cfd7ce;
  --accent: #007f72;
  --accent-strong: #005f56;
  --warm: #c6532b;
  --gold: #b7851d;
  --soft: #e6f4f0;
  --shadow: 0 18px 46px rgba(21, 32, 25, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  line-height: 1.45;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(238, 241, 237, 0.86) 360px),
    var(--bg);
}

body.settings-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.ghost-button {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.ghost-button:hover {
  color: #fff;
  border-color: var(--accent);
}

.app-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 10px 0 48px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  min-height: 66px;
  margin-bottom: 8px;
  padding: 0 8px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(24px, 3.1vw, 42px);
  line-height: 1.12;
  letter-spacing: 0;
}

.eyebrow,
.small-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 270px;
  justify-content: flex-end;
  color: var(--muted);
}

.topbar-status strong {
  display: inline-grid;
  place-items: center;
  min-width: 58px;
  height: 34px;
  color: #fff;
  border-radius: 8px;
  background: var(--ink);
}

.lab-grid {
  --interaction-panel-height: 740px;
  display: grid;
  grid-template-columns: minmax(780px, 1fr) 420px;
  grid-template-rows: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  height: var(--interaction-panel-height);
  min-width: 1210px;
  min-height: var(--interaction-panel-height);
}

.panel {
  border: 1px solid rgba(118, 131, 121, 0.26);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scene-panel {
  display: flex;
  flex-direction: column;
  height: var(--interaction-panel-height);
  min-height: var(--interaction-panel-height);
  overflow: hidden;
}

.scene-toolbar,
.instrument-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel-strong);
}

.scene-toolbar {
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.scene-host {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  background:
    linear-gradient(180deg, #f6fbf8 0%, #e7eee8 68%, #d8ded7 100%);
  overflow: hidden;
}

.scene-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-readout {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(0, 127, 114, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 26px rgba(21, 32, 25, 0.12);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.scene-readout div {
  min-width: 0;
}

.scene-readout span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.scene-readout strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.1;
}

.scene-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.instrument-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}

.instrument-strip > div {
  min-width: 0;
}

.instrument-strip strong,
.scene-toolbar strong {
  display: block;
  margin-top: 2px;
}

.control-panel {
  --control-button-w: 184px;
  --control-button-h: 48px;
  --control-button-gap: 8px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  width: 420px;
  min-width: 420px;
  max-width: 420px;
  height: var(--interaction-panel-height);
  min-height: var(--interaction-panel-height);
  overflow: hidden;
}

.control-panel > .control-block {
  display: none;
}

.steps-panel {
  display: grid;
  min-height: 0;
  overflow: hidden;
}

.step-list {
  display: grid;
  gap: var(--control-button-gap);
  grid-template-columns: repeat(2, var(--control-button-w));
  grid-auto-rows: var(--control-button-h);
  align-content: start;
  justify-content: center;
  min-height: 0;
}

.step-list > button {
  display: grid;
  place-items: center;
  width: var(--control-button-w);
  height: var(--control-button-h);
  min-width: var(--control-button-w);
  min-height: var(--control-button-h);
  max-width: var(--control-button-w);
  max-height: var(--control-button-h);
  flex: 0 0 var(--control-button-w);
  padding: 0 14px;
  overflow: hidden;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: 0;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.step-list > .step-button {
  grid-column: 1 / -1;
  width: calc(var(--control-button-w) + var(--control-button-w) + var(--control-button-gap));
  min-width: calc(var(--control-button-w) + var(--control-button-w) + var(--control-button-gap));
  max-width: calc(var(--control-button-w) + var(--control-button-w) + var(--control-button-gap));
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.step-button:hover,
.step-button.is-active {
  color: var(--accent-strong);
  background: var(--soft);
  border-color: var(--accent);
}

.step-list > .action-button {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}

.step-list > .action-button:hover {
  background: var(--accent-strong);
}

.step-list > .action-button:disabled {
  color: #fff;
  background: #8dbdb5;
  opacity: 1;
}

.control-block {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.control-block h2,
.section-heading h2 {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(52px, auto);
  gap: 12px;
}

.button-grid button {
  min-height: 52px;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  visibility: hidden;
  opacity: 0;
  background: rgba(229, 236, 232, 0.46);
  backdrop-filter: blur(14px) saturate(1.08);
  transition: opacity 180ms ease, visibility 180ms ease;
}

body.settings-open .settings-backdrop {
  visibility: visible;
  opacity: 1;
}

.compact-controls {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

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

.compact-controls input,
.compact-controls select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  color: var(--ink);
  background: #fff;
}

.parameter-block {
  margin-top: 16px;
}

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

.scene-parameter-grid {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 10px;
  width: min(460px, 92vw);
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 12px 12px 0;
  background: rgba(248, 250, 247, 0.9);
  box-shadow: 18px 0 44px rgba(21, 32, 25, 0.18);
  overflow-y: auto;
  transform: translateX(-104%);
  transition: transform 220ms ease;
  backdrop-filter: blur(18px) saturate(1.08);
}

body.settings-open .scene-parameter-grid {
  transform: translateX(0);
}

.settings-drawer-header {
  position: sticky;
  top: -18px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -18px -18px 4px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(118, 131, 121, 0.24);
  background: rgba(248, 250, 247, 0.86);
  backdrop-filter: blur(14px);
}

.settings-drawer-header h2 {
  margin: 2px 0 0;
  font-size: 19px;
}

.scene-parameter-grid h2 {
  font-size: 15px;
}

.scene-parameter-grid .control-block {
  padding-top: 0;
  border-top: 0;
}

.scene-parameter-grid .compact-controls,
.scene-parameter-grid .parameter-block {
  margin-top: 0;
}

.scene-parameter-grid .parameter-list {
  grid-template-columns: 1fr;
}

.parameter-item,
.parameter-editor {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.parameter-item strong,
.parameter-editor h3 {
  display: block;
  margin: 0 0 6px;
  font-size: 13px;
}

.parameter-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.38;
}

.parameter-editor {
  display: grid;
  gap: 7px;
}

.parameter-editor label {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.parameter-editor input {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 7px;
  color: var(--ink);
  background: #fff;
}

.status-line {
  display: grid;
  gap: 10px;
  margin: 0;
  min-height: 60px;
  padding: 14px;
  color: var(--accent-strong);
  border: 1px solid #b9dfd7;
  border-radius: 8px;
  background: #f2fbf8;
}

.status-line p {
  margin: 0;
}

.parallel-x-control {
  display: grid;
  gap: 8px;
}

.parallel-x-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.parallel-x-header strong {
  color: var(--ink);
}

.parallel-x-control input[type="range"] {
  width: 100%;
  min-height: 24px;
  accent-color: var(--accent);
}

.formula-page,
.analysis-grid {
  display: grid;
  gap: 18px;
  margin-top: 10px;
}

.formula-page {
  align-content: start;
  padding: 24px 18px;
}

.formula-panel,
.results-panel {
  padding: 18px;
}

.formula-list {
  display: grid;
  gap: 10px;
}

.formula-support-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.formula-page .formula-list {
  display: contents;
}

.formula-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 116px;
  padding: 12px;
  background: #fff;
  overflow-x: auto;
}

.formula-item.is-active {
  border-color: var(--accent);
  background: var(--soft);
}

.formula-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.result-grid div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.result-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 17px;
  word-break: break-word;
}

.conclusion {
  min-height: 42px;
  margin: 12px 0 0;
  color: var(--ink);
}

.tables-band {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(420px, 1.05fr) minmax(360px, 0.95fr);
  gap: 10px;
  align-content: start;
  margin-top: 10px;
  padding: 18px 8px;
  border: 1px solid rgba(118, 131, 121, 0.26);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.record-sheet {
  width: 100%;
  margin: 0;
  padding: 8px 10px 10px;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  overflow-x: hidden;
}

.topbar,
.lab-grid,
.tables-band,
.analysis-grid {
  width: 100%;
}

.record-sheet h2 {
  margin: 0 0 4px;
  text-align: center;
  font-family: "SimSun", "Songti SC", "Times New Roman", serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.meta-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  margin: 0 auto 4px;
  min-width: 0;
  font-family: "SimSun", "Songti SC", "Times New Roman", serif;
  font-size: 13px;
}

.meta-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.meta-row input {
  min-width: 0;
  width: 100%;
  height: 18px;
  border: 0;
  border-bottom: 0;
  border-radius: 0;
  padding: 2px 4px;
  background: transparent;
}

.pdf-table {
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  border: 2px solid #111;
  border-collapse: collapse;
  table-layout: fixed;
  color: #111;
  font-family: "SimSun", "Songti SC", "Times New Roman", serif;
  font-size: 14px;
}

#objectTable {
  width: 100%;
}

#parallelTable {
  width: 100%;
}

.pdf-table th,
.pdf-table td {
  height: 32px;
  border: 1.5px solid #111;
  padding: 2px 4px;
  text-align: center;
  vertical-align: middle;
}

.pdf-table thead th {
  font-weight: 400;
  background: #fff;
}

.pdf-table tbody th {
  font-weight: 400;
  background: #fff;
}

.pdf-table input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 1px 2px;
  text-align: center;
  color: #111;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
}

.pdf-table input:focus,
.meta-row input:focus {
  outline: 2px solid rgba(0, 127, 114, 0.22);
  border-color: var(--accent);
  background: #f3fbf9;
}

.pdf-table output {
  display: inline-block;
  min-width: 54px;
  font-weight: 400;
}

.muted-cell {
  color: #777;
  background: #f7f7f7;
}

@media (max-width: 1080px) {
  .app-shell {
    width: 100%;
  }

  .lab-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .lab-grid {
    --interaction-panel-height: 740px;
    height: auto;
    min-width: 0;
    min-height: 0;
    grid-template-rows: auto;
  }

  .scene-panel,
  .control-panel {
    height: var(--interaction-panel-height);
    min-height: var(--interaction-panel-height);
  }

  .control-panel {
    justify-self: center;
    width: 420px;
    min-width: 420px;
    max-width: 420px;
    overflow: hidden;
  }

  .steps-panel {
    flex: none;
    display: block;
    min-height: 0;
    overflow: hidden;
  }

  .step-list {
    grid-template-rows: none;
  }

  .control-panel > .control-block {
    display: none;
  }

  .button-grid {
    grid-auto-rows: auto;
  }

  .button-grid button {
    min-height: 44px;
  }

  .status-line {
    margin-top: 0;
    min-height: 52px;
  }

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

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

  .tables-band {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: 100%;
    padding-top: 8px;
  }

  .lab-grid {
    --interaction-panel-height: 720px;
  }

  .topbar {
    display: grid;
    align-items: start;
    gap: 8px;
    padding: 0 10px;
    min-height: 0;
  }

  .topbar h1 {
    font-size: 25px;
    line-height: 1.1;
  }

  .topbar-status {
    justify-content: space-between;
    min-width: 0;
  }

  .steps-panel {
    padding: 0;
    overflow: hidden;
  }

  .control-panel {
    --control-button-h: 48px;
    --control-button-gap: 8px;
    justify-self: stretch;
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 10px 8px;
  }

  .step-list {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-rows: none;
    overflow-x: visible;
    padding-bottom: 0;
    scroll-snap-type: none;
  }

  .step-button,
  .step-list > .action-button {
    scroll-snap-align: none;
  }

  .step-list > button {
    width: 100%;
    min-width: 0;
    max-width: none;
    font-size: 15px;
    padding: 0 8px;
  }

  .step-list > .step-button {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .status-line {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.35;
  }

  .scene-toolbar,
  .instrument-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scene-toolbar {
    display: grid;
  }

  .toolbar-actions,
  .button-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    display: grid;
  }

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

  .scene-readout {
    top: 8px;
    left: 8px;
    grid-template-columns: repeat(2, minmax(74px, 1fr));
    padding: 8px;
  }

  .scene-readout strong {
    font-size: 15px;
  }

  .formula-support-grid {
    grid-template-columns: 1fr;
  }

  .scene-parameter-grid {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .scene-parameter-grid .parameter-list {
    grid-template-columns: 1fr;
  }

  .parameter-editor label {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .tables-band {
    display: grid;
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .record-sheet {
    padding: 10px;
    overflow-x: auto;
  }

  .record-sheet h2 {
    font-size: 14px;
    white-space: nowrap;
  }

  .meta-row {
    width: max-content;
    min-width: 520px;
    gap: 20px;
  }

  .pdf-table {
    font-size: 13px;
  }

  #objectTable {
    min-width: 520px;
  }

  #periodTable {
    min-width: 700px;
  }

  #parallelTable {
    min-width: 660px;
  }

  .formula-page,
  .results-panel {
    padding: 12px;
  }
}
