/* 晚上躲怪物5 —— 夜半潜行 */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  background: #0b0714;
  color: #f6e8d8;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; border: 0; background: none; color: inherit; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
svg { display: block; }

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 100%;
  padding:
    max(8px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  gap: 8px;
  background:
    radial-gradient(120% 70% at 12% -8%, rgba(98, 58, 122, .55) 0%, rgba(30, 18, 48, 0) 55%),
    radial-gradient(90% 55% at 96% 4%, rgba(91, 48, 83, .42) 0%, rgba(20, 12, 32, 0) 60%),
    linear-gradient(180deg, #0d0818 0%, #171027 45%, #0b0714 100%);
}

/* ---------- ambient sky ---------- */
.sky { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.sky::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 18% 16%, rgba(255, 246, 226, .7), transparent 100%),
    radial-gradient(1.2px 1.2px at 72% 9%, rgba(255, 236, 205, .55), transparent 100%),
    radial-gradient(1.1px 1.1px at 88% 30%, rgba(199, 224, 255, .5), transparent 100%),
    radial-gradient(1.3px 1.3px at 33% 38%, rgba(255, 230, 200, .35), transparent 100%),
    radial-gradient(1px 1px at 9% 54%, rgba(255, 246, 226, .32), transparent 100%),
    radial-gradient(1.2px 1.2px at 56% 63%, rgba(199, 224, 255, .28), transparent 100%),
    radial-gradient(1.4px 1.4px at 91% 76%, rgba(255, 230, 200, .22), transparent 100%),
    radial-gradient(1px 1px at 24% 86%, rgba(255, 246, 226, .26), transparent 100%);
  opacity: .8;
  animation: twinkle 7s ease-in-out infinite alternate;
}
.star { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff4da; opacity: .35; }
.s1 { left: 8%; top: 22%; } .s2 { left: 29%; top: 8%; } .s3 { left: 47%; top: 28%; animation-delay: -1.4s; }
.s4 { left: 66%; top: 13%; } .s5 { left: 81%; top: 24%; animation-delay: -2.2s; } .s6 { left: 93%; top: 41%; }
.s7 { left: 14%; top: 47%; animation-delay: -3s; } .s8 { left: 38%; top: 58%; } .s9 { left: 74%; top: 52%; animation-delay: -1.8s; }
.s10 { left: 6%; top: 72%; } .s11 { left: 53%; top: 79%; animation-delay: -2.6s; } .s12 { left: 87%; top: 88%; }
.star { animation: starPulse 4.5s ease-in-out infinite alternate; }
@keyframes starPulse { from { opacity: .18; transform: scale(.8); } to { opacity: .7; transform: scale(1.25); } }
@keyframes twinkle { from { opacity: .55; } to { opacity: .9; } }
.moon-haze {
  position: absolute; right: -90px; top: -120px; width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 205, 148, .22) 0%, rgba(255, 158, 92, .09) 42%, transparent 68%);
  filter: blur(6px);
}

/* ---------- hud ---------- */
.hud {
  position: relative; z-index: 12; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  height: 44px; padding: 0 2px;
}
.hud-night {
  display: flex; align-items: center; gap: 7px; height: 38px;
  padding: 0 12px 0 5px; border-radius: 999px;
  background: linear-gradient(180deg, rgba(44, 29, 66, .84), rgba(25, 16, 42, .8));
  border: 1px solid rgba(255, 222, 184, .13);
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 255, 255, .07);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.moon-badge {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 32% 26%, #ffe6b8 0%, #ffb46b 48%, #d9782f 100%);
  box-shadow: 0 0 16px rgba(255, 145, 66, .45), inset 0 -2px 4px rgba(120, 52, 8, .32);
}
.night-copy { display: flex; align-items: baseline; gap: 6px; line-height: 1; }
.night-copy b { font-size: 13px; font-weight: 800; letter-spacing: .04em; color: #fff1dc; }
.night-copy em { font-style: normal; font-size: 10px; color: #b9a6c8; letter-spacing: .08em; }
.shard-track {
  display: flex; align-items: center; gap: 4px; height: 36px; padding: 0 10px;
  border-radius: 999px; background: rgba(21, 14, 35, .6);
  border: 1px solid rgba(255, 255, 255, .07);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.shard-slot {
  width: 18px; height: 18px; color: #ffce85; opacity: .24; transform: scale(.86);
  transition: opacity .25s ease, transform .3s cubic-bezier(.2, 1.5, .4, 1), filter .3s ease;
  filter: grayscale(1);
}
.shard-slot svg { width: 100%; height: 100%; }
.shard-slot.on { opacity: 1; transform: scale(1.08); filter: drop-shadow(0 0 6px rgba(255, 183, 94, .75)); }
.shard-slot.pop { animation: slotPop .45s ease; }
@keyframes slotPop { 0% { transform: scale(.6); } 55% { transform: scale(1.45); } 100% { transform: scale(1.08); } }
.hud-actions { display: flex; gap: 6px; flex: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: #f4e4d2;
  background: linear-gradient(180deg, rgba(44, 29, 66, .84), rgba(25, 16, 42, .8));
  border: 1px solid rgba(255, 222, 184, .13);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .85), inset 0 1px 0 rgba(255, 255, 255, .06);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
}
.icon-btn .mp-icon { width: 18px; height: 18px; opacity: .9; }
.icon-btn:active { transform: scale(.9); background: rgba(70, 44, 92, .9); }
.icon-btn:disabled { opacity: .32; }
.icon-btn:disabled:active { transform: none; }

/* ---------- stage / board ---------- */
.stage { position: relative; z-index: 5; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board {
  position: relative;
  width: min(calc(100vw - 20px), 470px);
  width: min(
    calc(100vw - 20px),
    470px,
    calc((100dvh - 285px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 0.7037)
  );
  min-width: 0;
  aspect-ratio: 760 / 1080;
  border-radius: 28px;
  overflow: hidden;
  background: #161022;
  box-shadow:
    0 34px 70px -26px rgba(0, 0, 0, .95),
    0 0 0 1px rgba(255, 225, 190, .1),
    0 0 42px -12px rgba(255, 138, 61, .22);
  isolation: isolate;
  touch-action: manipulation;
  transition: box-shadow .4s ease;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.entity-layer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.board-vignette {
  position: absolute; inset: 0; z-index: 7; pointer-events: none; border-radius: inherit;
  background:
    radial-gradient(120% 80% at 50% 34%, transparent 52%, rgba(5, 3, 10, .42) 100%),
    linear-gradient(180deg, rgba(8, 5, 15, .18), transparent 16%, transparent 84%, rgba(8, 5, 15, .26));
  box-shadow: inset 0 0 46px rgba(4, 2, 9, .55), inset 0 0 0 1px rgba(255, 232, 204, .06);
}
.tap-layer {
  position: absolute; z-index: 8;
  left: calc(30 / 760 * 100%); top: calc(50 / 1080 * 100%);
  width: calc(700 / 760 * 100%); height: calc(1000 / 1080 * 100%);
  display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(10, 1fr);
}
.cell-hit { width: 100%; height: 100%; border-radius: 10px; transition: background .15s ease; }
.cell-hit:active { background: rgba(255, 178, 105, .1); }

/* entities */
.ent { position: absolute; transform: translate(-50%, -50%); will-change: left, top; aspect-ratio: 1 / 1; }
.ent svg { width: 100%; height: 100%; }
.ent.cat { z-index: 6; width: 22%; transition: left .16s ease, top .16s ease; }
.ent.monster { z-index: 5; width: 24%; transition: left .18s ease, top .18s ease; }
.ent.shard { z-index: 4; width: 13%; transition: opacity .3s ease, transform .3s ease; }
.ent.shard svg { animation: shardFloat 3.2s ease-in-out infinite; overflow: visible; filter: drop-shadow(0 0 10px rgba(255, 193, 109, .45)); }
.ent.shard.taken { opacity: 0; transform: translate(-50%, -60%) scale(1.6); pointer-events: none; }
.cat-flip, .monster-flip { width: 100%; height: 100%; transition: transform .15s ease; }
.cat-flip.left, .monster-flip.left { transform: scaleX(-1); }
.ent.cat svg { overflow: visible; animation: catBob 3.4s ease-in-out infinite; }
.ent.cat.moving svg { animation: catHop .3s ease-out; }
.ent.monster svg { overflow: visible; animation: monsterBob 4.2s ease-in-out infinite; }
.ent.monster .pupil { transition: transform .18s ease; }
.ent.monster.spotted .monster-glow { opacity: 1; animation: alertGlow .5s ease-in-out infinite alternate; }
.hint-dot {
  position: absolute; width: 9px; height: 9px; border-radius: 50%; z-index: 3;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, #ffd8a2 0%, #ff9a4c 60%, rgba(255, 138, 61, 0) 72%);
  box-shadow: 0 0 10px rgba(255, 145, 70, .7);
  animation: dotPulse 1.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes dotPulse { 0%, 100% { opacity: .55; transform: translate(-50%, -50%) scale(.78); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); } }
@keyframes shardFloat { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-9%) rotate(5deg); } }
@keyframes catBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.5%); } }
@keyframes catHop { 0% { transform: translateY(0) scale(1); } 40% { transform: translateY(-9%) scale(1.04); } 100% { transform: translateY(0) scale(1); } }
@keyframes monsterBob { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-2%) rotate(1.4deg); } }
@keyframes alertGlow { from { opacity: .55; } to { opacity: 1; } }

/* status + banner */
.status-pill {
  position: relative; z-index: 11;
  display: flex; align-items: center; gap: 6px; max-width: calc(100% - 26px);
  padding: 7px 12px; border-radius: 999px; white-space: nowrap;
  background: rgba(16, 10, 26, .72);
  border: 1px solid rgba(255, 228, 194, .14);
  box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 11.5px; letter-spacing: .02em; color: #f4e5d3;
  transition: background .2s ease, color .2s ease, opacity .25s ease;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #ffb267; box-shadow: 0 0 8px #ff9a4c; flex: none; }
.status-pill.ready { background: rgba(255, 138, 61, .92); color: #341706; border-color: rgba(255, 229, 194, .6); }
.status-pill.ready .status-dot { background: #341706; box-shadow: none; }
.status-pill.flash { animation: statusFlash .35s ease; }
@keyframes statusFlash { 0% { transform: translateY(4px) scale(.96); } 100% { transform: translateY(0) scale(1); } }
.level-banner {
  position: absolute; z-index: 10; left: 0; right: 0; top: 11%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  opacity: 0; pointer-events: none; transform: translateY(8px);
}
.level-banner b {
  font-size: 21px; letter-spacing: .18em; color: #ffe9cc;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .9), 0 0 22px rgba(255, 138, 61, .5);
}
.level-banner span {
  font-size: 10px; letter-spacing: .28em; color: #e8b78a; padding-left: 8px;
  border-left: 1px solid rgba(255, 205, 158, .4);
}
.level-banner.show { animation: bannerIn 2.6s ease forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(10px); }
  18%, 72% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-6px); }
}
.catch-flash {
  position: absolute; inset: 0; z-index: 15; pointer-events: none; opacity: 0; border-radius: inherit;
  background: radial-gradient(circle at 50% 46%, rgba(255, 76, 60, .06) 30%, rgba(255, 42, 32, .55) 100%);
  box-shadow: inset 0 0 90px rgba(255, 42, 32, .7);
}
.board.danger .catch-flash { animation: dangerFlash .65s ease; }
.board.danger { animation: boardShake .5s ease; }
@keyframes dangerFlash { 0% { opacity: 0; } 18% { opacity: .95; } 100% { opacity: 0; } }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-7px) rotate(-.4deg); }
  32% { transform: translateX(6px) rotate(.35deg); }
  48% { transform: translateX(-4px); }
  64% { transform: translateX(3px); }
  80% { transform: translateX(-2px); }
}
.board.door-open { box-shadow: 0 34px 70px -26px rgba(0, 0, 0, .95), 0 0 0 1px rgba(255, 225, 190, .12), 0 0 60px -4px rgba(255, 163, 85, .4); }

/* ---------- scene motion ---------- */
.beam { transform-origin: 0 0; transform-box: view-box; transition: transform .18s ease; }
#doorGroup .door-lock { transition: opacity .3s ease, transform .3s ease; transform-box: fill-box; transform-origin: center; }
#doorGroup.open .door-lock { opacity: 0; transform: translateY(7px) scale(.45); }
#doorGroup .door-spill { transition: opacity .35s ease; }
#doorGroup.open .door-spill { opacity: .95; animation: doorBreath 2.2s ease-in-out infinite; }
#doorGroup .door-light { transition: opacity .3s ease; }
#doorGroup.open .door-light { opacity: 1; }
@keyframes doorBreath { 0%, 100% { opacity: .62; } 50% { opacity: 1; } }
.ent.cat.escaped svg { animation: catEscape .8s ease forwards; }
@keyframes catEscape { 0% { transform: translateY(0) scale(1); opacity: 1; } 100% { transform: translateY(-18%) scale(.72); opacity: 0; } }

/* ---------- controls ---------- */
.deck {
  position: relative; z-index: 9; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding-bottom: 2px;
}
.dpad {
  width: 146px; height: 146px; display: grid; gap: 5px;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, .45));
}
.dbtn {
  position: relative; display: grid; place-items: center; border-radius: 15px;
  color: #f6e5d1;
  background: linear-gradient(180deg, rgba(59, 39, 83, .92), rgba(28, 18, 44, .92));
  border: 1px solid rgba(255, 223, 186, .16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09), 0 3px 0 rgba(9, 5, 16, .7);
  transition: transform .09s ease, box-shadow .09s ease, background .15s ease;
  user-select: none; touch-action: manipulation;
}
.dbtn .mp-icon { width: 21px; height: 21px; opacity: .92; }
.dbtn:active { transform: translateY(2px) scale(.97); box-shadow: inset 0 2px 8px rgba(0, 0, 0, .4); background: rgba(80, 52, 106, .95); }
.dbtn.up { grid-area: 1 / 2; } .dbtn.left { grid-area: 2 / 1; } .dbtn.right { grid-area: 2 / 3; } .dbtn.down { grid-area: 3 / 2; }
.dbtn.wait {
  grid-area: 2 / 2; color: #3c1d08;
  background: radial-gradient(circle at 34% 24%, #ffd39a 0%, #ffa657 45%, #ff8438 100%);
  border-color: rgba(255, 246, 226, .55);
  box-shadow: 0 0 22px rgba(255, 140, 62, .36), inset 0 1px 0 rgba(255, 255, 255, .5), 0 3px 0 rgba(140, 60, 12, .55);
}
.dbtn.wait .mp-icon { width: 17px; height: 17px; opacity: .75; margin-bottom: 1px; }
.dbtn.wait span { font-size: 9px; font-weight: 800; letter-spacing: .18em; text-indent: .18em; line-height: 1; }
.dbtn.wait:active { background: radial-gradient(circle at 34% 24%, #ffc783 0%, #ff9445 45%, #ef6f23 100%); }
.tip {
  margin: 2px 0 0; text-align: center; font-size: 10.5px; line-height: 1.55; color: #cdbadb;
  letter-spacing: .03em; text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}
.tip span { color: #9f8bb3; font-size: 9.5px; letter-spacing: .02em; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s ease;
}
.modal.open { opacity: 1; visibility: visible; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: radial-gradient(90% 70% at 50% 40%, rgba(34, 20, 50, .72), rgba(6, 4, 11, .9));
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
}
.modal-card {
  position: relative; width: min(100%, 348px); border-radius: 28px; padding: 20px 20px 18px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 165, 92, .16), transparent 56%),
    linear-gradient(180deg, #2a1a3e 0%, #1a1029 100%);
  border: 1px solid rgba(255, 219, 178, .2);
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .08);
  text-align: center; transform: translateY(14px) scale(.97); transition: transform .3s cubic-bezier(.2, 1.2, .4, 1);
}
.modal.open .modal-card { transform: translateY(0) scale(1); }
.modal-art { width: 82px; height: 82px; margin: -50px auto 8px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 36% 30%, #4a2d5d, #22142f 70%);
  border: 1px solid rgba(255, 209, 156, .28);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .8), 0 0 30px rgba(255, 138, 61, .18);
}
.modal-art svg { width: 46px; height: 46px; overflow: visible; }
.modal-card h2 { margin: 4px 0 0; font-size: 21px; letter-spacing: .02em; color: #fff0db; font-weight: 800; }
.modal-card p { margin: 9px 0 0; font-size: 12.5px; line-height: 1.7; color: #bdaacb; }
.modal-stats { margin: 12px 0 0; font-size: 11px; letter-spacing: .08em; color: #e7b17f; min-height: 14px; }
.btn-primary {
  display: block; width: 100%; margin-top: 16px; padding: 13px 16px; border-radius: 16px;
  font-size: 14px; font-weight: 800; letter-spacing: .04em; color: #3a1a05;
  background: linear-gradient(180deg, #ffc07d 0%, #ff9a4c 42%, #ff8438 100%);
  border: 1px solid rgba(255, 242, 219, .6);
  box-shadow: 0 10px 24px -10px rgba(255, 123, 44, .65), inset 0 1px 0 rgba(255, 255, 255, .55);
  transition: transform .12s ease, filter .15s ease;
}
.btn-primary:active { transform: translateY(2px) scale(.985); filter: brightness(.96); }
.btn-ghost {
  display: block; width: 100%; margin-top: 8px; padding: 10px 14px; border-radius: 14px;
  font-size: 12px; letter-spacing: .04em; color: #cbb6da;
  border: 1px solid rgba(255, 255, 255, .08); background: rgba(255, 255, 255, .03);
  transition: background .15s ease;
}
.btn-ghost:active { background: rgba(255, 255, 255, .08); }
.btn-ghost[hidden] { display: none; }

/* short screens */
@media (max-height: 730px) {
  .dpad { width: 128px; height: 128px; gap: 4px; }
  .dbtn { border-radius: 13px; }
  .tip { font-size: 9.5px; line-height: 1.45; }
  .tip span { font-size: 8.5px; }
  .hud { height: 40px; }
  .hud-night, .icon-btn { height: 34px; }
  .icon-btn { width: 34px; }
  .shard-track { height: 32px; }
}
@media (max-width: 350px) {
  .night-copy b { font-size: 12px; }
  .shard-slot { width: 16px; height: 16px; }
  .status-pill { font-size: 10.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
