/* ==========================================================================
   ChessBro — Modern Responsive 2-Player Tabletop Chess PWA Stylesheet
   ========================================================================== */

:root {
  --target-size: 28px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  /* Default Theme: Classic Wood */
  --bg-app: #171311;
  --bg-surface: #241e1b;
  --bg-elevated: #312824;
  --border-subtle: rgba(255, 236, 209, 0.12);
  --text-primary: #f9f3eb;
  --text-muted: #bfb09f;
  --accent: #e09f3e;
  --accent-contrast: #1a1206;
  --danger: #ef4444;

  /* Board colors */
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --board-border: #4a3221;
  --board-shadow: 0 18px 48px rgba(0, 0, 0, 0.58);
  --sq-selected: rgba(255, 213, 59, 0.62);
  --sq-last-from: rgba(247, 217, 76, 0.36);
  --sq-last-to: rgba(247, 217, 76, 0.5);
  --hint-dot: rgba(22, 18, 14, 0.3);
  --hint-ring: rgba(217, 56, 41, 0.62);
  --coord-on-light: #8c6239;
  --coord-on-dark: #f5e6cc;
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

/* ==========================================================================
   6 Customizable Board & UI Themes
   ========================================================================== */

html[data-board-theme="wood"] {
  --bg-app: #171311;
  --bg-surface: #251e1a;
  --bg-elevated: #332923;
  --accent: #e5a443;
  --accent-contrast: #1c1306;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --board-border: #4e3524;
  --coord-on-light: #8f633e;
  --coord-on-dark: #f7e6ca;
}

html[data-board-theme="tournament"] {
  --bg-app: #141a14;
  --bg-surface: #1e271e;
  --bg-elevated: #2a362a;
  --border-subtle: rgba(218, 240, 210, 0.13);
  --text-primary: #f2f7f0;
  --text-muted: #a6b9a3;
  --accent: #85b65c;
  --accent-contrast: #101b09;
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --board-border: #334625;
  --sq-selected: rgba(246, 246, 105, 0.72);
  --sq-last-from: rgba(245, 246, 130, 0.45);
  --sq-last-to: rgba(245, 246, 130, 0.62);
  --coord-on-light: #5c7a3d;
  --coord-on-dark: #eeeed2;
}

html[data-board-theme="marble"] {
  --bg-app: #12161d;
  --bg-surface: #1b222d;
  --bg-elevated: #263040;
  --border-subtle: rgba(210, 226, 248, 0.14);
  --text-primary: #f1f5fb;
  --text-muted: #9fb0c7;
  --accent: #7da6e8;
  --accent-contrast: #0c1524;
  --sq-light: #e6ebf2;
  --sq-dark: #6f839d;
  --board-border: #2c3849;
  --sq-selected: rgba(114, 179, 255, 0.56);
  --sq-last-from: rgba(135, 192, 255, 0.34);
  --sq-last-to: rgba(135, 192, 255, 0.5);
  --coord-on-light: #526680;
  --coord-on-dark: #eef3fa;
}

html[data-board-theme="ocean"] {
  --bg-app: #091520;
  --bg-surface: #102334;
  --bg-elevated: #173147;
  --border-subtle: rgba(135, 220, 255, 0.15);
  --text-primary: #eaf7ff;
  --text-muted: #8eb7cf;
  --accent: #38bdf8;
  --accent-contrast: #041926;
  --sq-light: #c9e6f2;
  --sq-dark: #2c6e8f;
  --board-border: #133c54;
  --sq-selected: rgba(56, 189, 248, 0.55);
  --sq-last-from: rgba(56, 189, 248, 0.3);
  --sq-last-to: rgba(56, 189, 248, 0.46);
  --coord-on-light: #1e5773;
  --coord-on-dark: #d9f1fb;
}

html[data-board-theme="neon"] {
  --bg-app: #0c0916;
  --bg-surface: #161129;
  --bg-elevated: #221a3d;
  --border-subtle: rgba(192, 132, 252, 0.22);
  --text-primary: #f6f0ff;
  --text-muted: #b39ddb;
  --accent: #22d3ee;
  --accent-contrast: #061b22;
  --sq-light: #3b2d63;
  --sq-dark: #1d1436;
  --board-border: #5b21b6;
  --board-shadow: 0 0 38px rgba(139, 92, 246, 0.35), 0 16px 40px rgba(0, 0, 0, 0.7);
  --sq-selected: rgba(34, 211, 238, 0.48);
  --sq-last-from: rgba(217, 70, 239, 0.28);
  --sq-last-to: rgba(217, 70, 239, 0.45);
  --hint-dot: rgba(34, 211, 238, 0.55);
  --hint-ring: rgba(244, 63, 94, 0.75);
  --coord-on-light: #d8b4fe;
  --coord-on-dark: #67e8f9;
}

html[data-board-theme="sakura"] {
  --bg-app: #1d1317;
  --bg-surface: #2b1c22;
  --bg-elevated: #3c2730;
  --border-subtle: rgba(255, 209, 224, 0.16);
  --text-primary: #fff2f6;
  --text-muted: #d4a6b5;
  --accent: #f48fb1;
  --accent-contrast: #260c15;
  --sq-light: #fce8ee;
  --sq-dark: #be6e86;
  --board-border: #592b3a;
  --sq-selected: rgba(255, 182, 193, 0.7);
  --sq-last-from: rgba(244, 143, 177, 0.38);
  --sq-last-to: rgba(244, 143, 177, 0.56);
  --coord-on-light: #9e4b65;
  --coord-on-dark: #fff0f5;
}

/* ==========================================================================
   Reset & Base Typography
   ========================================================================== */

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
  overscroll-behavior: none;
}

h1,
h2,
h3 {
  margin: 0;
  text-wrap: balance;
}

p,
li {
  margin: 0;
  text-wrap: pretty;
}

img,
svg {
  display: block;
  max-inline-size: 100%;
}

[hidden] {
  display: none !important;
}

:where(button, select, textarea, input:not([type="checkbox"], [type="radio"]), [role="button"], label:has(input[type="checkbox"], input[type="radio"])) {
  min-block-size: var(--target-size);
  min-inline-size: var(--target-size);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: clip;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   App Shell Grid (Portrait Mobile/iPad Default + Wide Landscape Adaptation)
   ========================================================================== */

.app-shell {
  block-size: 100dvh;
  inline-size: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "topbar"
    "topplayer"
    "board"
    "bottomplayer"
    "dock";
  gap: 0.45rem;
  padding-top: max(0.45rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(0.45rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(0.6rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.6rem, env(safe-area-inset-right, 0px));
}

.topbar {
  grid-area: topbar;
}

.player-top {
  grid-area: topplayer;
}

.board-stage {
  grid-area: board;
}

.move-panel {
  display: none;
  grid-area: movepanel;
}

.player-bottom {
  grid-area: bottomplayer;
}

.bottom-dock {
  grid-area: dock;
}

/* Wide Landscape Layout (iPad Landscape & Desktop Monitors) */
@media (min-width: 900px) and (min-aspect-ratio: 6 / 5) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "board topbar"
      "board topplayer"
      "board movepanel"
      "board bottomplayer"
      "board dock";
    column-gap: 1.15rem;
    row-gap: 0.65rem;
    padding-top: max(0.8rem, env(safe-area-inset-top, 0px));
    padding-bottom: max(0.8rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }

  .move-panel {
    display: flex;
    flex-direction: column;
    min-block-size: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.7rem;
  }
}

/* Zen Fullscreen Fallback (for iOS Safari tab without Fullscreen API or clean mode) */
body.zen-fullscreen .topbar {
  padding-block: 0.15rem;
}

body.zen-fullscreen .brand-title,
body.zen-fullscreen .btn-label {
  display: none;
}

/* ==========================================================================
   Topbar & Buttons
   ========================================================================== */

.topbar {
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.45rem;
}

:where(.toolbar > :not(button, input, select, textarea, a, [role="button"], label)) {
  min-inline-size: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-inline-size: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  inline-size: 2.1rem;
  block-size: 2.1rem;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.brand-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.brand-title {
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-badge {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--accent);
}

.brand-badge.in-check {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.toolbar {
  display: flex;
  align-items: safe center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  padding: 0.4rem 0.72rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--bg-elevated);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
  font-weight: 700;
}

.btn-primary:hover {
  filter: brightness(1.07);
  background: var(--accent);
}

.btn-accent {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
}

.full-width {
  inline-size: 100%;
}

@media (max-width: 620px) {
  .btn-label {
    display: none;
  }
  .icon-btn {
    padding-inline: 0.55rem;
  }
}

/* ==========================================================================
   Player HUD Cards & Tabletop 180° Orientation
   ========================================================================== */

.player-card {
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.3s ease;
  max-inline-size: 760px;
  inline-size: 100%;
  margin-inline: auto;
}

.player-card.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(0, 0, 0, 0.28);
}

/* In Tabletop mode on Portrait screens, flip Top Player's bar 180deg so they read it upright! */
@media (max-aspect-ratio: 6 / 5), (max-width: 899px) {
  html[data-view-mode="tabletop"] .player-top {
    transform: rotate(180deg);
  }
}

.player-identity {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-inline-size: 0;
  flex: 1 1 auto;
}

.player-avatar {
  inline-size: 2.25rem;
  block-size: 2.25rem;
  flex: 0 0 2.25rem;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.18rem;
  display: grid;
  place-items: center;
}

.player-meta {
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.player-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.player-name {
  font-weight: 700;
  font-size: 0.92rem;
}

.check-tag {
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
  @media (prefers-reduced-motion: no-preference) {
    animation: pulseCheck 1s ease-in-out infinite;
  }
}

@keyframes pulseCheck {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-block-size: 1.15rem;
}

.captured-pieces {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.captured-pieces .mini-piece {
  inline-size: 1.05rem;
  block-size: 1.05rem;
  margin-inline-end: -0.22rem;
}

.material-badge {
  margin-inline-start: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

.player-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.chip-btn {
  display: inline-grid;
  place-items: center;
  padding: 0.25rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 0.85rem;
}

.chess-clock {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: 1.02rem;
  padding: 0.36rem 0.68rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  min-inline-size: 4.3rem;
  text-align: center;
}

.player-card.active-turn .chess-clock {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}

.chess-clock.low-time {
  background: var(--danger) !important;
  color: #fff !important;
}

/* ==========================================================================
   Chessboard Stage & Container-Queried 1:1 Square Board
   ========================================================================== */

.board-stage {
  min-block-size: 0;
  min-inline-size: 0;
  inline-size: 100%;
  block-size: 100%;
  container: boardstage / size;
  display: grid;
  place-items: center;
}

.board-frame {
  inline-size: min(100cqi, 100cqb);
  block-size: min(100cqi, 100cqb);
  aspect-ratio: 1 / 1;
  padding: clamp(4px, 1.1cqmin, 10px);
  border-radius: clamp(10px, 2cqmin, 18px);
  background: var(--board-border);
  box-shadow: var(--board-shadow);
  display: grid;
}

.chess-board {
  inline-size: 100%;
  block-size: 100%;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: clamp(6px, 1.2cqmin, 11px);
  overflow: clip;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 100%;
  block-size: 100%;
  padding: 0;
  border: 0;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

.square.light {
  background-color: var(--sq-light);
}

.square.dark {
  background-color: var(--sq-dark);
}

/* Wood subtle grain effect when wood theme is active */
html[data-board-theme="wood"] .square.dark {
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(0, 0, 0, 0.06) 100%);
}

.square.last-from::before,
.square.last-to::before,
.square.selected::before,
.square.drag-over::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.square.last-from::before {
  background: var(--sq-last-from);
}

.square.last-to::before {
  background: var(--sq-last-to);
}

.square.selected::before {
  background: var(--sq-selected);
}

.square.drag-over::before {
  background: var(--sq-selected);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.square:focus-visible {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 2;
}

/* Checked King Radial Alert */
.square.in-check::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 35, 35, 0.9) 0%, rgba(220, 20, 20, 0.55) 48%, transparent 74%);
  pointer-events: none;
  z-index: 1;
}

/* Legal Move Hints (Quiet Dot & Capture Ring) */
.move-hint {
  position: absolute;
  pointer-events: none;
  z-index: 3;
}

.move-hint.quiet {
  inline-size: 30%;
  block-size: 30%;
  border-radius: 50%;
  background: var(--hint-dot);
}

.move-hint.capture {
  inset: 6%;
  border-radius: 50%;
  border: clamp(3px, 0.8cqmin, 6px) solid var(--hint-ring);
}

/* Coordinates a-h & 1-8 */
.coord {
  position: absolute;
  font-size: clamp(9px, 2cqmin, 13px);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  opacity: 0.9;
}

.square.light .coord {
  color: var(--coord-on-light);
}

.square.dark .coord {
  color: var(--coord-on-dark);
}

.coord-rank {
  inset-block-start: 5%;
  inset-inline-start: 6%;
}

.coord-file {
  inset-block-end: 4%;
  inset-inline-end: 6%;
}

body.hide-coords .coord {
  display: none;
}

/* Chess Piece inside Square */
.square.has-animating-piece {
  z-index: 25;
}

.piece {
  position: relative;
  z-index: 2;
  inline-size: 86%;
  block-size: 86%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.34));
  /* Identity individual transform properties to preserve stacking context and compose cleanly with move translate/scale */
  translate: 0px 0px;
  rotate: 0deg;
  scale: 1;
  pointer-events: none;
  @media (prefers-reduced-motion: no-preference) {
    transition: rotate 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

.piece svg {
  inline-size: 100%;
  block-size: 100%;
}

/* Tabletop Mode: Rotate top player's pieces 180deg to face the opposite player! */
@supports (translate: 0px) {
  html[data-view-mode="tabletop"] .piece[data-top-player="true"] {
    rotate: 180deg;
  }
}

@supports not (translate: 0px) {
  html[data-view-mode="tabletop"] .piece[data-top-player="true"] {
    transform: rotate(180deg);
  }
}

.piece.is-animating {
  z-index: 25;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.48));
}

.piece.captured-ghost {
  position: absolute;
  z-index: 10;
}

.square.dragging-source .piece {
  opacity: 0.25;
}

/* Floating Drag Ghost */
.drag-ghost {
  position: fixed;
  inset-inline-start: 0;
  inset-block-start: 0;
  inline-size: 72px;
  block-size: 72px;
  pointer-events: none;
  z-index: 9999;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.55));
  will-change: transform;
}

.drag-ghost svg {
  inline-size: 100%;
  block-size: 100%;
}

.drag-ghost[data-rotated="true"] svg {
  transform: rotate(180deg);
}

/* ==========================================================================
   Bottom Quick Action Dock & Move List
   ========================================================================== */

.bottom-dock {
  display: flex;
  align-items: safe center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-inline-size: 760px;
  inline-size: 100%;
  margin-inline: auto;
}

.dock-btn {
  flex: 1 1 60px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.16rem;
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.74rem;
  font-weight: 600;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.dock-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
}

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

.move-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block-end: 0.45rem;
  margin-block-end: 0.45rem;
  border-block-end: 1px solid var(--border-subtle);
}

.move-panel-title {
  font-size: 0.92rem;
  font-weight: 700;
}

.move-count-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.modal-move-list {
  max-block-size: 210px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}

.move-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr 1fr;
  align-items: center;
  gap: 0.4rem;
  padding: 0.24rem 0.45rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.move-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

.move-num {
  color: var(--text-muted);
  font-weight: 600;
}

.move-san {
  font-weight: 600;
}

.move-san.latest {
  color: var(--accent);
  font-weight: 800;
}

.move-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
  padding: 0.65rem 0.4rem;
  text-align: center;
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */

.toast {
  position: fixed;
  inset-inline: 0;
  inset-block-end: max(4.5rem, calc(env(safe-area-inset-bottom, 0px) + 4.2rem));
  margin-inline: auto;
  inline-size: fit-content;
  max-inline-size: min(92%, 440px);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 9000;
  text-align: center;
}

/* ==========================================================================
   Native Modal Dialogs (Modern Web Guidance Compliant)
   ========================================================================== */

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.app-dialog {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 0;
  inline-size: min(92%, 500px);
  max-block-size: min(88dvh, 720px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.68);
}

.app-dialog[open] {
  display: flex;
  flex-direction: column;
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  padding: 1.15rem;
  gap: 0.95rem;
}

.dialog-inner.rotated-modal {
  transform: rotate(180deg);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dialog-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
}

.close-btn {
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 0.95rem;
  padding: 0;
}

.dialog-body {
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-inline-end: 0.15rem;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.setting-group h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Theme Swatch Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.55rem;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-elevated);
  text-align: start;
}

.theme-option[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.swatch {
  inline-size: 2rem;
  block-size: 2rem;
  flex: 0 0 2rem;
  border-radius: 6px;
  overflow: clip;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.swatch-wood i:nth-child(1), .swatch-wood i:nth-child(4) { background: #f0d9b5; }
.swatch-wood i:nth-child(2), .swatch-wood i:nth-child(3) { background: #b58863; }

.swatch-tournament i:nth-child(1), .swatch-tournament i:nth-child(4) { background: #eeeed2; }
.swatch-tournament i:nth-child(2), .swatch-tournament i:nth-child(3) { background: #769656; }

.swatch-marble i:nth-child(1), .swatch-marble i:nth-child(4) { background: #e6ebf2; }
.swatch-marble i:nth-child(2), .swatch-marble i:nth-child(3) { background: #6f839d; }

.swatch-ocean i:nth-child(1), .swatch-ocean i:nth-child(4) { background: #c9e6f2; }
.swatch-ocean i:nth-child(2), .swatch-ocean i:nth-child(3) { background: #2c6e8f; }

.swatch-neon i:nth-child(1), .swatch-neon i:nth-child(4) { background: #3b2d63; }
.swatch-neon i:nth-child(2), .swatch-neon i:nth-child(3) { background: #1d1436; }

.swatch-sakura i:nth-child(1), .swatch-sakura i:nth-child(4) { background: #fce8ee; }
.swatch-sakura i:nth-child(2), .swatch-sakura i:nth-child(3) { background: #be6e86; }

.theme-name {
  font-size: 0.84rem;
  font-weight: 700;
}

/* Segmented Controls */
.segmented-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.45rem;
}

.segmented-col-sm {
  grid-template-columns: 1fr;
}

.anim-speed-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-elevated);
  text-align: start;
  font-size: 0.86rem;
}

.seg-btn.seg-compact {
  align-items: center;
  text-align: center;
  font-weight: 700;
  padding-inline: 0.45rem;
}

.seg-btn small {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 400;
}

.seg-btn[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Checkboxes */
.toggles-list {
  gap: 0.35rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  inline-size: 1.2rem;
  block-size: 1.2rem;
  accent-color: var(--accent);
}

/* New Game Dialog */
.players-setup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 0.5rem;
}

@media (max-width: 520px) {
  .players-setup {
    grid-template-columns: 1fr;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.field-group input {
  padding: 0.5rem 0.68rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
}

.time-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 0.45rem;
}

.time-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.time-btn small {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.time-btn[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-block-start: 0.25rem;
}

/* Pawn Promotion Choices */
.promo-dialog {
  inline-size: min(92%, 400px);
}

.promo-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.promo-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.promo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 0.4rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 0.84rem;
}

.promo-btn:hover {
  border-color: var(--accent);
}

.promo-icon {
  inline-size: 3.1rem;
  block-size: 3.1rem;
}

/* Rules List */
.rules-summary ul {
  padding-inline-start: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-primary);
}

/* Game Over Dialog */
.gameover-dialog {
  inline-size: min(92%, 430px);
  text-align: center;
}

.gameover-crest {
  font-size: 3.2rem;
  line-height: 1;
  margin-inline: auto;
}

.gameover-subtitle {
  font-size: 1rem;
  color: var(--accent);
  font-weight: 700;
}

.gameover-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 0.65rem;
  border-radius: var(--radius-sm);
}

.gameover-actions {
  justify-content: center;
}

.confirm-dialog {
  inline-size: min(90%, 380px);
}
