html,
body {
  margin: 0;
  height: 100%;
  background: #070b1a;
  color: #e8ecff;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  height: 100%;
  display: flex;
}

/* 3D 区高度统一由 --scene-height 控制，窄屏媒体查询只需覆盖这一个变量 */
body {
  --scene-height: 100%;
}

#scene {
  display: block;
  width: 100%;
  height: var(--scene-height);
  align-self: flex-start;
}

#scene[hidden] {
  display: none;
}

body[data-question-type="model"] #scene-toolbar,
body[data-question-type="view"] #scene-toolbar,
body[data-question-type="section"] #scene-toolbar {
  display: none;
}

/* 三视图题：3D 区占上方约 58%，题干与选项在下方，避免互相遮挡 */
body[data-question-type="view"] {
  --scene-height: 58%;
}

/* 截面题：截面填充在图形中部，3D 区留出约 62% 高度便于辨认多边形边数 */
body[data-question-type="section"] {
  --scene-height: 62%;
}

.view-direction {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 18px;
  border: 1px solid rgba(102, 240, 255, 0.45);
  border-radius: 22px;
  background: rgba(14, 20, 46, 0.85);
  color: #b9e9ff;
  font-size: 15px;
  letter-spacing: 0.06em;
  pointer-events: none;
  white-space: nowrap;
}

.view-direction[hidden] {
  display: none;
}

.view-direction-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(102, 240, 255, 0.16);
  color: #66f0ff;
  font-size: 18px;
  line-height: 1;
}

.view-direction[data-view="front"] .view-direction-arrow {
  color: #66f0ff;
}

.view-direction[data-view="side"] .view-direction-arrow {
  color: #c08bff;
}

.view-direction[data-view="top"] .view-direction-arrow {
  color: #ffb45b;
}

#scene-toolbar {
  position: absolute;
  top: 12px;
  right: 68px;
  display: flex;
  gap: 8px;
}

/* 音效开关固定在画布外的右上角，与隐藏棱开关横向错开 */
.audio-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.mute-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #2b3566;
  border-radius: 50%;
  background: rgba(14, 20, 46, 0.82);
  color: #8593c8;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mute-toggle:hover {
  border-color: #3d4b8a;
  color: #b9c6ff;
}

.mute-toggle:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 2px;
}

.mute-toggle[data-state="on"] {
  border-color: #66f0ff;
  color: #66f0ff;
  box-shadow: 0 0 12px rgba(102, 240, 255, 0.3);
}

.mute-toggle[data-state="off"] {
  border-style: dashed;
  color: #5a648f;
}

.mute-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
}

.mute-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute-icon svg path:first-child {
  fill: currentColor;
  stroke: none;
}

body[data-game-state="idle"] #scene-toolbar {
  display: none;
}

#hidden-edge-toggle {
  min-width: 108px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  border: 1px solid #2b3566;
  background: rgba(14, 20, 46, 0.82);
  color: #8593c8;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#hidden-edge-toggle:hover {
  border-color: #3d4b8a;
  color: #b9c6ff;
}

#hidden-edge-toggle:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 2px;
}

#hidden-edge-toggle[data-state="on"] {
  border-color: #66f0ff;
  background: rgba(30, 78, 96, 0.9);
  color: #66f0ff;
  box-shadow: 0 0 12px rgba(102, 240, 255, 0.35);
}

#hidden-edge-toggle[data-state="on"]::before {
  content: "◉ ";
}

#hidden-edge-toggle[data-state="off"]::before {
  content: "○ ";
}

#hidden-edge-toggle[data-state="disabled"] {
  border-style: dashed;
  color: #5a648f;
  background: rgba(14, 20, 46, 0.6);
  cursor: not-allowed;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none;
}

.home-screen {
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 24px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(102, 240, 255, 0.12), transparent 55%),
    rgba(7, 11, 26, 0.78);
}

#game-title {
  margin: 0;
  font-size: clamp(30px, 6vw, 56px);
  letter-spacing: 0.08em;
  background: linear-gradient(100deg, #66f0ff, #c08bff 55%, #ff5bd2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 36px rgba(102, 240, 255, 0.25);
}

.home-intro {
  margin: 0;
  max-width: 34em;
  font-size: 16px;
  line-height: 1.7;
  color: #a9b6e6;
}

.start-button {
  min-width: 180px;
  min-height: 48px;
  padding: 0 32px;
  border: 1px solid #66f0ff;
  border-radius: 24px;
  background: rgba(30, 78, 96, 0.9);
  color: #66f0ff;
  font-family: inherit;
  font-size: 18px;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(102, 240, 255, 0.35);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.start-button:hover {
  background: rgba(41, 104, 128, 0.95);
  box-shadow: 0 0 26px rgba(102, 240, 255, 0.5);
}

.start-button:active {
  transform: translateY(1px);
}

.start-button:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 3px;
}

.question-screen {
  justify-content: flex-end;
  gap: 12px;
  padding: 16px;
  pointer-events: none;
}

body[data-question-type="model"] .question-screen {
  justify-content: center;
  align-items: center;
}

body[data-question-type="model"] .prompt-area,
body[data-question-type="model"] .options-area {
  width: min(560px, 100%);
}

.hud-area {
  position: absolute;
  top: 12px;
  left: 12px;
  min-height: 44px;
  pointer-events: none;
}

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid rgba(43, 53, 102, 0.9);
  border-radius: 22px;
  background: rgba(14, 20, 46, 0.82);
}

.hud-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 0 10px;
}

.hud-stat + .hud-stat {
  border-left: 1px solid rgba(43, 53, 102, 0.9);
}

.hud-label {
  font-size: 12px;
  letter-spacing: 0.1em;
  color: #8593c8;
  white-space: nowrap;
}

.hud-value {
  display: inline-block;
  min-width: 1.4em;
  color: #e8ecff;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}

.hud-stat:first-child .hud-value {
  color: #66f0ff;
}

.hud-value.is-bumped {
  animation: hud-bump 0.42s ease-out;
}

@keyframes hud-bump {
  0% {
    transform: scale(1);
    color: #ffb45b;
  }
  40% {
    transform: scale(1.55);
    color: #ff5bd2;
  }
  100% {
    transform: scale(1);
    color: inherit;
  }
}

.hud-hearts {
  color: #ff5bd2;
  font-size: 18px;
  letter-spacing: 0.12em;
  line-height: 1;
  text-shadow: 0 0 8px rgba(255, 91, 210, 0.45);
}

.hud-hearts.is-empty {
  color: #5a648f;
  text-shadow: none;
}

.question-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

.prompt-area,
.options-area {
  box-sizing: border-box;
  border: 1px solid #2b3566;
  border-radius: 16px;
  background: rgba(14, 20, 46, 0.82);
  padding: 16px;
  pointer-events: auto;
}

.question-index {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: #8593c8;
}

.question-prompt {
  margin: 0;
  font-size: 18px;
  line-height: 1.6;
}

.placeholder-note {
  margin: 0;
  color: #6b78a8;
  font-size: 14px;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.option-button {
  position: relative;
  min-height: 48px;
  min-width: 44px;
  padding: 10px 40px 10px 14px;
  border: 1px solid #2b3566;
  border-radius: 12px;
  background: rgba(21, 29, 62, 0.9);
  color: #dfe6ff;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.option-button:hover:not(:disabled) {
  border-color: #66f0ff;
  background: rgba(30, 48, 92, 0.95);
}

.option-button:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 2px;
}

.option-button:disabled {
  cursor: default;
  opacity: 0.85;
}

.option-button.is-correct {
  border-color: #4ade80;
  background: rgba(24, 84, 52, 0.92);
  color: #d8ffe6;
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.35);
  opacity: 1;
}

.option-button.is-wrong {
  border-color: #f87171;
  background: rgba(96, 30, 40, 0.92);
  color: #ffe0e0;
  box-shadow: 0 0 14px rgba(248, 113, 113, 0.3);
  opacity: 1;
}

.option-mark {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  font-weight: 700;
}

.option-button.is-correct .option-mark {
  color: #4ade80;
}

.option-button.is-wrong .option-mark {
  color: #f87171;
}

.thumb-area {
  display: none;
}

body[data-question-type="model"] .thumb-area {
  display: block;
}

.view-options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.view-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 44px;
  min-height: 88px;
  padding: 10px 12px;
  border: 1px solid #2b3566;
  border-radius: 12px;
  background: rgba(21, 29, 62, 0.9);
  color: #dfe6ff;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.view-option:hover:not(:disabled) {
  border-color: #66f0ff;
  background: rgba(30, 48, 92, 0.95);
}

.view-option:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 2px;
}

.view-option:disabled {
  cursor: default;
  opacity: 0.85;
}

.view-shape {
  display: block;
  width: 100%;
  max-width: 96px;
  height: 54px;
  fill: rgba(102, 240, 255, 0.16);
  stroke: #66f0ff;
  stroke-width: 2.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.view-shape-center {
  fill: #66f0ff;
  stroke: none;
}

.view-shape-label {
  color: #c9d3ff;
  letter-spacing: 0.04em;
}

.view-mark {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 20px;
  font-weight: 700;
}

.view-option.is-correct {
  border-color: #4ade80;
  background: rgba(24, 84, 52, 0.92);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.35);
  opacity: 1;
}

.view-option.is-correct .view-shape {
  stroke: #4ade80;
  fill: rgba(74, 222, 128, 0.16);
}

.view-option.is-correct .view-shape-center {
  fill: #4ade80;
}

.view-option.is-correct .view-mark {
  color: #4ade80;
}

.view-option.is-wrong {
  border-color: #f87171;
  background: rgba(96, 30, 40, 0.92);
  box-shadow: 0 0 14px rgba(248, 113, 113, 0.3);
  opacity: 1;
}

.view-option.is-wrong .view-shape {
  stroke: #f87171;
  fill: rgba(248, 113, 113, 0.14);
}

.view-option.is-wrong .view-shape-center {
  fill: #f87171;
}

.view-option.is-wrong .view-mark {
  color: #f87171;
}

body[data-question-type="model"] .options-area {
  border: none;
  background: none;
  padding: 0;
}

.thumb-stage {
  position: relative;
  width: min(440px, 100%);
  aspect-ratio: 1 / 1;
  max-height: 48vh;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
}

.thumb-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.thumb-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.thumb-cell {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid rgba(43, 53, 102, 0.9);
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.thumb-cell:hover:not(:disabled) {
  border-color: #66f0ff;
  background: rgba(30, 48, 92, 0.25);
}

.thumb-cell:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 2px;
}

.thumb-cell:disabled {
  cursor: default;
}

.thumb-cell.is-correct {
  border-color: #4ade80;
  box-shadow: 0 0 16px rgba(74, 222, 128, 0.45);
  background: rgba(24, 84, 52, 0.18);
}

.thumb-cell.is-wrong {
  border-color: #f87171;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.4);
  background: rgba(96, 30, 40, 0.18);
}

.thumb-mark {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 22px;
  font-weight: 700;
}

.thumb-cell.is-correct .thumb-mark {
  color: #4ade80;
}

.thumb-cell.is-wrong .thumb-mark {
  color: #f87171;
}

@media (max-width: 480px) {
  .options-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* 窄屏下 HUD 几乎占满整行，把右上角工具下移避免与分数区重叠 */
@media (max-width: 640px) {
  .audio-toolbar,
  #scene-toolbar {
    top: 72px;
  }
}

/* 竖屏手机：3D 区固定在上部约 55%，题干与选项排在下方并保持两列，避免遮住图形 */
@media (max-width: 640px) and (orientation: portrait) {
  body,
  body[data-question-type="view"],
  body[data-question-type="section"] {
    --scene-height: 55%;
  }

  .question-screen {
    gap: 8px;
    padding: 0 12px 12px;
  }

  .options-grid,
  .view-options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* 收窄形状卡，让 2x2 选项 + 题干在一屏内完整容纳 */
  .view-option {
    gap: 4px;
    min-height: 84px;
    padding: 6px 10px;
  }

  .view-shape {
    height: 42px;
  }

  .prompt-area,
  .options-area {
    padding: 12px;
  }

  .thumb-stage {
    max-height: none;
  }

  /* 320px 两列时按钮更窄，收紧内边距让「平行四边形」等长选项保持单行 */
  .option-button {
    padding-left: 12px;
    padding-right: 30px;
  }
}

/* 视口窄于约 900px 时居中标签会压住左侧 HUD，改为 HUD 下方左对齐 */
@media (max-width: 900px) {
  .view-direction {
    top: 72px;
    left: 12px;
    transform: none;
    max-width: calc(100% - 68px);
    padding: 4px 12px;
    font-size: 12px;
    white-space: nowrap;
    min-height: 36px;
  }

  .view-direction-arrow {
    flex: none;
    width: 24px;
    height: 24px;
    font-size: 16px;
  }
}

/* 矮视口（横屏或被浏览器工具栏压缩）：按可用高度收窄 3D 区，保证选项区完整可见 */
@media (max-height: 800px) and (orientation: portrait) {
  body,
  body[data-question-type="view"],
  body[data-question-type="section"] {
    --scene-height: 52%;
  }
}

@media (max-height: 720px) and (orientation: portrait) {
  body,
  body[data-question-type="view"],
  body[data-question-type="section"] {
    --scene-height: 42%;
  }
}

@media (max-height: 600px) and (orientation: portrait) {
  body,
  body[data-question-type="view"],
  body[data-question-type="section"] {
    --scene-height: 40%;
  }

  .question-prompt {
    font-size: 16px;
  }

  .view-option {
    min-height: 72px;
    padding: 6px 10px;
  }

  .view-shape {
    height: 40px;
  }
}

.continue-button {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 0 24px;
  border: 1px solid #66f0ff;
  border-radius: 24px;
  background: rgba(30, 78, 96, 0.9);
  color: #66f0ff;
  font-family: inherit;
  font-size: 17px;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(102, 240, 255, 0.3);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.continue-button:hover {
  background: rgba(41, 104, 128, 0.95);
}

.continue-button:focus-visible {
  outline: 2px solid #66f0ff;
  outline-offset: 3px;
}

/* 答错知识卡：全屏遮罩 + 居中模态卡片，展示期间答案与 3D 区均为 inert */
.knowledge-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(7, 11, 26, 0.78);
  pointer-events: auto;
}

.knowledge-backdrop[hidden] {
  display: none;
}

.knowledge-card {
  width: min(440px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid rgba(102, 240, 255, 0.45);
  border-radius: 18px;
  background: rgba(14, 20, 46, 0.96);
  box-shadow: 0 0 36px rgba(102, 240, 255, 0.18);
}

.knowledge-kicker {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: #66f0ff;
}

.knowledge-title {
  margin: 0 0 14px;
  font-size: 24px;
  letter-spacing: 0.06em;
  color: #e8ecff;
}

.knowledge-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.knowledge-stat {
  padding: 8px 10px;
  border: 1px solid rgba(43, 53, 102, 0.9);
  border-radius: 12px;
  background: rgba(21, 29, 62, 0.9);
  text-align: center;
}

.knowledge-stat dt {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #8593c8;
}

.knowledge-stat dd {
  margin: 4px 0 0;
  font-size: 18px;
  color: #e8ecff;
  font-variant-numeric: tabular-nums;
}

.knowledge-euler {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(74, 222, 128, 0.45);
  border-radius: 12px;
  background: rgba(24, 84, 52, 0.35);
  color: #d8ffe6;
  font-size: 14px;
  line-height: 1.5;
}

.knowledge-euler[hidden] {
  display: none;
}

.knowledge-fact {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: #c9d3ff;
}

/* 结算页：生命耗尽后覆盖全屏，展示本局成绩并提供「再来一局」 */
.result-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(7, 11, 26, 0.82);
  pointer-events: auto;
}

.result-backdrop[hidden] {
  display: none;
}

.result-card {
  width: min(440px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  padding: 24px 20px 20px;
  border: 1px solid rgba(192, 139, 255, 0.5);
  border-radius: 18px;
  background: rgba(14, 20, 46, 0.96);
  box-shadow: 0 0 36px rgba(192, 139, 255, 0.2);
  text-align: center;
}

.result-kicker {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: #c08bff;
}

.result-title {
  margin: 0 0 18px;
  font-size: 24px;
  letter-spacing: 0.06em;
  color: #e8ecff;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}

.result-stat {
  padding: 10px 12px;
  border: 1px solid rgba(43, 53, 102, 0.9);
  border-radius: 12px;
  background: rgba(21, 29, 62, 0.9);
}

.result-stat.is-score {
  grid-column: 1 / -1;
  border-color: rgba(102, 240, 255, 0.45);
  background: rgba(30, 78, 96, 0.45);
}

.result-stat-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #8593c8;
}

.result-stat-value {
  margin: 4px 0 0;
  font-size: 20px;
  color: #e8ecff;
  font-variant-numeric: tabular-nums;
}

.result-stat.is-score .result-stat-value {
  font-size: 30px;
  color: #66f0ff;
  text-shadow: 0 0 14px rgba(102, 240, 255, 0.35);
}

.result-replay {
  width: 100%;
}
