:root {
  --gold: #d8b25a;
  --gold-bright: #f0d488;
  --ink: #0b0d12;
  --hp: #c43a3a;
  --mp: #3a7bd5;
  --xp: #6bbf59;
  --boss: #8b2bc4;
}

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

html, body {
  height: 100%;
  background: #05060a;
  color: #e8e2d0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

#game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  background: #000;
  border: 1px solid #1d2230;
  box-shadow: 0 0 60px rgba(0,0,0,0.8), inset 0 0 0 2px #0a0c12;
  width: 960px;
  height: 600px;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 480 / 300;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  /* 小屏时贴边占满 */
  object-fit: contain;
}

/* ---------------- 触屏控件 ---------------- */
#touch-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
#touch-ui > * { pointer-events: auto; }

#joystick {
  position: absolute;
  left: 4%; bottom: 9%;
  width: 128px; height: 128px;
  pointer-events: auto;
  touch-action: none;
}
#joystick-base {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(20,24,34,0.4);
  border: 2px solid rgba(216,178,90,0.35);
}
#joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a5a7a, #1a2130);
  border: 2px solid rgba(216,178,90,0.6);
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* 环状操作区：闪避居中，法术沿拇指弧展开 */
#touch-actions {
  position: absolute;
  right: 22px; bottom: calc(26px + env(safe-area-inset-bottom));
  width: 176px; height: 176px;
  pointer-events: none;   /* 子按钮单独可点 */
}
#touch-actions .tbtn { pointer-events: auto; }
.tbtn {
  position: absolute;
  width: 54px; height: 54px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(24,28,40,0.55);
  border: 2px solid rgba(216,178,90,0.5);
  color: #e8dcc0;
  font-size: 19px; font-weight: 700;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
}
.tbtn:active { background: rgba(216,178,90,0.35); transform: scale(0.92); }
.tbtn[data-spell] { border-color: rgba(120,160,255,0.55); }

/* 攻击：中心大键（原闪避位） */
.tbtn.center {
  left: 50%; top: 50%;
  width: 76px; height: 76px;
  transform: translate(-50%, -50%);
  font-size: 28px;
  border-color: #e0c060; color: #ffe9a8;
  background: rgba(60,48,20,0.6);
}
.tbtn.center:active { transform: translate(-50%, -50%) scale(0.92); }

/* 四法术沿拇指弧（右下为锚点，向左上展开） */
.tbtn.r-a { right: 122px; bottom: 6px; }   /* 火（最顺手） */
.tbtn.r-b { right: 132px; bottom: 62px; }  /* 冰 */
.tbtn.r-c { right: 104px; bottom: 118px; } /* 电 */
.tbtn.r-d { right: 52px; bottom: 150px; }  /* 疗 */
.tbtn.r-e { right: 0; bottom: 130px; width: 42px; height: 42px; font-size: 15px; } /* F */
.tbtn.r-p { right: 176px; bottom: 112px; width: 40px; height: 40px; font-size: 15px; } /* Ⅱ */
/* 闪避：缩到弧上小键（紧邻火球上方，应急时伸手可达） */
.tbtn.r-dash { right: 60px; bottom: 4px; width: 46px; height: 46px; font-size: 16px; border-color: #7fc8ff; color: #dff0ff; background: rgba(30,46,70,0.55); }

/* ---------------- 手机适配 ---------------- */
@media (max-width: 900px) {
  #hud-top { padding: 10px 12px; gap: 10px; }
  #stats { min-width: 0; flex: 0 0 190px; }
  .bar-label { width: 28px; font-size: 11px; }
  #zone-name { font-size: 18px; letter-spacing: 2px; }
  #zone-sub { font-size: 10px; letter-spacing: 3px; }
  #revive-info { font-size: 10px; }
  #boss-name { font-size: 14px; }
  #boss-frame { top: 56px; width: 78%; }
  #skill-bar { gap: 4px; }
  .skill { width: 52px; height: 40px; }
  .skill .nm { font-size: 10px; }
  #hud-bottom { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  #hud-top { padding-top: max(10px, env(safe-area-inset-top)); }
}

.hidden { display: none !important; }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  background: linear-gradient(180deg, rgba(5,6,10,0.85), rgba(5,6,10,0));
}

#stats { display: flex; flex-direction: column; gap: 6px; min-width: 260px; }

.bar-wrap { display: flex; align-items: center; gap: 8px; }

.bar-label {
  width: 36px;
  font-size: 12px;
  letter-spacing: 2px;
  color: #9a8f74;
  text-align: right;
}

.bar {
  position: relative;
  flex: 1;
  height: 14px;
  background: rgba(20,22,30,0.85);
  border: 1px solid #2a2f3d;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}

.bar.xp { height: 8px; }

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.18s ease-out;
  border-radius: 2px 0 0 2px;
}

.bar-fill.hp { background: linear-gradient(90deg, #7a1f1f, var(--hp)); box-shadow: 0 0 8px rgba(196,58,58,0.5); }
.bar-fill.mp { background: linear-gradient(90deg, #1d3f7a, var(--mp)); box-shadow: 0 0 8px rgba(58,123,213,0.5); }
.bar-fill.xp { background: linear-gradient(90deg, #2f6b25, var(--xp)); box-shadow: 0 0 8px rgba(107,191,89,0.4); }
.bar-fill.boss { background: linear-gradient(90deg, #4a1370, var(--boss)); box-shadow: 0 0 12px rgba(139,43,196,0.6); }

.bar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  letter-spacing: 0.5px;
}

#zone-info { text-align: right; }
#zone-name { font-size: 22px; font-weight: 700; color: var(--gold-bright); letter-spacing: 4px; text-shadow: 0 0 12px rgba(216,178,90,0.4); }
#zone-sub { font-size: 12px; color: #8a7f64; letter-spacing: 6px; margin-top: 2px; }
#revive-info { font-size: 12px; color: #e0c060; letter-spacing: 3px; margin-top: 4px; text-shadow: 0 0 8px rgba(255,216,107,0.4); }

/* Boss frame */
#boss-frame {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  width: 60%;
  text-align: center;
  animation: bossIn 0.5s ease-out;
}
@keyframes bossIn { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
#boss-name { font-size: 18px; color: #d9a6ff; letter-spacing: 6px; margin-bottom: 5px; text-shadow: 0 0 14px rgba(139,43,196,0.7); }
.bar.boss { height: 12px; border-color: #4a1f6a; }

/* Skill bar */
#hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 14px 20px;
  display: flex;
  justify-content: center;
  background: linear-gradient(0deg, rgba(5,6,10,0.85), rgba(5,6,10,0));
}

#skill-bar { display: flex; gap: 8px; }

.skill {
  position: relative;
  width: 74px; height: 54px;
  background: rgba(18,20,28,0.9);
  border: 1px solid #2c3242;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
}

.skill .key {
  position: absolute;
  top: 2px; left: 4px;
  font-size: 9px;
  color: var(--gold);
  font-weight: 700;
}
.skill .cost {
  position: absolute;
  top: 2px; right: 4px;
  font-size: 9px;
  color: #5b8dd6;
}
.skill .nm { font-size: 12px; color: #cfc7b3; letter-spacing: 1px; }

.skill .cd {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  transform-origin: bottom;
}
.skill.ready { border-color: var(--gold); box-shadow: 0 0 10px rgba(216,178,90,0.25); }

/* ---------------- Overlay ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,12,20,0.92), rgba(2,3,6,0.98));
  z-index: 10;
  padding: 30px;
}

#overlay-inner {
  max-width: 640px;
  text-align: center;
}

.title-main {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 14px;
  color: var(--gold-bright);
  text-shadow: 0 0 30px rgba(216,178,90,0.5), 0 4px 0 rgba(0,0,0,0.6);
  margin-bottom: 6px;
  background: linear-gradient(180deg, #f5dca0, #b88a3c);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-sub {
  font-size: 14px;
  letter-spacing: 8px;
  color: #7a6f54;
  margin-bottom: 10px;
}

.title-note {
  font-size: 13px;
  letter-spacing: 1px;
  color: #8a7f64;
  margin-bottom: 24px;
  font-style: italic;
  opacity: 0.85;
}

.story {
  font-size: 15px;
  line-height: 2;
  color: #b8b0a0;
  margin-bottom: 26px;
  text-align: left;
  background: rgba(255,255,255,0.02);
  border-left: 2px solid var(--gold);
  padding: 16px 22px;
}

.story .speaker { color: var(--gold-bright); font-weight: 600; }
.story em { color: #c9a6e0; font-style: normal; }

.menu-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }

.btn {
  pointer-events: auto;
  cursor: pointer;
  background: linear-gradient(180deg, #2a2418, #181409);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 6px;
  padding: 12px 38px;
  border-radius: 3px;
  transition: all 0.18s;
  text-shadow: 0 0 8px rgba(216,178,90,0.4);
}
.btn:hover { background: linear-gradient(180deg, #3d3420, #241d0e); box-shadow: 0 0 18px rgba(216,178,90,0.4); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost { border-color: #3a3f4d; color: #9a9282; text-shadow: none; }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold-bright); }

.controls-hint {
  margin-top: 22px;
  font-size: 12px;
  color: #6f6755;
  line-height: 1.9;
  letter-spacing: 1px;
}
.controls-hint b { color: var(--gold); }

.chapter-title {
  font-size: 36px;
  letter-spacing: 16px;
  color: var(--gold-bright);
  margin-bottom: 8px;
  text-shadow: 0 0 24px rgba(216,178,90,0.4);
}
.chapter-place { font-size: 16px; color: #8a7f64; letter-spacing: 8px; margin-bottom: 24px; }

.end-flavor { font-size: 14px; color: #7a6f54; margin-top: 18px; letter-spacing: 2px; }

.victory-title { color: #f0d488; }
.gameover-title { color: #c43a3a; text-shadow: 0 0 30px rgba(196,58,58,0.5); -webkit-text-fill-color: #c43a3a; }
