/* ===== Jungle (Dou Shou Qi) — game UI =====
   Solitaire-style layout with a frosted-glass chrome that deliberately does
   NOT follow the light/dark theme: every surface uses fixed translucent
   colours layered over the same warm walnut "felt" the chess page uses, so
   the look is identical no matter the OS preference. The board keeps its own
   sand-and-wood palette with water, trap and den squares drawn in CSS. */

html, body { height: 100%; }
body.jungle-app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;               /* no horizontal scroll on small screens */
  /* Stage side padding lives in one var so the board can size itself to fit. */
  --spad: clamp(10px, 2.5vh, 26px);
  /* Walnut backdrop: the chess theme, so both board games sit together.
     Selector is body.jungle-app so it outranks base.css's body.gc-body background. */
  background: radial-gradient(120% 100% at 50% -10%, #7c5330 0%, #5e3d22 45%, #3d2815 100%);
  color: #f4ead9;
  font-family: var(--gc-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
}
body.jungle-app *, body.jungle-app *::before, body.jungle-app *::after { box-sizing: border-box; }

/* ---------- Top bar (frosted glass over the felt) ---------- */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap;
  padding: 10px clamp(12px, 3vw, 28px);
  background: rgba(0, 0, 0, .26);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  border-bottom: 1px solid rgba(255, 255, 255, .10);
  box-shadow: 0 2px 14px rgba(0, 0, 0, .28);
  z-index: 20;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__logo {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(140deg, #f0c674, #cf9b45);
  color: #3a2410;                    /* ink for the lion mark inside */
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35), inset 0 0 0 2px rgba(0, 0, 0, .12);
}
.topbar__logo svg { width: 23px; height: 23px; display: block; }
.topbar__title { margin: 0; font-size: clamp(18px, 3.4vw, 24px); letter-spacing: -.02em; white-space: nowrap; color: #f7eede; }
.topbar__controls { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.topbar__btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Segmented control (mode / difficulty) ---------- */
.segmented {
  display: inline-flex; gap: 4px; padding: 4px;
  background: rgba(0, 0, 0, .28); border: 1px solid rgba(255, 255, 255, .14); border-radius: 12px;
}
.segmented[hidden] { display: none; }
.seg {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 14px; border: 0; border-radius: 9px; background: transparent; color: rgba(255, 255, 255, .72);
  transition: background .15s ease, color .15s ease;
}
.seg--sm { padding: 6px 11px; font-size: 13px; }
.seg:hover { color: #fff; }
.seg[aria-selected="true"] {
  /* Frosted light-glass chip: translucent white fill + real backdrop blur, with
     inset edge highlights so it reads as a raised glass tile, not flat white. */
  background: rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px) saturate(160%);
  -webkit-backdrop-filter: blur(8px) saturate(160%);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), inset 0 0 0 1px rgba(255, 255, 255, .22), 0 3px 10px rgba(0, 0, 0, .3);
}
.seg:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(240, 198, 116, .5); }

/* ---------- Buttons (glass) ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 15px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .20); background: rgba(255, 255, 255, .10); color: #f4ead9;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .34); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(240, 198, 116, .5); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--primary { background: linear-gradient(#f0c674, #cf9b45); border-color: #cf9b45; color: #3a2410; }
.btn--primary:hover:not(:disabled) { background: linear-gradient(#f6d184, #d8a950); }

/* ---------- Stage + board ---------- */
.stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  padding: var(--spad);
  overflow: hidden;                 /* never show a scrollbar here */
  /* faint diagonal weave over the felt */
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, .045) 0 2px, transparent 2px 6px);
  /* 7:9 board: derive width from whichever axis binds — the viewport WIDTH
     (minus stage padding twice and a 16px scrollbar allowance) or the height
     left after the top bar + the tray and caption lines (chrome ≈ 196px). */
  --bw: min(calc(100vw - var(--spad) * 2 - 16px), calc((100vh - 196px) * 0.7778), 470px);
}
.board-wrap {
  position: relative;
  width: var(--bw); height: calc(var(--bw) * 9 / 7);
}
/* One thin line above the board holding the animals each side has lost. */
.tray {
  width: var(--bw);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 18px;
}
.tray__got { display: inline-flex; gap: 1px; flex-wrap: nowrap; overflow: hidden; }
.tray__chip { display: inline-block; width: 15px; height: 15px; color: #f2e8c9; opacity: .9; }
.tray__chip .beast { width: 100%; height: 100%; }
/* On the dark backdrop the cream face fill would blob out; keep just the strokes. */
.tray__chip .face { fill: none; }
/* Each chip wears the colour of the side that lost it, so the two piles tell
   apart without any text label. */
.tray__chip--r { color: #ffb3a8; }
.tray__chip--b { color: #a8d3ff; }
/* Small, single-line "X to move" caption right-aligned under the board. */
.board-status {
  width: var(--bw); margin: 0;
  font-size: 12px; font-weight: 600; line-height: 1.2; text-align: right;
  color: #d8c3a3; text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%; height: 100%;
  background: linear-gradient(160deg, #e5d2a8, #cdb083);
  border: 6px solid #4a3526; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .3);
  user-select: none; touch-action: manipulation;
}

/* ---------- Squares ---------- */
.sq {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(74, 53, 38, .38);
}
/* River: cool blue with pale streaks so the two lakes read at a glance. */
.sq--water {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .22) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #79c2d8, #3d94b6 55%, #2a769e);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3), inset 0 -3px 8px rgba(0, 40, 60, .25);
}
/* Traps: hatched warning ground, tinted to the owning side. */
.sq--trap {
  background:
    repeating-linear-gradient(45deg, rgba(190, 60, 40, .3) 0 3px, transparent 3px 8px),
    linear-gradient(160deg, #f0dcae, #dfb87e);
}
.sq--trap-b { background: repeating-linear-gradient(45deg, rgba(40, 100, 190, .3) 0 3px, transparent 3px 8px), linear-gradient(160deg, #cfe2f2, #9dc4e4); }
/* Den: a dark hollow sunk into the middle of the back rank.
   `closest-side` makes the gradient radius exactly half the cell, so the disc
   is a true circle centred on the square and tangent to its edges — stops are
   then fractions of that inscribed circle instead of the corner distance. */
.sq--den   { background: radial-gradient(circle closest-side at 50% 50%, #6d3122 0 74%, #96543a 75% 90%, #c19263 91% 100%); }
.sq--den-b { background: radial-gradient(circle closest-side at 50% 50%, #1b3a5e 0 74%, #35618d 75% 90%, #7aa6c6 91% 100%); }
/* Terrain lettering (陷 trap, 穴 den) kept faint so pieces stay legible. */
.terr {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--bw) * .052); font-weight: 700; line-height: 1;
  font-family: "PingFang SC", "Microsoft YaHei", "Heiti SC", system-ui, sans-serif;
  color: rgba(74, 53, 38, .5); pointer-events: none;
}
.sq--den .terr, .sq--den-b .terr { color: rgba(255, 255, 255, .6); text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }

/* ---------- Animal tokens ---------- */
.tok {
  position: relative; z-index: 1;
  width: 86%; height: 86%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 34%, #fffdf3, #ecdcae);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .38), inset 0 0 0 2px rgba(60, 40, 10, .16);
  transition: transform .08s ease;
}
.sq:hover .tok { transform: scale(1.06); }
/* Beast marks are inline SVG. Each svg root carries its own pen (fill/stroke)
   so a slot only has to supply the ink colour through `color`, plus a box. */
.beast { display: block; width: 100%; height: 100%; overflow: visible; }
.tok__face { display: block; width: 80%; height: 80%; margin-bottom: 5%; color: #3a2a12; }
/* side ring + rank pip identify owner and strength at a glance */
.tok--r { box-shadow: 0 2px 4px rgba(0, 0, 0, .38), inset 0 0 0 3px #c8342b; }
.tok--b { box-shadow: 0 2px 4px rgba(0, 0, 0, .38), inset 0 0 0 3px #22599c; }
.tok__rank {
  position: absolute; right: -4%; bottom: -6%;
  min-width: 42%; height: 42%; padding: 0 2%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  font-size: calc(var(--bw) * .032); font-weight: 800; line-height: 1;
  color: #fff; background: #7a4a1e;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 255, 255, .35);
  font-family: var(--gc-font, system-ui, sans-serif);
}
.tok--r .tok__rank { background: #a82a22; }
.tok--b .tok__rank { background: #1d4a85; }
/* an animal standing in the enemy trap has lost its rank */
.tok--trap { filter: saturate(.72); box-shadow: 0 2px 4px rgba(0, 0, 0, .38), inset 0 0 0 3px #d08a12, 0 0 0 2px rgba(208, 138, 18, .5); }
.tok--trap .tok__rank { background: #b06a10; }

/* ---------- Highlights ---------- */
.sq--sel .tok { box-shadow: 0 0 0 3px #ffe066, 0 2px 6px rgba(0, 0, 0, .45); }
.sq--last::before {
  content: ""; position: absolute; inset: 6%; border-radius: 12%;
  box-shadow: inset 0 0 0 3px rgba(240, 198, 116, .8); pointer-events: none;
}
/* legal destination dot / capture ring */
.dot { position: absolute; width: 32%; height: 32%; border-radius: 50%; background: rgba(58, 36, 16, .42); pointer-events: none; z-index: 0; }
.dot--cap {
  width: 96%; height: 96%; background: transparent;
  border: 4px solid rgba(214, 64, 48, .72);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

/* ---------- Modals (frosted glass; the overlay itself scrolls, never the card) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1100;
  display: flex; padding: 16px;
  overflow-y: auto;                 /* the overlay scrolls, not the card */
  overscroll-behavior: contain;
}
.modal[hidden] { display: none; }
.modal__backdrop { position: fixed; inset: 0; background: rgba(6, 12, 20, .5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal__panel {
  position: relative; z-index: 1; width: min(94vw, 520px);
  margin: auto;                     /* centres AND lets a too-tall card scroll in from the top */
  padding: 0; border-radius: 16px;
  /* Frosted glass: translucent warm-brown tint + heavy backdrop blur so the walnut shows through. */
  background: rgba(30, 20, 12, .58);
  backdrop-filter: blur(26px) saturate(140%);
  -webkit-backdrop-filter: blur(26px) saturate(140%);
  color: #f4ead9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .5);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .2);
}
.modal__head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.modal__head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.modal__x { margin-left: auto; border: 0; background: transparent; cursor: pointer; font-size: 26px; line-height: 1; color: #d8c3a3; padding: 0 4px; }
.modal__x:hover { color: #fff; }
.modal__body { padding: 6px 20px 4px; font-size: 14px; line-height: 1.6; color: #e6d6bd; }
.modal__lead { margin: 10px 0 12px; color: #f7eede; }
.modal__body h3 { margin: 16px 0 6px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #f0c674; }
.modal__body ul { margin: 0 0 6px; padding-left: 20px; }
.modal__body li { margin: 3px 0; }
.modal__body b { color: #fff; }
kbd { font: 600 12px/1.4 ui-monospace, "Segoe UI", monospace; padding: 1px 6px; border-radius: 5px; color: #f4ead9; background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .22); }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }

/* End-of-game card */
.modal__panel--end { width: min(92vw, 380px); text-align: center; padding: 22px 20px 8px; }
.end__medal { display: flex; justify-content: center; min-height: 48px; }
.end__medal-icon { width: 48px; height: 48px; color: #ffd75e; }
.end__medal-icon--draw { color: #a8d3ff; }
/* Explicit rule: a class-level display would otherwise beat the UA's [hidden]. */
.end__medal-icon[hidden] { display: none; }
.end__title { margin: 8px 0 2px; font-size: 24px; letter-spacing: -.01em; }
.end__sub { margin: 0; font-size: 14px; color: #e6d6bd; }
.modal__foot--end { justify-content: center; padding-top: 18px; }

/* ---------- Back-to-center link (glass chip, theme-independent) ---------- */
.gc-back {
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: #f4ead9; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); opacity: .85;
}
.gc-back:hover { opacity: 1; color: #fff; }

/* Small screens: let the control row drop below the brand row. */
@media (max-width: 620px) {
  .topbar__controls { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .seg, .tok { transition: none; }
}
