/* ===== Chess — 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 a warm brown "felt", so the look is identical no
   matter the OS preference. The board keeps a fixed classic wood-on-cream
   palette so the pieces stay legible. */

html, body { height: 100%; }
body.chess-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);
  /* Solitaire-style "felt", but in brown: a warm radial base the stage sits on.
     Selector is body.chess-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.chess-app *, body.chess-app *::before, body.chess-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, .24);
  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; font-size: 22px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.topbar__title { margin: 0; font-size: clamp(19px, 3.4vw, 25px); 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, .55); }

/* ---------- 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, .55); }
.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 brown felt, mirroring Solitaire's surface */
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, .05) 0 2px, transparent 2px 6px);
  /* Largest square that clears the top bar + the caption line under the board
     (chrome ≈ 174px) and fits the viewport width (minus padding + scrollbar). */
  --bs: min(calc(100vw - var(--spad) * 2 - 16px), calc(100vh - 174px), 700px);
}
.board-wrap {
  position: relative;
  width: var(--bs); height: var(--bs);
}
/* Small, single-line "X to move" caption right-aligned under the board. */
.board-status {
  width: var(--bs); 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 {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
  border: 6px solid #4a3526; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  overflow: hidden; user-select: none; touch-action: manipulation;
}
.sq {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--bs) * .082);        /* pieces scale with the board */
  line-height: 1; cursor: pointer;
}
.sq--light { background: #efeab5; }
.sq--dark  { background: #a8784f; }
.sq .pc { position: relative; z-index: 1; transition: transform .08s ease; }
.sq .pc--w { color: #f8f8f8; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
.sq .pc--b { color: #16130f; text-shadow: 0 1px 1px rgba(255,255,255,.25); }

/* coordinate labels */
.sq__coord { position: absolute; font-size: max(8px, calc(var(--bs) * .021)); font-weight: 700; opacity: .5; pointer-events: none; z-index: 0; }
.sq__file { right: 3px; bottom: 2px; }
.sq__rank { left: 3px; top: 2px; }
.sq--light .sq__coord { color: #8a6b3f; }
.sq--dark  .sq__coord { color: #f0e6d0; }

/* highlights */
.sq--selected::after { content: ""; position: absolute; inset: 0; background: rgba(255, 210, 60, .42); }
.sq--last::after      { content: ""; position: absolute; inset: 0; background: rgba(120, 190, 90, .34); }
.sq--check            { box-shadow: inset 0 0 0 3px rgba(220, 50, 47, .85); }
.hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 2; }
.hint::before { content: ""; width: 26%; height: 26%; border-radius: 50%; background: rgba(30, 30, 30, .28); }
.hint--cap::before { width: 90%; height: 90%; background: transparent; border: 4px solid rgba(220, 50, 47, .55); }

/* ---------- Promotion chooser ---------- */
.promo { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(6, 12, 20, .5); }
.promo[hidden] { display: none; }
.promo__inner {
  background: rgba(28, 18, 10, .78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .16); border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .5); padding: 14px 16px; text-align: center;
}
.promo__label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 8px; color: #f4ead9; }
.promo__opts { display: flex; gap: 8px; }
.promo__opts button {
  appearance: none; cursor: pointer; font-size: 34px; line-height: 1;
  width: 56px; height: 56px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .18); background: rgba(255, 255, 255, .08); color: #f4ead9;
}
.promo__opts button:hover { border-color: #f0c674; background: rgba(255, 255, 255, .16); }
.link-btn { appearance: none; border: 0; background: transparent; cursor: pointer; font: inherit; font-size: 13px; color: #f0c674; padding: 6px; text-decoration: underline; }
.link-btn[hidden] { display: none; }

/* ---------- Rules modal (frosted glass) ---------- */
.modal { position: fixed; inset: 0; z-index: 1100; overflow: auto; display: grid; place-content: center; place-content: safe center; padding: 16px; }
.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);
  padding: 0; border-radius: 16px;
  /* Frosted glass: translucent warm tint + heavy backdrop blur so the felt shows through. */
  background: rgba(30, 20, 12, .55);
  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; padding: 12px 20px 16px; }

/* ---------- 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, .sq .pc { transition: none; }
}
