:root {
  --primary: #7be8ff;
  --secondary: #3b82c4;
  --gold: #d4b06a;
  --crimson: #b8292f;
  --ink-bg: #04070c;
  --text-main: #ede6d6;
  --text-dim: rgba(237, 230, 214, 0.52);
  --line-gold: rgba(212, 176, 106, 0.34);
  --font-title: 'STXingkai', 'FZShuTi', 'STKaiti', 'KaiTi', '楷体', serif;
  --font-body: 'STKaiti', 'KaiTi', 'STSong', 'SimSun', '宋体', serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink-bg);
  color: var(--text-main);
  font-family: var(--font-body);
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 1;
}

/* 电影胶片暗角与受击反馈 */
#screen-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(2, 4, 8, 0.78) 100%);
  transition: box-shadow 0.28s ease;
}

#screen-vignette.damage-flash {
  box-shadow: inset 0 0 130px rgba(184, 41, 47, 0.92);
}

#burst-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(circle at center, rgba(255, 252, 240, 0.85), var(--primary) 42%, transparent 78%);
  opacity: 0;
  transition: opacity 0.55s ease-out;
}

#burst-flash.active {
  opacity: 0.55;
  transition: opacity 0.05s ease-in;
}

.hud-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-6px);
}

/* 顶部极简无框 HUD */
#hud-top {
  position: fixed;
  top: 22px;
  left: 28px;
  right: 28px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#hud-top > * {
  pointer-events: auto;
}

/* 左上角：无框书法 + 朱砂印 + 细金线导航 */
.hud-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  font-family: var(--font-title);
  font-size: 32px;
  letter-spacing: 5px;
  color: #f6efe0;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.85), 0 0 22px rgba(212, 176, 106, 0.25);
}

.red-seal {
  display: inline-block;
  padding: 2px 5px;
  background: var(--crimson);
  color: #f8ece4;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  border: 1px solid rgba(255, 210, 190, 0.35);
  box-shadow: 0 0 12px rgba(184, 41, 47, 0.5);
  writing-mode: vertical-rl;
  line-height: 1;
}

.ink-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line-gold);
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-divider {
  width: 1px;
  height: 11px;
  background: var(--line-gold);
}

.sep {
  color: rgba(212, 176, 106, 0.35);
  font-size: 11px;
}

.ink-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 2px;
  cursor: pointer;
  padding: 2px 3px;
  position: relative;
  transition: color 0.25s ease, text-shadow 0.25s ease;
}

.ink-link:hover {
  color: var(--text-main);
}

.ink-link.active {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(212, 176, 106, 0.5);
}

.ink-link.active::after {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: -3px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.ink-link.muted {
  opacity: 0.35;
  text-decoration: line-through;
}

/* 中央挥毫招式 */
.hud-center {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none !important;
}

.stance-banner {
  text-align: center;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.stance-banner.pulse {
  transform: scale(1.1);
}

.stance-name {
  font-family: var(--font-title);
  font-size: 40px;
  letter-spacing: 10px;
  color: #fbf7ee;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.9), 0 0 28px var(--primary);
  line-height: 1.1;
}

.stance-sub {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--gold);
  opacity: 0.85;
}

.charge-bar-wrap {
  width: 240px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.charge-bar-wrap.visible {
  opacity: 1;
}

.charge-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.charge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), #ffffff, var(--primary));
  box-shadow: 0 0 12px var(--primary);
  transition: width 0.05s linear;
}

.charge-label {
  margin-top: 5px;
  font-size: 10px;
  text-align: center;
  letter-spacing: 4px;
  color: var(--primary);
}

/* 右上无框战绩 */
.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  transition: opacity 0.4s ease;
}

.hud-right.mode-hidden {
  opacity: 0;
  pointer-events: none;
}

.battle-row {
  display: flex;
  gap: 20px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-gold);
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.m-label {
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--text-dim);
}

.m-val {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 2px;
  color: #f6efe0;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
}

.m-val.gold {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(212, 176, 106, 0.55);
}

.hp-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 210px;
}

.hp-line {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.12);
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--primary));
  box-shadow: 0 0 10px var(--primary);
  transition: width 0.25s ease;
}

.hp-fill.low {
  background: linear-gradient(90deg, #991b1b, #ef4444);
  box-shadow: 0 0 12px #ef4444;
}

.hp-num {
  font-size: 12px;
  color: var(--gold);
  width: 26px;
  text-align: right;
}

/* 底部极简一字口诀条 */
#gesture-guide {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.scroll-rule {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 24px;
  background: linear-gradient(90deg, transparent, rgba(4, 7, 12, 0.72) 15%, rgba(4, 7, 12, 0.72) 85%, transparent);
  border-top: 1px solid rgba(212, 176, 106, 0.18);
  border-bottom: 1px solid rgba(212, 176, 106, 0.18);
  white-space: nowrap;
}

.guide-item {
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  transition: color 0.25s ease, text-shadow 0.25s ease, transform 0.25s ease;
}

.guide-item em {
  font-style: normal;
  color: rgba(212, 176, 106, 0.75);
  margin-right: 3px;
}

.guide-item i {
  font-style: normal;
  font-size: 10px;
  opacity: 0.45;
  margin-left: 3px;
}

.guide-item.active {
  color: #ffffff;
  text-shadow: 0 0 12px var(--primary);
  transform: translateY(-1px);
}

.guide-item.active em {
  color: var(--primary);
}

.g-dot {
  width: 3px;
  height: 3px;
  transform: rotate(45deg);
  background: var(--line-gold);
}

/* 右下角暗金直角手势追踪窗 */
#camera-panel {
  position: fixed;
  right: 24px;
  bottom: 62px;
  z-index: 10;
  width: 176px;
  padding: 5px;
  background: rgba(4, 7, 12, 0.62);
  border: 1px solid rgba(212, 176, 106, 0.22);
  transition: opacity 0.6s ease;
}

.corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--gold);
  border-style: solid;
  pointer-events: none;
}

.corner.tl { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.corner.tr { top: -1px; right: -1px; border-width: 1px 1px 0 0; }
.corner.bl { bottom: -1px; left: -1px; border-width: 0 0 1px 1px; }
.corner.br { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }

.camera-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: rgba(2, 4, 8, 0.85);
}

#webcam, #hand-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#webcam {
  opacity: 0.28;
  filter: grayscale(0.75) contrast(1.2);
}

#hand-canvas {
  z-index: 2;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 3px;
  color: rgba(212, 176, 106, 0.55);
  z-index: 3;
}

.camera-placeholder.hidden {
  display: none;
}

.camera-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-dim);
}

/* 挥毫大字飘字提示 */
.toast-banner {
  position: fixed;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  z-index: 15;
  font-family: var(--font-title);
  font-size: clamp(32px, 5vw, 58px);
  letter-spacing: clamp(6px, 1vw, 14px);
  color: #fcf9f2;
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.9), 0 0 36px var(--primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
}

.toast-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* 开场电影海报遮罩 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at center, rgba(4, 7, 12, 0.35), rgba(2, 4, 8, 0.86));
  transition: opacity 0.65s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.poster-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 34px;
  padding: 24px;
}

.poster-hero {
  display: flex;
  align-items: flex-start;
  gap: 22px;
}

.vertical-title {
  font-family: var(--font-title);
  font-size: clamp(68px, 10vw, 96px);
  font-weight: 400;
  writing-mode: vertical-rl;
  letter-spacing: 14px;
  line-height: 1;
  color: #f7f1e3;
  text-shadow: 0 6px 36px rgba(0, 0, 0, 0.95), 0 0 40px rgba(123, 232, 255, 0.35);
}

.vertical-poem {
  writing-mode: vertical-rl;
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--gold);
  opacity: 0.8;
  padding-top: 12px;
  border-right: 1px solid var(--line-gold);
  padding-right: 12px;
}

.poster-seal {
  writing-mode: vertical-rl;
  background: var(--crimson);
  color: #f8ece4;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 4px;
  border: 1px solid rgba(255, 220, 200, 0.4);
  box-shadow: 0 0 22px rgba(184, 41, 47, 0.55);
  margin-top: 16px;
}

.poster-seal.large {
  writing-mode: horizontal-tb;
  padding: 8px 22px;
  font-size: 18px;
  letter-spacing: 8px;
  margin-top: 0;
}

.poster-actions {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.sword-btn {
  position: relative;
  min-width: 196px;
  padding: 13px 28px;
  background: rgba(6, 10, 16, 0.65);
  border: 1px solid var(--line-gold);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 4px;
  cursor: pointer;
  transition: all 0.28s ease;
}

.sword-btn::before,
.sword-btn::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border: 1px solid var(--gold);
  transition: all 0.28s ease;
}

.sword-btn::before {
  top: -3px;
  left: -3px;
  border-right: none;
  border-bottom: none;
}

.sword-btn::after {
  bottom: -3px;
  right: -3px;
  border-left: none;
  border-top: none;
}

.sword-btn.primary {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(212, 176, 106, 0.18), rgba(6, 10, 16, 0.78));
  box-shadow: 0 0 26px rgba(212, 176, 106, 0.18);
}

.sword-btn:hover {
  border-color: #f6efe0;
  color: #ffffff;
  box-shadow: 0 0 30px rgba(123, 232, 255, 0.28);
  transform: translateY(-2px);
}

.sword-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.loading-status {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--gold);
  opacity: 0.85;
}

.final-stats {
  display: flex;
  gap: 36px;
  padding: 16px 32px;
  border-top: 1px solid var(--line-gold);
  border-bottom: 1px solid var(--line-gold);
}

.final-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.final-stats span {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-dim);
}

.final-stats strong {
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--gold);
}

@media (max-width: 900px) {
  .scroll-rule {
    display: none;
  }
  .hud-center {
    position: static;
    transform: none;
  }
  #hud-top {
    top: 14px;
    left: 14px;
    right: 14px;
  }
  .stance-name {
    font-size: 28px;
  }
  #camera-panel {
    width: 136px;
    right: 14px;
    bottom: 14px;
  }
}
