/* ============================================================================
   assets/kid3d/engine.css  ·  3D 课件舞台与叠层 UI
   只负责 #k3dStage 内部：画布、加载遮罩、工具条、词卡、测验 HUD、结算弹窗。
   页面外壳（页头/词表/FAQ/页脚/广告位）在 assets/site.css。
   ========================================================================== */

.k3d-stage {
  position: relative;
  height: clamp(380px, 60vh, 620px);
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #f2f7fd, #e4edf8);
  border: 1px solid var(--line);
  box-shadow: 0 18px 46px rgba(28, 42, 80, .13);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  z-index: 0;
}
.k3d-stage.dragging { cursor: grabbing; }
.k3d-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }

/* ── 加载遮罩 ───────────────────────────────────────────────────────────── */
.k3d-loading {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(180deg, #f7fbff, #e8f0fa);
  font-size: 13.5px; color: var(--ink-2); text-align: center; padding: 24px;
}
.k3d-loading.gone { display: none; }
.k3d-spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #d5e2f2; border-top-color: var(--accent);
  animation: k3d-spin .85s linear infinite;
}
@keyframes k3d-spin { to { transform: rotate(360deg); } }
.k3d-err { line-height: 1.9; }
.k3d-err b { display: block; font-size: 15px; color: #b4453a; margin-bottom: 6px; }
.k3d-err span { font-size: 12.5px; color: var(--ink-3); }

/* ── 工具条（右上）───────────────────────────────────────────────────────── */
.k3d-toolbar {
  position: absolute; top: 12px; right: 12px; z-index: 12;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
  max-width: calc(100% - 24px);
}
.k3d-seg {
  display: flex; background: rgba(255, 255, 255, .9); backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 233, 243, .95); border-radius: 999px; padding: 3px;
  box-shadow: 0 6px 18px rgba(28, 42, 80, .1);
}
.k3d-seg button {
  font: inherit; font-size: 12.5px; font-weight: 700; color: var(--ink-2);
  background: transparent; border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  transition: .16s; white-space: nowrap;
}
.k3d-seg button.on { background: linear-gradient(180deg, #ffb073, #ff7a2e); color: #fff; box-shadow: 0 6px 14px rgba(255, 122, 46, .32); }
.k3d-ico {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; background: rgba(255, 255, 255, .9); backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 233, 243, .95); border-radius: 50%; cursor: pointer;
  box-shadow: 0 6px 18px rgba(28, 42, 80, .1); transition: .16s;
}
.k3d-ico:hover { border-color: #ffcda6; transform: translateY(-1px); }

/* ── 已学进度（左上）────────────────────────────────────────────────────── */
.k3d-progress {
  position: absolute; top: 14px; left: 14px; z-index: 11;
  font-size: 12px; font-weight: 700; color: var(--ink-2);
  background: rgba(255, 255, 255, .88); backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 233, 243, .95); border-radius: 999px; padding: 7px 13px;
  box-shadow: 0 6px 18px rgba(28, 42, 80, .1); pointer-events: none;
  transition: opacity .25s;
}
/* 移动端窄屏：quiz HUD 会压到进度胶囊 → HUD 出现时先把进度淡出 */
@media (max-width: 640px) {
  .k3d-stage:has(.k3d-hud:not([hidden])) .k3d-progress { opacity: 0; }
}

/* ── 首次提示 toast ─────────────────────────────────────────────────────── */
.k3d-hint {
  position: absolute; left: 50%; bottom: 20px; transform: translate(-50%, 14px); z-index: 11;
  font-size: 12.5px; font-weight: 600; color: #fff; background: rgba(30, 37, 54, .82);
  backdrop-filter: blur(6px); border-radius: 999px; padding: 9px 18px;
  opacity: 0; transition: .3s; pointer-events: none; white-space: nowrap;
}
.k3d-hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 词卡（底部）───────────────────────────────────────────────────────── */
.k3d-card {
  position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 22px); z-index: 14;
  width: min(430px, calc(100% - 28px));
  background: rgba(255, 255, 255, .97); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 20px; padding: 16px 18px 15px;
  box-shadow: 0 18px 40px rgba(28, 42, 80, .2);
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s cubic-bezier(.2, .9, .3, 1.2);
}
.k3d-card.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.k3d-card .x {
  position: absolute; top: 8px; right: 10px; width: 28px; height: 28px; border: 0; cursor: pointer;
  background: #f2f6fc; color: var(--ink-3); border-radius: 50%; font-size: 16px; line-height: 1;
}
.k3d-card .x:hover { background: #e8eef8; color: var(--ink); }
.k3d-card .top { display: flex; align-items: center; gap: 12px; }
.k3d-card .emoji { font-size: 30px; line-height: 1; }
.k3d-card .en { font-size: 24px; font-weight: 800; letter-spacing: -.3px; }
.k3d-card .ipa { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.k3d-card .mean { font-size: 15px; font-weight: 700; color: var(--accent-2); margin: 8px 0 0; }
.k3d-card .acts { display: flex; gap: 9px; margin-top: 13px; flex-wrap: wrap; }
.k3d-card .acts button {
  flex: 1 1 0; min-width: 130px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  color: var(--ink-2); background: #f4f7fc; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: .16s;
}
.k3d-card .acts button:hover { border-color: #ffcda6; color: var(--accent-2); background: #fff7f1; }
.k3d-card .acts button.playing { background: #fff1e6; border-color: #ffcda6; color: var(--accent-2); }

/* ── 测验 HUD（顶部居中）────────────────────────────────────────────────── */
.k3d-hud {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 13;
  display: flex; align-items: center; gap: 11px;
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px 8px 10px;
  box-shadow: 0 10px 26px rgba(28, 42, 80, .14); max-width: calc(100% - 96px);
}
.k3d-hud[hidden] { display: none; }
.k3d-hud .ask { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.k3d-hud .ask b { color: var(--accent-2); }
.k3d-hud .bar { width: 84px; height: 7px; border-radius: 999px; background: #e7eef8; overflow: hidden; flex: 0 0 auto; }
.k3d-hud .bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #ffb073, #ff7a2e); transition: width .3s; }
.k3d-hud .prog { font-size: 12px; color: var(--ink-3); font-weight: 700; white-space: nowrap; }

/* ── 答对/答错反馈 ─────────────────────────────────────────────────────── */
.k3d-flash {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%) scale(.7); z-index: 16;
  font-size: 26px; font-weight: 800; color: #fff; padding: 12px 26px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .3s cubic-bezier(.2, .9, .3, 1.5);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .18); white-space: nowrap;
}
.k3d-flash.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.k3d-flash.ok { background: #34c77b; }
.k3d-flash.no { background: #ef6a5e; }

/* ── 结算弹窗 ──────────────────────────────────────────────────────────── */
.k3d-result {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 18px; background: rgba(24, 34, 56, .46); backdrop-filter: blur(3px);
}
.k3d-result[hidden] { display: none; }
.k3d-result .panel {
  width: min(430px, 100%); text-align: center; padding: 24px 22px;
  animation: k3d-pop .3s cubic-bezier(.2, .9, .3, 1.4);
  max-height: 100%; overflow: auto; box-shadow: 0 24px 60px rgba(20, 30, 60, .3);
}
@keyframes k3d-pop { from { transform: scale(.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.k3d-result h3 { font-size: 20px; margin-bottom: 6px; }
.k3d-result .score { font-size: 15px; font-weight: 800; color: var(--accent-2); margin-bottom: 18px; }
.k3d-result .btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.k3d-result .ad-slot { margin-top: 18px; min-height: 90px; }

@media (max-width: 640px) {
  .k3d-stage { height: clamp(340px, 56vh, 520px); border-radius: 18px; }
  /* 工具条保持单行、整体缩小：折列会叠两层、盖住右上模型还占视野 */
  .k3d-toolbar { top: 10px; right: 10px; gap: 6px; }
  .k3d-seg { padding: 2px; }
  .k3d-seg button { padding: 5px 10px; font-size: 11.5px; }
  .k3d-ico { width: 30px; height: 30px; font-size: 15px; }
  .k3d-hud { padding: 7px 12px 7px 9px; gap: 8px; max-width: calc(100% - 76px); }
  .k3d-hud .ask { font-size: 13.5px; }
  .k3d-hud .bar { width: 54px; }
  .k3d-card { bottom: 12px; padding: 14px 15px; }
  .k3d-card .en { font-size: 21px; }
  .k3d-progress { top: 10px; left: 10px; font-size: 10.5px; padding: 5px 9px; }
}
