:root {
  --gold: #d9b45a;
  --gold-dim: #8a6d2c;
  --ink: #efe6d2;
  --bg: #120e0b;
  --board: min(96vw, calc(100dvh - 210px), 720px);
  --sq: calc(var(--board) / 8);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: "Georgia", "Songti TC", "PMingLiU", serif;
  overflow: hidden; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}

.sky {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(217,180,90,.18), transparent 55%),
    radial-gradient(ellipse at 50% 110%, rgba(90,40,120,.25), transparent 60%),
    repeating-linear-gradient(0deg, #17120e 0 38px, #1b1510 38px 40px),
    var(--bg);
}

.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

/* ---------- 主選單 ---------- */
#menu { justify-content: center; gap: 14px; }
.title {
  font-size: clamp(48px, 13vw, 96px); margin: 0; letter-spacing: .15em;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(217,180,90,.5), 0 3px 0 #5a4418;
}
.subtitle { margin: 0 0 18px; opacity: .75; }

button {
  font: inherit; color: var(--ink); cursor: pointer;
  background: linear-gradient(#3a2f25, #261e17);
  border: 1px solid var(--gold-dim); border-radius: 10px;
}
button:active { transform: translateY(1px); filter: brightness(1.2); }
button.big { width: min(340px, 86vw); padding: 14px; font-size: 20px; }
button.small { padding: 8px 14px; font-size: 16px; }
button.gold { background: linear-gradient(#c9a24a, #8a6d2c); color: #1a120a; border-color: #f0d68a; font-weight: bold; }

.panel {
  width: min(360px, 90vw); padding: 18px;
  background: rgba(30,24,19,.95); border: 1px solid var(--gold-dim); border-radius: 14px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.row { font-size: 18px; }
.row b { color: var(--gold); font-size: 26px; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 32px; }
.level-hint { font-size: 14px; opacity: .7; min-height: 1.2em; }
.seg { display: flex; gap: 6px; width: 100%; }
.seg button { flex: 1; padding: 10px 4px; font-size: 15px; }
.seg button.on { background: linear-gradient(#c9a24a, #8a6d2c); color: #1a120a; }

/* ---------- 對局 ---------- */
#game { gap: 4px; height: 100dvh; padding-left: 0; padding-right: 0; }
#view { flex: 1; width: 100%; min-height: 0; position: relative; }
#view canvas { display: block; touch-action: none; }
.topbar {
  width: min(100%, 900px); padding: 6px 12px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#status { font-size: 19px; color: var(--gold); text-align: center; flex: 1; }
#status.check { color: #ff6b5a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.tray { width: min(100%, 900px); padding: 0 12px; min-height: 28px; font-size: 24px; line-height: 28px; letter-spacing: -2px; }
.info { min-height: 1.3em; font-size: 15px; opacity: .75; }

.board-wrap {
  position: relative; width: var(--board); height: var(--board);
  border: 6px solid #4a3a28; border-radius: 6px;
  box-shadow: 0 0 0 2px var(--gold-dim), 0 20px 50px rgba(0,0,0,.7);
  box-sizing: content-box;
}
#board, #fx { position: absolute; inset: 0; }
#fx { pointer-events: none; }

.sq {
  position: absolute; width: var(--sq); height: var(--sq);
}
.sq.light { background: linear-gradient(135deg, #cdbb98, #b6a27c); }
.sq.dark  { background: linear-gradient(135deg, #5b4a3a, #43362a); }
.sq .coord { position: absolute; font-size: calc(var(--sq) * .16); opacity: .55; left: 3px; top: 1px; color: #1a120a; }
.sq.dark .coord { color: #e8dcc0; }
.sq.last::after { content: ""; position: absolute; inset: 0; background: rgba(217,180,90,.35); }
.sq.sel::after  { content: ""; position: absolute; inset: 0; background: rgba(120,200,255,.35); }
.sq.incheck { background: radial-gradient(circle, #ff5a3a 0%, #a01a10 45%, transparent 75%), #5b4a3a; }
.sq .dot {
  position: absolute; left: 50%; top: 50%; width: 30%; height: 30%;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: rgba(40,160,255,.55); box-shadow: 0 0 10px rgba(80,180,255,.8); z-index: 2;
}
.sq .ring {
  position: absolute; inset: 4%; border-radius: 50%; z-index: 2;
  border: calc(var(--sq) * .07) solid rgba(255,80,60,.6);
}

.pc {
  position: absolute; width: var(--sq); height: var(--sq); z-index: 3;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sq) * .82); line-height: 1;
  font-family: "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", serif;
  transition: left .35s ease, top .35s ease;
  pointer-events: none;
}
.pc.w { color: #f6efdf; text-shadow: 0 1px 0 #fff, 0 -1px 0 #8b8270, 0 3px 4px rgba(0,0,0,.7), 0 0 1px #6b6352; }
.pc.b { color: #1e1a1d; text-shadow: 0 1px 0 #6a5f6e, 0 -1px 0 #000, 0 3px 4px rgba(0,0,0,.8), 0 0 6px rgba(150,90,200,.35); }
.pc.moving { z-index: 6; }

/* ---------- 戰鬥特效 ---------- */
@keyframes lunge {
  0% { transform: translate(0,0) scale(1); }
  35% { transform: translate(calc(var(--dx) * -.25), calc(var(--dy) * -.25)) scale(1.15) rotate(-8deg); }
  60% { transform: translate(calc(var(--dx) * .55), calc(var(--dy) * .55)) scale(1.25) rotate(10deg); }
  100% { transform: translate(0,0) scale(1); }
}
.pc.lunge { animation: lunge .45s ease-in-out; z-index: 7; }

@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6%, 2%) rotate(-6deg); }
  40% { transform: translate(6%, -2%) rotate(6deg); }
  60% { transform: translate(-4%, 1%) rotate(-3deg); }
  80% { transform: translate(4%, 0) rotate(3deg); }
}
.pc.hit { animation: shake .3s linear; filter: brightness(1.8) drop-shadow(0 0 8px #fff); }

.shard {
  position: absolute; width: var(--sq); height: var(--sq);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sq) * .82); line-height: 1;
  font-family: "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", serif;
  transition: transform .8s cubic-bezier(.2,.7,.3,1), opacity .8s ease-in;
}
.spark {
  position: absolute; width: calc(var(--sq) * 1.4); height: calc(var(--sq) * 1.4);
  margin: calc(var(--sq) * -.2); border-radius: 50%;
  background: radial-gradient(circle, rgba(255,240,190,.95), rgba(255,170,60,.5) 35%, transparent 70%);
  animation: spark .5s ease-out forwards;
}
@keyframes spark { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }

/* ---------- 視窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center;
}
.modal h2 { color: var(--gold); margin: 4px 0; font-size: 30px; }
.modal p { margin: 0 0 8px; }
.promo-row { display: flex; gap: 8px; }
.promo-row button { width: 64px; height: 64px; font-size: 48px; line-height: 1; padding: 0; font-family: "Segoe UI Symbol", "Apple Symbols", serif; }

.pc-mini { font-family: "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", serif; }
.pc-mini.w { color: #f6efdf; text-shadow: 0 0 1px #6b6352, 0 2px 2px rgba(0,0,0,.6); }
.pc-mini.b { color: #1e1a1d; text-shadow: 0 0 1px #8a7f8e, 0 0 4px rgba(150,90,200,.4); }
.sq .coord.file { left: auto; top: auto; right: 4px; bottom: 1px; }
