/* =====================================================================
   BOARD ARENA — Fluent acrylic design system
   Dark-only (index.html declares color-scheme: dark).
   Accent colour is injected per game via --accent.
   ===================================================================== */

:root {
  --bg: #06070f;
  --bg-2: #0b0d1a;

  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --surface-3: rgba(255, 255, 255, 0.14);
  --stroke: rgba(255, 255, 255, 0.1);
  --stroke-2: rgba(255, 255, 255, 0.2);

  --text: #e9edf8;
  --muted: #929cb8;
  --accent: #8b5cf6;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Per-character fallback: JP covers shogi/囲碁, TC covers xiangqi. */
  --cjk: 'Noto Serif JP', 'Noto Serif TC', 'Noto Serif SC', serif;

  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

#app {
  position: relative;
  z-index: 1;
}

/* ======================= ANIMATED BACKDROP ======================= */

.bg-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(1200px 700px at 12% -10%, #1a1440 0%, transparent 60%),
    radial-gradient(1000px 600px at 92% 4%, #0d2c40 0%, transparent 58%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 60%);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.42;
  will-change: transform;
}

.blob-1 {
  width: 46vw;
  height: 46vw;
  left: -8vw;
  top: -12vw;
  background: #7c3aed;
  animation: drift1 26s ease-in-out infinite;
}

.blob-2 {
  width: 40vw;
  height: 40vw;
  right: -10vw;
  top: 8vh;
  background: #0ea5e9;
  animation: drift2 32s ease-in-out infinite;
}

.blob-3 {
  width: 38vw;
  height: 38vw;
  left: 32vw;
  bottom: -18vw;
  background: #10b981;
  opacity: 0.3;
  animation: drift3 36s ease-in-out infinite;
}

@keyframes drift1 {
  50% {
    transform: translate3d(9vw, 7vh, 0) scale(1.15);
  }
}
@keyframes drift2 {
  50% {
    transform: translate3d(-11vw, 10vh, 0) scale(0.88);
  }
}
@keyframes drift3 {
  50% {
    transform: translate3d(6vw, -9vh, 0) scale(1.2);
  }
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, #000 20%, transparent 78%);
}

/* ======================= ACRYLIC SURFACES ======================= */

.glass,
.glass-strong {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.glass-strong {
  background: rgba(20, 22, 38, 0.72);
  border-color: var(--stroke-2);
  backdrop-filter: blur(42px) saturate(190%);
  -webkit-backdrop-filter: blur(42px) saturate(190%);
}

/* Fluent's signature acrylic grain. */
.glass::before,
.glass-strong::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: var(--noise);
  opacity: 0.03;
  mix-blend-mode: overlay;
  pointer-events: none;
}

/* ============================== HOME ============================== */

.home {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(36px, 7vh, 80px) clamp(16px, 4vw, 32px) 56px;
}

.hero {
  text-align: center;
  margin-bottom: clamp(32px, 5vh, 56px);
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  animation: fadeUp 0.6s var(--ease) both;
}

.hero-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: livePulse 2s ease-out infinite;
}

.hero-title {
  margin: 22px 0 14px;
  font-size: clamp(2.6rem, 8vw, 5rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  animation: fadeUp 0.7s var(--ease) 0.08s both;
}

.hero-title .grad {
  background: linear-gradient(100deg, #a78bfa 5%, #38bdf8 45%, #34d399 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  background-size: 220% 100%;
  animation: hueSlide 8s ease-in-out infinite;
}

.hero-sub {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  animation: fadeUp 0.7s var(--ease) 0.16s both;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 20px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 22px 20px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(26px) saturate(170%);
  -webkit-backdrop-filter: blur(26px) saturate(170%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition:
    transform 0.35s var(--ease),
    box-shadow 0.3s ease,
    border-color 0.3s ease;
  animation: cardIn 0.6s var(--ease) backwards;
  animation-delay: var(--delay, 0ms);
}

.game-card:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.card-glow {
  position: absolute;
  inset: -40% -10% auto -10%;
  height: 200px;
  background: radial-gradient(ellipse at 50% 0%, var(--accent), transparent 70%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.game-card:hover .card-glow {
  opacity: 0.3;
}

.card-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 30px;
  line-height: 1;
  font-family: var(--cjk);
  color: #fff;
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 85%, #fff 5%), color-mix(in srgb, var(--accent) 45%, #05060d));
  box-shadow:
    0 10px 26px color-mix(in srgb, var(--accent) 35%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.35s var(--ease);
}

.game-card:hover .card-icon {
  transform: rotate(-7deg) scale(1.08);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
}

.card-title-row {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
}

.card-title-row h2 {
  font-size: 1.22rem;
}

.card-en {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.card-body p {
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.5;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.tag {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.71rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: color-mix(in srgb, var(--accent) 70%, #fff);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.card-cta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.87rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--accent) 75%, #fff);
  padding-top: 12px;
  border-top: 1px solid var(--stroke);
}

.card-cta .arrow {
  transition: transform 0.3s var(--ease);
}

.game-card:hover .card-cta .arrow {
  transform: translateX(6px);
}

.home-footer {
  margin-top: 44px;
  text-align: center;
  font-size: 0.78rem;
  color: rgba(146, 156, 184, 0.65);
}

/* =========================== GAME SCREEN =========================== */

.game-screen {
  /* Vertical space the board can NOT use: page padding + topbar + grid gaps.
     The board is sized from what is left, so it never pushes itself offscreen. */
  --chrome: 130px;
  /* Never shrink below this, even on a very short window — a postage-stamp
     board is worse than a little scrolling. */
  --board-min: 280px;
  --board-max: 720px;

  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1380px;
  margin: 0 auto;
  padding: clamp(12px, 2vh, 20px) clamp(12px, 3vw, 28px) 40px;
  animation: fadeUp 0.45s var(--ease) both;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  border-radius: 18px;
}

.btn-icon {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--surface-2);
  cursor: pointer;
  transition: 0.2s ease;
}

.btn-icon:hover {
  background: var(--surface-3);
  border-color: var(--stroke-2);
  transform: translateX(-2px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar-icon {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-size: 21px;
  font-family: var(--cjk);
  color: #fff;
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 85%, #fff 5%), color-mix(in srgb, var(--accent) 45%, #05060d));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.topbar-title h1 {
  font-size: 1.1rem;
}

.topbar-en {
  font-size: 0.74rem;
  color: var(--muted);
}

.status-pill {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 600;
  border: 1px solid var(--stroke);
  background: var(--surface-2);
  transition: 0.3s ease;
}

.status-pill.ok {
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.45);
  background: rgba(16, 185, 129, 0.14);
}

.status-pill.danger {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(239, 68, 68, 0.14);
  animation: nudge 0.4s ease;
}

.status-pill.think {
  color: color-mix(in srgb, var(--accent) 65%, #fff);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.spinner {
  width: 0.9em;
  height: 0.9em;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  gap: 20px;
  align-items: start;
}

/* ============================== BOARD ============================== */

.board-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Widest the board may be so that its HEIGHT still fits the leftover viewport.
   dvh (not vh) so a mobile browser's collapsing URL bar does not clip it. */
.board-frame {
  width: min(
    100%,
    max(var(--board-min), calc((100dvh - var(--chrome)) * var(--cols) / var(--rows))),
    var(--board-max)
  );
  padding: clamp(7px, 1.2vw, 14px);
  border-radius: 22px;
  container-type: inline-size;
}

/* Shogi also has to fit two hand trays above and below the board. */
.game--shogi {
  --chrome: 250px;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: var(--cols) / var(--rows);
  border-radius: 10px;
  overflow: hidden;
  font-size: calc(100cqi / var(--cols));
  cursor: pointer;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.board-bg,
.board-hl,
.board-pieces {
  position: absolute;
  inset: 0;
}

.board-bg {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
}

.board-hl,
.board-pieces {
  pointer-events: none;
}

.board-pieces {
  perspective: 900px;
}

/* --- checkered boards --- */

.board--chess .cell.even,
.board--checkers .cell.even {
  background: linear-gradient(150deg, #eeeae1, #ddd6c9);
}

.board--chess .cell.odd,
.board--checkers .cell.odd {
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 46%, #2b2942), color-mix(in srgb, var(--accent) 26%, #1b1a2c));
}

/* --- othello: felt --- */

.board--othello .cell {
  background: #147a55;
  box-shadow: inset -1px -1px 0 rgba(0, 0, 0, 0.28);
}

.board--othello .cell.odd {
  background: #128050;
}

/* --- caro: graph paper --- */

.board--caro .board-bg {
  background:
    radial-gradient(ellipse 70% 70% at 50% 50%, rgba(59, 130, 246, 0.12), transparent 70%),
    linear-gradient(150deg, #202844, #141a2e);
}

.board--caro .cell {
  box-shadow: inset -1px -1px 0 rgba(255, 255, 255, 0.14);
}

/* --- shogi: light wood with a printed grid --- */

.board--shogi .board-bg {
  background: linear-gradient(155deg, #f0d29c, #e2bd84 55%, #d4ac72);
}

.board--shogi .cell {
  box-shadow: inset -1px -1px 0 rgba(78, 48, 16, 0.55);
}

/* --- line boards (go / xiangqi) --- */

.board--go .board-bg,
.board--xiangqi .board-bg {
  display: block;
  background: linear-gradient(155deg, #e7bd7c, #dbab66 50%, #cb9950);
}

.line-svg {
  display: block;
  width: 100%;
  height: 100%;
  color: rgba(58, 36, 10, 0.8);
}

.river-text {
  fill: rgba(58, 36, 10, 0.72);
  font-family: var(--cjk);
  font-size: 42px;
  letter-spacing: 10px;
  text-anchor: middle;
  dominant-baseline: middle;
}

/* ============================== PIECES ============================== */

.piece {
  position: absolute;
  translate: -50% -50%;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  /* Explicit 100%/100% tracks: percentage heights cannot resolve against an
     auto-sized grid row, which silently halves every disc and highlight. */
  display: grid;
  grid-template: 100% / 100%;
  place-items: center;
  transition:
    left 0.3s var(--ease),
    top 0.3s var(--ease);
  will-change: left, top;
}

.piece .glyph {
  position: relative;
  line-height: 1;
  user-select: none;
}

.piece.moving {
  z-index: 6;
}

.piece.captured {
  animation: capOut 0.32s ease-in forwards;
  z-index: 1;
}

.piece.pop {
  animation: piecePop 0.36s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.piece.flipping {
  animation: promoFlash 0.3s ease;
}

.board--othello .piece.flipping,
.board--checkers .piece.flipping {
  animation: flipY 0.15s linear;
}

/* --- chess: pure glyphs --- */

.board--chess .glyph {
  font-size: 0.8em;
}

.board--chess .p0 .glyph {
  color: #fdfaf3;
  -webkit-text-stroke: 0.022em #2f2823;
  text-shadow: 0 0.035em 0.05em rgba(0, 0, 0, 0.55);
}

.board--chess .p1 .glyph {
  color: #23262f;
  -webkit-text-stroke: 0.016em rgba(255, 255, 255, 0.42);
  text-shadow: 0 0.035em 0.05em rgba(0, 0, 0, 0.5);
}

/* --- go: glass stones --- */

.board--go .piece::before {
  content: '';
  width: 90%;
  height: 90%;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 27%, #6f7686, #24272f 46%, #090a0e);
  box-shadow:
    0 0.06em 0.14em rgba(0, 0, 0, 0.6),
    inset 0 -0.04em 0.08em rgba(255, 255, 255, 0.09);
}

.board--go .p1::before {
  background: radial-gradient(circle at 33% 27%, #ffffff, #f0ebe0 48%, #bdb5a6);
  box-shadow:
    0 0.06em 0.14em rgba(0, 0, 0, 0.5),
    inset 0 -0.05em 0.1em rgba(0, 0, 0, 0.14);
}

/* --- caro: accent gems --- */

.board--caro .piece::before {
  content: '';
  width: 78%;
  height: 78%;
  border-radius: 32%;
  background: radial-gradient(circle at 32% 26%, #93c5fd, #3b82f6 52%, #1d4ed8);
  box-shadow:
    0 0.05em 0.12em rgba(0, 0, 0, 0.5),
    0 0 0.3em rgba(59, 130, 246, 0.45),
    inset 0 0.04em 0.06em rgba(255, 255, 255, 0.45);
}

.board--caro .p1::before {
  background: radial-gradient(circle at 32% 26%, #fda4af, #f43f5e 52%, #be123c);
  box-shadow:
    0 0.05em 0.12em rgba(0, 0, 0, 0.5),
    0 0 0.3em rgba(244, 63, 94, 0.45),
    inset 0 0.04em 0.06em rgba(255, 255, 255, 0.45);
}

/* --- othello: discs --- */

.board--othello .piece::before {
  content: '';
  width: 84%;
  height: 84%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #4a505c, #1a1d24 52%, #06070a);
  box-shadow:
    0 0.05em 0.12em rgba(0, 0, 0, 0.55),
    inset 0 -0.05em 0.08em rgba(255, 255, 255, 0.1);
}

.board--othello .p1::before {
  background: radial-gradient(circle at 34% 28%, #ffffff, #f2efe8 52%, #c6c0b4);
  box-shadow:
    0 0.05em 0.12em rgba(0, 0, 0, 0.45),
    inset 0 -0.05em 0.08em rgba(0, 0, 0, 0.14);
}

/* --- checkers --- */

.board--checkers .piece::before {
  content: '';
  width: 82%;
  height: 82%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #fb7185, #e11d48 55%, #881337);
  box-shadow:
    0 0.06em 0.13em rgba(0, 0, 0, 0.5),
    inset 0 0 0 0.05em rgba(255, 255, 255, 0.18),
    inset 0 -0.05em 0.09em rgba(0, 0, 0, 0.35);
}

.board--checkers .p1::before {
  background: radial-gradient(circle at 34% 28%, #4b5364, #232833 55%, #0a0c11);
}

.board--checkers .kind-king::after {
  content: '♛';
  position: absolute;
  font-size: 0.42em;
  color: #fde68a;
  text-shadow: 0 0.03em 0.04em rgba(0, 0, 0, 0.6);
}

/* --- xiangqi: wooden discs --- */

.board--xiangqi .piece::before {
  content: '';
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 26%, #fdf1d6, #ebd3a4 58%, #c9a86c);
  box-shadow:
    0 0.05em 0.11em rgba(0, 0, 0, 0.55),
    inset 0 0 0 0.035em rgba(122, 82, 30, 0.55),
    inset 0 -0.045em 0.08em rgba(122, 82, 30, 0.28);
}

.board--xiangqi .glyph {
  font-family: var(--cjk);
  font-weight: 700;
  font-size: 0.52em;
}

.board--xiangqi .p0 .glyph {
  color: #b91c1c;
}

.board--xiangqi .p1 .glyph {
  color: #1c1f26;
}

/* --- shogi: pentagonal koma --- */

.board--shogi .piece {
  filter: drop-shadow(0 0.035em 0.055em rgba(0, 0, 0, 0.55));
}

.board--shogi .piece::before {
  content: '';
  position: absolute;
  inset: 4%;
  clip-path: polygon(50% 0%, 82% 12%, 97% 100%, 3% 100%, 18% 12%);
  background: linear-gradient(170deg, #fbeac4, #eed5a2 55%, #dcbd80);
}

.board--shogi .piece.rot180::before {
  clip-path: polygon(50% 100%, 82% 88%, 97% 0%, 3% 0%, 18% 88%);
}

.board--shogi .glyph {
  font-family: var(--cjk);
  font-weight: 700;
  font-size: 0.46em;
  color: #3b2a14;
  margin-top: 0.06em;
}

.board--shogi .piece.rot180 .glyph {
  rotate: 180deg;
  margin-top: -0.06em;
}

.board--shogi .kind-promoted .glyph {
  color: #b1261c;
}

/* =========================== HIGHLIGHTS =========================== */

.hl {
  position: absolute;
  translate: -50% -50%;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid;
  grid-template: 100% / 100%;
  place-items: center;
  pointer-events: none;
}

.hl::before {
  content: '';
}

.hl.last-from::before,
.hl.last-to::before {
  width: 88%;
  height: 88%;
  border-radius: 22%;
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  box-shadow: inset 0 0 0 0.03em color-mix(in srgb, var(--accent) 55%, transparent);
}

.hl.last-from::before {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.hl.sel::before {
  width: 94%;
  height: 94%;
  border-radius: 24%;
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  box-shadow:
    inset 0 0 0 0.055em var(--accent),
    0 0 0.35em color-mix(in srgb, var(--accent) 65%, transparent);
}

.hl.target::before {
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 80%, #fff);
  box-shadow: 0 0 0.25em color-mix(in srgb, var(--accent) 70%, transparent);
  animation: dotPulse 1.7s ease-in-out infinite;
}

.hl.target-capture::before {
  width: 96%;
  height: 96%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.07em color-mix(in srgb, #ff5f70 88%, transparent);
  animation: dotPulse 1.7s ease-in-out infinite;
}

.hl.hint::before {
  width: 92%;
  height: 92%;
  border-radius: 24%;
  background: rgba(251, 191, 36, 0.22);
  box-shadow: inset 0 0 0 0.05em #fbbf24;
  animation: hintPulse 1.1s ease-in-out infinite;
}

.hl.check::before {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(239, 68, 68, 0.72), rgba(239, 68, 68, 0) 68%);
  animation: checkPulse 0.95s ease-in-out infinite;
}

.hl.winline::before {
  width: 92%;
  height: 92%;
  border-radius: 24%;
  background: rgba(250, 204, 21, 0.3);
  box-shadow: inset 0 0 0 0.05em rgba(250, 204, 21, 0.9);
  animation: winGlow 0.9s ease-in-out infinite alternate;
}

/* ========================= SHOGI HANDS ========================= */

.hand {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 48px;
  width: min(
    100%,
    max(var(--board-min), calc((100dvh - var(--chrome)) * var(--cols) / var(--rows))),
    var(--board-max)
  );
  padding: 7px 12px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.hand[hidden] {
  display: none;
}

.hand-empty {
  font-size: 0.76rem;
  color: var(--muted);
}

.hand-tile {
  position: relative;
  width: 38px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  border: 0;
  background: none;
  font-family: var(--cjk);
  font-size: 19px;
  font-weight: 700;
  color: #3b2a14;
  transition: transform 0.2s var(--ease), filter 0.2s ease;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.hand-tile > span {
  position: relative;
  z-index: 1;
}

.hand-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 82% 12%, 97% 100%, 3% 100%, 18% 12%);
  background: linear-gradient(170deg, #fbeac4, #eed5a2 55%, #dcbd80);
}

.hand-tile:hover:not(:disabled) {
  transform: translateY(-4px);
}

.hand-tile.on {
  transform: translateY(-5px);
  filter: drop-shadow(0 0 6px var(--accent)) drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}

.hand-tile:disabled {
  cursor: default;
  opacity: 0.82;
}

.hand-tile .cnt {
  position: absolute;
  z-index: 2;
  right: -3px;
  bottom: -3px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 10px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.hand-top .hand-tile::before {
  clip-path: polygon(50% 100%, 82% 88%, 97% 0%, 3% 0%, 18% 88%);
}

.hand-top .hand-tile > span {
  rotate: 180deg;
}

/* ============================== PANEL ============================== */

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.pcard {
  padding: 16px;
  border-radius: 18px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-size: 20px;
  border: 1px solid var(--stroke);
  background: var(--surface-2);
}

.avatar-you {
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 60%, transparent), transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.pinfo {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.pinfo b {
  font-size: 0.92rem;
}

.psub {
  font-size: 0.73rem;
  color: var(--muted);
}

.turn-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  transition: 0.3s ease;
}

.turn-dot.active {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
  animation: livePulse 1.8s ease-out infinite;
}

.vs-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 11px 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.vs-line::before,
.vs-line::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--stroke), transparent);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.ctl-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.22);
}

.seg button {
  padding: 8px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.22s ease;
}

.seg button:hover {
  color: var(--text);
  background: var(--surface-2);
}

.seg button.on {
  color: #fff;
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 92%, #fff), color-mix(in srgb, var(--accent) 55%, #000));
  box-shadow: 0 5px 16px color-mix(in srgb, var(--accent) 38%, transparent);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  padding: 11px 10px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.2s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--stroke-2);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn[hidden] {
  display: none;
}

.btn.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 92%, #fff), color-mix(in srgb, var(--accent) 52%, #000));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 34%, transparent);
}

.btn.primary:hover:not(:disabled) {
  box-shadow: 0 12px 28px color-mix(in srgb, var(--accent) 46%, transparent);
}

/* --------------------------- score card --------------------------- */

.score[hidden] {
  display: none;
}

.disc-score {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.ds {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  border-radius: 11px;
  font-size: 0.8rem;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.2);
}

.ds b {
  margin-left: auto;
  font-size: 1rem;
}

.ds.you {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.mini-disc {
  width: 15px;
  height: 15px;
  flex: none;
  border-radius: 50%;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.35);
}

.mini-disc.d0 {
  background: radial-gradient(circle at 34% 28%, #4a505c, #0a0c11);
}

.mini-disc.d1 {
  background: radial-gradient(circle at 34% 28%, #fff, #c6c0b4);
}

.score-note {
  margin-top: 9px;
  font-size: 0.73rem;
  color: var(--muted);
}

/* ---------------------------- history ---------------------------- */

.history-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.history::-webkit-scrollbar {
  width: 6px;
}

.history::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}

.history li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 9px;
  font-size: 0.79rem;
  animation: fadeUp 0.3s var(--ease) both;
}

.history li:nth-child(odd) {
  background: rgba(255, 255, 255, 0.035);
}

.mv-n {
  width: 24px;
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.mv-by {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
}

.mv-by.you {
  color: color-mix(in srgb, var(--accent) 70%, #fff);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.mv-by.bot {
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
}

.mv-t {
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ======================= OVERLAYS / MODALS ======================= */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 5, 12, 0.58);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.24s ease both;
}

.modal {
  width: min(100%, 420px);
  padding: 30px 28px 24px;
  text-align: center;
  animation: modalIn 0.42s var(--ease) both;
}

.modal h2 {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.modal h3 {
  font-size: 1.05rem;
  margin-bottom: 16px;
}

.choose-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.choose-btn {
  min-width: 62px;
  height: 62px;
  padding: 0 16px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  border: 1px solid var(--stroke);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--cjk);
  font-size: 24px;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.2s var(--ease);
}

.choose-btn:hover {
  transform: translateY(-4px) scale(1.06);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 34%, transparent);
}

.result-emoji {
  font-size: 62px;
  line-height: 1;
  margin-bottom: 12px;
  animation: trophyIn 0.7s var(--ease) 0.12s both;
}

.result-reason {
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 62%, #fff);
}

.result-sub {
  margin: 10px 0 20px;
  font-size: 0.88rem;
  color: var(--muted);
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
}

/* ============================== TOAST ============================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 100;
  translate: -50% 14px;
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 0.86rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.3s ease,
    translate 0.3s var(--ease);
}

.toast.show {
  opacity: 1;
  translate: -50% 0;
}

/* ============================ KEYFRAMES ============================ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    translate: 0 14px;
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    translate: 0 26px;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.94);
  }
}

@keyframes trophyIn {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-25deg);
  }
  60% {
    transform: scale(1.16) rotate(6deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes livePulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 0%, rgba(52, 211, 153, 0.55));
  }
  70%,
  100% {
    box-shadow: 0 0 0 9px rgba(52, 211, 153, 0);
  }
}

@keyframes hueSlide {
  50% {
    background-position: 100% 0;
  }
}

@keyframes nudge {
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes piecePop {
  from {
    scale: 0.35;
    opacity: 0;
  }
}

@keyframes capOut {
  to {
    scale: 0.35;
    opacity: 0;
  }
}

@keyframes flipY {
  to {
    rotate: y 180deg;
  }
}

@keyframes promoFlash {
  50% {
    scale: 1.28;
    filter: brightness(1.7);
  }
}

@keyframes dotPulse {
  50% {
    opacity: 0.45;
    scale: 0.82;
  }
}

@keyframes hintPulse {
  50% {
    opacity: 0.35;
  }
}

@keyframes checkPulse {
  50% {
    opacity: 0.4;
    scale: 0.88;
  }
}

@keyframes winGlow {
  to {
    opacity: 0.45;
  }
}

/* ============================ RESPONSIVE ============================ */

/* ---- big desktop: let the board breathe ---- */
@media (min-width: 1500px) and (min-height: 900px) {
  .game-screen {
    --board-max: 820px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 360px;
  }
}

/* ---- landscape, but not much width (tablets, phones on their side) ----
   Height is the scarce resource here, so KEEP the two columns: stacking would
   waste the width and squeeze the board into nothing. */
@media (max-width: 1140px) and (orientation: landscape) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(230px, 30vw, 320px);
    gap: 14px;
  }

  .game-screen {
    gap: 12px;
    padding-bottom: 20px;
  }

  /* Let the panel scroll inside itself instead of pushing the page taller —
     that way the board stays put while you reach the controls. */
  .panel {
    max-height: calc(100dvh - 96px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
  }

  .panel::-webkit-scrollbar {
    width: 6px;
  }

  .panel::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 3px;
  }

  .history {
    max-height: 130px;
  }
}

/* ---- portrait tablets and narrow windows: stack, panel side by side ---- */
@media (max-width: 1040px) and (orientation: portrait) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    align-items: start;
  }

  .history {
    max-height: 180px;
  }
}

/* ---- short viewports: claw back every vertical pixel ---- */
@media (max-height: 620px) {
  .game-screen {
    --chrome: 96px;
    --board-min: 240px;
    gap: 10px;
    padding-top: 8px;
    padding-bottom: 14px;
  }

  .game--shogi {
    --chrome: 190px;
  }

  .topbar {
    padding: 6px 12px;
  }

  .btn-icon,
  .topbar-icon {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  .topbar-title h1 {
    font-size: 0.95rem;
  }

  .topbar-en {
    display: none;
  }

  .hand {
    min-height: 40px;
    padding: 4px 10px;
  }

  .hand-tile {
    width: 30px;
    height: 34px;
    font-size: 15px;
  }

  .hand-empty {
    font-size: 0.7rem;
  }

  .home {
    padding-top: 28px;
  }
}

/* ---- phones ---- */
@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .status-pill {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .hand-tile {
    width: 34px;
    height: 38px;
    font-size: 17px;
  }

  .modal {
    padding: 24px 20px 20px;
  }

  .result-emoji {
    font-size: 48px;
  }
}

/* Portrait phones have width to spare vertically, not horizontally: let the
   board use the full column instead of being capped by the height budget. */
@media (max-width: 640px) and (orientation: portrait) {
  .board-frame,
  .hand {
    width: 100%;
  }
}

/* ---- touch: hover styling never "sticks" to a tapped element ---- */
@media (hover: none) {
  .game-card:hover {
    border-color: var(--stroke);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  }

  .game-card:hover .card-glow {
    opacity: 0;
  }

  .game-card:hover .card-icon,
  .game-card:hover .card-cta .arrow {
    transform: none;
  }

  .btn:hover:not(:disabled),
  .btn-icon:hover,
  .hand-tile:hover:not(:disabled),
  .choose-btn:hover {
    transform: none;
  }
}

/* ---- coarse pointer: tap targets big enough to hit ---- */
@media (pointer: coarse) {
  .btn {
    padding: 13px 10px;
  }

  .seg button {
    padding: 11px 4px;
  }

  .btn-icon {
    width: 44px;
    height: 44px;
  }
}

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