:root {
  --ink: #2b2433;
  --ink-soft: #4a3f52;
  --parchment: #f6ead2;
  --parchment-2: #ecdcbb;
  --parchment-3: #dfc99f;
  --moss: #35563d;
  --moss-deep: #1b2f25;
  --moss-dark: #12211a;
  --gold: #e8b45c;
  --gold-deep: #b4772d;
  --magic: #8767e8;
  --magic-2: #5b8df0;
  --rose: #d75f55;
  --green: #6fbf73;
  --shadow: rgba(20, 16, 26, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --btn-scale: 1;
  --joy-scale: 1;
  --ui: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #17251d;
  color: var(--ink);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body { touch-action: none; }

button, input, select { font-family: var(--ui); }
button { cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }

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

#vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background:
    radial-gradient(ellipse at center, transparent 52%, rgba(18, 14, 24, 0.20) 78%, rgba(14, 11, 20, 0.52) 100%),
    linear-gradient(to bottom, rgba(20, 28, 20, 0.05), transparent 22%, transparent 78%, rgba(16, 22, 16, 0.12));
}
#time-tint {
  position: absolute; inset: 0; pointer-events: none; z-index: 3; opacity: 0;
  background:
    radial-gradient(circle at 50% 48%, rgba(120, 150, 255, 0.04), rgba(46, 66, 150, 0.24) 75%, rgba(24, 30, 70, 0.5)),
    repeating-radial-gradient(circle at 50% 50%, rgba(160, 190, 255, 0.1) 0 1px, transparent 2px 12px);
  transition: opacity .25s ease;
}
#time-tint.on { opacity: 1; animation: timePulse 2.4s ease-in-out infinite; }
@keyframes timePulse { 50% { opacity: .75; } }

#damage-flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 4; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(190, 40, 30, 0.55) 100%);
  transition: opacity .22s ease;
}
#damage-flash.on { opacity: 1; transition: none; }

/* ============ HUD ============ */
#hud {
  position: absolute; inset: 0; z-index: 10;
  pointer-events: none;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
}
#hud > * { pointer-events: none; }

#hud-top-left {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  display: flex; flex-direction: column; gap: 8px;
}
.hud-brand {
  display: flex; align-items: center; gap: 8px;
  color: #f8efd8;
  font-size: 15px;
  text-shadow: 0 2px 0 rgba(18, 22, 16, 0.55), 0 0 14px rgba(0,0,0,.25);
  letter-spacing: 1px;
}
.brand-mark { color: var(--gold); font-size: 18px; }
.chip {
  font-size: 11px; color: #e9f0d9; letter-spacing: 0;
  background: rgba(28, 42, 32, 0.62);
  border: 1px solid rgba(248, 239, 216, 0.28);
  padding: 2px 7px; border-radius: 2px;
  backdrop-filter: blur(4px);
}
.hud-card {
  background: linear-gradient(180deg, rgba(30, 42, 32, 0.80), rgba(24, 34, 27, 0.76));
  border: 1px solid rgba(238, 224, 186, 0.22);
  box-shadow: 0 4px 18px rgba(10, 16, 12, 0.25), inset 0 0 0 1px rgba(255,255,255,.03);
  border-radius: 3px;
  color: #f3ead3;
  backdrop-filter: blur(6px);
}
.status-card { padding: 7px 10px; width: 236px; }
.status-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.status-row.small { margin-top: 5px; gap: 10px; color: #cfddbb; font-size: 11px; }
.status-row.small b { color: var(--gold); font-weight: normal; }
.status-label { color: #d9e6c6; font-size: 11px; }
.bar { flex: 1; height: 9px; background: rgba(8, 14, 10, 0.6); border: 1px solid rgba(238, 224, 186, 0.25); }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7fcb72, #b8dc75); transition: width .18s ease; }
#health-text { font-size: 11px; color: #e9f0d9; width: 26px; text-align: right; }
.fps { margin-left: auto; color: #9ccf8d; }

#hud-top-right {
  position: absolute;
  top: calc(10px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  display: flex; gap: 6px; align-items: flex-start;
}
.icon-btn {
  pointer-events: auto;
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 52px; height: 50px; padding: 4px 6px;
  color: #f4ecd8;
  background: linear-gradient(180deg, rgba(41, 57, 44, 0.82), rgba(26, 38, 30, 0.82));
  border: 1px solid rgba(238, 224, 186, 0.28);
  border-radius: 3px;
  box-shadow: 0 3px 0 rgba(12, 18, 14, 0.45);
  backdrop-filter: blur(6px);
  transition: transform .08s ease, background .12s ease, border-color .12s ease;
}
.icon-btn:hover { background: linear-gradient(180deg, rgba(56, 76, 58, 0.9), rgba(33, 48, 38, 0.9)); border-color: rgba(232, 180, 92, 0.6); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(12, 18, 14, 0.45); }
.icon-btn .ic { font-size: 17px; line-height: 1; height: 19px; display: flex; align-items: center; }
.icon-btn .glyph { font-size: 15px; color: var(--gold); }
.icon-btn .ib-label { font-size: 10px; letter-spacing: 0.5px; color: #d9e3c8; }
.keycap {
  font-size: 9px; line-height: 1.3; padding: 0 3px;
  border: 1px solid rgba(238, 224, 186, 0.32);
  border-bottom-width: 2px;
  border-radius: 2px;
  color: #c9d7b7;
  background: rgba(10, 16, 12, 0.3);
}
.icon-btn .keycap { position: absolute; top: 2px; right: 3px; font-size: 8px; }

/* 准星与蓄力 */
#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 64px; height: 64px; transform: translate(-50%, -50%);
  color: var(--gold);
  opacity: .92; transition: opacity .15s;
}
#crosshair.no-crosshair { opacity: 0; }
#crosshair svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#crosshair .charge-track { fill: none; stroke: rgba(248, 239, 216, 0.18); stroke-width: 2; }
#crosshair .charge-ring {
  fill: none; stroke: var(--gold); stroke-width: 3;
  stroke-linecap: butt;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
  filter: drop-shadow(0 0 4px rgba(232, 180, 92, 0.5));
  transition: stroke .2s;
}
#crosshair .dot {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px;
  transform: translate(-50%, -50%);
  background: #fff7df;
  box-shadow: 0 0 5px rgba(255, 240, 200, 0.9);
  border-radius: 50%;
}
#hit-marker {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6);
  font-size: 26px; color: #ffe9ad; opacity: 0;
  text-shadow: 0 0 8px rgba(255, 210, 120, 0.9);
  pointer-events: none;
}
#hit-marker.pop { animation: hitpop .28s ease-out; }
@keyframes hitpop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.5); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

#cast-readout {
  position: absolute; left: 50%; top: calc(50% + 44px);
  transform: translateX(-50%);
  display: flex; gap: 8px; align-items: baseline;
  font-size: 12px; color: #fbf1d9;
  text-shadow: 0 2px 4px rgba(0,0,0,.5);
  opacity: 0; transition: opacity .18s;
  white-space: nowrap;
}
#cast-readout.on { opacity: 1; }
#cast-charge { color: var(--gold); font-size: 11px; }

/* 法术栏 */
#spellbar {
  position: absolute; left: 50%; bottom: calc(12px + var(--safe-b));
  transform: translateX(-50%);
  display: flex; gap: 5px;
  pointer-events: auto;
  padding: 6px;
  background: linear-gradient(180deg, rgba(26, 38, 30, 0.72), rgba(18, 28, 22, 0.82));
  border: 1px solid rgba(238, 224, 186, 0.22);
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(8, 14, 10, 0.35);
  backdrop-filter: blur(7px);
}
.spell-slot {
  position: relative;
  width: 60px; height: 62px;
  padding: 3px 2px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: rgba(9, 15, 11, 0.45);
  border: 1px solid rgba(238, 224, 186, 0.16);
  border-radius: 2px;
  color: #e8e1cc;
  transition: transform .1s ease, border-color .15s, background .15s;
  overflow: hidden;
  touch-action: manipulation;
}
.spell-slot:hover { border-color: rgba(232, 180, 92, 0.55); background: rgba(22, 34, 26, 0.7); }
.spell-slot .slot-icon { width: 30px; height: 30px; image-rendering: auto; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.spell-slot .slot-name { font-size: 9px; color: #d8e2c8; white-space: nowrap; line-height: 1; }
.spell-slot .slot-key {
  position: absolute; top: 2px; left: 3px;
  font-size: 8px; color: #9fb28f;
}
.spell-slot .slot-cd {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 0%;
  background: rgba(8, 12, 9, 0.66);
  pointer-events: none;
}
.spell-slot.active {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(77, 64, 38, 0.7), rgba(32, 40, 28, 0.8));
  box-shadow: 0 0 0 1px rgba(232, 180, 92, 0.28), 0 0 14px rgba(232, 180, 92, 0.23);
  transform: translateY(-3px);
}
.spell-slot.active .slot-name { color: #ffe9b8; }
.spell-slot .slot-glow {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 34%, var(--spell-color, #e8b45c) 0%, transparent 68%);
  mix-blend-mode: screen;
}
.spell-slot.active .slot-glow { opacity: .25; }

/* 小提示卡 */
#quick-help {
  position: absolute;
  left: calc(12px + var(--safe-l));
  bottom: calc(12px + var(--safe-b));
  width: 268px;
  padding: 9px 11px 10px;
  font-size: 11px;
  transition: opacity .2s, transform .2s;
}
#quick-help.off { opacity: 0; transform: translateY(8px); pointer-events: none; }
.qh-title { color: var(--gold); font-size: 11px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.qh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; color: #dbe6cc; }
.qh-grid b { color: #f5edda; font-weight: normal; }
.qh-tip { margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(238, 224, 186, 0.16); color: #aebf9b; font-size: 10px; }

/* 手势小窗 */
#gesture-hud { position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(200px + var(--safe-b)); pointer-events: auto; }
.gesture-panel { display: flex; gap: 8px; padding: 7px; width: 300px; }
.gesture-video-wrap { position: relative; width: 140px; height: 105px; background: #101a14; overflow: hidden; border: 1px solid rgba(238,224,186,.2); }
#gesture-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
#gesture-video.no-mirror { transform: none; }
#gesture-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-state { position: absolute; left: 3px; bottom: 3px; font-size: 9px; color: #c6e0c0; background: rgba(10,18,12,.6); padding: 1px 4px; }
.gesture-info { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.gesture-title { display: flex; align-items: center; gap: 6px; color: #f4ecd8; font-size: 13px; }
#gesture-dot { width: 7px; height: 7px; border-radius: 50%; background: #7fd278; box-shadow: 0 0 6px #7fd278; }
#gesture-dot.bad { background: #e0a14a; box-shadow: 0 0 6px #e0a14a; }
.gesture-meter { height: 6px; background: rgba(8,14,10,.65); border: 1px solid rgba(238,224,186,.2); }
.gesture-meter i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #8f7be8, #73d2c0); transition: width .15s; }
.gesture-actions { display: flex; gap: 4px; }
.mini-btn {
  background: rgba(54, 74, 56, 0.75); color: #e9f0d9; border: 1px solid rgba(238,224,186,.22);
  font-size: 10px; padding: 3px 7px; border-radius: 2px;
}
.mini-btn:hover { border-color: var(--gold); }
.mini-btn.danger { color: #f0c4b8; border-color: rgba(217, 95, 85, 0.4); }

/* ============ 触屏控件 ============ */
#touch-ui { position: absolute; inset: 0; z-index: 18; pointer-events: none; }
#touch-ui > * { pointer-events: auto; }
#joystick {
  --joy-d: calc(132px * var(--joy-scale));
  position: absolute;
  left: calc(22px + var(--safe-l));
  bottom: calc(88px + var(--safe-b));
  width: var(--joy-d); height: var(--joy-d);
  border-radius: 50%;
  touch-action: none;
}
.joystick-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(246, 234, 210, 0.35);
  background: radial-gradient(circle, rgba(30, 44, 34, 0.34) 0%, rgba(20, 32, 24, 0.16) 65%, transparent 70%);
  box-shadow: inset 0 0 18px rgba(10, 18, 12, 0.35), 0 0 0 6px rgba(20, 32, 24, 0.1);
}
#joystick::before, #joystick::after {
  content: ""; position: absolute; background: rgba(246, 234, 210, 0.16);
}
#joystick::before { width: 1px; height: 60%; left: 50%; top: 20%; }
#joystick::after { height: 1px; width: 60%; top: 50%; left: 20%; }
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--joy-d) * 0.42); height: calc(var(--joy-d) * 0.42);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, rgba(255, 245, 222, 0.9), rgba(181, 195, 143, 0.65) 45%, rgba(76, 100, 72, 0.8));
  border: 2px solid rgba(255, 248, 228, 0.55);
  box-shadow: 0 5px 14px rgba(8, 14, 10, 0.5), inset 0 0 12px rgba(255,255,255,.15);
}
#joystick.dashing #joystick-knob { box-shadow: 0 0 20px rgba(232, 180, 92, 0.9), 0 5px 14px rgba(8, 14, 10, 0.5); }
.joystick-tip {
  position: absolute; left: 50%; bottom: -17px; transform: translateX(-50%);
  font-size: 9px; color: rgba(238, 230, 208, 0.6); white-space: nowrap;
}
#touch-actions {
  position: absolute; right: calc(20px + var(--safe-r)); bottom: calc(84px + var(--safe-b));
  display: flex; align-items: flex-end; gap: calc(12px * var(--btn-scale));
}
.touch-round {
  --d: calc(64px * var(--btn-scale));
  width: var(--d); height: var(--d); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #f8f0db; font-size: calc(15px * var(--btn-scale));
  background: radial-gradient(circle at 38% 32%, rgba(84, 110, 78, 0.9), rgba(36, 54, 42, 0.88));
  border: 2px solid rgba(246, 234, 210, 0.4);
  box-shadow: 0 5px 16px rgba(8, 14, 10, 0.42), inset 0 -4px 0 rgba(8, 14, 10, 0.25);
  touch-action: none;
}
.touch-round.cast {
  --d: calc(86px * var(--btn-scale));
  background: radial-gradient(circle at 36% 30%, rgba(182, 146, 224, 0.94), rgba(92, 64, 150, 0.92) 55%, rgba(48, 36, 86, 0.95));
  border-color: rgba(255, 224, 168, 0.55);
}
.touch-round.held { transform: scale(0.94); filter: brightness(1.25); }
#btn-jump { margin-bottom: calc(6px * var(--btn-scale)); }
.touch-corner {
  position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(10px + var(--safe-b));
  font-size: 9px; color: rgba(238, 230, 208, 0.6);
  background: transparent; border: 1px solid rgba(238, 230, 208, 0.22);
  border-radius: 2px; padding: 2px 6px;
}
#touch-ui.big .touch-round { border-width: 3px; }

/* ============ 覆盖界面 ============ */
#screens { position: absolute; inset: 0; z-index: 40; pointer-events: none; }
.screen {
  position: absolute; inset: 0;
  display: none;
  pointer-events: auto;
  overflow: auto;
  overscroll-behavior: contain;
  isolation: isolate;
}
.screen.open { display: flex; }
.screen.modal {
  align-items: center; justify-content: center;
  background: rgba(16, 16, 22, 0.52);
  backdrop-filter: blur(7px);
  padding: 18px;
}
.screen:not(.modal) { background: transparent; }

/* 加载 */
#screen-loading {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(92, 118, 76, 0.32), transparent 55%),
    radial-gradient(ellipse at 50% 100%, #24382a, #101b15 70%);
  color: #f4ecd8;
  z-index: 60;
}
.loading-wrap { text-align: center; width: min(520px, 84vw); }
.loading-sigil {
  font-size: 44px; color: var(--gold);
  animation: sigilSpin 8s linear infinite;
  text-shadow: 0 0 22px rgba(232, 180, 92, 0.45);
  margin-bottom: 2px;
}
@keyframes sigilSpin { to { transform: rotate(360deg); } }
.game-logo {
  font-family: var(--ui);
  font-size: clamp(38px, 8vw, 64px);
  margin: 0 0 4px;
  letter-spacing: 5px;
  color: #fbf0d2;
  text-shadow:
    0 3px 0 #6b4a28,
    0 6px 0 rgba(40, 28, 40, 0.65),
    0 0 28px rgba(232, 180, 92, 0.18);
  line-height: 1.12;
}
.game-logo.big { font-size: calc(clamp(56px, 8.6vw, 96px) * var(--site-type, 1)); letter-spacing: 8px; white-space: nowrap; }
.logo-sub { margin: 2px 0 30px; color: #d8cba9; letter-spacing: 5px; font-size: 13px; }
.loading-bar {
  height: 12px; border: 1px solid rgba(246, 234, 210, 0.3);
  background: rgba(8, 14, 10, 0.5); padding: 2px;
}
.loading-bar i { display: block; width: 4%; height: 100%; background: linear-gradient(90deg, #8f7be8, var(--gold)); transition: width .3s ease; }
.loading-text { color: #d8e2c8; font-size: 12px; margin: 10px 0 4px; }
.loading-tip { color: #93a787; font-size: 11px; line-height: 1.7; margin-top: 22px; }

/* 标题 */
#screen-title { color: #f4ecd8; overflow: hidden; }
.title-scrim {
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(15, 24, 18, 0.88) 0%, rgba(16, 26, 20, 0.62) 34%, rgba(16, 26, 20, 0.12) 70%, transparent 100%),
    linear-gradient(0deg, rgba(12, 20, 15, 0.55), transparent 40%);
}
.title-content {
  position: relative; z-index: 2;
  width: min(560px, 88vw);
  margin: auto 0;
  padding-left: max(6vw, calc(24px * var(--site-space, 1)));
  padding-top: calc(20px + var(--safe-t));
  padding-bottom: calc(44px + var(--safe-b));
}
.title-kicker { color: var(--gold); font-size: 12px; letter-spacing: 3px; margin-bottom: 8px; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
.title-desc { color: #e2d8bd; font-size: 13px; line-height: 2; margin: 10px 0 26px; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.title-menu { display: flex; flex-direction: column; gap: 8px; width: min(350px, 100%); }
.title-foot {
  display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 24px;
  color: var(--site-muted); font-size: 10px;
}
.title-foot span::before { content: "·"; margin-right: 5px; color: var(--gold); }
.title-credit {
  position: absolute; right: 18px; bottom: calc(12px + var(--safe-b));
  color: rgba(232, 224, 200, 0.42); font-size: 9px;
}

.menu-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; text-align: left;
  padding: 8px 14px; min-height: 44px;
  color: #f4ecd8;
  background: linear-gradient(180deg, rgba(47, 64, 49, 0.72), rgba(26, 40, 31, 0.76));
  border: 2px solid rgba(246, 234, 210, 0.26);
  border-radius: 2px;
  box-shadow: 3px 3px 0 rgba(10, 16, 12, 0.38);
  font-size: 14px; letter-spacing: 1px;
  transition: transform calc(80ms * var(--site-motion, 1)), border-color calc(150ms * var(--site-motion, 1)), background calc(150ms * var(--site-motion, 1));
  backdrop-filter: blur(5px);
}
.menu-btn small { font-size: 10px; color: #b9c9aa; letter-spacing: 0; }
.menu-btn:hover { border-color: rgba(232, 180, 92, 0.66); background: linear-gradient(180deg, rgba(62, 82, 62, 0.8), rgba(34, 51, 39, 0.82)); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 rgba(10, 16, 12, 0.38); }
.menu-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(10,16,12,.38); }
.menu-btn.primary {
  color: #2a2014;
  background: linear-gradient(180deg, #f4d492, #dcae5e);
  border-color: #fff0c7;
  text-shadow: 0 1px 0 rgba(255, 248, 224, 0.5);
  font-size: 16px;
}
.menu-btn.primary small { color: #6b4a22; }
.menu-btn.primary:hover { background: linear-gradient(180deg, #ffe4a8, #eabd6d); }
.menu-btn.subtle { background: rgba(24, 36, 28, 0.4); color: #c8d3b8; }
.menu-btn.small { min-height: 34px; font-size: 12px; padding: 5px 12px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* 弹窗 */
.modal-panel {
  position: relative;
  width: min(920px, 96vw);
  max-height: calc(100dvh - 36px - var(--safe-t) - var(--safe-b));
  display: flex; flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 250, 236, 0.99), rgba(243, 230, 203, 0.99));
  border: 3px solid #3a2e38;
  box-shadow:
    0 0 0 3px #d9c39a,
    0 0 0 7px #3a2e38,
    0 26px 60px rgba(6, 10, 8, 0.55);
  border-radius: 3px;
  padding: calc(18px * var(--site-space, 1)) calc(20px * var(--site-space, 1));
  overflow: hidden;
  animation: panelIn calc(180ms * var(--site-motion, 1)) ease-out;
}
.modal-panel.narrow { width: min(460px, 94vw); }
.modal-panel.wide { width: min(980px, 96vw); }
@keyframes panelIn { from { transform: translateY(10px) scale(.985); opacity: 0; } }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 2px dashed rgba(58, 46, 56, 0.25); }
.panel-head h2 { margin: 0; font-size: calc(26px * var(--site-type, 1)); letter-spacing: 3px; color: var(--ink); }
.panel-sub { color: var(--ink-soft); font-size: 12px; margin: 8px 0 2px; }
.panel-foot { margin-top: 12px; padding-top: 8px; border-top: 1px dashed rgba(58, 46, 56, 0.25); color: #6f6272; font-size: 10px; }
.panel-foot.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.close-btn {
  flex: none; width: 32px; height: 32px;
  background: #3a2e38; color: #f6ead2;
  border: 2px solid #2b2433; box-shadow: 2px 2px 0 #b99c6b;
  font-size: 20px; line-height: 1; border-radius: 2px;
}
.close-btn:hover { background: var(--rose); }
.close-btn.light { background: rgba(58,46,56,.72); }

/* 设置 */
.settings-layout { display: grid; grid-template-columns: 170px 1fr; gap: calc(16px * var(--site-space, 1)); min-height: 360px; flex: 1; overflow: hidden; margin-top: 12px; }
.settings-tabs { display: flex; flex-direction: column; gap: 4px; border-right: 1px dashed rgba(58,46,56,.25); padding-right: 12px; }
.settings-tabs button {
  text-align: left; padding: 9px 10px;
  background: transparent; border: 1px solid transparent;
  color: var(--ink-soft); font-size: 13px;
  border-radius: 2px;
}
.settings-tabs button:hover { background: rgba(58,46,56,.06); }
.settings-tabs button.active { background: #3a2e38; color: #f6ead2; border-color: #2b2433; box-shadow: 2px 2px 0 #b99c6b; }
.settings-body { overflow: auto; padding-right: 6px; scrollbar-width: thin; }
.settings-pane { display: none; padding-bottom: 6px; }
.settings-pane.active { display: block; }
.settings-pane h3 { font-size: 15px; margin: 2px 0 12px; color: var(--ink); letter-spacing: 1px; }
.settings-pane h4 { font-size: 12px; margin: 14px 0 6px; color: var(--ink-soft); }
.setting-row {
  display: grid; grid-template-columns: 130px 1fr 52px;
  align-items: center; gap: 12px;
  padding: 7px 2px;
  border-bottom: 1px dotted rgba(58, 46, 56, 0.16);
  font-size: 12px;
}
.setting-row label { color: var(--ink); }
.setting-row output { text-align: right; color: var(--gold-deep); font-size: 11px; }
.hint { color: #7a6c7c; font-size: 10px; line-height: 1.8; margin: 10px 0 0; }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.mode-card {
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 9px;
  border: 2px solid rgba(58, 46, 56, 0.24);
  background: rgba(255, 252, 242, 0.55);
  cursor: pointer;
  border-radius: 2px;
}
.mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.mode-card .mc-icon { font-size: 19px; color: var(--gold-deep); line-height: 1.2; }
.mode-card b { font-size: 12px; }
.mode-card small { font-size: 9px; color: #7a6c7c; line-height: 1.4; }
.mode-card:has(input:checked) { border-color: #3a2e38; background: #fffaf0; box-shadow: 2px 2px 0 #b99c6b; }
.mode-card:has(input:checked) .mc-icon { color: var(--magic); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 6px; background: rgba(58, 46, 56, 0.18);
  border: 1px solid rgba(58,46,56,.25); border-radius: 0; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 0;
  background: var(--gold); border: 2px solid #3a2e38; box-shadow: 1px 1px 0 #b99c6b;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 0; background: var(--gold);
  border: 2px solid #3a2e38; cursor: pointer;
}
select {
  background: #fffaf0; border: 2px solid rgba(58,46,56,.35); color: var(--ink);
  padding: 4px 6px; font-size: 12px; border-radius: 2px;
}
input.switch {
  -webkit-appearance: none; appearance: none;
  width: 42px; height: 22px; margin: 0;
  background: rgba(58,46,56,.22); border: 2px solid rgba(58,46,56,.4);
  position: relative; cursor: pointer; border-radius: 2px;
  justify-self: start;
}
input.switch::after {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 14px; height: 14px; background: #fffaf0; border: 1px solid rgba(58,46,56,.4);
  transition: transform .12s;
}
input.switch:checked { background: var(--moss); border-color: #243a2c; }
input.switch:checked::after { transform: translateX(20px); background: var(--gold); }

.gesture-state-card {
  background: rgba(255, 252, 242, 0.6);
  border: 2px dashed rgba(58,46,56,.25);
  padding: 10px 12px; margin-bottom: 10px;
}
.gesture-state-card > div:first-child { display: flex; align-items: center; gap: 7px; font-size: 13px; }
#gesture-settings-dot { width: 8px; height: 8px; border-radius: 50%; background: #9a8f95; box-shadow: none; }
#gesture-settings-dot.on { background: #63b96a; box-shadow: 0 0 7px rgba(99,185,106,.9); }
#gesture-settings-dot.bad { background: #d8a04c; box-shadow: 0 0 7px rgba(216,160,76,.85); }
.gesture-state-card p { font-size: 10px; color: #6f6272; line-height: 1.7; margin: 6px 0 9px; }
.gesture-state-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.gesture-map { margin-top: 12px; border-top: 1px dashed rgba(58,46,56,.25); padding-top: 8px; }
.gesture-map div { display: flex; justify-content: space-between; font-size: 11px; padding: 3px 0; color: #6f6272; }
.gesture-map b { color: var(--ink); font-weight: normal; }

/* 法术书 */
#screen-spellbook {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(72, 54, 90, 0.45), transparent 70%),
    rgba(14, 14, 20, 0.74);
  backdrop-filter: blur(8px);
  padding: 14px;
}
.book-wrap {
  position: relative;
  width: min(1100px, 97vw);
  max-height: calc(100dvh - 28px);
  display: flex; flex-direction: column;
  padding: 16px 20px 12px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(58,46,56,.08) 0 1px, transparent 1px),
    linear-gradient(180deg, #fbf2dd, #efdcb7);
  border: 3px solid #3a2e38;
  box-shadow: 0 0 0 3px #d9c39a, 0 0 0 7px #3a2e38, 0 34px 70px rgba(4,8,6,.6);
  border-radius: 3px;
  animation: panelIn .2s ease-out;
}
.book-wrap::after {
  content: ""; position: absolute; inset: 8px; pointer-events: none;
  border: 1px solid rgba(58,46,56,.18);
}
.book-head { display: flex; justify-content: space-between; align-items: flex-start; position: relative; z-index: 1; }
.book-kicker { font-size: 10px; color: var(--gold-deep); letter-spacing: 2px; }
.book-head h2 { margin: 2px 0 8px; font-size: 30px; letter-spacing: 6px; }
.book-body { display: grid; grid-template-columns: 1fr 330px; gap: 18px; min-height: 0; flex: 1; position: relative; z-index: 1; }
.book-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; align-content: start;
  overflow: auto; padding: 2px 4px 2px 0;
  scrollbar-width: thin;
}
.book-card {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  padding: 8px;
  background: rgba(255, 252, 242, 0.62);
  border: 2px solid rgba(58, 46, 56, 0.24);
  border-radius: 2px;
  text-align: left;
  transition: transform .08s, border-color .15s, background .15s;
}
.book-card:hover { border-color: #3a2e38; transform: translateY(-1px); background: #fffaf0; }
.book-card.active { border-color: #3a2e38; background: #fffaf0; box-shadow: 3px 3px 0 #c5a976; }
.book-card img { width: 36px; height: 36px; image-rendering: auto; flex: none; }
.book-card .bc-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.book-card .bc-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-card .bc-key { font-size: 9px; color: #8a7a80; }
.book-card .bc-rune { position: absolute; right: 5px; bottom: 3px; font-size: 8px; color: #b9a488; letter-spacing: 1px; }
.book-detail {
  position: relative;
  border-left: 2px solid rgba(58,46,56,.18);
  padding-left: 18px;
  display: flex; flex-direction: column;
  min-height: 0; overflow: auto; scrollbar-width: thin;
}
.detail-top { display: flex; gap: 12px; align-items: center; }
.detail-icon {
  width: 64px; height: 64px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(255,252,242,.9), rgba(223,201,159,.45));
  border: 2px solid rgba(58,46,56,.25);
}
.detail-icon img { width: 46px; height: 46px; image-rendering: auto; }
.detail-key { font-size: 9px; color: var(--gold-deep); letter-spacing: 1px; }
.book-detail h3 { margin: 2px 0 1px; font-size: 24px; letter-spacing: 2px; }
.detail-type { font-size: 10px; color: #7a6c7c; }
.detail-desc { font-size: 12px; line-height: 2; margin: 14px 0 8px; color: #463b4b; }
.detail-tip {
  font-size: 10px; line-height: 1.8; color: #6f6272;
  padding: 8px 10px; border-left: 3px solid var(--gold);
  background: rgba(232, 180, 92, 0.12);
}
.detail-foot { margin-top: auto; padding-top: 12px; font-size: 9px; color: #8a7a80; }
#btn-book-equip { margin-top: 12px; align-self: flex-start; color: #f6ead2; background: #3a2e38; border-color: #2b2433; }
#btn-book-equip:hover { background: var(--magic); }
.book-foot { text-align: center; font-size: 9px; color: #8a7a80; padding-top: 8px; position: relative; z-index: 1; }

/* 帮助 */
.help-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; overflow: auto; margin-top: 10px; padding-right: 4px; }
.help-columns h3 { font-size: 15px; margin: 4px 0 8px; color: var(--ink); letter-spacing: 1px; }
.help-columns h3 + h3, .dot-list + h3 { margin-top: 16px; }
.key-list { list-style: none; margin: 0; padding: 0; }
.key-list li { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 11px; color: var(--ink-soft); }
.key-list li span { width: 104px; flex: none; }
.key { font-style: normal; display: inline-block; font-size: 9px; padding: 1px 5px; color: var(--ink); background: #fffaf0; border: 1px solid rgba(58,46,56,.3); border-bottom-width: 2px; }
.key-list b { font-weight: normal; }
.dot-list { margin: 0; padding-left: 14px; font-size: 11px; line-height: 1.9; color: var(--ink-soft); }
.dot-list li::marker { color: var(--gold-deep); }
.dot-list b { color: var(--ink); }

/* 许可 */
.credits-body { overflow: auto; padding-right: 4px; margin-top: 8px; }
.credit-row { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px dotted rgba(58,46,56,.18); font-size: 11px; }
.credit-row b { font-size: 12px; color: var(--ink); font-weight: normal; }
.credit-row span { color: #6f6272; line-height: 1.7; }
.credit-note { margin-top: 12px; font-size: 10px; line-height: 1.8; color: #7a6c7c; }

/* 手势授权 / 校准 */
.consent-visual {
  width: 74px; height: 74px; margin: 14px auto 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #f6ead2;
  background: radial-gradient(circle, #6b54b8, #3a2e5c);
  border: 3px solid #3a2e38; box-shadow: 3px 3px 0 #b99c6b;
}
.consent-actions { display: flex; gap: 8px; margin-top: 14px; }
.consent-actions .menu-btn { flex: 1; align-items: center; color: var(--ink); background: #fffaf0; border-color: rgba(58,46,56,.35); text-shadow: none; }
.consent-actions .menu-btn.primary { color: #2a2014; background: linear-gradient(180deg, #f4d492, #dcae5e); border-color: #3a2e38; }
.confirm-text { font-size: 13px; line-height: 1.9; color: var(--ink-soft); margin: 12px 0 4px; }
.calibrate-visual { position: relative; width: 180px; height: 180px; margin: 10px auto 4px; display: flex; align-items: center; justify-content: center; }
.calib-ring { position: absolute; inset: 0; border: 2px dashed rgba(58,46,56,.35); border-radius: 50%; animation: calibSpin 9s linear infinite; }
@keyframes calibSpin { to { transform: rotate(360deg); } }
.calib-hand { font-size: 58px; color: var(--magic); }
.calib-count { position: absolute; right: 4px; bottom: 2px; font-size: 22px; color: var(--gold-deep); }
.calib-text { text-align: center; font-size: 12px; color: var(--ink-soft); line-height: 1.8; min-height: 44px; }
.calibrate-visual.ok .calib-ring { border-color: #4f9c58; border-style: solid; }
.calibrate-visual.ok .calib-hand { color: #4f9c58; }

/* 旋转提示 */
#rotate-overlay {
  position: absolute; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #2a3e30, #101b15 75%);
  color: #f4ecd8; text-align: center; padding: 24px;
}
.rotate-inner h2 { font-size: 22px; letter-spacing: 2px; margin: 10px 0 6px; }
.rotate-inner p { font-size: 11px; color: #b7c7a8; }
.phone-icon { font-size: 50px; display: inline-block; animation: phoneTurn 2.4s ease-in-out infinite; }
@keyframes phoneTurn { 0%, 20% { transform: rotate(0); } 55%, 80% { transform: rotate(90deg); } 100% { transform: rotate(90deg); } }

#pause-veil {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(10, 16, 12, 0.28);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

/* 提示条 */
#toasts {
  position: absolute; left: 50%; top: calc(18% + var(--safe-t)); transform: translateX(-50%);
  z-index: 70; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none; width: min(520px, 90vw);
}
.toast {
  padding: 7px 14px;
  color: #f8f0db; font-size: 12px; letter-spacing: .5px;
  background: rgba(26, 38, 30, 0.88);
  border: 1px solid rgba(238, 224, 186, 0.32);
  box-shadow: 0 4px 14px rgba(8, 14, 10, 0.35);
  border-left: 3px solid var(--gold);
  border-radius: 2px;
  animation: toastIn .18s ease-out;
  text-align: center;
}
.toast.bad { border-left-color: var(--rose); }
.toast.good { border-left-color: var(--green); }
.toast.fade { opacity: 0; transform: translateY(-5px); transition: opacity .3s, transform .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }

#fps-corner {
  position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(88px + var(--safe-b));
  z-index: 15; font-size: 10px; color: #b9d3a5;
  background: rgba(20, 30, 24, 0.6); border: 1px solid rgba(238,224,186,.2);
  padding: 2px 6px; pointer-events: none;
}

/* 小屏 */
@media (max-width: 900px) {
  .modal-panel { padding: 14px; }
  .settings-layout { grid-template-columns: 1fr; min-height: 0; }
  .settings-tabs { flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px dashed rgba(58,46,56,.25); padding: 0 0 8px; margin-bottom: 4px; }
  .settings-tabs button { flex: 1; text-align: center; padding: 7px 6px; font-size: 11px; }
  .settings-body { max-height: 52vh; }
  .book-body { grid-template-columns: 1fr; }
  .book-detail { border-left: none; border-top: 2px solid rgba(58,46,56,.18); padding-left: 0; padding-top: 12px; }
  .detail-desc { margin-top: 8px; }
  .help-columns { grid-template-columns: 1fr; gap: 6px; }
  .title-content { width: min(430px, 88vw); }
  .game-logo.big { font-size: clamp(48px, 13vw, 74px); letter-spacing: 6px; }
  .hud-brand { font-size: 13px; }
  .status-card { width: 205px; }
  .icon-btn { min-width: 46px; height: 45px; }
  .icon-btn .ib-label { font-size: 9px; }
  .icon-btn .keycap { display: none; }
  #quick-help { display: none; }
  .title-credit { display: none; }
}

@media (max-width: 640px) {
  .mode-cards { grid-template-columns: 1fr; }
  .mode-card { flex-direction: row; align-items: center; gap: 8px; padding: 7px 9px; }
  .mode-card small { margin-left: auto; }
  .book-grid { grid-template-columns: 1fr 1fr; }
  .book-wrap { padding: 12px; }
  .book-head h2 { font-size: 23px; }
  .detail-icon { width: 52px; height: 52px; }
  .detail-icon img { width: 38px; height: 38px; }
  .book-detail h3 { font-size: 20px; }
  .setting-row { grid-template-columns: 108px 1fr 44px; gap: 8px; }
  #hud-top-left .status-card { width: 178px; }
  .status-row.small { gap: 6px; font-size: 9px; }
  .spell-slot { width: 44px; height: 50px; }
  .spell-slot .slot-icon { width: 24px; height: 24px; }
  .spell-slot .slot-name { display: none; }
  #spellbar { gap: 3px; padding: 4px; }
  #cast-readout { top: calc(50% + 38px); }
}

/* 触摸设备隐藏键位小标签 */
@media (pointer: coarse) {
  .keycap { display: none; }
  .icon-btn { min-width: 44px; height: 44px; }
}

@media (max-height: 520px) {
  .game-logo.big { font-size: 46px; }
  .title-desc { margin-bottom: 12px; }
  .title-menu { gap: 5px; }
  .menu-btn { min-height: 36px; padding: 5px 12px; font-size: 12px; }
  .menu-btn small { display: none; }
  .title-foot { margin-top: 12px; }
  .modal-panel { padding: 12px 16px; }
  .panel-head h2 { font-size: 20px; }
  .settings-body { max-height: 46vh; }
  .book-head h2 { font-size: 22px; }
  .book-body { gap: 10px; }
  .detail-desc { font-size: 11px; line-height: 1.7; }
  .calibrate-visual { width: 120px; height: 120px; }
}

/* 横屏触屏：HUD 更紧凑 */
/* 短横屏标题：左文案右菜单，避免菜单被裁切 */
@media (max-height: 520px) and (orientation: landscape) {
  .title-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
    grid-template-areas:
      "kicker menu"
      "logo menu"
      "desc menu"
      "foot menu";
    grid-template-rows: auto auto 1fr auto;
    column-gap: 26px;
    align-items: start;
    width: min(790px, 94vw);
    padding-top: calc(10px + var(--safe-t));
    padding-bottom: calc(10px + var(--safe-b));
  }
  .title-kicker { grid-area: kicker; margin-bottom: 4px; }
  .game-logo.big { grid-area: logo; font-size: clamp(36px, 13vh, 52px); letter-spacing: 5px; margin: 0; }
  .title-desc { grid-area: desc; margin: 6px 0 0; font-size: 12px; line-height: 1.75; }
  .title-menu { grid-area: menu; width: 100%; align-self: center; gap: 5px; }
  .title-menu .menu-btn { min-height: 42px; padding: 5px 12px; }
  .title-foot { grid-area: foot; margin-top: 8px; }
  .title-credit { display: none; }
}

@media (max-height: 380px) and (orientation: landscape) {
  .title-content { grid-template-columns: minmax(0, 1fr) minmax(238px, 300px); column-gap: 16px; }
  .title-kicker { font-size: 10px; letter-spacing: 1px; white-space: nowrap; }
  .title-desc { font-size: 11px; line-height: 1.6; }
  .title-menu .menu-btn { min-height: 36px; }
  .title-foot { display: none; }
}

@media (pointer: coarse) {
  #fps-corner { display: none; }
}

/* 横屏触屏：法术书与说明并排，避免第三行法术被藏进滚动区 */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 719px) and (max-height: 520px) {
  .book-wrap { overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
  .book-body { display: block; flex: 0 0 auto; }
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  .book-card { padding: 5px 6px; gap: 6px; }
  .book-card img { width: 28px; height: 28px; }
  .book-card .bc-key { display: none; }
  .book-detail {
    border-left: none;
    border-top: 2px solid rgba(58, 46, 56, 0.18);
    margin-top: 10px;
    padding-left: 0;
    padding-top: 10px;
    overflow: visible;
  }
  .detail-icon { width: 46px; height: 46px; }
  .detail-icon img { width: 34px; height: 34px; }
  .detail-desc { font-size: 10.5px; line-height: 1.6; }
}

@media (pointer: coarse) and (orientation: landscape) and (min-width: 720px) {
  .book-body { grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; }
  .book-detail {
    border-left: 2px solid rgba(58, 46, 56, 0.18);
    border-top: none;
    padding-left: 12px;
    padding-top: 0;
  }
  .book-grid { gap: 6px; }
  .book-card { padding: 5px 7px; gap: 7px; }
  .book-card img { width: 32px; height: 32px; }
  .detail-desc { font-size: 11px; line-height: 1.65; }
  .help-columns { grid-template-columns: 1fr 1fr; gap: 16px; }
  .help-columns h3 { font-size: 13px; margin-bottom: 5px; }
  .help-columns li { font-size: 10px; padding: 2px 0; }
}

@media (pointer: coarse) and (orientation: landscape) {
  #hud-top-left { gap: 5px; }
  .hud-brand { font-size: 12px; }
  .status-card { padding: 5px 8px; width: 190px; }
  .status-row.small { margin-top: 3px; font-size: 9px; }
  #hud-top-right { gap: 4px; }
  .icon-btn { min-width: 42px; height: 40px; padding: 3px 4px; }
  .icon-btn .ic { font-size: 14px; height: 16px; }
  .icon-btn .ib-label { font-size: 8px; }
  #spellbar { bottom: calc(6px + var(--safe-b)); }
  #joystick { bottom: calc(64px + var(--safe-b)); }
  #touch-actions { bottom: calc(62px + var(--safe-b)); }
  #gesture-hud { bottom: calc(140px + var(--safe-b)); }
  #fps-corner { bottom: calc(60px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}