/* =================================================== */
/* /chem/wall/ · 可拖动、可点亮的 500 张化学卡片墙            */
/* =================================================== */

body:has(.chem-wall-app) {
  overflow: hidden !important;
  background: #0d0d0c !important;
}

body:has(.chem-wall-app) .md-header,
body:has(.chem-wall-app) .md-tabs,
body:has(.chem-wall-app) .md-footer,
body:has(.chem-wall-app) .md-top {
  display: none !important;
}

body:has(.chem-wall-app) .md-main,
body:has(.chem-wall-app) .md-content,
body:has(.chem-wall-app) .md-typeset,
body:has(.chem-wall-app) .md-content__inner {
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  max-width: none !important;
}

.chem-wall-app {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow: hidden;
  background: #0d0d0c;
  color: #f4f1e7;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
}

.chem-wall-app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 30%, rgba(13, 13, 12, .38) 100%),
    linear-gradient(180deg, rgba(13, 13, 12, .42), transparent 22%, transparent 76%, rgba(13, 13, 12, .82));
  z-index: 2;
}

.wall-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: grab;
}

/* 卡片层：777 个节点启动时一次建好，只显示露在表面的那部分（见 chem-wall-interactive.js） */
.wall-layer {
  position: absolute;
  inset: 0;
  z-index: 0;              /* 独立层叠上下文：卡片的 z-index 不会越过 HUD */
  overflow: hidden;
  contain: strict;
}

/* 透明命中层：接收全部指针事件，卡片节点本身不参与命中测试 */
.wall-hit {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

.chem-wall-app.is-dragging .wall-hit {
  cursor: grabbing;
}

.wall-card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw, 156px);
  height: var(--ch, 208px);
  visibility: hidden;
  pointer-events: none;
  transform-origin: 50% 50%;
  box-sizing: border-box;
  background: #e4e1d8;
  /* 不用模糊阴影：几百张卡同时移动时，阴影的光栅化开销最大 */
  border: 1px solid rgba(13, 13, 12, .42);
  contain: layout paint style;
}

.wall-card img {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  user-select: none;
}

.wall-card img:not([src]) {
  visibility: hidden;
}

/* 只有手里拖着的那一张单独成层。被推开 / 漂移的卡不提升：
   几十个合成层在真实 GPU 上会超出显存预算，出现大块未绘制的黑色区域 */
.wall-card.is-held {
  will-change: transform;
}

.wall-card.is-held {
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 34px -8px rgba(0, 0, 0, .6);
}

.wall-card.is-hover {
  outline: 2px solid rgba(255, 255, 255, .92);
  outline-offset: -1px;
}

.wall-card.is-lit {
  outline: 2px solid #d8b45a;
  outline-offset: -1px;
  border-color: #d8b45a;
}

/* 左下角：卡片右下角是二维码 */
.wall-lit-date {
  position: absolute;
  left: 5%;
  bottom: 4%;
  padding: 2px 5px;
  border: 1px solid rgba(216, 180, 90, .55);
  background: rgba(13, 13, 12, .82);
  color: #d8b45a;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(6px, calc(var(--cw, 156px) * .05), 9px);
  line-height: 1.2;
  letter-spacing: .05em;
  white-space: nowrap;
}

/* --------------------------------------------------- */
/* HUD                                                  */
/* --------------------------------------------------- */

.wall-hud {
  position: absolute;
  left: 26px;
  right: 26px;
  top: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
}

.wall-hud::before {
  content: "";
  position: absolute;
  left: -26px;
  right: -26px;
  top: -20px;
  height: 104px;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(13, 13, 12, .96) 40%, rgba(13, 13, 12, 0));
}

.wall-brand,
.wall-tools,
.wall-help,
.wall-modal {
  pointer-events: auto;
}

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

.wall-back {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(244, 241, 231, .18);
  border-radius: 50%;
  color: #8e8b80;
  font-size: 15px;
  text-decoration: none;
  transition: color .2s ease, border-color .2s ease;
}

.wall-back:hover {
  color: #f4f1e7;
  border-color: rgba(244, 241, 231, .45);
}

.wall-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: #9966cc;
  color: #fff;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  font-weight: 700;
}

.wall-title {
  font-family: "Cascadia Mono", Consolas, monospace;
  text-shadow: 0 1px 8px rgba(13, 13, 12, .95);
  font-size: 10px;
  letter-spacing: .22em;
  color: #8e8b80;
  white-space: nowrap;
}

.wall-title b {
  color: #d8b45a;
  font-weight: 400;
}

.wall-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wall-today {
  font-family: "Cascadia Mono", Consolas, monospace;
  text-shadow: 0 1px 8px rgba(13, 13, 12, .95);
  font-size: 9px;
  letter-spacing: .12em;
  color: #77746a;
  white-space: nowrap;
}

.wall-today b {
  color: #d8b45a;
  font-weight: 400;
}

.wall-btn {
  appearance: none;
  border: 1px solid rgba(244, 241, 231, .18);
  border-radius: 999px;
  background: rgba(23, 22, 20, .72);
  color: #c7c3b7;
  padding: 8px 15px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 9px;
  letter-spacing: .1em;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}

.wall-btn:hover {
  color: #f4f1e7;
  border-color: rgba(244, 241, 231, .42);
  background: rgba(30, 29, 26, .85);
}

.wall-help {
  position: absolute;
  text-shadow: 0 1px 8px rgba(13, 13, 12, .95);
  left: 30px;
  bottom: 26px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 9px;
  line-height: 1.5;
  letter-spacing: .10em;
  color: #8e8b80;
  pointer-events: none;
  /* the cards are light now: keep the hint on its own dark panel */
  padding: 7px 10px;
  border: 1px solid rgba(244, 241, 231, .10);
  border-radius: 4px;
  background: rgba(13, 13, 12, .82);
}

.wall-help__sub {
  color: #57554e;
  font-size: 8px;
}

.wall-help__credit {
  color: #46443e;
  font-size: 7px;
  letter-spacing: .03em;
  margin-top: 4px;
}

/* --------------------------------------------------- */
/* Modal                                                */
/* --------------------------------------------------- */

.wall-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.wall-modal[hidden] {
  display: none !important;
}

.wall-modal:not([hidden]) .wall-modal__backdrop,
.wall-modal:not([hidden]) .wall-modal__close {
  animation: wall-fade-in .38s ease both;
}

.wall-modal.is-leaving .wall-modal__backdrop,
.wall-modal.is-leaving .wall-modal__close {
  animation: wall-fade-out .5s ease both;
}

@keyframes wall-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes wall-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.wall-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 7, 6, .9);
  /* 不用 backdrop-filter：全屏模糊在三维动画期间每帧都要重算，是打开卡片时卡顿的主因 */
  will-change: opacity;
}

.wall-modal__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  max-width: min(92vw, 620px);
  max-height: 94dvh;
}

.wall-modal__close {
  position: absolute;
  right: 0;
  top: -42px;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(244, 241, 231, .22);
  border-radius: 50%;
  background: rgba(23, 22, 20, .7);
  color: #c7c3b7;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* 放大卡片：figure 提供透视；wall-fly 承载「抽出 / 插回」动画；wall-tilt 承载倾斜 */
.wall-modal__figure {
  position: relative;
  width: var(--mw, 420px);
  height: var(--mh, 560px);
  perspective: 1000px;
  perspective-origin: 50% 50%;
  touch-action: none;
}

.wall-fly {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  box-shadow: 0 28px 70px rgba(0, 0, 0, .55);
}

.wall-fly.is-flying {
  will-change: transform;
}

.wall-tilt {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: 50% 50%;
  will-change: transform;
  background: #eeece5;
}

.wall-tilt::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(13, 13, 12, .18);
  pointer-events: none;
}

.wall-tilt img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

/* 光照：亮斑跟着倾斜方向移动，另一侧略暗，浅色卡面上也看得出立体感 */
.wall-glare {
  position: absolute;
  inset: -25%;
  pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%),
    rgba(255, 255, 255, .55) 0%, rgba(255, 255, 255, .12) 22%, rgba(255, 255, 255, 0) 38%,
    rgba(0, 0, 0, .10) 62%, rgba(0, 0, 0, .26) 100%);
  opacity: var(--ga, 0);
  transition: opacity .35s ease;
}

.wall-modal__figure.is-lit .wall-tilt::after {
  border: 2px solid #d8b45a;
  box-shadow: inset 0 0 28px rgba(216, 180, 90, .25);
}

.wall-modal__figure.is-lit .wall-fly {
  box-shadow: 0 28px 70px rgba(0, 0, 0, .55), 0 0 0 1px rgba(216, 180, 90, .5), 0 0 60px rgba(216, 180, 90, .22);
}

.wall-lit-chip {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 8px;
  border: 1px solid rgba(216, 180, 90, .65);
  background: rgba(13, 13, 12, .88);
  color: #d8b45a;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 9px;
  letter-spacing: .08em;
}

.wall-lit-chip[hidden] {
  display: none;
}

.wall-modal__bar {
  transition: opacity .32s ease, transform .32s ease;
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 92vw;
  padding: 11px 15px 11px 18px;
  border: 1px solid rgba(244, 241, 231, .16);
  border-radius: 999px;
  background: rgba(23, 22, 20, .92);
}

.wall-modal__bar.is-hidden {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.wall-modal__meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.wall-modal__meta b {
  font-size: 12px;
  font-weight: 400;
  color: #f4f1e7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.wall-modal__meta span {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 8px;
  letter-spacing: .06em;
  color: #807d72;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.wall-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-left: auto;
}

.wall-light {
  border: 1px solid #d8b45a;
  border-radius: 999px;
  background: #d8b45a;
  color: #181510;
  padding: 10px 16px;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s ease, color .2s ease, opacity .2s ease;
}

.wall-light:hover {
  background: #e5c674;
}

.wall-light[disabled] {
  border-color: rgba(216, 180, 90, .25);
  background: rgba(216, 180, 90, .12);
  color: #7f6d3f;
  cursor: default;
}

.wall-round {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(244, 241, 231, .18);
  border-radius: 50%;
  background: rgba(13, 13, 12, .45);
  color: #c7c3b7;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}

.wall-round svg {
  width: 18px;
  height: 18px;
}

.wall-round:hover {
  color: #f4f1e7;
  border-color: rgba(244, 241, 231, .46);
  background: rgba(40, 38, 34, .8);
}

.wall-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 120;
  transform: translateX(-50%) translateY(12px);
  padding: 9px 15px;
  border: 1px solid rgba(244, 241, 231, .16);
  border-radius: 999px;
  background: rgba(23, 22, 20, .94);
  color: #d7d2c5;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
}

.wall-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --------------------------------------------------- */
/* Responsive                                           */
/* --------------------------------------------------- */

@media screen and (max-width: 700px) {
  .wall-hud {
    left: 14px;
    right: 14px;
    top: 13px;
    gap: 8px;
  }

  .wall-brand {
    gap: 8px;
  }

  .wall-back {
    width: 24px;
    height: 24px;
  }

  .wall-mark {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .wall-title {
    display: none;
  }

  .wall-tools {
    gap: 7px;
  }

  .wall-today {
    font-size: 8px;
    letter-spacing: .05em;
  }

  .wall-btn {
    padding: 7px 10px;
    font-size: 8px;
  }

  .wall-help {
    left: 15px;
    bottom: 16px;
    font-size: 8px;
  }

  .wall-help__sub {
    font-size: 7px;
  }

  .wall-help__credit {
    font-size: 6px;
    max-width: 150px;
    white-space: normal;
    line-height: 1.4;
  }

  .wall-modal {
    padding: 14px;
  }

  .wall-modal__panel {
    gap: 12px;
    width: 100%;
  }


  .wall-modal__bar {
    gap: 12px;
    padding: 9px 12px;
    width: 100%;
    border-radius: 20px;
  }

  .wall-modal__meta b {
    max-width: 150px;
    font-size: 11px;
  }

  .wall-modal__meta span {
    max-width: 150px;
    font-size: 7px;
  }

  .wall-light {
    padding: 9px 12px;
    font-size: 11px;
  }

  .wall-round {
    width: 38px;
    height: 38px;
  }

  .wall-round#wall-copy {
    display: none !important;
  }

  .wall-toast {
    bottom: 92px;
    font-size: 10px;
  }
}


@media (prefers-reduced-motion: reduce) {
  .wall-modal:not([hidden]) .wall-modal__backdrop,
  .wall-modal:not([hidden]) .wall-modal__close,
  .wall-modal.is-leaving .wall-modal__backdrop,
  .wall-modal.is-leaving .wall-modal__close {
    animation: none;
  }
}
