/* 页面样式：开始页、三栏实验台、成绩单，以及窄屏和打印布局。 */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f2f5f2;
  color: #163c36;
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input {
  touch-action: manipulation;
}

button {
  cursor: pointer;
  border: 1px solid #b9cdc5;
  border-radius: 9px;
  padding: 10px 15px;
  background: #fff;
  color: #234e43;
}

button:hover {
  border-color: #137c63;
  background: #edf8ef;
}

button:disabled {
  opacity: .4;
  cursor: default;
}

.primary {
  background: #156f57;
  color: white;
  border: 0;
}

.danger {
  color: #a34b36;
}

header {
  background: #fff;
  border-bottom: 1px solid #d8e3dc;
  padding: 18px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.brand {
  text-decoration: none;
  color: #1b5547;
  font-weight: 750;
  font-size: 23px;
}

.brand small {
  font-weight: 400;
  font-size: 12px;
  margin-left: 18px;
  color: #778e83;
}

#top {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

main {
  max-width: 1600px;
  margin: auto;
}

/* 开始页与模式入口 */
.intro {
  max-width: 1000px;
  margin: 7vh auto;
  padding: 40px;
}

.eyebrow {
  color: #598370;
  letter-spacing: 3px;
  font-size: 12px;
}

.intro h1 {
  font-size: clamp(30px, 4.5vw, 56px);
  letter-spacing: -2px;
  line-height: 1.25;
  margin: 18px 0;
}

.intro p {
  color: #6b8176;
  max-width: 560px;
}

.intro-visual {
  float: right;
  width: 230px;
  max-width: 35%;
  margin: 10px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 35px 0;
}

.mode-card {
  padding: 25px;
  text-align: left;
  border-radius: 16px;
}

.mode-card b {
  display: block;
  font-size: 22px;
}

.mode-card span {
  display: block;
  margin-top: 8px;
  color: #6f8479;
  font-size: 14px;
}

#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #214f40;
  color: #fff;
  border-radius: 12px;
  padding: 15px 22px;
  max-width: 650px;
  width: max-content;
  z-index: 20;
  box-shadow: 0 8px 35px #173a3420;
  display: none;
  font-size: 14px;
}

#toast[data-type="error"] {
  background: #874634;
}

/* 成绩单 */
.report {
  max-width: 1050px;
  margin: 30px auto;
  padding: 25px;
}

.report-score {
  font-size: 58px;
  line-height: 1.2;
}

.report table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  background: white;
}

.report th,
.report td {
  text-align: left;
  padding: 14px;
  border-bottom: 1px solid #e2e8df;
  vertical-align: top;
}

.report th {
  background: #e5eee6;
}

.report-actions {
  display: flex;
  gap: 12px;
  margin: 22px 0;
}

/* 表单与键盘焦点 */
select {
  display: block;
  width: 100%;
  max-width: 100%;
  white-space: normal;
  border: 1px solid #b9cdc5;
  border-radius: 8px;
  background: white;
  padding: 8px;
  color: #254e42;
  font: inherit;
  font-size: 13px;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid #d8a958;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  header,
  .report-actions,
  #toast {
    display: none;
  }
  .report {
    margin: 0;
    max-width: none;
  }
  .report table {
    font-size: 11px;
  }
}

/* 仪器架、实验台和阶段目标 */
.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 255px) minmax(0, 1fr) minmax(220px, 275px);
  gap: 1px;
  background: #d8e3dc;
  min-height: calc(100vh - 80px);
}

.workspace > * { min-width: 0; }

.shelf,
.panel {
  padding: 20px 16px;
  background: #fff;
}

.shelf h3,
.panel h3 {
  margin: 0;
  color: #376052;
  font-size: 15px;
}

.shelf-help {
  margin: 5px 0 12px;
  color: #506f64;
  font-size: 12px;
}

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

.mobile-shelf { display: none; }

.bench {
  padding: 23px clamp(14px, 2vw, 34px);
  background: #f3f6f2;
}

.crumb,
.stage-head,
.bench-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.crumb,
.stage-head {
  font-size: 12px;
  color: #456f60;
}

.progress {
  height: 4px;
  background: #dce6df;
  margin: 11px 0 16px;
  border-radius: 4px;
  overflow: hidden;
}

.progress div {
  height: 100%;
  background: #368a71;
}

.bench h2 {
  margin: 0;
  font-size: clamp(19px, 2.1vw, 30px);
  line-height: 1.25;
}

#restart {
  font-size: 12px;
  padding: 5px 8px;
  flex: none;
}

.stage {
  --unit: clamp(76px, 13vw, 126px);
  margin: 14px 0 12px;
  background: #fbfdfb;
  border: 1px solid #cadbd2;
  border-radius: 14px;
}

.stage-head { padding: 10px 13px 0; }

.apparatus {
  position: relative;
  isolation: isolate;
  height: clamp(205px, 26vw, 325px);
  background:
    linear-gradient(to bottom, transparent 79%, #d5e2db 79%, #d5e2db 80%, #e7efe8 80%),
    radial-gradient(ellipse at 50% 75%, #edf5ed, #fbfdfb 72%);
}

.tray {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 5px;
  min-height: 52px;
  padding: 7px 10px;
  border-top: 1px solid #dde7df;
}

.instrument { position: relative; }

.instrument > button {
  position: relative;
  display: grid;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding: 3px 1px;
  touch-action: none;
  user-select: none;
  cursor: grab;
  -webkit-touch-callout: none;
}

.instrument > button:active { cursor: grabbing; }

.rack-tool > button,
.tray-tool > button {
  border-color: #dbe7df;
  background: #f5f9f6;
}

.tray-tool { width: 65px; }

.tool-visual {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 120 / 110;
  pointer-events: none;
}

.tool-visual img,
.tool-state {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.rack-tool .tool-visual,
.tray-tool .tool-visual { width: 36px; }

.tool-label {
  color: #295448;
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.apparatus-tool {
  position: absolute;
  width: var(--unit);
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
}

.apparatus-tool > button {
  padding: 0;
  border-color: transparent;
  background: transparent;
}

.apparatus-tool .tool-label {
  position: relative;
  display: block;
  margin-top: -8px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #f0f7f0;
  white-space: nowrap;
}

.heater-stack { top: calc(var(--y) - var(--unit) * .54); z-index: 2; }
.funnel-stack { top: calc(var(--y) - var(--unit) * .67); z-index: 2; }
.paper-stack { top: calc(var(--y) - var(--unit) * .25); z-index: 2; width: calc(var(--unit) * .62); }
.ice-stack { top: calc(var(--y) - var(--unit) * .20); z-index: 2; }
.flask-cover { top: calc(var(--y) - var(--unit) * .39); z-index: 3; width: calc(var(--unit) * .6); }
.ice-cover { top: calc(var(--y) - var(--unit) * .59); z-index: 3; width: calc(var(--unit) * .6); }

.ice-stack .tool-label {
  position: absolute;
  top: 53%;
  left: calc(100% - 22px);
}

.paper-stack .tool-label,
.flask-cover .tool-label,
.ice-cover .tool-label,
.funnel-stack .tool-label {
  position: absolute;
  top: 50%;
  left: 74%;
}

[data-instrument='pump'] .tool-visual { transform: scaleX(-1); }

.apparatus-tool:has([data-instrument='tube']) { width: 67px; z-index: 2; }
.apparatus-tool [data-instrument='tube'] { min-height: 38px; align-content: center; }
.apparatus-tool [data-instrument='tube'] .tool-visual { display: none; }
.apparatus-tool [data-instrument='tube'] .tool-label { margin: 0; }


.vacuum-line {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  width: calc(34% - var(--unit) * .73);
  height: 16%;
  left: calc(48% + var(--unit) * .32);
  top: 59%;
  fill: none;
  stroke: #52796f;
  stroke-width: 4;
}

.vacuum-line.backflow {
  stroke: #b96540;
  stroke-dasharray: 4 3;
  animation: backflow 0.6s linear infinite;
}

@keyframes backflow { to { stroke-dashoffset: -14; } }

.instrument.lit {
  z-index: 5;
}

.instrument.lit > button,
.instrument > button.drop-target,
.instrument > button.selected {
  border: 2px solid #228262;
  background: #e5f6e6;
  box-shadow: 0 0 0 2px #82c79788;
}

.instrument-tip {
  position: absolute;
  z-index: 7;
  display: block;
  bottom: calc(100% + 5px);
  left: 50%;
  width: max-content;
  max-width: min(190px, 41vw);
  transform: translateX(-50%);
  padding: 5px 8px;
  border-radius: 6px;
  color: white;
  background: #205c4a;
  font-size: 11px;
  pointer-events: none;
}

.rack-tool.lit:nth-child(3n+1) .instrument-tip {
  left: 0;
  transform: none;
}

.rack-tool.lit:nth-child(3n) .instrument-tip {
  right: 0;
  left: auto;
  transform: none;
}

.apparatus-tool.lit:has([data-instrument='pump']) .instrument-tip {
  left: auto;
  right: 0;
  transform: none;
}

.drag-image {
  position: fixed;
  z-index: 25;
  top: -32px;
  left: -32px;
  width: 64px;
  height: 64px;
  opacity: .85;
  pointer-events: none;
}

.instrument-menu {
  position: fixed;
  z-index: 12;
  width: min(260px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  overflow: auto;
  border-radius: 11px;
  border: 1px solid #97bcad;
  background: #fff;
  padding: 8px;
  box-shadow: 0 10px 28px #1a3d3428;
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  padding-left: 5px;
  font-size: 13px;
}

.menu-close { padding: 3px 10px; }

.instrument-menu [data-choice] {
  width: 100%;
  min-height: 40px;
  margin-top: 4px;
  padding: 6px 9px;
  text-align: left;
  font-size: 13px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.metric {
  background: white;
  border: 1px solid #dbe5dc;
  border-radius: 8px;
  padding: 7px;
  font-size: 12px;
  color: #506e62;
}

.metric b {
  display: block;
  font-size: clamp(13px, 1.4vw, 19px);
  font-weight: 650;
  color: #295c49;
}

.goal,
.status,
.operation-log { font-size: 14px; }

.teach {
  background: #eff7f0;
  border-radius: 8px;
  font-size: 13px;
  padding: 8px 10px;
}

summary { cursor: pointer; }

.next {
  width: 100%;
  margin: 7px 0 20px;
}

.primary:hover { background: #105c47; }

.operation-log {
  padding-inline-start: 20px;
  color: #426557;
}

.operation-log li + li { margin-top: 5px; }

.status { margin: 7px 0 0; color: #8a4d32; }
.status:empty { display: none; }

.bubble {
  fill: #fff;
  animation: bubble 1.2s infinite ease-out;
}

.crystals {
  fill: #fffdf1;
  stroke: #80a59f;
  stroke-width: 1.1;
}

@keyframes bubble {
  from { opacity: .9; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-40px); }
}

.splash .tool-state { animation: shake .18s 6; }

@keyframes shake {
  50% { transform: translateX(6px); }
}

#fold-dialog {
  width: min(760px, calc(100vw - 22px));
  max-height: calc(100dvh - 22px);
  padding: 12px;
  border: 1px solid #a2beae;
  border-radius: 12px;
}

#fold-dialog::backdrop { background: #142e26a8; }

.dialog-close { display: block; margin: 0 0 7px auto; }
.hint { font-size: 12px; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 195px minmax(0, 1fr) 210px; }
}

@media (max-width: 850px) {
  .workspace { grid-template-columns: 180px minmax(0, 1fr); }
  .shelf { grid-row: 1 / 3; }
  .panel { grid-column: 2; }
}

@media (max-width: 570px) {
  header { padding: 9px 12px; }
  .brand { font-size: 17px; }
  .brand small { display: none; }
  #top { font-size: 12px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .shelf,
  .panel { grid-column: 1; grid-row: auto; padding: 10px 12px; }
  .shelf h3 { display: none; }
  .mobile-shelf { display: flex; align-items: center; justify-content: space-between; }
  #shelf-toggle { padding: 4px 9px; }
  .shelf:not(.expanded) .instruments,
  .shelf:not(.expanded) .shelf-help { display: none; }
  .instruments { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .rack-tool.lit .instrument-tip { left: 0; right: auto; transform: none; }
  .rack-tool.lit:nth-child(6n) .instrument-tip,
  .rack-tool.lit:nth-child(6n - 1) .instrument-tip { right: 0; left: auto; }
  .rack-tool .tool-visual { width: 26px; }
  .rack-tool .tool-label { font-size: 10px; }
  .bench { padding: 10px 9px; }
  .stage { --unit: clamp(72px, 22vw, 104px); }
  .intro { padding: 17px; margin: 3vh auto; }
  .mode-grid { grid-template-columns: minmax(0, 1fr); }
  #toast { max-width: calc(100vw - 24px); }
  .report { padding: 12px; }
  .report table { font-size: 11px; }
  .report th,
  .report td { padding: 7px 4px; overflow-wrap: anywhere; }
}

/* 页脚备案号 */
.site-footer {
  padding: 12px 16px 20px;
  text-align: center;
  font-size: 12px;
}
.site-footer a {
  color: #7a8a80;
  text-decoration: none;
}
