:root {
  --gold-1: #f3d684;
  --gold-2: #b89339;
  --rad: #57e08a;
  --dire: #ff5247;
  --d1: #1b2433;
  --d2: #0e151f;
  --ink: #ece4cf;
  --muted: #9aa3b5;
  --c: 10px;
  --oct: polygon(var(--c) 0, calc(100% - var(--c)) 0, 100% var(--c), 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, var(--c) 100%, 0 calc(100% - var(--c)), 0 var(--c));
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: var(--ink);
  font-family: "Marcellus", "PingFang SC", "Microsoft YaHei", Georgia, serif;
  background:
    radial-gradient(700px 520px at 12% 8%, rgba(40, 130, 80, 0.22), transparent 60%),
    radial-gradient(760px 560px at 90% 95%, rgba(150, 35, 35, 0.2), transparent 60%),
    radial-gradient(1100px 820px at 50% 45%, #0f1828, #05080f 80%);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.game { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; position: relative; }

/* ===== 金色棱角面板（可靠的双层描边，不依赖 mask） ===== */
.gp { position: relative; background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 45%, #4a3a18 60%, var(--gold-1)); clip-path: var(--oct); }
.gp::before { content: ""; position: absolute; inset: 1.6px; background: linear-gradient(160deg, var(--d1), var(--d2)); clip-path: var(--oct); }

/* ===== 静音 ===== */
.mute { position: absolute; top: -6px; right: -6px; z-index: 8; width: 40px; height: 40px; --c: 8px; cursor: pointer; border: none; color: var(--gold-1); font-size: 16px; }
.mute::before { background: linear-gradient(160deg, #222c3d, #0e151f); }

/* ===== HUD ===== */
.hud { --c: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px; }
.hud-title { font-family: "Cinzel", serif; font-weight: 900; font-size: 20px; letter-spacing: 1px; color: var(--gold-1); text-shadow: 0 0 14px rgba(243, 200, 90, 0.35); white-space: nowrap; }
.emblem { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; }
.emblem.radiant { background: radial-gradient(circle at 35% 30%, #b6ffd0, #2faf6a 60%, #14633c); box-shadow: 0 0 14px rgba(80, 230, 140, 0.5); }
.emblem.dire { background: radial-gradient(circle at 35% 30%, #ffc2bc, #d23a2f 60%, #7a1410); box-shadow: 0 0 14px rgba(255, 90, 70, 0.5); }

/* ===== 数据卡 ===== */
.stats { display: flex; gap: 8px; }
.stat { --c: 9px; flex: 1; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-label { font-family: "Cinzel", serif; font-size: 10px; letter-spacing: 1.5px; color: var(--muted); }
.stat-num { font-family: "Cinzel", serif; font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat:first-child .stat-num { color: var(--gold-1); }

/* ===== 棋盘 ===== */
.board { --c: 16px; padding: 5px; background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 45%, #4a3a18 60%, var(--gold-1)); clip-path: var(--oct); }
.arena { --c: 13px; position: relative; aspect-ratio: 1 / 1; overflow: hidden; clip-path: var(--oct); background: #080c14; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ===== 覆盖层 ===== */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, rgba(8, 12, 20, 0.7), rgba(4, 6, 11, 0.92)); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); transition: opacity 0.25s; }
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card { width: 88%; text-align: center; }
.overlay-card h2 { font-family: "Cinzel", serif; font-size: 28px; font-weight: 900; color: var(--gold-1); text-shadow: 0 0 18px rgba(243, 200, 90, 0.4); margin-bottom: 4px; }
.overlay-card p { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.ranks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rank { --c: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 8px; cursor: pointer; border: none; color: var(--ink); font-family: inherit; font-size: 14px; font-weight: 700; transition: transform 0.12s; }
.rank::before { background: linear-gradient(160deg, #26324a, #121a28); }
.rank:hover { transform: translateY(-2px); }
.rank.active::before { background: linear-gradient(160deg, #3a4d2f, #1a2a18); }
.rank.active { box-shadow: 0 0 18px rgba(243, 200, 90, 0.3); }
.rk { position: relative; }
.medal { position: relative; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; color: #fff7df; border: 2px solid rgba(255, 255, 255, 0.25); box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.3); flex-shrink: 0; }
.medal.herald { background: radial-gradient(circle at 35% 30%, #c9d2dc, #7d8794 70%, #4b515b); }
.medal.crusader { background: radial-gradient(circle at 35% 30%, #f0b36b, #c2772f 70%, #7c4615); }
.medal.legend { background: radial-gradient(circle at 35% 30%, #bfe2ff, #5aa0d0 70%, #2c5f8c); }
.medal.immortal { background: radial-gradient(circle at 35% 30%, #ffd9a0, #ff6a3c 60%, #a01818); }

/* ===== 按钮 ===== */
.btn { --c: 10px; border: none; cursor: pointer; color: var(--ink); font-family: "Cinzel", serif; font-weight: 700; font-size: 15px; padding: 12px; }
.btn::before { background: linear-gradient(160deg, #212c3f, #0e151f); transition: background 0.15s; }
.btn:hover::before { background: linear-gradient(160deg, #2a3850, #131c2a); }
.btn-primary { margin-top: 16px; width: 62%; --c: 10px; border: none; cursor: pointer; font-family: "Cinzel", serif; font-weight: 700; font-size: 15px; color: #2a1c05; padding: 12px; background: linear-gradient(180deg, var(--gold-1), var(--gold-2)); clip-path: var(--oct); }

/* ===== 方向控制盘 ===== */
.dpad { display: grid; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 60px); gap: 8px; justify-content: center; align-self: center; }
.pad { --c: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--gold-1); border: none; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; transition: transform 0.08s; }
.pad::before { background: linear-gradient(180deg, #232f43, #0e151f); transition: background 0.08s; }
button.pad:active::before, button.pad.pressed::before { background: linear-gradient(180deg, #3aa86a, #1d6b43); }
button.pad:active, button.pad.pressed { transform: scale(0.93); color: #06250f; }
.pad.up { grid-column: 2; grid-row: 1; }
.pad.left { grid-column: 1; grid-row: 2; }
.pad.core { grid-column: 2; grid-row: 2; cursor: default; }
.pad.core::before { background: radial-gradient(circle at 50% 45%, #1b2738, #0d1421); }
.pad.core span { position: relative; width: 13px; height: 13px; border-radius: 50%; background: var(--rad); box-shadow: 0 0 14px var(--rad); animation: pulse 1.6s ease-in-out infinite; }
.pad.right { grid-column: 3; grid-row: 2; }
.pad.down { grid-column: 2; grid-row: 3; }
@keyframes pulse { 0%, 100% { opacity: 0.5; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.1); } }

/* ===== 底部 ===== */
.controls { display: flex; gap: 10px; }
.controls .btn { flex: 1; }
.voicebar { display: flex; align-items: center; justify-content: center; gap: 8px; }
.voice-label { font-family: "Cinzel", serif; font-size: 12px; color: var(--muted); white-space: nowrap; }
.voice-select {
  flex: 0 1 auto;
  max-width: 70%;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #141d2c;
  border: 1px solid rgba(246, 221, 146, 0.3);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.voice-select:focus { outline: none; border-color: var(--gold-1); }

.hint { text-align: center; font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
