:root {
  --chess-v2-bg: #262522;
  --chess-v2-panel: #312e2b;
  --chess-v2-panel-2: #3a3835;
  --chess-v2-panel-3: #45433f;
  --chess-v2-text: #f4f4f2;
  --chess-v2-muted: #aaa7a2;
  --chess-v2-green: #81b64c;
  --chess-v2-green-dark: #5f8f35;
  --chess-v2-light-square: #ebecd0;
  --chess-v2-dark-square: #779556;
  --chess-v2-yellow: #f4c95d;
}

html:has(.chess-v2-page), body.chess-v2-page { background: var(--chess-v2-bg); }
body.chess-v2-page { min-height: 100dvh; color: var(--chess-v2-text); }
.chess-v2-page .background-orb { display: none; }
.chess-v2-page .chess-v2-shell { width: min(760px, 100%); min-height: 100dvh; margin: 0 auto; padding: 0 14px 36px; }

.chess-v2-lobby-bar {
  min-height: 72px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.chess-v2-lobby-bar > div { display: grid; justify-items: center; gap: 1px; }
.chess-v2-lobby-bar small { color: var(--chess-v2-muted); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.chess-v2-lobby-bar strong { font-size: 1.08rem; }
.chess-v2-icon-button {
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 13px;
  background: var(--chess-v2-panel);
  color: var(--chess-v2-text);
  text-decoration: none;
  font: 800 1.6rem/1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chess-v2-icon-button:active { transform: scale(.96); }

.chess-v2-auth-card {
  margin: 44px auto;
  max-width: 420px;
  padding: 36px 28px;
  border-radius: 24px;
  background: var(--chess-v2-panel);
  text-align: center;
}
.chess-v2-auth-icon { font-size: 3rem; }
.chess-v2-auth-card h1 { margin: 12px 0 8px; }
.chess-v2-auth-card p { margin: 0; color: var(--chess-v2-muted); }

.chess-v2-lobby { display: grid; gap: 14px; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.chess-v2-lobby.hidden { display: none; }
.chess-v2-lobby-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
  border-radius: 22px;
  background: linear-gradient(145deg, #363c30, #2d2f2a 66%);
  box-shadow: 0 18px 55px rgba(0,0,0,.22);
}
.chess-v2-lobby-hero .step-label { color: #a7cf79; }
.chess-v2-lobby-hero h1 { margin: 3px 0 7px; font-size: clamp(2rem, 7vw, 3.2rem); letter-spacing: -.045em; }
.chess-v2-lobby-hero p:last-child { margin: 0; color: #c5c5c1; }
.chess-v2-new-game {
  flex: 0 0 auto;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--chess-v2-green);
  color: #18220f;
  font: 900 .92rem/1 system-ui, sans-serif;
  box-shadow: 0 7px 0 #5d8739;
  cursor: pointer;
}
.chess-v2-new-game span { font-size: 1.1rem; }
.chess-v2-new-game:active { transform: translateY(3px); box-shadow: 0 4px 0 #5d8739; }

.chess-v2-game-section { padding: 16px; border-radius: 19px; background: var(--chess-v2-panel); }
.chess-v2-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chess-v2-section-heading h2 { margin: 0; font-size: .92rem; }
.chess-v2-section-heading > span { min-width: 28px; padding: 4px 8px; border-radius: 999px; background: var(--chess-v2-panel-3); color: #d7d5d2; text-align: center; font-size: .72rem; font-weight: 850; }
.chess-v2-game-list { display: grid; gap: 8px; }
.chess-v2-page .chess-game-row {
  grid-template-columns: auto minmax(0,1fr) auto;
  gap: 11px;
  padding: 11px;
  border: 0;
  border-radius: 13px;
  background: #292825;
  color: var(--chess-v2-text);
  box-shadow: none;
}
.chess-v2-page .chess-game-row.turn { background: #34422b; box-shadow: inset 3px 0 var(--chess-v2-green); }
.chess-v2-page .chess-game-row .chess-avatar { background: var(--chess-v2-panel-3); }
.chess-v2-page .chess-row-copy small { color: var(--chess-v2-muted); }
.chess-v2-page .chess-game-row .button { min-height: 38px; border: 0; border-radius: 10px; }
.chess-v2-page .chess-game-row .button.primary { background: var(--chess-v2-green); color: #17210e; }
.chess-v2-page .chess-game-row .button.secondary,
.chess-v2-page .chess-game-row .button.ghost { background: var(--chess-v2-panel-3); color: #eee; }
.chess-v2-page .chess-empty { color: var(--chess-v2-muted); }

/* Active game is a dedicated screen, not a WhatDew panel page. */
.chess-v2-game {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0,1fr);
  align-content: start;
  background: var(--chess-v2-bg);
}
.chess-v2-game.hidden { display: none; }
.chess-v2-game-header {
  min-height: 64px;
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 10px 7px;
}
.chess-v2-game-title { min-width: 0; display: flex; align-items: center; gap: 8px; }
.chess-v2-game-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.chess-v2-game-title > span { padding: 5px 8px; border-radius: 8px; background: var(--chess-v2-panel); color: #cfcdc9; font-size: .72rem; font-weight: 850; white-space: nowrap; }
.chess-v2-header-actions { display: flex; align-items: center; gap: 7px; }
.chess-v2-header-actions .chess-v2-icon-button { min-width: 42px; min-height: 42px; }
.chess-v2-live { display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 999px; background: rgba(129,182,76,.14); color: #c9f59e; font-size: .7rem; font-weight: 900; }
.chess-v2-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--chess-v2-green); box-shadow: 0 0 0 3px rgba(129,182,76,.14); }
.chess-v2-live[data-state="error"] { color: #fecaca; background: rgba(239,68,68,.12); }
.chess-v2-live[data-state="error"] i { background: #ef4444; }
.chess-v2-live[data-state="syncing"] i { background: #facc15; }

.chess-v2-player {
  width: min(100%, 640px);
  min-height: 62px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 9px;
}
.chess-v2-page .chess-v2-player .chess-player-strip {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.chess-v2-page .chess-v2-player .chess-player-strip .chess-turn-chip { display: none; }
.chess-v2-page .chess-player-id { min-width: 0; }
.chess-v2-page .chess-player-id strong { color: #f3f2ef; font-size: .96rem; }
.chess-v2-page .chess-player-id small { color: var(--chess-v2-muted); }
.chess-v2-page .chess-avatar { width: 42px; height: 42px; border-radius: 10px; background: var(--chess-v2-panel-3); }
.chess-v2-clock {
  min-width: 104px;
  padding: 8px 12px;
  border-radius: 9px;
  background: #11110f;
  color: #f4f4ef;
  font: 800 clamp(1.2rem, 4.7vw, 1.65rem)/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: -.04em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.chess-v2-clock.is-running { background: #f1f1e9; color: #272622; }
.chess-v2-clock.is-low { background: #9e2e2e; color: #fff; }
.chess-v2-clock[data-kind="daily"] { min-width: 88px; font-size: 1rem; letter-spacing: 0; }

.chess-v2-variant-note { width: min(100%, 640px); margin: 0 auto; padding: 7px 11px; background: #3a3835; color: #d6d3cd; font-size: .72rem; text-align: center; }
.chess-v2-variant-note.hidden { display: none; }

.chess-v2-board-wrap {
  width: min(calc(100% + 28px), 640px);
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.chess-v2-board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(8, minmax(0,1fr));
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.chess-v2-page .chess-square {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
.chess-v2-page .chess-square.light { background: var(--chess-v2-light-square); }
.chess-v2-page .chess-square.dark { background: var(--chess-v2-dark-square); }
.chess-v2-page .chess-piece {
  position: relative;
  z-index: 2;
  color: #161616;
  font-family: Georgia, "Times New Roman", serif !important;
  font-size: clamp(2rem, 10.8vw, 5rem);
  font-weight: 400;
  font-style: normal;
  font-variant-emoji: text;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0,0,0,.16);
  filter: none;
  pointer-events: none;
}
.chess-v2-page .chess-square[aria-label*=" white "] .chess-piece {
  color: #f5f4ed;
  -webkit-text-stroke: 1.4px #252525;
  text-shadow: 0 1px 1px rgba(0,0,0,.45);
}
.chess-v2-page .chess-square[aria-label*=" black "] .chess-piece {
  color: #242420;
  -webkit-text-stroke: .5px rgba(255,255,255,.28);
}
.chess-v2-page .chess-coordinate { display: none !important; }
.chess-v2-page .chess-square.last-move { box-shadow: inset 0 0 0 999px rgba(244,201,93,.34); }
.chess-v2-page .chess-square.selected { box-shadow: inset 0 0 0 4px rgba(244,201,93,.9); }
.chess-v2-page .chess-square.destination::before {
  content: "";
  position: absolute;
  z-index: 1;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(35,35,32,.34);
}
.chess-v2-page .chess-square.capture::before { width: 78%; background: transparent; border: 5px solid rgba(35,35,32,.28); }
.chess-v2-page .chess-square.in-check { box-shadow: inset 0 0 0 999px rgba(192,50,50,.46); }

.chess-v2-game-footer {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 7px 9px calc(12px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
}
.chess-v2-game-footer .chess-status-message { min-height: 19px; margin: 0; color: #c9c7c2; font-size: .78rem; text-align: center; }
.chess-v2-actions { display: flex; justify-content: center; gap: 8px; }
.chess-v2-action {
  min-height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 11px;
  background: var(--chess-v2-panel);
  color: #d9d7d2;
  font: 800 .76rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.chess-v2-action-primary { background: var(--chess-v2-green); color: #18220f; }
.chess-v2-history { color: var(--chess-v2-muted); font-size: .75rem; }
.chess-v2-history summary { width: max-content; margin: 0 auto; cursor: pointer; }
.chess-v2-page .chess-move-history { color: #ddd; }

/* Pending challenges replace the meaningless pre-acceptance board. */
.chess-v2-pending {
  width: min(520px, calc(100% - 24px));
  margin: 8dvh auto 20px;
  padding: 30px 22px;
  display: grid;
  justify-items: center;
  gap: 7px;
  text-align: center;
  border-radius: 22px;
  background: radial-gradient(circle at 50% 0%, rgba(129,182,76,.22), transparent 50%), var(--chess-v2-panel);
}
.chess-v2-pending.hidden { display: none; }
.chess-v2-pending-avatar { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 20px; background: var(--chess-v2-panel-3); font-size: 2.2rem; }
.chess-v2-pending > p:first-of-type { margin: 8px 0 0; color: #a7cf79; font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.chess-v2-pending h2 { margin: 0; font-size: 1.65rem; }
.chess-v2-pending > p:last-of-type { max-width: 400px; margin: 0; color: var(--chess-v2-muted); }
.chess-v2-pending > span:last-child { margin-top: 8px; display: inline-flex; align-items: center; gap: 7px; color: #c9f59e; font-size: .75rem; font-weight: 800; }
.chess-v2-pending > span:last-child i { width: 7px; height: 7px; border-radius: 50%; background: var(--chess-v2-green); }
#chessGameView[data-game-status="pending"] .chess-v2-player,
#chessGameView[data-game-status="pending"] .chess-v2-board-wrap,
#chessGameView[data-game-status="pending"] .chess-v2-variant-note { display: none !important; }
#chessGameView[data-game-status="pending"] .chess-v2-game-footer { width: min(520px, 100%); }

/* New-game and time-control sheets, matching the dark Choose Time reference. */
.chess-v2-sheet {
  width: min(100% - 22px, 560px);
  max-height: min(90dvh, 820px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 24px;
  background: #20201e;
  color: var(--chess-v2-text);
  box-shadow: 0 28px 90px rgba(0,0,0,.62);
}
.chess-v2-sheet::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.chess-v2-sheet-handle { width: 38px; height: 4px; margin: 8px auto 2px; border-radius: 99px; background: #66645f; }
.chess-v2-sheet > header {
  min-height: 62px;
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.chess-v2-sheet > header > div { text-align: center; }
.chess-v2-sheet header small { color: var(--chess-v2-muted); font-size: .64rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.chess-v2-sheet header h2 { margin: 0; font-size: 1.08rem; text-align: center; }
.chess-v2-sheet-close { width: 42px; height: 42px; border: 0; border-radius: 50%; background: #33322f; color: #eee; font: 500 1.65rem/1 system-ui; cursor: pointer; }
.chess-v2-sheet-scroll { max-height: calc(min(90dvh, 820px) - 78px); overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.chess-v2-setup-section + .chess-v2-setup-section { margin-top: 18px; }
.chess-v2-setup-section > label { display: block; margin: 0 0 8px; color: #b8b6b1; font-size: .72rem; font-weight: 900; text-transform: uppercase; letter-spacing: .07em; }
.chess-v2-variant-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.chess-v2-variant-grid button {
  min-height: 66px;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: #2d2c29;
  color: #eee;
  text-align: left;
  cursor: pointer;
}
.chess-v2-variant-grid button span { color: #b8b6b1; font-weight: 850; text-align: center; }
.chess-v2-variant-grid button strong { font-size: .78rem; }
.chess-v2-variant-grid button[aria-pressed="true"] { border-color: var(--chess-v2-green); background: #35442b; box-shadow: inset 0 0 0 1px var(--chess-v2-green); }
.chess-v2-time-row {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: 44px minmax(0,1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 13px;
  background: #2d2c29;
  color: #eee;
  text-align: left;
  cursor: pointer;
}
.chess-v2-time-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #3b3935; font-size: 1.35rem; }
.chess-v2-time-row > span:nth-child(2) { display: grid; gap: 2px; }
.chess-v2-time-row strong { font-size: 1rem; }
.chess-v2-time-row small { color: var(--chess-v2-muted); }
.chess-v2-time-row > span:last-child { color: #8d8a85; font-size: 1.4rem; }
.chess-v2-friend-list { display: grid; gap: 7px; }
.chess-v2-friend-button {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 42px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  background: #2d2c29;
  color: #eee;
  text-align: left;
  cursor: pointer;
}
.chess-v2-friend-button > span:first-child { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #3b3935; font-size: 1.25rem; }
.chess-v2-friend-button > span:nth-child(2) { min-width: 0; display: grid; gap: 2px; }
.chess-v2-friend-button strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chess-v2-friend-button small, .chess-v2-sheet-status { color: var(--chess-v2-muted); }
.chess-v2-sheet-status { margin: 8px 2px 0; font-size: .75rem; }

.chess-v2-time-section + .chess-v2-time-section { margin-top: 22px; }
.chess-v2-time-section h3 { margin: 0 0 9px; font-size: .88rem; }
.chess-v2-time-section h3 small { margin-left: 5px; color: var(--chess-v2-muted); font-size: .7rem; font-weight: 650; }
.chess-v2-time-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 7px; }
.chess-v2-time-grid button {
  min-height: 52px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  background: #30302d;
  color: #e9e8e4;
  font: 800 .8rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.chess-v2-time-grid button[aria-pressed="true"] { border-color: #fff; background: #f1f0ec; color: #22211f; box-shadow: inset 0 0 0 1px #fff; }
.chess-v2-time-grid-days { grid-template-columns: repeat(3, 1fr); }

.chess-v2-legacy-dialog { display: none !important; }
.chess-variant-native-select { position: fixed !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }

@media (max-width: 720px) {
  body.chess-v2-page:has(#chessGameView:not(.hidden)) {
    overflow: hidden;
    background: var(--chess-v2-bg) !important;
  }
  body.chess-v2-page:has(#chessGameView:not(.hidden)) .mobile-app-header,
  body.chess-v2-page:has(#chessGameView:not(.hidden)) .mobile-global-nav,
  body.chess-v2-page:has(#chessGameView:not(.hidden)) .chess-v2-lobby-bar { display: none !important; }
  body.chess-v2-page:has(#chessGameView:not(.hidden)) .chess-v2-shell { width: 100%; height: 100dvh; min-height: 100dvh; margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: none; }
  .chess-v2-page .chess-v2-game { min-height: 100dvh; }
  .chess-v2-board-wrap { width: 100%; }
  .chess-v2-player { width: 100%; padding-inline: 10px; }
  .chess-v2-clock { min-width: 96px; }
  .chess-v2-game-footer { width: 100%; }
  .chess-v2-live { padding-inline: 7px; font-size: 0; }
  .chess-v2-live i { margin: 0; }
  .chess-v2-sheet { inset: auto 0 0; width: 100%; max-width: 640px; max-height: min(92dvh, 840px); margin: 0 auto; border-radius: 22px 22px 0 0; }
  .chess-v2-sheet-scroll { max-height: calc(min(92dvh, 840px) - 76px); }
}

@media (max-width: 430px) {
  .chess-v2-page .chess-v2-shell { padding-inline: 10px; }
  body.chess-v2-page:has(#chessGameView:not(.hidden)) .chess-v2-shell { padding-inline: 0; }
  .chess-v2-lobby-hero { align-items: stretch; display: grid; }
  .chess-v2-new-game { width: 100%; }
  .chess-v2-game-header { grid-template-columns: 44px minmax(0,1fr) auto; padding-inline: 7px; }
  .chess-v2-game-title { gap: 5px; }
  .chess-v2-game-title strong { font-size: .78rem; }
  .chess-v2-game-title > span { font-size: .64rem; }
  .chess-v2-clock { min-width: 91px; padding: 7px 9px; }
  .chess-v2-page .chess-avatar { width: 38px; height: 38px; }
  .chess-v2-variant-grid { grid-template-columns: 1fr 1fr; }
  .chess-v2-time-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .chess-v2-new-game, .chess-v2-icon-button { transition: none; }
}
