:root {
  --canvas: #111820;
  --paper: #1c252f;
  --white: #151d25;
  --ink: #eef1ef;
  --muted: #9aa6aa;
  --line: #34424d;
  --soft-line: #2a3640;
  --active: #263841;
  --accent: #49bd7d;
  --physics: #65a8d4;
  --chemistry: #dd8a70;
  --biology: #72bb8e;
  --earth: #d1aa5f;
  --display: "STKaiti", "KaiTi", "Songti SC", serif;
  --body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --utility: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { width: 100%; height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 var(--body);
}

button, a { font: inherit; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--physics);
  outline-offset: 2px;
}

.site-header {
  position: relative;
  z-index: 40;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  background: #141b22;
  border-bottom: 1px solid var(--line);
}

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

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .08em;
}

.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border: 1px solid #6f8998;
  border-radius: 50%;
  background: #1b252d;
}

.brand-mark::before,
.brand-mark::after,
.brand-mark > span {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #88a7b8;
}

.brand-mark::before { transform: translate(-6px, -7px); }
.brand-mark::after { transform: translate(6px, 4px); }
.brand-mark > span { transform: translate(0, 0); }

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: var(--muted);
  font: 10px var(--utility);
  letter-spacing: .08em;
}

.header-meta i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #647681;
}

.menu-button {
  display: none;
  width: 38px;
  height: 38px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1b242c;
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 16px;
  height: 1px;
  margin: 4px auto;
  background: var(--ink);
}

.app-shell {
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
}

.catalog {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.catalog-heading {
  flex: 0 0 auto;
  padding: 21px 16px 16px;
  border-bottom: 1px solid var(--soft-line);
}

.eyebrow {
  margin: 0 0 6px;
  color: #7d909a;
  font: 9px var(--utility);
  letter-spacing: .13em;
}

.catalog-heading h1 {
  margin: 0;
  font: 700 22px/1.25 var(--display);
  letter-spacing: .08em;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 17px;
  padding: 4px;
  border: 1px solid #3a4853;
  border-radius: 12px;
  background: #222c36;
}

.mode-button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #a8b2b6;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mode-button.active {
  background: var(--accent);
  color: #0c2819;
  box-shadow: 0 4px 14px rgba(73, 189, 125, .18);
}

.catalog-search {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #26313b;
  color: #a8b2b6;
  transition: border-color .16s ease, background-color .16s ease;
}

.catalog-search:focus-within {
  border-color: rgba(73, 189, 125, .6);
  background: #293640;
}

.catalog-search > span {
  position: relative;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.catalog-search > span::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 1.5px;
  right: -5px;
  bottom: -2px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(45deg);
}

.catalog-search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
}

.catalog-search input::placeholder { color: #89969c; }

.search-empty {
  margin: 20px 8px;
  padding: 18px 10px;
  border: 1px dashed #42515b;
  border-radius: 9px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.catalog-scroll {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px 12px 22px;
  scrollbar-color: #c5d0d5 transparent;
  scrollbar-width: thin;
}

.catalog-scroll::-webkit-scrollbar { width: 5px; }
.catalog-scroll::-webkit-scrollbar-thumb { background: #c5d0d5; border-radius: 10px; }

.subject-group { --subject-color: var(--physics); padding-top: 17px; }
.subject-chemistry { --subject-color: var(--chemistry); }
.subject-biology { --subject-color: var(--biology); }
.subject-earth { --subject-color: var(--earth); }

.subject-heading {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.subject-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dbe0df;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
}

.subject-title > i {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--subject-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--subject-color) 12%, transparent);
}

.subject-heading > small {
  color: #7f8e94;
  font: 9px var(--utility);
}

.subject-heading small b {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 5px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .16s ease;
}

.subject-heading:hover .subject-title { color: #fff; }
.subject-group.collapsed .subject-heading small b { transform: translateY(2px) rotate(-45deg); }
.subject-group.collapsed .experiment-list { display: none; }

.experiment-list { display: grid; gap: 2px; }

.experiment-button {
  --indicator-opacity: 0;
  position: relative;
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}

.experiment-button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2px;
  border-radius: 4px;
  background: var(--subject-color);
  opacity: var(--indicator-opacity);
}

.experiment-button > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.experiment-button > small {
  flex: 0 0 auto;
  color: #829096;
  font-size: 9px;
}

.experiment-button:hover { background: #242f38; }
.experiment-button.active {
  --indicator-opacity: 1;
  background: var(--active);
  color: #f5f7f5;
  font-weight: 700;
}
.experiment-button.active > small { color: var(--subject-color); }

.catalog-footer {
  flex: 0 0 auto;
  display: grid;
  gap: 5px;
  padding: 13px 20px 15px;
  color: #74848c;
  border-top: 1px solid var(--soft-line);
  font-size: 9px;
}

.catalog-footer a:hover { color: var(--ink); }

.teacher-catalog {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 21px 12px 24px;
  color: var(--muted);
}

.tool-list { display: grid; gap: 5px; padding-top: 13px; }

.tool-button {
  position: relative;
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease;
}

.tool-button:hover { background: #242f38; }
.tool-button.active {
  border-color: rgba(73, 189, 125, .28);
  background: rgba(73, 189, 125, .1);
}

.tool-mark {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(73, 189, 125, .42);
  border-radius: 11px;
  background: #1e342a;
}

.tool-mark i {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.tool-mark i:nth-child(1) { left: 7px; top: 8px; }
.tool-mark i:nth-child(2) { left: 15px; top: 5px; }
.tool-mark i:nth-child(3) { right: 6px; top: 9px; }
.tool-mark i:nth-child(4) { width: 14px; height: 12px; left: 10px; bottom: 6px; border-radius: 9px 9px 7px 7px; }

.tool-copy { min-width: 0; display: grid; gap: 3px; }
.tool-copy strong {
  overflow: hidden;
  color: #edf3ef;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.tool-copy small { color: #83918c; font-size: 9px; }
.tool-button.active .tool-copy small { color: #70c894; }
.tool-button > b { color: #6f8178; font-size: 15px; font-weight: 400; }
.tool-button.active > b { color: var(--accent); }

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr);
  padding: 10px 10px 10px 12px;
  background: #10171e;
}

.workspace-tools {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 5px;
  color: var(--muted);
}

.workspace-subject {
  padding-top: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
}

.open-separately {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px;
  color: #9da9ad;
  font-size: 10px;
  font-weight: 700;
}

.open-separately b { font-size: 14px; font-weight: 400; }
.open-separately:hover { color: var(--physics); }

.frame-wrap {
  grid-row: 2;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #34434d;
  border-radius: 10px;
  background: #121920;
  box-shadow: 0 14px 38px rgba(0, 0, 0, .22);
}

.lab-frame {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #121920;
  opacity: 1;
  transition: opacity .16s ease;
}

.workspace.loading .lab-frame,
.workspace.load-error .lab-frame { opacity: .18; }

.frame-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: #141c23;
  color: var(--muted);
  transition: opacity .16s ease, visibility .16s ease;
}

.frame-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.frame-loader p { margin: 0; font-size: 11px; }

.frame-loading-state,
.frame-error-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.frame-error-state {
  width: min(360px, calc(100vw - 48px));
  padding: 26px;
  border: 1px solid #34434d;
  border-radius: 12px;
  background: #19232b;
  box-shadow: 0 18px 42px rgba(0, 0, 0, .22);
}

.frame-error-state[hidden],
.frame-loading-state[hidden] { display: none; }

.frame-error-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #df9a58;
  border-radius: 50%;
  color: #f0ad67;
  font: 700 17px/1 Georgia, serif;
}

.frame-error-state strong {
  color: #f3f6f7;
  font: 700 17px/1.2 "STKaiti", "KaiTi", "Songti SC", serif;
  letter-spacing: .04em;
}

.frame-error-state p { color: #9da9ad; line-height: 1.7; }
.frame-error-state > div { display: flex; gap: 8px; }
.frame-error-state button,
.frame-error-state a {
  min-width: 90px;
  padding: 9px 14px;
  border: 1px solid #52636d;
  border-radius: 7px;
  background: #202d36;
  color: #dfe7ea;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.frame-error-state button {
  border-color: #418494;
  background: #1f6878;
}

.frame-error-state button:hover,
.frame-error-state a:hover { filter: brightness(1.12); }
.frame-error-state button:focus-visible,
.frame-error-state a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.loader-mark { display: flex; align-items: center; gap: 5px; height: 12px; }
.loader-mark i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: loader-pulse 1s ease-in-out infinite;
}
.loader-mark i:nth-child(2) { animation-delay: .12s; }
.loader-mark i:nth-child(3) { animation-delay: .24s; }

@keyframes loader-pulse {
  0%, 100% { transform: translateY(0); opacity: .45; }
  50% { transform: translateY(-4px); opacity: 1; }
}

.no-script {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  background: var(--white);
  text-align: center;
}
.no-script a { color: var(--physics); text-decoration: underline; }

.catalog-backdrop { display: none; }

@media (max-width: 860px) {
  .site-header { height: 58px; padding: 0 14px; justify-content: flex-start; gap: 10px; }
  .brand { gap: 9px; }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .brand strong { font-size: 14px; }
  .header-meta { display: none; }
  .menu-button { display: block; flex: 0 0 38px; }
  .app-shell { height: calc(100dvh - 58px); grid-template-columns: 1fr; }

  .catalog {
    position: fixed;
    z-index: 30;
    left: 0;
    top: 58px;
    bottom: 0;
    width: min(86vw, 330px);
    transform: translateX(-102%);
    box-shadow: 16px 0 40px rgba(24, 42, 54, .18);
    transition: transform .22s ease;
  }

  body.catalog-open .catalog { transform: translateX(0); }
  .catalog-backdrop {
    position: fixed;
    z-index: 20;
    inset: 58px 0 0;
    display: block;
    border: 0;
    background: rgba(15, 31, 43, .38);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .22s ease, visibility .22s ease;
  }
  body.catalog-open .catalog-backdrop { opacity: 1; visibility: visible; pointer-events: auto; }

  .workspace { padding: 0; grid-template-rows: 34px minmax(0, 1fr); }
  .workspace-tools { padding: 7px 12px 0; background: #151e26; }
  .frame-wrap { border: 0; border-top: 1px solid #34434d; border-radius: 0; box-shadow: none; }
}

@media (max-width: 480px) {
  .open-separately span { display: none; }
  .catalog-heading { padding-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .loader-mark i { animation: none; }
}
