/* ==========================================================================
   V7.13 3D 桌面：纸张厚度、桌面透视、3D 骰子与立体战斗卡。
   由 body.skin-3d 控制（js/main.js 的 applyDepth，顶栏「🎲 3D」开关），只在档案皮肤 body.skin-archive 下生效。
   做法：纯 CSS 的透视与投影，不用 WebGL；角度都很小，保证文字清楚。
   ========================================================================== */

/* ---------- 台灯光圈：桌面中间亮、四周暗；电脑上随鼠标轻微移动 ---------- */
body.skin-archive.skin-3d::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 55% at var(--lamp-x, 50%) var(--lamp-y, 18%), rgba(233, 201, 138, 0.2), rgba(233, 201, 138, 0.05) 55%, transparent 75%),
    radial-gradient(ellipse 120% 90% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- 纸张厚度：当前这页底下叠着几层纸 ---------- */
body.skin-3d .log-entry.entry-event {
  box-shadow:
    0 1px 0 #ddd2b4,
    0 2px 0 #cfc3a2,
    0 3px 0 #c4b793,
    0 4px 0 #b8aa85,
    0 5px 0 #a99a75,
    0 16px 22px rgba(0, 0, 0, 0.5),
    0 34px 46px -14px rgba(0, 0, 0, 0.45),
    inset 40px 30px 70px rgba(255, 249, 232, 0.22),
    inset -20px -24px 60px rgba(90, 70, 40, 0.1);
}
body.skin-3d .log-entry.entry-event:not(.entry-current) {
  box-shadow:
    0 1px 0 #cfc3a2,
    0 2px 0 #b8aa85,
    0 10px 16px rgba(0, 0, 0, 0.45);
}

/* 翻页：新的一页从上方翻下来 */
@keyframes pageFlipIn {
  0% { opacity: 0; transform: perspective(1400px) rotateX(-68deg) translateY(-18px); box-shadow: 0 40px 60px rgba(0, 0, 0, 0.2); }
  55% { opacity: 1; }
  80% { transform: perspective(1400px) rotateX(4deg); }
  100% { opacity: 1; transform: perspective(1400px) rotateX(0deg); }
}
body.skin-3d .log-entry.entry-current {
  transform-origin: 50% 0%;
  animation: pageFlipIn 0.7s cubic-bezier(0.2, 0.75, 0.25, 1) both;
}
/* 一般记录（结果、系统提示）像小纸条落下 */
@keyframes slipDrop {
  0% { opacity: 0; transform: perspective(1200px) rotateX(-35deg) translateY(-10px); }
  100% { opacity: 1; transform: none; }
}
body.skin-3d .log-entry:not(.entry-event):last-child {
  transform-origin: 50% 0%;
  animation: slipDrop 0.45s ease-out both;
}

/* ---------- 选项车票：一张张滑进来，按下去像被压住 ---------- */
@keyframes ticketIn {
  0% { opacity: 0; transform: perspective(900px) translateX(36px) rotateY(-28deg); }
  100% { opacity: 1; transform: perspective(900px) translateX(0) rotateY(0); }
}
body.skin-3d #choicesArea .choice-btn {
  transform-origin: 0% 50%;
  animation: ticketIn 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  box-shadow:
    0 1px 0 #c7b68a,
    0 2px 0 #b5a378,
    0 8px 12px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 250, 235, 0.45);
}
body.skin-3d #choicesArea .choice-btn:nth-child(2) { animation-delay: 0.06s; }
body.skin-3d #choicesArea .choice-btn:nth-child(3) { animation-delay: 0.12s; }
body.skin-3d #choicesArea .choice-btn:nth-child(4) { animation-delay: 0.18s; }
body.skin-3d #choicesArea .choice-btn:nth-child(5) { animation-delay: 0.24s; }
body.skin-3d #choicesArea .choice-btn:hover:not(:disabled) {
  box-shadow:
    0 1px 0 #c7b68a,
    0 2px 0 #b5a378,
    0 14px 20px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 250, 235, 0.55);
}
body.skin-3d #choicesArea .choice-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b5a378, 0 3px 5px rgba(0, 0, 0, 0.45);
  transition: none;
}

/* ---------- 守则便签：交错歪斜，钉在软木板上 ---------- */
body.skin-3d .rule-card {
  box-shadow:
    0 1px 0 #d8cca8,
    0 2px 0 #c8bb94,
    0 12px 18px rgba(0, 0, 0, 0.5),
    inset 20px 20px 40px rgba(255, 250, 235, 0.25);
}
body.skin-3d .rule-card:nth-child(odd) { transform: rotate(-1.3deg); }
body.skin-3d .rule-card:nth-child(even) { transform: rotate(1.1deg); }

/* ---------- 档案夹：叠着几层纸的牛皮纸夹 ---------- */
body.skin-3d .panel-left {
  box-shadow:
    3px 0 0 #b89c66,
    6px 0 0 #a88c58,
    9px 0 0 #957a4a,
    0 26px 40px rgba(0, 0, 0, 0.55);
}

/* ---------- 电脑：三栏像摊在桌上，随鼠标轻微倾斜 ---------- */
@media (min-width: 821px) {
  body.skin-3d .main-layout {
    perspective: 2200px;
    perspective-origin: 50% 10%;
  }
  body.skin-3d .panel-left,
  body.skin-3d .panel-center,
  body.skin-3d .panel-right {
    transition: transform 0.35s ease-out;
    will-change: transform;
  }
  body.skin-3d .panel-left {
    transform-origin: 100% 50%;
    transform: rotateY(calc(5deg + var(--tilt-y, 0) * 1.2deg)) rotateX(calc(var(--tilt-x, 0) * 0.8deg)) rotateZ(-0.6deg);
  }
  body.skin-3d .panel-center {
    transform-origin: 50% 0%;
    transform: rotateX(calc(2deg + var(--tilt-x, 0) * 0.8deg)) rotateY(calc(var(--tilt-y, 0) * 0.8deg));
  }
  body.skin-3d .panel-right {
    transform-origin: 0% 50%;
    transform: rotateY(calc(-5deg + var(--tilt-y, 0) * 1.2deg)) rotateX(calc(var(--tilt-x, 0) * 0.8deg)) rotateZ(0.5deg);
  }
  /* 顶栏像一条黄铜导轨 */
  body.skin-3d .top-bar {
    box-shadow: 0 1px 0 rgba(255, 230, 170, 0.25) inset, 0 -2px 0 rgba(0, 0, 0, 0.4) inset, 0 10px 24px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- 减少动态效果：只保留静态的厚度与投影 ---------- */
@media (prefers-reduced-motion: reduce) {
  body.skin-3d .log-entry.entry-current,
  body.skin-3d .log-entry:not(.entry-event):last-child,
  body.skin-3d #choicesArea .choice-btn {
    animation: none;
  }
  body.skin-3d .panel-left,
  body.skin-3d .panel-center,
  body.skin-3d .panel-right {
    transition: none;
  }
}

/* ==========================================================================
   V7.13 样板第二版：更明显的空间感
   ========================================================================== */

/* 透视木纹桌面：木板线条往画面上方收拢，越远越暗 */
body.skin-archive.skin-3d::after {
  content: '';
  position: fixed;
  left: -60%;
  right: -60%;
  top: -10%;
  bottom: -60%;
  z-index: 0;
  pointer-events: none;
  transform-origin: 50% 100%;
  transform: perspective(700px) rotateX(58deg);
  background:
    linear-gradient(to bottom, rgba(8, 6, 4, 1) 0%, rgba(8, 6, 4, 0.85) 18%, rgba(8, 6, 4, 0.15) 55%, rgba(8, 6, 4, 0) 75%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.55) 0 2px, transparent 2px 118px),
    repeating-linear-gradient(90deg, #3a2a1c 0 37px, #3f2e1f 37px 61px, #35261a 61px 90px, #412f20 90px 120px),
    #33251a;
  opacity: 0.95;
}
/* 内容放在桌面之上 */
body.skin-3d .main-layout,
body.skin-3d .game-screen,
body.skin-3d .creation-screen {
  position: relative;
  z-index: 1;
}
/* 顶栏保持 sticky 并压在内容之上（设置菜单要盖住下面的档案） */
body.skin-3d .top-bar { z-index: 50; }
/* 桌面露出来：去掉原本铺满的背景色 */
body.skin-archive.skin-3d {
  background: #0d0a07;
}

/* 纸张浮在桌上：更远更软的投影，随手叠放的错位 */
body.skin-3d .log-entry {
  box-shadow: 0 2px 0 #cbbf9f, 0 18px 26px rgba(0, 0, 0, 0.55), 0 40px 60px -20px rgba(0, 0, 0, 0.6);
}
body.skin-3d .log-entry:nth-child(4n + 1) { rotate: -0.7deg; }
body.skin-3d .log-entry:nth-child(4n + 2) { rotate: 0.5deg; translate: 6px 0; }
body.skin-3d .log-entry:nth-child(4n + 3) { rotate: -0.3deg; translate: -4px 0; }
body.skin-3d .log-entry:nth-child(4n) { rotate: 0.8deg; }
body.skin-3d .log-entry.entry-current {
  rotate: 0deg;
  translate: 0 0;
  box-shadow:
    0 1px 0 #ddd2b4,
    0 2px 0 #cfc3a2,
    0 3px 0 #c4b793,
    0 4px 0 #b8aa85,
    0 5px 0 #a99a75,
    0 26px 34px rgba(0, 0, 0, 0.6),
    0 60px 80px -20px rgba(0, 0, 0, 0.6),
    inset 40px 30px 70px rgba(255, 249, 232, 0.22),
    inset -20px -24px 60px rgba(90, 70, 40, 0.1);
}

/* V7.15：三栏都会自己滚动。给会滚动的栏加 3D 透视（rotateX / rotateY）后，Chrome 的点击判定会偏移，
   窗口越窄偏得越多（实测 821～1200px 宽时，左栏折叠标题和右栏标签页点不到）。
   所以三栏只用平面的 rotateZ 轻微歪斜，3D 感靠纸板厚度、投影、桌面透视和台灯光。改动后要跑 resize 点击测试。 */
@media (min-width: 821px) {
  body.skin-3d .main-layout { perspective: none; }
  body.skin-3d .panel-left { transform: rotateZ(-0.6deg); }
  body.skin-3d .panel-center { transform: none; }
  body.skin-3d .panel-right { transform: rotateZ(0.5deg); }
}

/* 手机：报告纸往后微倾，像斜放在桌上 */
@media (max-width: 820px) {
  body.skin-3d .panel-center {
    perspective: 1100px;
  }
  body.skin-3d .story-log .log-entry {
    transform: rotateX(3deg);
    transform-origin: 50% 100%;
  }
  body.skin-3d .story-log .log-entry.entry-current {
    transform: none;
  }
}

/* ==========================================================================
   V7.13 样板 C：3D 二十面骰 + 立体战斗卡
   ========================================================================== */
.d3-scene { display: none; }
body.skin-3d .d3-scene {
  display: block;
  position: relative;
  width: var(--d3);
  height: var(--d3);
  perspective: 520px;
  flex-shrink: 0;
}
body.skin-3d .d3-die {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
body.skin-3d .d3-face {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  backface-visibility: hidden;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: #4a3c28; /* 棱线 */
}
body.skin-3d .d3-fill {
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 5%, 96% 97.5%, 4% 97.5%);
  background: #e6dbc0;
}
body.skin-3d .d3-num {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -62%);
  font-family: var(--font-serif, 'Noto Serif SC', serif);
  font-weight: 700;
  line-height: 1;
  color: #3b1f14;
  text-shadow: 0 1px 0 rgba(255, 250, 235, 0.5);
}
body.skin-3d .d3-shadow {
  position: absolute;
  left: 50%;
  bottom: -4%;
  width: 78%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.65), transparent);
  transform: translateX(-50%);
}
/* 落定后：大成功金色描边、大失败暗红 */
body.skin-3d .d3-scene.landed.crit .d3-num { color: #8a5a00; }
body.skin-3d .d3-scene.landed.crit .d3-face { background: #d9a520; }
body.skin-3d .d3-scene.landed.fumble .d3-num { color: #8c1414; }
body.skin-3d .d3-scene.landed.fumble .d3-face { background: #7a1010; }
body.skin-3d .d3-scene.landed.crit { filter: drop-shadow(0 0 10px rgba(255, 196, 60, 0.75)); }
body.skin-3d .d3-scene.landed.fumble { filter: drop-shadow(0 0 10px rgba(200, 30, 30, 0.7)); }

/* 检定区：骰子替换原来的数字方块；滚动中先藏起结果，落定再揭晓 */
body.skin-3d #diceVisual { display: none; }
body.skin-3d .dice-box { gap: 18px; overflow: visible; }
body.skin-3d .dice-box .dice-formula,
body.skin-3d .dice-box .dice-result { transition: opacity 0.25s ease, transform 0.25s ease; }
body.skin-3d .dice-box.d3-pending .dice-formula,
body.skin-3d .dice-box.d3-pending .dice-result { opacity: 0; transform: translateY(4px); }

/* 战斗区小骰子：放在调查员卡右上角 */
body.skin-3d .d3-scene.d3-combat {
  position: absolute;
  right: 8px;
  bottom: 6px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 3;
}
body.skin-3d .d3-scene.d3-combat.show { opacity: 1; }

/* 立体战斗卡：两张卡斜着相对，有纸板厚度 */
body.skin-3d .combatants { perspective: 900px; padding: 6px 10px; }
body.skin-3d .combatant {
  --cb: rotateY(0deg);
  transform: var(--cb);
  transform-style: preserve-3d;
  box-shadow:
    1px 1px 0 #b9ab86,
    2px 2px 0 #a89a74,
    3px 3px 0 #978862,
    4px 4px 0 #85774f,
    6px 14px 22px rgba(0, 0, 0, 0.55);
}
body.skin-3d .combatant.player-side { --cb: rotateY(14deg) rotateX(4deg); --hit-y: 26deg; --lunge-x: 22px; }
body.skin-3d .combatant.enemy-side { --cb: rotateY(-14deg) rotateX(4deg); --hit-y: -26deg; --lunge-x: -22px; }

@keyframes card3dHit {
  0% { transform: var(--cb); }
  16% { transform: var(--cb) translateZ(-46px) rotateY(var(--hit-y)) rotateZ(calc(var(--hit-y) * -0.12)); box-shadow: 0 0 0 2px rgba(220, 50, 40, 0.85), 0 0 22px rgba(220, 50, 40, 0.6); }
  42% { transform: var(--cb) translateZ(-10px) rotateY(calc(var(--hit-y) * -0.35)); }
  68% { transform: var(--cb) rotateY(calc(var(--hit-y) * 0.12)); }
  100% { transform: var(--cb); }
}
/* 暴击：整张卡被打得翻一圈 */
@keyframes card3dCrit {
  0% { transform: var(--cb); filter: none; }
  12% { transform: var(--cb) translateZ(-60px) rotateY(calc(var(--hit-y) * 2)); filter: brightness(1.9) saturate(0.4); box-shadow: 0 0 0 3px rgba(255, 210, 90, 0.95), 0 0 30px rgba(255, 120, 40, 0.75); }
  60% { transform: var(--cb) translateZ(-20px) rotateY(calc(var(--hit-y) * 13.85)); filter: none; }
  82% { transform: var(--cb) rotateY(calc(var(--hit-y) * 13.6)); }
  100% { transform: var(--cb) rotateY(calc(var(--hit-y) * 13.846)); }
}
@keyframes card3dLunge {
  0% { transform: var(--cb); }
  35% { transform: var(--cb) translateX(var(--lunge-x)) translateZ(48px) rotateY(calc(var(--hit-y) * -0.6)); }
  100% { transform: var(--cb); }
}
/* 敌人倒下：卡片往后仰倒在桌上，再被烧掉 */
@keyframes card3dBurn {
  0% { transform: var(--cb); filter: none; opacity: 1; }
  25% { transform: var(--cb) rotateX(-12deg) translateZ(14px); filter: sepia(0.6) contrast(1.2); }
  100% { transform: var(--cb) rotateX(62deg) translateZ(-30px) translateY(18px); filter: sepia(1) brightness(0.45) blur(0.6px); opacity: 0.35; }
}
body.skin-3d .combatant.card-hit { animation: card3dHit 0.42s cubic-bezier(0.2, 0.8, 0.3, 1); }
body.skin-3d .combatant.card-hit-crit { animation: card3dCrit 0.62s cubic-bezier(0.2, 0.7, 0.3, 1); }
body.skin-3d .combatant.card-lunge { animation: card3dLunge 0.36s ease-out; }
body.skin-3d .combatant.card-burn { animation: card3dBurn 1.4s ease-in forwards; }

@media (prefers-reduced-motion: reduce) {
  body.skin-3d .combatant.card-hit,
  body.skin-3d .combatant.card-hit-crit,
  body.skin-3d .combatant.card-lunge { animation: none; }
  body.skin-3d .combatant.card-burn { animation: none; opacity: 0.35; }
}

/* 骰子落定前：继续按钮与本次检定的结果记录先不出现 */
body.skin-3d.d3-rolling #choicesArea,
body.skin-3d .log-entry.d3-hold { visibility: hidden; }

/* 建角页：档案夹斜放在桌上（只在电脑；整页滚动，不是内部滚动区，点击判定不受影响——改动后要跑 hit 测试） */
@media (min-width: 821px) {
  body.skin-3d .creation-screen { perspective: 1800px; perspective-origin: 50% 0%; }
  body.skin-3d .creation-card {
    transform: rotateX(3deg);
    transform-origin: 50% 0%;
  }
}
