/* 数学实验室的 body 已有 math-demo-detail-page；不要依赖 :has()，
   否则旧教室浏览器会露出全站页脚和通用弹窗。 */
body.math-demo-detail-page,
body.math-demo-detail-page .main {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fff;
}

body.math-demo-detail-page .page-gradient,
body.math-demo-detail-page .footer,
body.math-demo-detail-page .mz-footer,
body.math-demo-detail-page .mz-modal {
  display: none;
}

.math-demo-detail-page.main-wrapper {
  position: fixed;
  inset: 0 0 0 52px;
  z-index: 2;
  width: auto;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 12px;
  overflow: hidden;
  background: #fff;
}

.sidebar:hover ~ .math-demo-detail-page.main-wrapper {
  margin: 0;
}

.math-demo-detail-page .content-container {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.math-demo-detail-page .math-demo-mobile-detail-heading {
  display: none;
}

.math-demo-detail-page .math-demo-workbench {
  display: grid;
  grid-template-columns: clamp(250px, 19vw, 320px) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #dce7f4;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 36px rgba(38, 79, 129, .09);
}

.math-demo-detail-page .math-demo-directory {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 20px 15px;
  border-right: 1px solid #dce7f4;
  background: linear-gradient(180deg, #f7faff 0%, #f3f7fd 100%);
}

.math-demo-detail-page .math-demo-directory-heading,
.math-demo-detail-page .math-demo-stage-toolbar,
.math-demo-detail-page .math-demo-stage-actions,
.math-demo-detail-page .math-demo-share,
.math-demo-detail-page .share-buttons {
  display: flex;
  align-items: center;
}

.math-demo-detail-page .math-demo-directory-heading {
  gap: 9px;
  color: #172f54;
  padding: 0 3px;
}

.math-demo-detail-page .math-demo-directory-heading i {
  color: #347cf4;
  font-size: 1rem;
}

.math-demo-detail-page .math-demo-directory-heading h2,
.math-demo-detail-page .math-demo-stage-toolbar h2 {
  margin: 0;
  color: #172f54;
  font-size: 1rem;
  line-height: 1.35;
}

.math-demo-detail-page .math-demo-directory-heading h2 {
  font-size: 1.08rem;
}

.math-demo-detail-page .math-demo-directory-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 15px 0 12px;
  padding: 0 12px;
  border: 1px solid #d8e5f6;
  border-radius: 12px;
  background: #fff;
  color: #7c92b1;
}

.math-demo-detail-page .math-demo-directory-search:focus-within {
  border-color: #6ba0f6;
  box-shadow: 0 0 0 3px rgba(52, 124, 244, .11);
}

.math-demo-detail-page .math-demo-directory-search input {
  width: 100%;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #1e3659;
  font: inherit;
  font-size: .84rem;
}

.math-demo-detail-page .math-demo-stage-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
  padding: 3px;
  border: 1px solid #dce7f5;
  border-radius: 12px;
  background: rgba(255, 255, 255, .74);
}

.math-demo-detail-page .math-demo-stage-tabs button {
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #647b9d;
  cursor: pointer;
  font: inherit;
  font-size: .8rem;
  font-weight: 650;
}

.math-demo-detail-page .math-demo-stage-tabs button:hover,
.math-demo-detail-page .math-demo-stage-tabs button.is-active {
  border-color: #347cf4;
  background: #347cf4;
  color: #fff;
}

.math-demo-detail-page .math-demo-directory-tree {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 3px;
  scrollbar-width: thin;
  scrollbar-color: #c0d7f8 transparent;
}

.math-demo-detail-page .math-demo-directory-tree::-webkit-scrollbar {
  width: 5px;
}

.math-demo-detail-page .math-demo-directory-tree::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c0d7f8;
}

.math-demo-detail-page .math-demo-directory-group h3 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 3px 9px;
  color: #3f5d84;
  font-size: .96rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.math-demo-detail-page .math-demo-directory-group h3::before {
  width: 4px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #5f9dff, #347cf4);
  box-shadow: 0 2px 6px rgba(52, 124, 244, .2);
  content: "";
}

.math-demo-detail-page .math-demo-directory-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 2px 0;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #405a7c;
  font-size: .86rem;
  line-height: 1.35;
  text-decoration: none;
}

.math-demo-detail-page .math-demo-directory-item-media {
  display: grid;
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  place-items: center;
  border-radius: 8px;
  background: #e9f1ff;
  color: #7d9cd0;
  overflow: hidden;
  text-align: center;
}

.math-demo-detail-page .math-demo-directory-item-cover {
  display: none;
}

.math-demo-detail-page .math-demo-directory-item-cover img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.math-demo-detail-page .math-demo-directory-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.math-demo-detail-page .math-demo-directory-item:hover,
.math-demo-detail-page .math-demo-directory-item.is-current {
  border-color: #d4e3fb;
  background: #fff;
  color: #2468d8;
  box-shadow: 0 4px 13px rgba(43, 92, 157, .08);
}

.math-demo-detail-page .math-demo-directory-item.is-current {
  font-weight: 700;
}

.math-demo-detail-page .math-demo-directory-item.is-current .math-demo-directory-item-media {
  background: #347cf4;
  color: #fff;
}

.math-demo-detail-page .math-demo-mobile-list-logo {
  display: none;
}

.math-demo-detail-page .math-demo-directory-empty,
.math-demo-detail-page .math-demo-state {
  margin: auto;
  color: #8297b6;
  font-size: .84rem;
  text-align: center;
}

.math-demo-detail-page .math-demo-stage {
  display: flex;
  position: relative;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 0;
}

.math-demo-detail-page .math-demo-stage-toolbar {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 4;
}

.math-demo-detail-page .math-demo-stage-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 7px;
  flex: 0 0 auto;
}

.math-demo-detail-page .math-demo-header-actions-anchor {
  display: contents;
}

.math-demo-detail-page .math-demo-share,
.math-demo-detail-page .share-buttons {
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.math-demo-detail-page .share-btn,
.math-demo-detail-page .math-demo-toolbar-button,
.math-demo-detail-page .desktop-actions-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #dbe7f5;
  border-radius: 10px;
  background: #fff;
  color: #536a8a;
  cursor: pointer;
  font: inherit;
}

.math-demo-detail-page .desktop-actions {
  position: static;
  top: auto;
  right: auto;
  z-index: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  width: auto;
  max-width: none;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.math-demo-detail-page .desktop-actions:hover {
  box-shadow: none;
}

.math-demo-detail-page .desktop-actions-btn {
  flex: 0 0 34px;
  margin: 0;
}

.math-demo-detail-page .header-account-menu {
  position: absolute;
  top: 56px;
  right: 16px;
  z-index: 8;
}

.math-demo-detail-page .math-demo-toolbar-button[hidden],
.math-demo-detail-page .share-btn[hidden] {
  display: none;
}

.math-demo-detail-page .math-demo-fullscreen-button {
  width: auto;
  min-width: 78px;
  gap: 7px;
  padding: 0 12px;
  font-size: .78rem;
  font-weight: 700;
}

.math-demo-detail-page .share-btn:hover,
.math-demo-detail-page .math-demo-toolbar-button:hover {
  border-color: #80adf6;
  background: #f2f7ff;
  color: #347cf4;
}

.math-demo-detail-page .math-demo-frame-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.math-demo-detail-page .math-demo-frame-wrap iframe {
  display: none;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.math-demo-detail-page .math-demo-stage.has-demo iframe {
  display: block;
}

.math-demo-detail-page .math-demo-stage.has-demo .math-demo-state {
  display: none;
}

.math-demo-detail-page .math-demo-stage.has-error .math-demo-state {
  color: #c34b56;
}

.math-demo-detail-page .math-demo-stage:fullscreen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.math-demo-detail-page .math-demo-stage:fullscreen .math-demo-stage-toolbar {
  padding-right: 14px;
}

.math-demo-detail-page .post-share[data-share-module] .share-copy-bubble {
  top: calc(100% + 6px);
  bottom: auto;
  left: 50%;
  padding: 3px 7px;
  border-radius: 5px;
  background: #263f65;
  color: #fff;
  font-size: .68rem;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
}

.math-demo-detail-page .post-share[data-share-module] .share-copy-bubble.is-visible,
.math-demo-detail-page .post-share[data-share-module] .share-copy-bubble.show {
  opacity: 1;
}

.math-demo-detail-page .post-share[data-share-module] .share-wechat-popover {
  top: calc(100% + 10px);
  bottom: auto;
  transform: translate(-50%, -6px);
}

.math-demo-detail-page .post-share[data-share-module] .share-wechat:hover .share-wechat-popover,
.math-demo-detail-page .post-share[data-share-module] .share-wechat.is-open .share-wechat-popover {
  transform: translate(-50%, 0);
}

.math-demo-detail-page .math-demo-modal[hidden] {
  display: none;
}

.math-demo-detail-page .math-demo-modal {
  position: fixed;
  z-index: 1300;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.math-demo-detail-page .math-demo-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 36, 58, .42);
  backdrop-filter: blur(3px);
}

.math-demo-detail-page .math-demo-modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  max-height: min(84vh, 760px);
  overflow: auto;
  padding: 22px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(20, 50, 90, .24);
}

.math-demo-detail-page .math-demo-modal-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  color: #1c3558;
  font-size: 1rem;
}

.math-demo-detail-page .math-demo-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #f1f5f9;
  color: #536a8a;
  cursor: pointer;
  font-size: 1.25rem;
}

body.math-demo-modal-open {
  overflow: hidden;
}

@media (max-width: 1000px) {
  .math-demo-detail-page.main-wrapper {
    inset: 68px 0 0;
    padding: 8px;
    overflow: auto;
  }

  .math-demo-detail-page .math-demo-workbench {
    min-height: calc(100dvh - 84px);
    grid-template-columns: minmax(210px, 34vw) minmax(0, 1fr);
  }
}

@media (max-width: 700px) {
  /* 手机端拆分“找实验”和“做实验”：列表不加载 iframe，详情不重复目录。 */
  body.tools-detail-page:has(.math-demo-page-list) .mobile-header,
  body.tools-detail-page.math-demo-mobile-list .mobile-header {
    pointer-events: auto;
  }

  body.tools-detail-page:has(.math-demo-page-list) .mobile-header-logo,
  body.tools-detail-page.math-demo-mobile-list .mobile-header-logo {
    display: none;
  }

  body.tools-detail-page:has(.math-demo-page-list) .mobile-header-inner,
  body.tools-detail-page.math-demo-mobile-list .mobile-header-inner {
    padding-left: 10px;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-workbench,
  .math-demo-detail-page.math-demo-page-detail .math-demo-workbench {
    display: block;
    height: auto;
    min-height: 0;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory {
    max-height: none;
    min-height: calc(100dvh - 84px);
    padding: 18px 14px;
    border-right: 0;
    border-bottom: 0;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-heading {
    display: flex;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-mobile-list-logo {
    position: fixed;
    z-index: 1002;
    top: 8px;
    left: 20px;
    display: flex;
    width: 80px;
    height: 44px;
    align-items: center;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-mobile-list-logo img {
    width: auto;
    height: auto;
    max-width: 80px;
    max-height: 44px;
    display: block;
    object-fit: contain;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-tree {
    gap: 18px;
    padding-right: 0;
    overflow: visible;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-group[hidden] {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-group h3 {
    grid-column: 1 / -1;
    margin-bottom: 1px;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-item {
    display: flex;
    min-height: 116px;
    margin: 0;
    padding: 7px;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    border-color: #dce7f4;
    background: rgba(255, 255, 255, .82);
    box-shadow: 0 5px 14px rgba(43, 92, 157, .06);
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-item-cover {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border: 1px solid #dce7f4;
    border-radius: 9px;
    background: #edf3fb;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-item-cover + .math-demo-directory-item-media {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-item-media {
    width: 100%;
    height: 64px;
    flex: 0 0 64px;
    border-radius: 9px;
    font-size: 1.35rem;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-item-title {
    padding: 0 3px 2px;
    color: #28486f;
    font-size: .86rem;
    font-weight: 700;
    text-align: center;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-stage {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-directory {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-stage {
    min-height: calc(100dvh - 84px);
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-workbench {
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-stage-toolbar {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-frame-wrap {
    min-height: calc(100dvh - 84px);
  }

  .math-demo-detail-page .math-demo-mobile-detail-heading {
    position: fixed;
    z-index: 1001;
    top: 8px;
    right: 156px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
  }

  body.tools-detail-page .math-demo-mobile-detail-heading .math-demo-mobile-info-card {
    position: static;
    min-width: 0;
    max-width: calc(100% - 40px);
    margin: 0;
    padding: 7px 10px 7px 7px;
    border-radius: 14px;
    pointer-events: auto;
  }

  .math-demo-detail-page .math-demo-mobile-info-card h1 {
    overflow: hidden;
    margin: 0;
    color: #172f54;
    font-size: .9rem;
    font-weight: 700;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .math-demo-detail-page .math-demo-mobile-fullscreen {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border: 1px solid #dbe8fb;
    border-radius: 10px;
    background: #fff;
    color: #347cf4;
    pointer-events: auto;
    text-decoration: none;
  }

  .math-demo-detail-page .math-demo-workbench {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(520px, 1fr);
    height: auto;
  }

  .math-demo-detail-page .math-demo-directory {
    max-height: 38dvh;
    padding: 15px 13px;
    border-right: 0;
    border-bottom: 1px solid #dce7f4;
  }

  .math-demo-detail-page.math-demo-page-detail .math-demo-directory-heading {
    display: none;
  }

  .math-demo-detail-page.math-demo-page-list .math-demo-directory-search {
    margin-top: 15px;
  }

  .math-demo-detail-page .math-demo-stage {
    min-height: 520px;
  }

  .math-demo-detail-page .math-demo-stage-toolbar {
    top: 10px;
    right: 10px;
  }

  .math-demo-detail-page .math-demo-stage-actions {
    justify-content: flex-end;
  }

}
