:root {
  --bg: #080a18;
  --panel: rgba(14, 17, 40, 0.88);
  --edge: rgba(120, 135, 255, 0.35);
  --text: #eef0ff;
  --muted: #9aa2d6;
  --you: #38d6ff;
  --bot: #ff5266;
  --gold: #ffd166;
  --green: #3ddc97;
  --accent: #6c7cff;
  --sq-dark: #222a5c;
  --sq-light: #0d1028;
  --move-ms: 220ms;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }
button { font-family: inherit; }

/* ---------- Pages ---------- */
.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at top, rgba(108, 124, 255, 0.12), transparent 60%), var(--bg);
}
#home { padding-top: max(24px, 5vh); }

.panel {
  width: min(440px, 100%);
  padding: 24px 22px 18px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--edge);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
  animation: rise 0.35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.logo {
  margin: 0;
  font-size: clamp(30px, 8.5vw, 46px);
  font-weight: 950;
  letter-spacing: 0.02em;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--you), #b9a8ff 50%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 24px rgba(108, 124, 255, 0.45));
}
.hook { margin: 8px 0 18px; color: var(--muted); font-size: 15px; line-height: 1.4; }

.settings { display: grid; gap: 10px; margin-bottom: 18px; }
.setting { display: grid; gap: 6px; text-align: left; }
.setting-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.seg button:active { transform: scale(0.97); }
.seg button.on { background: rgba(108, 124, 255, 0.28); border-color: var(--accent); }

.primary-btn {
  width: 100%;
  min-height: 52px;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 950;
  letter-spacing: 0.1em;
  color: #fff;
  background: linear-gradient(90deg, #3a8dff, #6c7cff);
  box-shadow: 0 10px 30px rgba(108, 124, 255, 0.4);
  cursor: pointer;
}
.secondary-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.secondary-btn:disabled { opacity: 0.4; cursor: default; }
.row { display: flex; gap: 10px; }
.row .secondary-btn { margin-top: 10px; }
.text-btn {
  min-height: 44px;
  margin-top: 8px;
  padding: 8px 12px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.back-link {
  display: inline-block;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
.panel > .back-link { display: block; text-align: left; margin: -6px 0 8px; }
.back-link.center { display: block; text-align: center; margin: 12px 0 0; }
.back-link:hover { color: var(--text); }

.howto { margin: 14px 0 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
kbd {
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
}
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: inline; }
  .kbd-only { display: none; }
}
.record { margin: 10px 0 0; font-size: 13px; color: var(--gold); min-height: 1em; }

/* ---------- About article ---------- */
.about {
  width: min(640px, 100%);
  padding: 22px;
  border-radius: 18px;
  background: rgba(12, 14, 34, 0.95);
  border: 1px solid rgba(120, 135, 255, 0.18);
  color: var(--muted);
  line-height: 1.6;
  font-size: 15px;
  user-select: text;
  -webkit-user-select: text;
  margin-bottom: 24px;
}
.about h2, .about h3 { color: var(--text); margin: 18px 0 8px; }
.about h2 { margin-top: 0; font-size: 22px; }
.about h3 { font-size: 17px; }
.about ul { padding-left: 20px; margin: 0; }
.about li { margin-bottom: 6px; }
.about strong { color: var(--text); }
.about details { padding: 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.about summary { color: var(--text); cursor: pointer; font-weight: 600; }
.about details p { margin: 8px 0 0; }
.about a { color: var(--you); }
.about .more { margin: 16px 0 0; }

/* ---------- Play screen ---------- */
.play-page {
  justify-content: flex-start;
  gap: 10px;
  padding-top: max(12px, env(safe-area-inset-top));
}
.play-top {
  width: min(560px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chip-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: rgba(10, 12, 30, 0.75);
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}
.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 16px;
  color: var(--muted);
}
.captures {
  width: min(560px, 100%);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.captures b { font-size: 18px; color: var(--text); }
.cap.you b { color: var(--you); }
.cap.bot b { color: var(--bot); }
.status {
  width: min(560px, 100%);
  min-height: 1.5em;
  margin: 2px 0;
  text-align: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.02em;
}
.status.bot { color: var(--muted); }
.status.hint { color: var(--gold); }
.status.warn { color: #ff8a8a; animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}
/* 竖屏时棋盘铺满宽度（两侧各 16px），每格至少 40px（360px 宽的手机约 41px） */
.board {
  width: min(calc(100vw - 32px), 540px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--edge);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55), 0 0 40px rgba(108, 124, 255, 0.18);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.sq {
  position: relative;
  min-width: 0;
  min-height: 0;
  cursor: default;
}
.sq.lt { background: var(--sq-light); }
.sq.dk {
  background: var(--sq-dark);
  cursor: pointer;
}
.sq.last { background-color: #3b3566; }
.sq.dk.last { background-color: #3f3f7a; }
.sq.sel { box-shadow: inset 0 0 0 3px var(--gold); }
.sq.target::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(61, 220, 151, 0.8);
  pointer-events: none;
}
.sq.flash::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px #ff5266;
  animation: blink 0.9s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}

.piece {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  transition: transform var(--move-ms) ease;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.28), 0 5px 12px rgba(0, 0, 0, 0.55);
  z-index: 2;
}
.piece.dark {
  background: radial-gradient(circle at 35% 30%, #8c93ff, #3c44b8 60%, #252a80);
  border: 2px solid #b5bcff;
}
.piece.light {
  background: radial-gradient(circle at 35% 30%, #ffffff, #dfe4fb 60%, #b9c2ec);
  border: 2px solid #8f9ad8;
}
.piece.king .crown {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -52%);
  font-size: 46%;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.8), 0 1px 0 rgba(0, 0, 0, 0.4);
}
.piece.ghost {
  position: fixed;
  inset: auto;
  margin: 0;
  transition: none;
  pointer-events: none;
  z-index: 50;
  transform: scale(1.12);
  opacity: 0.95;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.6));
}

.last-move {
  width: min(560px, 100%);
  min-height: 1.3em;
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.controls { width: min(560px, 100%); }
.controls .secondary-btn { margin-top: 4px; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(8, 10, 24, 0.72);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  z-index: 20;
}
.result-title { margin: 0; font-size: clamp(36px, 10vw, 52px); font-weight: 950; letter-spacing: 0.05em; }
.result-title.win { color: var(--gold); text-shadow: 0 0 30px rgba(255, 209, 102, 0.45); }
.result-title.lose { color: var(--bot); text-shadow: 0 0 30px rgba(255, 82, 102, 0.45); }
.result-title.draw { color: var(--you); text-shadow: 0 0 30px rgba(56, 214, 255, 0.4); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stats div { padding: 10px 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.challenge { margin: 0 0 6px; color: var(--gold); font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(30px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(20, 24, 52, 0.95);
  border: 1px solid var(--edge);
  font-size: 14px;
  z-index: 30;
}

@media (min-width: 720px) {
  .board { width: min(540px, calc(100vh - 240px)); }
}
