.lab-page {
  --lab-bg: #06191b;
  --lab-panel: #0a2527;
  --lab-panel-2: #103335;
  --lab-line: rgba(231, 249, 242, .13);
  --lab-muted: rgba(236, 249, 244, .62);
  --lab-accent: #76dfd1;
  --lab-warn: #ffcc72;
  margin: 0;
  color: #f1faf6;
  background: var(--lab-bg);
}
.lab-page * { box-sizing: border-box; }
.lab-page button, .lab-page input { font: inherit; }
.lab-main { min-height: 100dvh; }
.skip-link { position: fixed; z-index: 100; top: -70px; left: 12px; padding: 12px 16px; color: #052124; background: var(--lab-accent); }
.skip-link:focus { top: 8px; }
.sr-only { position: absolute; overflow: hidden; width: 1px; height: 1px; padding: 0; margin: -1px; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.lab-appbar {
  position: sticky; z-index: 40; top: 0; display: grid; height: 64px; padding: 0 18px;
  align-items: center; grid-template-columns: 44px 1fr auto; gap: 10px;
  border-bottom: 1px solid var(--lab-line); background: rgba(5, 26, 28, .94); backdrop-filter: blur(14px);
}
.lab-appbar > div { display: grid; gap: 2px; }
.lab-appbar strong { font-size: .98rem; }
.lab-appbar span { color: var(--lab-muted); font-size: .69rem; }
.lab-back, .icon-button {
  display: grid; min-width: 44px; min-height: 44px; place-items: center; border: 1px solid var(--lab-line);
  border-radius: 4px; color: #f4fcf8; background: transparent; text-decoration: none; cursor: pointer;
}
.lab-back { font-size: 1.65rem; line-height: 1; }
.icon-button { padding: 0 12px; font-size: .78rem; }

.lab-shell { min-height: calc(100dvh - 64px); padding: 0; }
.mode-switch {
  position: sticky; z-index: 35; top: 64px; display: grid; height: 62px; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--lab-line); background: #0a2426;
}
.mode-switch button {
  min-width: 0; border: 0; border-right: 1px solid var(--lab-line); color: var(--lab-muted);
  background: transparent; cursor: pointer; font-size: .86rem; font-weight: 730;
}
.mode-switch button:last-child { border-right: 0; }
.mode-switch button span { margin-right: 8px; color: var(--lab-accent); font: .66rem "Space Mono", monospace; }
.mode-switch button[aria-selected="true"] { color: #fff; background: rgba(118,223,209,.07); box-shadow: inset 0 -3px var(--lab-accent); }

.lab-workspace { display: grid; min-height: calc(100dvh - 126px); grid-template-columns: minmax(0, 1fr) 400px; }
.table-pane {
  position: sticky; top: 126px; display: grid; align-content: center; min-width: 0; height: calc(100dvh - 126px);
  padding: 52px 28px 90px; background:
    radial-gradient(circle at 50% 42%, rgba(38, 106, 94, .16), transparent 42%),
    #051719;
}
#routeCanvas { display: block; width: min(100%, 1080px); max-height: 70dvh; margin: auto; aspect-ratio: 2.03 / 1; touch-action: none; user-select: none; }
.table-tools {
  position: absolute; z-index: 3; top: 14px; left: 50%; display: flex; max-width: calc(100% - 24px);
  transform: translateX(-50%); border: 1px solid var(--lab-line); border-radius: 5px; background: rgba(7, 33, 35, .93);
}
.table-tools button {
  min-width: 62px; min-height: 44px; padding: 0 12px; border: 0; border-right: 1px solid var(--lab-line);
  color: var(--lab-muted); background: transparent; cursor: pointer; font-size: .76rem;
}
.table-tools button:last-child { border-right: 0; }
.table-tools button[aria-pressed="true"] { color: #052326; background: var(--lab-accent); }
.table-tools button:disabled { opacity: .28; cursor: not-allowed; }
.stage-hint {
  position: absolute; z-index: 2; bottom: 58px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  padding: 7px 11px; border: 1px solid var(--lab-line); border-radius: 99px; color: var(--lab-muted);
  background: rgba(5, 25, 27, .83); font-size: .7rem; pointer-events: none;
}
.playback-float {
  position: absolute; z-index: 3; right: 18px; bottom: 13px; left: 18px; display: grid; height: 38px;
  align-items: center; grid-template-columns: 58px 48px 1fr 48px; gap: 9px; color: var(--lab-muted);
  font: .67rem "Space Mono", monospace;
}
.playback-float button { height: 36px; border: 1px solid var(--lab-line); color: #fff; background: rgba(9,39,41,.95); cursor: pointer; }
.playback-float button:disabled { opacity: .35; }
.playback-float input { width: 100%; accent-color: var(--lab-accent); }
.solve-overlay {
  position: absolute; z-index: 20; inset: 0; display: grid; align-content: center; padding: 24px;
  background: rgba(3, 20, 22, .89); backdrop-filter: blur(4px);
}
.solve-overlay[hidden] { display: none; }
.solve-overlay > * { width: min(500px, 90%); margin-right: auto; margin-left: auto; }
.solve-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; }
.solve-heading strong { font-size: 1.05rem; }
.solve-heading button { min-width: 64px; min-height: 40px; border: 1px solid var(--lab-line); color: #fff; background: transparent; cursor: pointer; }
.solve-overlay progress { height: 8px; border: 0; accent-color: var(--lab-accent); }
.solve-overlay > span { margin-top: 12px; color: var(--lab-muted); font-size: .76rem; }

.lab-sheet {
  position: relative; z-index: 10; display: grid; min-width: 0; height: calc(100dvh - 126px);
  grid-template-rows: auto auto 1fr; border-left: 1px solid var(--lab-line); background: var(--lab-panel);
}
.sheet-handle { display: none; }
.sheet-summary { display: grid; align-items: center; grid-template-columns: 1fr auto; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--lab-line); }
.sheet-summary > div { display: grid; min-width: 0; padding-left: 18px; gap: 3px; position: relative; }
.status-dot { position: absolute; top: 5px; left: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--lab-accent); box-shadow: 0 0 0 5px rgba(118,223,209,.1); }
.sheet-summary strong { font-size: .87rem; }
.sheet-summary small { overflow: hidden; color: var(--lab-muted); font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.primary-action {
  min-height: 44px; padding: 0 17px; border: 1px solid var(--lab-accent); color: #062326;
  background: var(--lab-accent); cursor: pointer; font-weight: 780;
}
.panel-tabs { display: grid; height: 48px; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--lab-line); }
.panel-tabs button { border: 0; color: var(--lab-muted); background: transparent; cursor: pointer; font-size: .76rem; }
.panel-tabs button[aria-selected="true"] { color: #fff; box-shadow: inset 0 -2px var(--lab-accent); }
.panel-tabs span { display: inline-grid; min-width: 18px; height: 18px; margin-left: 3px; place-items: center; border-radius: 10px; background: rgba(255,255,255,.08); font-size: .61rem; }
.sheet-scroll { overflow: auto; min-height: 0; overscroll-behavior: contain; }
.control-panel[hidden] { display: none; }
.panel-section { padding: 20px 18px; border-bottom: 1px solid var(--lab-line); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.section-heading > div { display: grid; gap: 3px; }
.section-heading span, .manual-header span { color: var(--lab-muted); font-size: .67rem; }
.section-heading strong, .manual-header strong { font-size: .87rem; }
.section-heading output { color: var(--lab-muted); font: .66rem "Space Mono", monospace; }
.role-grid, .pocket-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.role-grid button, .pocket-grid button, .segmented button, .nudge-grid button, .manual-actions button, .preset-grid button {
  min-height: 44px; padding: 5px 7px; border: 1px solid var(--lab-line); color: var(--lab-muted); background: transparent; cursor: pointer; font-size: .72rem;
}
.role-grid button[aria-pressed="true"], .pocket-grid button[aria-pressed="true"], .segmented button[aria-pressed="true"], .preset-grid button[aria-pressed="true"] {
  border-color: var(--lab-accent); color: #fff; background: rgba(118,223,209,.10);
}
.nudge-grid { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; margin-top: 10px; }
.nudge-grid button { padding: 0; }
.pocket-grid { grid-template-columns: repeat(3, 1fr); }
.inline-check { display: flex; align-items: center; gap: 6px; color: var(--lab-muted); font-size: .68rem; }
.inline-check input { width: 18px; height: 18px; accent-color: var(--lab-accent); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 12px; }
.segmented button + button { border-left: 0; }
.leave-controls label, .power-control { display: grid; grid-template-columns: 1fr auto; gap: 8px; color: var(--lab-muted); font-size: .72rem; }
.leave-controls input, .power-control input { width: 100%; grid-column: 1 / 3; accent-color: var(--lab-accent); }
.text-action { min-height: 36px; border: 0; color: var(--lab-accent); background: transparent; cursor: pointer; font-size: .7rem; }
.validation-message { margin: 16px; padding: 12px; border: 1px solid rgba(255,184,111,.35); color: #ffd7a3; background: rgba(140,70,24,.14); font-size: .73rem; line-height: 1.55; }
.validation-message[hidden] { display: none; }

.empty-state { padding: 54px 28px; text-align: center; }
.empty-state p { margin: 10px 0 0; color: var(--lab-muted); font-size: .75rem; line-height: 1.6; }
.solution-picker { display: flex; overflow-x: auto; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--lab-line); scrollbar-width: none; }
.solution-picker .empty-state { min-width: 100%; }
.solution-chip { flex: 0 0 148px; min-height: 76px; padding: 10px; border: 1px solid var(--lab-line); color: var(--lab-muted); background: transparent; text-align: left; cursor: pointer; }
.solution-chip strong, .solution-chip small { display: block; }
.solution-chip strong { margin-bottom: 6px; color: #fff; font-size: .76rem; }
.solution-chip small { font-size: .64rem; line-height: 1.45; }
.solution-chip[aria-pressed="true"] { border-color: var(--lab-accent); background: rgba(118,223,209,.09); }
.solution-detail { padding: 18px; }
.solution-detail[hidden] { display: none; }
.solution-detail header { display: flex; justify-content: space-between; gap: 12px; }
.solution-detail header span { color: var(--lab-accent); font-size: .66rem; }
.solution-detail h2 { margin: 5px 0 0; font-size: 1.2rem; }
.solution-detail header > strong { color: var(--lab-accent); font-size: .63rem; white-space: nowrap; }
.metric-grid { display: grid; margin: 18px 0; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--lab-line); }
.metric-grid div { padding: 12px; border-right: 1px solid var(--lab-line); border-bottom: 1px solid var(--lab-line); }
.metric-grid div:nth-child(2n) { border-right: 0; }
.metric-grid div:nth-last-child(-n+2) { border-bottom: 0; }
.metric-grid dt { color: var(--lab-muted); font-size: .63rem; }
.metric-grid dd { margin: 6px 0 0; font-size: .8rem; font-weight: 760; }
.warning-list { display: grid; gap: 7px; }
.warning-list p { margin: 0; padding: 9px 11px; border-left: 2px solid var(--lab-warn); color: #ffe1ab; background: rgba(255,204,114,.07); font-size: .69rem; }

.manual-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 18px; border-bottom: 1px solid var(--lab-line); }
.manual-header > div { display: grid; gap: 4px; }
.switch { display: flex; align-items: center; gap: 7px; color: var(--lab-muted); font-size: .66rem; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: relative; width: 35px; height: 20px; border-radius: 11px; background: rgba(255,255,255,.15); }
.switch span::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; content: ""; transition: transform .16s; }
.switch input:checked + span { background: var(--lab-accent); }
.switch input:checked + span::after { transform: translateX(15px); }
.cue-editor { display: grid; grid-template-columns: 132px 1fr; gap: 20px; padding: 20px 18px; }
.strike-pad {
  position: relative; width: 116px; aspect-ratio: 1; border: 5px solid #e5e5dc; border-radius: 50%;
  background: radial-gradient(circle at 38% 33%, #fff, #d9d8cc 74%); box-shadow: inset -8px -10px 18px rgba(0,0,0,.16); touch-action: none;
}
.strike-pad::before, .strike-pad::after { position: absolute; background: rgba(12,41,43,.21); content: ""; }
.strike-pad::before { top: 50%; left: 10%; width: 80%; height: 1px; }
.strike-pad::after { top: 10%; left: 50%; width: 1px; height: 80%; }
.strike-pad span { position: absolute; z-index: 2; width: 14px; height: 14px; border: 3px solid #fff; border-radius: 50%; background: #e3543f; box-shadow: 0 2px 7px rgba(0,0,0,.35); transform: translate(-50%, -50%); }
.cue-editor output { display: block; width: 116px; margin-top: 8px; color: var(--lab-muted); font: .65rem "Space Mono", monospace; text-align: center; }
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.preset-grid button { min-width: 0; }
.power-control { margin: 0 18px 18px; }
.manual-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 18px; }
.manual-feedback { margin: 15px 18px 22px; color: var(--lab-muted); font-size: .7rem; line-height: 1.55; }

.settings-dialog { width: min(560px, calc(100% - 24px)); padding: 0; border: 1px solid var(--lab-line); color: #f3fbf7; background: #0b292b; }
.settings-dialog::backdrop { background: rgba(0, 8, 9, .72); backdrop-filter: blur(3px); }
.settings-dialog header { display: flex; justify-content: space-between; gap: 20px; padding: 22px; border-bottom: 1px solid var(--lab-line); }
.settings-dialog header span { color: var(--lab-accent); font-size: .68rem; }
.settings-dialog h2 { margin: 5px 0 0; font-size: 1.3rem; }
.settings-dialog header button { width: 44px; height: 44px; border: 1px solid var(--lab-line); color: #fff; background: transparent; font-size: 1.4rem; }
.setting-row { display: grid; align-items: center; grid-template-columns: 1fr auto; gap: 8px 14px; padding: 17px 22px; border-bottom: 1px solid var(--lab-line); }
.setting-row > span { display: grid; gap: 4px; }
.setting-row strong { font-size: .82rem; }
.setting-row small, .settings-dialog form > p { color: var(--lab-muted); font-size: .68rem; line-height: 1.5; }
.setting-row input[type="range"] { width: 100%; grid-column: 1 / 3; accent-color: var(--lab-accent); }
.setting-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--lab-accent); }
.setting-row output { color: var(--lab-accent); font: .72rem "Space Mono", monospace; }
.settings-dialog form > p { margin: 0; padding: 17px 22px; }

.lab-about {
  display: grid; padding-top: 100px; padding-bottom: 100px; grid-template-columns: .85fr 1.15fr; gap: clamp(45px, 8vw, 110px);
  color: #112d2c; background: #f4f2eb;
}
.lab-about::before { position: absolute; z-index: -1; right: 0; left: 0; height: 100%; background: #f4f2eb; content: ""; }
.lab-about h2 { margin: 0; font-size: clamp(2.2rem, 5vw, 4.8rem); line-height: .99; letter-spacing: -.055em; }
.lab-about > div:last-child > p { margin: 0; color: #586a68; line-height: 1.8; }
.lab-about dl { display: grid; margin: 30px 0 0; grid-template-columns: repeat(2, 1fr); border: 1px solid #cad1cd; }
.lab-about dl div { padding: 17px; border-right: 1px solid #cad1cd; border-bottom: 1px solid #cad1cd; }
.lab-about dl div:nth-child(2n) { border-right: 0; }
.lab-about dl div:nth-last-child(-n+2) { border-bottom: 0; }
.lab-about dt { color: #71807e; font-size: .7rem; }
.lab-about dd { margin: 5px 0 0; font-weight: 780; }

button:focus-visible, input:focus-visible, [tabindex]:focus-visible, a:focus-visible { outline: 3px solid rgba(118,223,209,.5); outline-offset: 3px; }

/* 课程页通过同源 iframe 复用完整实验室。嵌入态只改变外壳，不复制渲染或求解逻辑。 */
.lab-page.lab-embedded { overflow: hidden; }
.lab-embedded .skip-link,
.lab-embedded .lab-appbar,
.lab-embedded .mode-switch,
.lab-embedded .lab-about { display: none; }
.lab-embedded .lab-shell,
.lab-embedded .lab-workspace { min-height: 700px; }
.lab-embedded .lab-workspace { grid-template-columns: minmax(0, 1fr) 390px; }
.lab-embedded .table-pane {
  position: relative; top: auto; height: 700px; padding-top: 58px;
}
.lab-embedded .lab-sheet { height: 700px; }
.lab-embedded .sheet-handle { display: none; }

@media (max-width: 980px) and (orientation: portrait) {
  body.lab-page { overflow-x: hidden; padding-bottom: calc(116px + env(safe-area-inset-bottom)); }
  .lab-appbar { height: 56px; padding-top: env(safe-area-inset-top); }
  .lab-shell { min-height: calc(100dvh - 56px); }
  .mode-switch { top: 56px; height: 52px; }
  .mode-switch button { font-size: .76rem; }
  .mode-switch button span { display: none; }
  .lab-workspace { display: block; min-height: calc(100dvh - 108px); }
  .table-pane { position: relative; top: auto; align-content: start; height: calc(100dvh - 108px); min-height: 500px; padding: 58px 12px 86px; }
  #routeCanvas { width: auto; height: min(62dvh, calc(100dvh - 300px), 650px); max-width: 94vw; max-height: none; aspect-ratio: 1 / 2.03; }
  .table-tools { top: 8px; width: calc(100% - 16px); justify-content: center; }
  .table-tools button { min-width: 0; flex: 1; padding: 0 7px; }
  .stage-hint { bottom: 54px; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
  .playback-float { right: 10px; bottom: 7px; left: 10px; grid-template-columns: 54px 1fr 39px; }
  .playback-float [data-current-time] { display: none; }
  .solve-overlay { position: fixed; top: 108px; bottom: 0; }
  .lab-sheet {
    position: fixed; z-index: 50; right: 0; bottom: 0; left: 0; display: grid; height: calc(52dvh + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); grid-template-rows: 24px auto auto 1fr; border-top: 1px solid var(--lab-line); border-left: 0;
    border-radius: 16px 16px 0 0; box-shadow: 0 -18px 55px rgba(0,0,0,.36); transition: height .23s ease;
  }
  .lab-sheet[data-sheet-state="collapsed"] { height: calc(116px + env(safe-area-inset-bottom)); }
  .lab-sheet[data-sheet-state="full"] { height: calc(100dvh - 56px); }
  .sheet-handle { display: grid; height: 24px; padding: 0; place-items: center; border: 0; background: transparent; cursor: ns-resize; touch-action: none; }
  .sheet-handle span { width: 42px; height: 4px; border-radius: 3px; background: rgba(255,255,255,.27); }
  .sheet-summary { padding: 8px 14px 10px; }
  .panel-tabs { height: 44px; }
  .lab-sheet[data-sheet-state="collapsed"] .panel-tabs, .lab-sheet[data-sheet-state="collapsed"] .sheet-scroll { visibility: hidden; }
  .sheet-scroll { padding-bottom: 12px; }
  .cue-editor { grid-template-columns: 122px 1fr; gap: 12px; }
  .strike-pad { width: 108px; }
  .cue-editor output { width: 108px; }
  .lab-about { grid-template-columns: 1fr; gap: 34px; padding-top: 78px; padding-bottom: 78px; }
}

@media (max-width: 720px) {
  .lab-appbar > div span { display: none; }
  .sheet-summary small { max-width: 48vw; }
  .role-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 980px) {
  body.lab-page.lab-embedded { overflow: hidden; padding-bottom: 0; }
  .lab-embedded .lab-shell,
  .lab-embedded .lab-workspace { min-height: 0; }
  .lab-embedded .lab-workspace { display: block; }
  .lab-embedded .table-pane {
    position: relative; top: auto; height: clamp(700px, 205vw, 770px); min-height: clamp(700px, 205vw, 770px);
    padding: 18px 12px 72px;
  }
  .lab-embedded #routeCanvas {
    width: min(100%, 350px); height: auto; max-width: 100%; max-height: none; aspect-ratio: 1 / 2.03;
  }
  .lab-embedded .table-tools { right: 12px; left: auto; width: auto; transform: none; }
  .lab-embedded .table-tools button { display: none; }
  .lab-embedded .table-tools [data-action="reset"] { display: block; min-width: 58px; border: 0; }
  .lab-embedded .stage-hint { bottom: 54px; }
  .lab-embedded .playback-float { bottom: 4px; height: 44px; }
  .lab-embedded .playback-float button { height: 44px; }
  .lab-embedded .lab-sheet {
    position: relative; inset: auto; display: grid; height: auto; min-height: 420px; padding-bottom: 0;
    grid-template-rows: auto auto 1fr; border-top: 1px solid var(--lab-line); border-left: 0;
    border-radius: 0; box-shadow: none;
  }
  .lab-embedded .lab-sheet[data-sheet-state] { height: auto; }
  .lab-embedded .lab-sheet[data-sheet-state] .panel-tabs,
  .lab-embedded .lab-sheet[data-sheet-state] .sheet-scroll { visibility: visible; }
  .lab-embedded .sheet-handle { display: none; }
  .lab-embedded .sheet-summary { min-height: 54px; padding: 7px 14px 8px; }
  .lab-embedded .sheet-summary .primary-action { display: none; }
  .lab-embedded .panel-tabs { height: 48px; }
  .lab-embedded .manual-header { min-height: 54px; padding: 12px 14px; }
  .lab-embedded .manual-header .switch { display: none; }
  .lab-embedded .cue-editor { grid-template-columns: 98px minmax(0, 1fr); gap: 14px; padding: 14px; }
  .lab-embedded .strike-pad { width: 92px; }
  .lab-embedded .cue-editor output { width: 92px; }
  .lab-embedded .preset-grid { gap: 5px; }
  .lab-embedded .preset-grid button { min-height: 44px; padding: 3px; }
  .lab-embedded .power-control { margin: 0 14px 14px; }
  .lab-embedded .manual-actions { gap: 7px; padding: 0 14px; }
  .lab-embedded .manual-feedback { margin: 12px 14px 17px; }
}

@media (max-height: 600px) and (orientation: landscape), (max-width: 980px) and (orientation: landscape) {
  .lab-appbar { height: 50px; }
  .mode-switch { top: 50px; height: 46px; }
  .lab-workspace { min-height: calc(100dvh - 96px); grid-template-columns: minmax(0, 1fr) minmax(310px, 38vw); }
  .table-pane { top: 96px; height: calc(100dvh - 96px); padding: 48px 18px 54px; }
  .lab-sheet { height: calc(100dvh - 96px); }
  .lab-about { display: none; }
}

@media (max-width: 980px) and (orientation: landscape) {
  .lab-embedded .lab-workspace { display: block; min-height: 0; }
  .lab-embedded .table-pane { height: clamp(700px, 205vw, 770px); }
  .lab-embedded .lab-sheet { height: auto; min-height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  .lab-sheet, .switch span::after { transition: none; }
}
