/* Chess App - Professional Styling */

:root {
  --primary: #1a1a2e;
  --secondary: #16213e;
  --accent: #e94560;
  --accent-light: #f05a7f;
  --light: #f0f2f5;
  --light-bg: #ffffff;
  --text-dark: #1a1a2e;
  --text-light: #666;
  --border: #ddd;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --highlight: #baca44;
  --check: #e94560;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

  /* Royal-classic accents — used by the lobby hero, footer and primary CTA.
     Deliberately scoped to those pieces so the board/game pages keep their
     existing palette. */
  --royal-green: #1f4a3a;
  --royal-green-deep: #102a20;
  --gold: #c9a227;
  --gold-light: #e7cf86;
  --parchment: #f4f1e8;
}

html[data-theme="light"] {
  --primary: #f5f5f5;
  --secondary: #ffffff;
  --text-dark: #1a1a2e;
  --text-light: #666;
  --light-bg: #f9f9f9;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* The `hidden` attribute must always win. Without this, a `display` rule on a
   class (e.g. .button { display: inline-flex } or .modal { display: flex })
   overrides the UA [hidden] rule, leaving "hidden" elements — like the Claim
   Victory button — visible when JS sets el.hidden = true. */
[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--primary);
  color: var(--text-dark);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Keep content clear of the notch / status bar / home indicator when the
     app runs as an installed PWA (these resolve to 0 in normal browsers). */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.container {
  flex: 1;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
}

/* Typography */
h1, h2, h3 {
  color: var(--text-dark);
  margin-bottom: 15px;
  font-weight: 600;
}

h1 {
  font-size: 2em;
  margin: 30px 0 20px 0;
}

h2 {
  font-size: 1.4em;
}

h3 {
  font-size: 1.1em;
  margin-top: 15px;
  margin-bottom: 10px;
}

p {
  margin-bottom: 12px;
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

a:hover {
  color: var(--accent-light);
}

/* Cards */
.card {
  background: var(--light-bg);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card.highlight {
  border-color: var(--accent);
  border-width: 2px;
}

/* Forms */
.label {
  display: block;
  font-size: 0.9em;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1em;
  font-family: inherit;
  background: var(--light-bg);
  color: var(--text-dark);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.1);
}

/* Buttons */
.button {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

.button-primary {
  background: var(--accent);
  color: white;
}

.button-primary:hover {
  background: var(--accent-light);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
}

.button-primary:active {
  transform: scale(0.98);
}

.button-secondary {
  background: var(--light);
  color: var(--text-dark);
  border: 1px solid var(--border);
}

/* Hover-capable pointers only: on touch screens the :hover state sticks after
   a tap, which left dark-mode secondary buttons as light-on-light text (e.g.
   the simulation Undo button). Dark text because the hover bg is always light. */
@media (hover: hover) {
  .button-secondary:hover {
    background: #e8eef0;
    color: #1a1a2e;
  }
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon {
  font-size: 1.2em;
}

/* Code Display */
.code-display {
  background: var(--primary);
  color: var(--light);
  padding: 20px;
  border-radius: 8px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 2em;
  font-weight: bold;
  letter-spacing: 2px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  position: relative;
  margin-bottom: 15px;
}

.copy-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1em;
  transition: background 0.2s;
}

.copy-btn:hover {
  background: var(--accent-light);
}

/* Chess Board */
.chess-board {
  display: grid;
  /* minmax(0, 1fr) on BOTH axes: plain 1fr tracks refuse to shrink below the
     piece glyph's min-content size, so on narrow screens (or with a large
     system font) the squares outgrow the aspect-ratio-locked board box and
     spill past its border. Locking rows and columns to equal shares of the
     box means the grid can never be bigger than the board. */
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 0;
  aspect-ratio: 1 / 1;
  background: var(--board-dark);
  border: 3px solid var(--text-dark);
  border-radius: 8px;
  margin: 20px 0;
  max-width: 100%;
  padding: 2px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.square {
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* 1.5em floor (not 2em): with an enlarged browser/system font, 2em can
     exceed the square itself and push the grid out of the board frame. */
  font-size: clamp(1.5em, 8vw, 4em);
  user-select: none;
  transition: all 0.15s;
  position: relative;
  /* Snappier taps on mobile (no 300ms delay / double-tap-zoom on the board). */
  touch-action: manipulation;
}

/* Read-only board (results screen): no interaction affordances. */
.result-board {
  margin-top: 4px;
}

.result-board .square {
  cursor: default;
}

.result-board .square:hover {
  filter: none;
}

/* Replay controls (results screen). */
.replay-status {
  text-align: center;
  font-weight: 600;
  margin: 10px 0;
  font-variant-numeric: tabular-nums;
}

.replay-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.replay-controls .button {
  flex: 1;
  min-width: 0;
  padding: 10px 8px;
}

.replay-controls .button:disabled {
  opacity: 0.4;
}

/* "Who played who" chips shown above the replay / simulation boards. */
.replay-players {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 0.95em;
}

.replay-players .player-color {
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replay-vs {
  opacity: 0.7;
  font-size: 0.85em;
}

/* Clickable move-history rows + the currently shown move. */
.move-row {
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
}

.move-row:hover {
  background: rgba(0, 0, 0, 0.06);
}

html:not([data-theme="light"]) .move-row:hover {
  background: rgba(255, 255, 255, 0.07);
}

.move-row.active {
  background: var(--accent);
  color: #fff;
}

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

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

.square.selected {
  background: var(--highlight) !important;
}

.square.legal-move::after {
  content: '';
  display: block;
  width: 30%;
  height: 30%;
  background: var(--highlight);
  border-radius: 50%;
  opacity: 0.6;
}

.square.check {
  background: var(--check) !important;
  animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.square:hover {
  filter: brightness(1.1);
}

.piece {
  display: inline-block;
  line-height: 1;
  pointer-events: none;
}

/* Solid glyphs are colored here. White and black use OPPOSITE outlines — white
   pieces are bright with a dark ring, black pieces are near-black with a light
   ring — so they read as clear opposites on any board square.
   paint-order keeps the outline outside the glyph instead of eating the fill. */
.piece {
  paint-order: stroke fill;
}

.piece.white {
  color: #ffffff;
  -webkit-text-stroke: 2.5px #161616;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
}

.piece.black {
  color: #0c0c0c;
  -webkit-text-stroke: 2.5px #f4f1e8;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
}

.square.last-move {
  box-shadow: inset 0 0 0 4px rgba(186, 202, 68, 0.7);
}

/* A legal target that holds an enemy piece reads as a capture ring. */
.square.legal-move:has(.piece)::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 4px solid var(--highlight);
  opacity: 0.85;
}

/* Game Controls */
.game-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  /* Keep a clear gap before the chat card / move list that follows. */
  margin: 4px 0 20px;
}

.game-controls .button {
  flex: 1;
  min-width: 120px;
}

/* Board Headers */
.board-header,
.board-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-weight: 600;
}

.player-info {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.95em;
}

.player-color {
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.1);
}

.player-color.white {
  background: var(--board-light);
}

.player-color.black {
  background: var(--board-dark);
  color: white;
}

.player-turn {
  background: var(--accent);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: bold;
}

.time-info {
  font-size: 0.95em;
  color: var(--text-light);
}

/* Utility Classes */
.muted {
  color: var(--text-light);
  font-size: 0.95em;
}

.text-center {
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(233, 69, 96, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
}

/* The `hidden` attribute alone is defeated by the `display: flex` above
   (author styles override the UA [hidden] rule), which would leave this
   full-screen overlay on top of the board swallowing every tap. This makes
   `hidden` win again. */
.modal[hidden] {
  display: none;
}

.modal:not([hidden]) {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--light-bg);
  border-radius: 16px 16px 0 0;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--light-bg);
}

.modal-close {
  background: none;
  border: none;
  font-size: 2em;
  cursor: pointer;
  color: var(--text-dark);
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 20px;
}

/* Lists */
.game-list {
  list-style: none;
}

.game-list li {
  background: var(--primary);
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border);
}

.game-list li:hover {
  background: var(--secondary);
  border-color: var(--accent);
}

.game-list-item-title {
  font-weight: 600;
  margin-bottom: 5px;
}

.game-list-item-meta {
  font-size: 0.85em;
  color: var(--text-light);
}

/* Past-game row: tappable main area + delete button */
.game-list-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-list-item-main {
  flex: 1;
  min-width: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2em;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-light);
  flex: 0 0 auto;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(233, 69, 96, 0.12);
}

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

/* Collapsible section toggle (Past games) */
.collapse-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  padding: 4px 0;
  font-family: inherit;
  font-size: 1.4em;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
}

.collapse-toggle .chevron {
  font-size: 0.7em;
  color: var(--text-light);
  transition: transform 0.2s;
}

.collapse-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

.count-badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 11px;
  background: var(--light);
  color: var(--text-light);
  font-size: 0.6em;
  font-weight: 700;
  vertical-align: middle;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
}

table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

table td:first-child {
  font-weight: 600;
  width: 40px;
}

/* Help Page */
ol, ul {
  margin: 15px 0 15px 25px;
}

ol li, ul li {
  margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 640px) {
  .container {
    padding: 15px;
  }

  .card {
    padding: 15px;
    margin-bottom: 15px;
  }

  h1 {
    font-size: 1.5em;
  }

  h2 {
    font-size: 1.2em;
  }

  .chess-board {
    margin: 15px 0;
  }

  .board-header,
  .board-footer {
    font-size: 0.9em;
  }

  .game-controls {
    gap: 8px;
  }

  .game-controls .button {
    min-width: 100px;
    padding: 10px 15px;
  }

  .code-display {
    font-size: 1.5em;
    letter-spacing: 1px;
  }

  .modal-content {
    border-radius: 12px 12px 0 0;
  }
}

/* Dark Mode */
html:not([data-theme="light"]) {
  --primary: #1a1a2e;
  --secondary: #16213e;
  --light-bg: #2d3e50;
  --light: #3d4d60;
  --border: #3d4d60;
  --text-dark: #f0f0f0;
  --text-light: #b0b0b0;
}

html:not([data-theme="light"]) .player-color.white {
  background: var(--board-light);
  color: var(--text-dark);
}

html:not([data-theme="light"]) .player-color.black {
  background: var(--board-dark);
  color: white;
}

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

/* Share buttons (host screen) */
.share-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.share-row .button {
  flex: 1;
  min-width: 110px;
}

/* Chat */
.chat-badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6em;
  font-weight: 700;
  vertical-align: middle;
  text-align: center;
  line-height: 1.6;
}

.chat-badge[hidden] {
  display: none;
}

/* Floating "N new messages" pill — jumps to the chat when tapped. */
.chat-fab {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1500;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.9em;
  font-family: inherit;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  animation: fabIn 0.2s ease-out;
}

.chat-fab[hidden] {
  display: none;
}

@keyframes fabIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.chat-messages {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
  margin-bottom: 12px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.chat-msg.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg.theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-who {
  font-size: 0.72em;
  color: var(--text-light);
  margin: 0 8px 2px;
  font-weight: 600;
}

.chat-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--light);
  color: var(--text-dark);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.35;
}

.chat-msg.mine .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.theirs .chat-bubble {
  border-bottom-left-radius: 4px;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form .input {
  flex: 1;
}

.chat-form .button {
  flex: 0 0 auto;
}

/* "New version available" prompt */
.update-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2500;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 92vw;
  padding: 10px 12px 10px 16px;
  border-radius: 12px;
  background: var(--secondary);
  color: #fff;
  font-size: 0.9em;
  font-weight: 600;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  animation: fabIn 0.2s ease-out;
}

.update-banner-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.update-banner-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.update-banner-dismiss {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.3em;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

/* Toasts */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  width: max-content;
  max-width: 90vw;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95em;
  color: #fff;
  background: var(--secondary);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  text-align: center;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-error {
  background: var(--accent);
}

.toast-success {
  background: #2e9e5b;
}

.toast-hide {
  opacity: 0;
  transform: translateY(10px);
}

/* Print */
@media print {
  body {
    background: white;
  }
  .game-controls,
  .modal {
    display: none;
  }
}

/* ------------------------------------------------------------------ *
 * App footer (bug report + version) — shown site-wide via chess_foot
 * ------------------------------------------------------------------ */
.app-footer {
  max-width: 600px;
  margin: 8px auto 0;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.82em;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.app-footer a {
  color: var(--text-light);
  font-weight: 600;
}

.app-footer a:hover {
  color: var(--gold);
}

.app-footer-sep {
  opacity: 0.5;
}

.app-version {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

/* ------------------------------------------------------------------ *
 * Royal-classic lobby hero
 * ------------------------------------------------------------------ */
.hero {
  position: relative;
  margin: -20px -20px 22px;
  padding: 40px 24px 30px;
  text-align: center;
  color: var(--parchment);
  background:
    radial-gradient(120% 90% at 50% -10%, var(--royal-green) 0%, var(--royal-green-deep) 70%);
  border-radius: 0 0 22px 22px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(16, 42, 32, 0.35);
}

/* Faint chequer texture behind the hero — pure CSS, no images. */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 48px 48px;
  background-position: 0 0, 24px 24px;
  opacity: 0.5;
  pointer-events: none;
}

.hero > * {
  position: relative;
  z-index: 1;
}

/* Compact hero for sub-pages (e.g. Settings). */
.hero-compact {
  padding: 22px 24px 18px;
}

/* Corner action (settings gear / back arrow) on the hero. */
.hero-gear {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  z-index: 2;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--gold-light);
  text-decoration: none;
}

.hero-compact .hero-gear {
  left: 16px;
  right: auto;
}

.hero-gear:hover {
  color: #fff;
}

.hero-crown {
  font-size: 3rem;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  margin-bottom: 6px;
}

.hero-compact .hero-crown {
  font-size: 2rem;
}

.hero-title {
  font-family: Georgia, 'Times New Roman', 'Playfair Display', serif;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #fff;
  margin: 0;
}

.hero-rule {
  width: 120px;
  height: 0;
  margin: 12px auto 14px;
  border: none;
  border-top: 1px solid var(--gold);
  position: relative;
  opacity: 0.8;
}

/* Little gold diamond centred on the rule. */
.hero-rule::after {
  content: "♦";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--gold);
  font-size: 0.7rem;
  background: var(--royal-green-deep);
  padding: 0 8px;
}

.hero-tagline {
  margin: 0 0 10px;
  color: var(--gold-light);
  font-size: 1.02rem;
  font-weight: 600;
}

.hero-quote {
  margin: 0 auto;
  max-width: 30ch;
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.5;
  color: rgba(244, 241, 232, 0.82);
  min-height: 2.6em;
}

/* Gold primary call-to-action (Host a game). */
/* WhatsApp-green CTA for the community group link on the lobby. */
.button-whatsapp {
  background: #25d366;
  color: #fff;
}

.button-whatsapp:hover {
  background: #1ebe5b;
  color: #fff;
}

.button-royal {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 55%, #a9851d 100%);
  color: #2a2412;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 14px rgba(201, 162, 39, 0.35);
}

.button-royal:hover {
  filter: brightness(1.04);
  box-shadow: 0 6px 18px rgba(201, 162, 39, 0.45);
}

.button-royal:active {
  transform: scale(0.98);
}

/* ------------------------------------------------------------------ *
 * Spectator / watching indicators
 * ------------------------------------------------------------------ */
.spectator-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
  color: var(--text-light);
  font-size: 0.8em;
  font-weight: 600;
}

html:not([data-theme="light"]) .spectator-pill {
  background: rgba(255, 255, 255, 0.1);
}

.spectator-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--light);
  color: var(--text-dark);
  font-size: 0.9em;
  font-weight: 600;
  text-align: center;
}

/* ------------------------------------------------------------------ *
 * Reconnect (QR) + alerts panels
 * ------------------------------------------------------------------ */
.qr-canvas {
  display: block;
  width: 220px;
  max-width: 70vw;
  height: auto;
  margin: 6px auto 12px;
  padding: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  image-rendering: pixelated;
}

.link-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin: 10px 0;
}

.link-row .input {
  flex: 1;
  font-size: 0.82em;
  font-family: 'Monaco', 'Courier New', monospace;
}

.muted-small {
  font-size: 0.82em;
  color: var(--text-light);
}

.alerts-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  font-weight: 600;
  color: #2e9e5b;
}

/* ------------------------------------------------------------------ *
 * Pawn-promotion picker
 * ------------------------------------------------------------------ */
.promotion-picker {
  position: fixed;
  inset: 0;
  z-index: 2200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.promotion-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.promotion-panel {
  position: relative;
  z-index: 1;
  background: var(--light-bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: fabIn 0.18s ease-out;
}

.promotion-title {
  text-align: center;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text-dark);
}

.promotion-choices {
  display: flex;
  gap: 10px;
}

.promotion-choice {
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--board-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2em;
  line-height: 1;
  transition: transform 0.12s, border-color 0.12s;
}

.promotion-choice:nth-child(even) {
  background: var(--board-dark);
}

.promotion-choice:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.promotion-choice .piece {
  pointer-events: none;
}

/* ------------------------------------------------------------------ *
 * Win celebration — falling confetti overlay
 * ------------------------------------------------------------------ */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3000;
}

/* ------------------------------------------------------------------ *
 * Single-player practice board
 * ------------------------------------------------------------------ */
.solo-status {
  margin: 10px 0 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--check);
  color: #fff;
  font-weight: 600;
  text-align: center;
}

.solo-history {
  line-height: 2;
  word-spacing: 2px;
}

.solo-move {
  display: inline-block;
  margin-right: 4px;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ *
 * Help page — Grant background image, faded behind the content
 * ------------------------------------------------------------------ */
.help-bg {
  position: fixed;
  inset: 0;
  background: url('../assets/bigg.jpg') center 20% / cover no-repeat;
  opacity: 0.10;
  pointer-events: none;
  z-index: -1;
}

/* In dark mode nudge opacity up very slightly so it still reads */
html:not([data-theme="light"]) .help-bg {
  opacity: 0.08;
}

/* ------------------------------------------------------------------ *
 * vs-Computer setup screen
 * ------------------------------------------------------------------ */
.cpu-setup-section {
  margin-bottom: 18px;
}

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

.difficulty-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--light-bg);
  color: var(--text-dark);
  font-family: inherit;
  font-size: 1.15em;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1;
}

.difficulty-btn span {
  font-size: 0.52em;
  font-weight: 600;
  color: var(--text-light);
  letter-spacing: 0.2px;
  white-space: nowrap;
}

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

.difficulty-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.difficulty-btn.active span {
  color: rgba(255,255,255,0.85);
}

.color-choice-row {
  display: flex;
  gap: 10px;
}

.color-choice-btn {
  flex: 1;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--light-bg);
  color: var(--text-dark);
  font-family: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.color-choice-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* "CPU is thinking" bar */
.cpu-thinking {
  margin: 8px 0 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--light);
  color: var(--text-light);
  font-size: 0.9em;
  font-weight: 600;
  text-align: center;
  animation: pulse 1s ease-in-out infinite;
}

/* Level badge shown during play */
.cpu-level-badge {
  font-size: 0.8em;
  font-weight: 600;
  color: var(--text-light);
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--light);
  border: 1px solid var(--border);
}

/* Board orientation selector */
.board-rotate-row {
  display: flex;
  gap: 5px;
  margin: 8px 0 4px;
}
.rotate-btn {
  flex: 1;
  padding: 5px 2px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.72em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.rotate-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* SAN move history — two moves per row */
.cpu-move-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88em;
}
.cpu-move-row:last-child { border-bottom: none; }
.cpu-move-num {
  width: 22px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text-light);
  font-size: 0.85em;
}
.cpu-move-san {
  flex: 1;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Move time limit slider (host game setup) */
.time-limit-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  margin-bottom: 2px;
}
.time-limit-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.time-limit-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.time-limit-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
