/* ===== 奥了个奥 · 奥特曼 × 假面骑士（动效增强 / 低功耗版） ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: #fff;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  background:
    radial-gradient(1.5px 1.5px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 130px 80px, #9fd8ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70px 150px, #ffd9ec 50%, transparent 51%),
    radial-gradient(1px 1px at 200px 40px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 300px 120px, #b8ffd9 50%, transparent 51%),
    radial-gradient(1px 1px at 350px 200px, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40px 240px, #ffe9a8 50%, transparent 51%),
    radial-gradient(1px 1px at 260px 280px, #fff 50%, transparent 51%),
    radial-gradient(ellipse at 50% -20%, #2a1b5e 0%, transparent 60%),
    radial-gradient(ellipse at 50% 120%, #10305e 0%, transparent 60%),
    linear-gradient(180deg, #0b1026 0%, #17103a 55%, #0b1026 100%);
  background-size: 380px 320px, 380px 320px, 380px 320px, 380px 320px,
    380px 320px, 380px 320px, 380px 320px, 380px 320px, 100% 100%, 100% 100%, 100% 100%;
}

#app {
  height: 100vh;
  height: 100dvh; /* 动态视口高度：移动端地址栏收缩时始终占满全屏 */
  display: flex; flex-direction: column; align-items: center;
}

/* ===== 顶部 HUD ===== */
#hud {
  width: 100%; max-width: 480px;
  display: flex; gap: 6px; align-items: center; justify-content: center;
  padding: calc(8px + env(safe-area-inset-top)) 10px 6px;
  z-index: 50;
}
.hud-chip {
  background: rgba(30, 36, 80, .82);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px; font-weight: 700;
  white-space: nowrap;
}
#hudLevel { color: #ffd54f; }
.hud-btn { cursor: pointer; transition: transform .15s, background .15s; }
.hud-btn:active { transform: scale(.88); background: rgba(255,255,255,.22); }

/* ===== 舞台缩放 ===== */
#stageWrap { flex: 1; width: 100%; display: flex; justify-content: center; overflow: hidden; }
#stage { width: 440px; height: 740px; transform-origin: top center; position: relative; }

/* ===== 牌桌 ===== */
#board { position: relative; width: 440px; height: 500px; margin: 0 auto; }
#board.board-hit { animation: boardHitKf .3s ease; }
@keyframes boardHitKf {
  25% { transform: translateY(-5px); }
  55% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* ===== 牌（动画只走 transform / opacity，GPU 合成，不触发重排重绘） ===== */
.tile {
  position: absolute;
  width: 64px; height: 64px;
  border-radius: 13px;
  background: linear-gradient(145deg, #ffffff 0%, #e9edff 100%);
  box-shadow: 0 5px 0 rgba(8, 10, 40, .45), 0 8px 16px rgba(0, 0, 0, .35),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  transition: filter .2s ease, transform .15s ease;
}
.tile .e { font-size: 29px; line-height: 1.1; pointer-events: none; }
.tile .n { font-size: 12px; font-weight: 800; color: #2b2f55; margin-top: 1px; pointer-events: none; letter-spacing: 1px; }
/* 自定义牌面图片：assets/tiles/<id>.png 存在时自动替换 emoji */
.tile .pic { display: none; width: 42px; height: 42px; object-fit: contain; pointer-events: none; }
.tile.has-img .pic { display: block; }
.tile.has-img .e { display: none; }
.tile.in-tray .pic, .tile.in-hold .pic { width: 34px; height: 34px; }
.tile.side-ultra { border-bottom: 4px solid #ff2d55; }
.tile.side-rider { border-bottom: 4px solid #00e676; }

/* 可点击牌的光晕呼吸：伪元素 opacity 动画，合成器直接处理，低功耗 */
.tile.free::after {
  content: ''; position: absolute; inset: -4px;
  border-radius: 16px;
  box-shadow: 0 0 16px 2px rgba(150, 200, 255, .55);
  opacity: 0; pointer-events: none;
  animation: glowPulse 2.8s ease-in-out infinite;
}
@keyframes glowPulse { 50% { opacity: .45; } }
.tile.free:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 9px 0 rgba(8,10,40,.45), 0 14px 22px rgba(0,0,0,.4), 0 0 18px rgba(255,235,130,.55);
}
.tile.blocked { filter: brightness(.42) saturate(.55); cursor: not-allowed; }

/* 入场错落动画 */
.tile.spawning { animation: spawnIn .42s cubic-bezier(.34, 1.56, .64, 1) backwards; }
@keyframes spawnIn {
  from { transform: scale(0) rotate(-25deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

/* 洗牌翻转 */
.tile.flipping { animation: flipY .4s ease; }
@keyframes flipY { 50% { transform: rotateY(90deg) scale(1.05); } }

/* 卡槽 / 暂存区中的牌 */
.tile.in-tray, .tile.in-hold {
  position: static;
  width: 52px; height: 52px;
  border-radius: 11px;
  box-shadow: 0 3px 0 rgba(8, 10, 40, .45), 0 4px 10px rgba(0, 0, 0, .3);
  animation: none;
}
.tile.in-tray::after, .tile.in-hold::after { display: none; }
.tile.in-tray .e, .tile.in-hold .e { font-size: 23px; }
.tile.in-tray .n, .tile.in-hold .n { font-size: 10px; }
.tile.in-hold { cursor: pointer; }
.tile.in-hold:hover { transform: translateY(-3px) scale(1.06); }

.tile.matching { animation: pop .34s ease forwards !important; }
/* 提示高亮：金色脉冲（opacity 通道，低功耗） */
.tile.hinted { z-index: 999; }
.tile.hinted::after {
  content: ''; position: absolute; inset: -5px;
  border-radius: 17px;
  box-shadow: 0 0 22px 5px rgba(255, 215, 64, .95);
  opacity: 0; pointer-events: none;
  animation: hintBlink .5s ease-in-out 5;
}
@keyframes hintBlink { 50% { opacity: 1; } }
.tile.land { animation: landPop .26s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes landPop {
  0% { transform: scale(.55); }
  60% { transform: scale(1.16); }
  100% { transform: scale(1); }
}
.tile.shake { animation: shake .3s ease; }
.tile.flying { pointer-events: none; margin: 0; animation: none; will-change: transform; }

@keyframes pop {
  35% { transform: scale(1.3) rotate(8deg); filter: brightness(1.4); }
  100% { transform: scale(0) rotate(-12deg); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ===== 消除粒子 & 飘分（fixed + transform，合成器动画） ===== */
.particle {
  position: fixed; z-index: 9998; pointer-events: none;
  font-size: 18px; line-height: 1;
  transform: translate(-50%, -50%);
  animation: burstGo .68s cubic-bezier(.2, .7, .4, 1) forwards;
  will-change: transform, opacity;
}
@keyframes burstGo {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.35); }
}
.float-score {
  position: fixed; z-index: 9998; pointer-events: none;
  transform: translate(-50%, -50%);
  font-size: 26px; font-weight: 900; color: #ffd54f; white-space: nowrap;
  text-shadow: 0 2px 10px rgba(255, 150, 0, .6), 0 1px 2px #000;
  animation: floatUp .9s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes floatUp {
  20% { transform: translate(-50%, -95%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -240%) scale(.95); opacity: 0; }
}

/* ===== 关卡横幅 ===== */
#banner {
  position: fixed; left: 50%; top: 34%;
  transform: translate(-50%, -50%) scale(.6);
  z-index: 120; pointer-events: none;
  font-size: 38px; font-weight: 900; letter-spacing: 6px; white-space: nowrap;
  background: linear-gradient(90deg, #ffd54f, #ff8a65 45%, #4dff9d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, .75));
  opacity: 0;
}
#banner.show { animation: bannerIn 1.5s cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  26% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -56%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -72%) scale(.96); }
}

/* ===== 暂存区 ===== */
#holdRow {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 6px 0 4px;
  min-height: 56px;
}
.row-label { font-size: 12px; color: rgba(255,255,255,.55); font-weight: 700; }
.hold-slot {
  width: 54px; height: 54px;
  border: 2px dashed rgba(255, 215, 100, .4);
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 215, 100, .05);
}

/* ===== 卡槽 ===== */
#trayRow {
  display: flex; justify-content: center; gap: 6px;
  background: rgba(10, 14, 45, .72);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255,255,255,.08);
  border-radius: 16px;
  padding: 8px 10px;
  width: 436px; margin: 0 auto;
}
.slot {
  width: 54px; height: 54px;
  border-radius: 11px;
  background: rgba(255, 255, 255, .06);
  border: 2px dashed rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center;
}
.slot.danger { border-color: rgba(255, 60, 90, .75); animation: slotBlink .8s ease infinite; }
@keyframes slotBlink { 50% { background: rgba(255, 60, 90, .22); } }

/* ===== 道具 ===== */
#props { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; margin-top: 12px; }
.prop-btn {
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, .22);
  background: linear-gradient(160deg, rgba(90, 110, 255, .35), rgba(150, 70, 255, .35));
  color: #fff;
  font-size: 13px; font-weight: 700;
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(60, 60, 200, .35);
  transition: transform .12s, opacity .2s;
}
.prop-btn b { color: #ffd54f; margin-left: 2px; }
.prop-btn:active { transform: scale(.92); }
.prop-btn:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

/* ===== 弹层 ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 30, .78);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
  padding: 20px;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.panel {
  width: 100%; max-width: 380px;
  background: linear-gradient(165deg, rgba(40, 30, 90, .95), rgba(15, 18, 55, .97));
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255,255,255,.12);
  transform: scale(.85) translateY(20px);
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
  max-height: 92vh; overflow-y: auto;
}
.overlay.show .panel { transform: scale(1) translateY(0); }

.game-title {
  font-size: 46px; font-weight: 900; letter-spacing: 4px;
  background: linear-gradient(90deg, #ff5f6d, #ffd54f 40%, #4dff9d 75%, #40c4ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 14px rgba(255, 120, 120, .35));
}
.game-sub { margin: 8px 0 16px; font-size: 15px; color: rgba(255,255,255,.85); font-weight: 700; }
.game-sub .vs { color: #ffd54f; font-weight: 900; }

.demo-tiles { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.demo-tiles .tile { position: static; width: 52px; height: 52px; cursor: default; animation: none; }
.demo-tiles .tile::after { display: none; }
.demo-tiles .tile .e { font-size: 23px; }
.demo-tiles .tile .n { font-size: 10px; }

.big-btn {
  font-family: inherit;
  display: block; width: 100%;
  border: none;
  border-radius: 16px;
  padding: 15px 0;
  font-size: 19px; font-weight: 900; letter-spacing: 2px;
  color: #1a1030;
  background: linear-gradient(90deg, #ffd54f, #ffab40);
  box-shadow: 0 6px 0 #b26a00, 0 12px 26px rgba(255, 170, 40, .4);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b26a00, 0 6px 14px rgba(255,170,40,.35); }
.ghost-btn {
  font-family: inherit;
  display: block; width: 100%; margin-top: 12px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 16px;
  padding: 12px 0;
  font-size: 15px; font-weight: 700;
  color: rgba(255, 255, 255, .85);
  background: transparent;
  cursor: pointer;
}
.ghost-btn:active { transform: scale(.97); }

.howto { margin-top: 18px; text-align: left; font-size: 13px; color: rgba(255,255,255,.8); }
.howto summary { cursor: pointer; text-align: center; font-weight: 800; color: #9fd8ff; }
.howto ul { margin: 10px 0 0 18px; line-height: 1.9; }
.howto b { color: #ffd54f; }
.best-line { margin-top: 14px; font-size: 13px; color: rgba(255,255,255,.6); }
.best-line span { color: #ffd54f; font-weight: 800; }

#resultTitle { font-size: 34px; font-weight: 900; letter-spacing: 2px; }
#resultDesc { margin: 10px 0 18px; font-size: 14px; color: rgba(255,255,255,.8); line-height: 1.7; }
.result-stats { display: flex; justify-content: center; gap: 24px; margin-bottom: 22px; font-size: 15px; }
.result-stats b { color: #ffd54f; font-size: 19px; margin-left: 4px; }

/* ===== Toast ===== */
#toast {
  position: fixed; left: 50%; bottom: 18%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 24, 60, .92);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #ffd54f;
  font-size: 14px; font-weight: 700;
  padding: 10px 20px;
  border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 庆祝彩带 ===== */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 150; overflow: hidden; }
#confetti span {
  position: absolute; top: -40px;
  font-size: 26px;
  animation: confettiFall linear forwards;
  will-change: transform;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* ===== 低功耗：切后台暂停一切动画；尊重系统"减弱动态效果" ===== */
body.bg-paused *, body.bg-paused *::before, body.bg-paused *::after {
  animation-play-state: paused !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01s !important;
  }
}
