:root {
  --amber: #f6c26b;
  --amber-dim: #c99a4b;
  --ink: #e8e4d8;
  --panel: rgba(12, 16, 26, 0.86);
  --panel-line: rgba(246, 194, 107, 0.28);
  --shadow: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #05070d;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#game-root {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 10%, #0c1220 0%, #05070d 60%),
    #05070d;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  z-index: 10;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 8px; max-width: 70%; }
.pill {
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--amber);
  box-shadow: 0 2px 12px var(--shadow);
}
.key-chip {
  align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--amber);
  font-size: 13px;
  letter-spacing: 0.06em;
  box-shadow: 0 2px 12px var(--shadow);
}
.key-chip img { width: 22px; height: auto; filter: drop-shadow(0 0 6px rgba(246,194,107,0.6)); }
.objective {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  text-shadow: 0 1px 4px #000;
  max-width: 30ch;
  background: rgba(5,7,13,0.5);
  padding: 6px 10px;
  border-radius: 8px;
  border-left: 3px solid var(--amber-dim);
}
.hud-right { display: flex; align-items: center; gap: 10px; }
.hearts { display: flex; gap: 5px; }
.heart {
  width: 20px; height: 20px;
  background: radial-gradient(circle at 35% 30%, #ffb8a0, #e0637a 70%);
  clip-path: polygon(50% 0%, 100% 38%, 88% 100%, 50% 82%, 12% 100%, 0% 38%);
  filter: drop-shadow(0 1px 3px #000);
}
.heart.lost { background: #3a3f4d; clip-path: polygon(50% 0%, 100% 38%, 88% 100%, 50% 82%, 12% 100%, 0% 38%); }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--amber);
  font-size: 17px;
  cursor: pointer;
}

/* ---------- Badges ---------- */
.badges {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px;
  z-index: 10;
  pointer-events: none;
}
.badge {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.1em;
}
.sneak-badge { background: rgba(60,120,150,0.85); color: #eaf6ff; }
.hide-badge { background: rgba(20,24,38,0.9); color: #cfd6e6; border: 1px solid #565e78; }

/* ---------- 灵视 side button ---------- */
.vision-btn {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  top: 17%;
  transform: translateY(-50%);
  z-index: 11;
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 1px solid var(--panel-line);
  background: rgba(10,14,24,0.82);
  color: var(--amber);
  font-size: 16px; line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
/* embedded (iframe) — push the top UI down below the outer shell */
.embedded .hud {
  padding-top: calc(52px + env(safe-area-inset-top));
}
.embedded .vision-btn {
  top: 26%;
}
.vision-btn small { display: block; font-size: 11px; color: #cfd6e6; }
.vision-btn.active { background: rgba(246,194,107,0.9); color: #221705; }
.vision-btn.spent { opacity: 0.45; cursor: default; }
.vision-btn:active { transform: translateY(-50%) scale(0.95); }

/* ---------- Touch controls ---------- */
.touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  bottom: 0;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  z-index: 12;
  pointer-events: none;
  touch-action: none;
}
.touch-controls button { pointer-events: auto; touch-action: none; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}
.dbtn {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(246,194,107,0.4);
  background: rgba(10,14,24,0.72);
  color: var(--amber);
  font-size: 20px;
  touch-action: none;
}
.dbtn[data-dir="up"]    { grid-column: 2; grid-row: 1; }
.dbtn[data-dir="left"]  { grid-column: 1; grid-row: 2; }
.dbtn[data-dir="right"] { grid-column: 3; grid-row: 2; }
.dbtn[data-dir="down"]  { grid-column: 2; grid-row: 3; }
.action-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-left: 12px; }
.abtn {
  min-width: 74px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--panel-line);
  background: rgba(10,14,24,0.78);
  color: var(--ink);
  font-size: 15px; line-height: 1.25;
  touch-action: none;
}
.abtn.sneak.active, .abtn.sneak:active { background: rgba(60,120,150,0.75); color: #eaf6ff; }
.abtn.act.active, .abtn.act:active { background: rgba(246,194,107,0.85); color: #1a1408; }
.abtn.restart { font-size: 13px; min-width: 60px; padding: 9px; align-self: flex-start; margin-top: 6px; }
.hud-right .abtn.restart { margin-top: 0; margin-left: auto; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: radial-gradient(90% 80% at 50% 40%, rgba(8,12,20,0.7), rgba(3,4,8,0.96));
  backdrop-filter: blur(2px);
  animation: fadeIn .35s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.title-box, .card {
  max-width: 620px;
  width: min(90vw, 620px);
  text-align: center;
  padding: 34px 30px;
}
.card-cg {
  display: block;
  width: min(92%, 540px);
  max-height: 340px;
  object-fit: contain;
  margin: 0 auto 16px;
  border-radius: 16px;
  border: 1px solid rgba(246,194,107,0.22);
  box-shadow: 0 12px 30px rgba(0,0,0,0.55);
}
@media (max-width: 480px) {
  .card-cg { width: min(84%, 310px); margin-bottom: 12px; }
}
/* Opening CG as the title backdrop */
.title-screen {
  background-image: radial-gradient(90% 80% at 50% 40%, rgba(6,10,18,0.35), rgba(3,4,8,0.86)), url("assets/cg-intro-cell.webp");
  background-size: cover;
  background-position: center 25%;
}
.title-box {
  padding: 26px 30px;
  background: rgba(7,11,19,0.72);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.6);
}
.kicker { letter-spacing: 0.5em; color: var(--amber-dim); font-size: 13px; margin-bottom: 10px; }
.title { font-size: clamp(30px, 6vw, 54px); letter-spacing: 0.06em; text-shadow: 0 0 24px rgba(246,194,107,0.35); }
.subtitle { margin-top: 12px; color: var(--ink); opacity: 0.8; font-size: 15px; }
.title-cat { margin: 22px auto 6px; width: 150px; height: 150px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 8px 22px rgba(0,0,0,0.7)); }
.title-cat img { max-width: 100%; max-height: 140px; object-fit: contain; }

.title-actions, .btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }
.map-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 16px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--ink); font-size: 13px;
  cursor: pointer;
}
.map-toggle input { accent-color: var(--amber); width: 16px; height: 16px; cursor: pointer; }
.primary-btn, .ghost-btn {
  padding: 13px 26px;
  border-radius: 999px;
  font-size: 16px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}
.primary-btn { background: linear-gradient(180deg, #f6c26b, #dca04a); color: #221705; border: none; box-shadow: 0 6px 18px rgba(0,0,0,0.5); font-weight: 600; }
.primary-btn:active { transform: translateY(1px) scale(0.98); }
.ghost-btn { background: transparent; border: 1px solid var(--panel-line); color: var(--ink); }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.card h2 { font-size: clamp(20px, 4vw, 30px); margin-bottom: 14px; color: var(--amber); }
.card p { line-height: 1.8; white-space: pre-line; opacity: 0.95; font-size: 15px; }
.howto-list { text-align: left; margin: 8px auto 4px; display: inline-block; }
.howto-list li { margin: 10px 0; line-height: 1.6; font-size: 14px; list-style: none; }
.howto-list li b { color: var(--amber); }

.card.win { position: relative; overflow: hidden; }
.win-glow { position: absolute; inset: -40%; background: radial-gradient(circle, rgba(246,194,107,0.35), transparent 60%); animation: pulse 3s ease-in-out infinite; pointer-events: none; }
@keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

/* ---------- Catch flash / toast ---------- */
.caught-banner {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 30;
  font-size: clamp(28px, 8vw, 54px);
  font-weight: 800;
  color: #ff5b6b;
  text-shadow: 0 0 24px rgba(255,60,80,0.7), 0 2px 6px #000;
  letter-spacing: 0.15em;
  pointer-events: none;
  animation: flash 0.9s ease;
}
@keyframes flash { 0% { opacity: 0; transform: translate(-50%,-50%) scale(0.7); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1); } }

.toast {
  position: absolute;
  top: calc(16% + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  z-index: 15;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  font-size: 14px;
  color: var(--ink);
  animation: fadeIn .2s ease;
  max-width: 86vw;
  text-align: center;
}

/* Desktop: show hint to use keyboard; hide touch controls */
@media (min-width: 760px) {
  .touch-controls { display: none !important; }
}
@media (max-width: 759px) {
  .touch-controls:not(.hidden) { display: flex !important; }
}
