:root {
  --bg: #101318;
  --panel: #181d25;
  --panel-2: #202734;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --light-square: #e8edf2;
  --dark-square: #7890a8;
  --selected: #facc15;
  --target: rgba(34, 197, 94, 0.45);
  --last: rgba(59, 130, 246, 0.42);
  --danger: #f87171;
  --ok: #86efac;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1f2937 0, var(--bg) 48rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

#board {
  position: relative;
  touch-action: none;
  user-select: none;
}

.pageShell {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.heroPanel,
.contentGrid,
.card,
.boardPanel {
  border: 1px solid var(--border);
  background: rgba(24, 29, 37, 0.92);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.heroPanel {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-radius: 1.25rem;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.contentGrid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 1rem;
  border-radius: 1.25rem;
  padding: 1rem;
}

.boardPanel,
.sidePanel,
.card {
  min-width: 0;
}

.boardPanel {
  border-radius: 1rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.56);
}

.sidePanel {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.card {
  border-radius: 1rem;
  padding: 1rem;
}

.eyebrow {
  color: var(--ok);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  font-weight: 800;
  margin: 0 0 0.3rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.35rem;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0.85rem;
}

.subtle,
.hint {
  color: var(--muted);
}

.subtle {
  margin-bottom: 0;
}

.statusCard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  padding: 0.35rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.pill.ok {
  color: var(--ok);
}

.pill.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: min(100%, 620px, calc(100vw - 4rem));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 10px solid #0f172a;
  border-radius: 0.75rem;
  overflow: hidden;
  user-select: none;
}

.clockRail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.clockCard {
  display: grid;
  gap: 0.15rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.85);
}

.clockCard.active {
  border-color: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.4);
}

.clockCard.low {
  border-color: rgba(248, 113, 113, 0.7);
}

.clockLabel {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.clockValue {
  font-size: clamp(1.1rem, 2.2vw, 1.55rem);
  line-height: 1;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background-clip: padding-box;
  appearance: none;
  line-height: 1;
  font-size: clamp(1.6rem, 6vw, 4rem);
  touch-action: none;
  color: #0f172a;
}

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

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

.square.inactive {
  cursor: default;
}

.square:not(.inactive) {
  cursor: pointer;
}

.square.premove-ready {
  cursor: crosshair;
}

.square.right-marked {
  box-shadow: inset 0 0 0 9999px rgba(245, 158, 11, 0.35);
}

.square.premove-from,
.square.premove-to {
  box-shadow: inset 0 0 0 9999px rgba(34, 197, 94, 0.35);
}

.square.drag-source {
  filter: brightness(1.12);
}

.square.drag-source .piece-image {
  opacity: 0.25;
}

.square.in-check {
  box-shadow: inset 0 0 0 9999px rgba(239, 68, 68, 0.45);
}

.square.selected::after,
.square.last::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.square.selected::after {
  background: rgba(250, 204, 21, 0.45);
  box-shadow: inset 0 0 0 4px var(--selected);
}

.square.last::after {
  background: var(--last);
}

.square.target::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 3;
}

.square.capture-target::before {
  width: 78%;
  height: 78%;
  background: transparent;
  border: 0.25rem solid rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.coord {
  position: absolute;
  left: 0.25rem;
  bottom: 0.18rem;
  font-size: 0.68rem;
  font-weight: 800;
  opacity: 0.65;
}

.piece-image {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.boardFooter {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  margin-top: 0.9rem;
}

label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

select,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: #0f172a;
  color: var(--text);
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.8rem;
}

.twoCols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

button {
  width: 100%;
  border: 0;
  border-radius: 0.75rem;
  background: #38bdf8;
  color: #082f49;
  font-weight: 800;
  padding: 0.8rem 1rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.hint {
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
}

.inlineToggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.2rem 0 0.8rem;
  color: var(--text);
}

.inlineToggle input {
  width: auto;
  margin: 0;
}

.dropdownCard {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: #0f172a;
}

.dropdownCard summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.9rem;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
}

.dropdownCard summary::-webkit-details-marker {
  display: none;
}

.dropdownSummary {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.dropdownBody {
  padding: 0 0.9rem 0.9rem;
}

.largeStatus {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}

.fenBox,
.engineInfo {
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: #0f172a;
  color: var(--muted);
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.moveHistory {
  margin: 0;
  padding-left: 1.2rem;
  max-height: 12rem;
  overflow: auto;
  color: var(--muted);
}

.moveHistory li {
  margin-bottom: 0.25rem;
}

.statsGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.statsHeading {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.statsHeading:not(:first-of-type) {
  margin-top: 1rem;
}

.statItem {
  display: grid;
  gap: 0.2rem;
  padding: 0.8rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: #0f172a;
  text-align: center;
}

.statValue {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.statLabel {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.statsList {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.statsListItem {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.statsListItem:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.statsListLabel {
  color: var(--muted);
  font-size: 0.88rem;
}

.statsListValue {
  font-weight: 700;
  text-align: right;
}

.statsDetailBlock {
  margin-top: 0.9rem;
}

.statsMiniList {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.statsMiniListRow {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.extra-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: stretch;
}

.secondary-action-button,
.promotion-button,
.game-over-panel button {
  border: 0;
  border-radius: 0.5rem;
  padding: 0.55rem 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

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

.extra-controls .secondary-action-button {
  width: auto;
  flex: 1 1 8.5rem;
  min-width: 8.5rem;
}

.promotion-overlay {
  position: fixed;
  z-index: 9999;
  display: grid;
  grid-template-columns: repeat(4, 4rem);
  gap: 0.35rem;
  padding: 0.5rem;
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.35);
}

.promotion-button {
  width: 4rem;
  height: 4rem;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.95);
}

.promotion-button img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
}

.game-over-panel {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.game-over-panel-title {
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.game-over-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.game-over-actions button {
  width: auto;
  flex: 1 1 8rem;
}

.drag-ghost-piece {
  position: fixed;
  z-index: 10000;
  width: var(--drag-ghost-size, 52px) !important;
  height: var(--drag-ghost-size, 52px) !important;
  max-width: var(--drag-ghost-size, 52px) !important;
  max-height: var(--drag-ghost-size, 52px) !important;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0.5rem 0.65rem rgba(0, 0, 0, 0.35));
}

.board-drawing-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

.board-arrow {
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  opacity: 0.9;
}

.normal-arrow {
  stroke: rgba(245, 158, 11, 0.9);
}

.premove-arrow {
  stroke: rgba(34, 197, 94, 0.9);
}

.preview-arrow {
  stroke: rgba(250, 204, 21, 0.9);
}

@media (max-width: 880px) {

  .heroPanel,
  .contentGrid {
    grid-template-columns: 1fr;
  }

  .heroPanel {
    align-items: flex-start;
    flex-direction: column;
  }

  .statsGrid {
    grid-template-columns: 1fr;
  }

  .clockRail {
    grid-template-columns: 1fr;
  }
}

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

.cardHeadingRow h2 {
  margin: 0;
}

.competitiveActions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.competitiveActions>* {
  flex: 1 1 10rem;
}

.buttonLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.8rem;
  border-radius: 0.75rem;
  background: #38bdf8;
  color: #082f49;
  font-weight: 800;
  padding: 0.8rem 1rem;
  text-decoration: none;
}

.buttonLink:hover {
  filter: brightness(1.08);
}

.buttonLink.secondary {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.competitiveCaveat {
  margin-top: 0.75rem;
}

.competitiveResult {
  margin-top: 0.8rem;
  padding: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.65rem;
  line-height: 1.45;
}

.competitiveResult.success {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.1);
}

.competitiveResult.warning {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.1);
}

.leaderboardScroll {
  margin-top: 0.85rem;
  overflow-x: auto;
}

.leaderboardTable {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.leaderboardTable th,
.leaderboardTable td {
  padding: 0.55rem 0.45rem;
  text-align: right;
  border-bottom: 1px solid rgba(148, 163, 184, 0.22);
  white-space: nowrap;
}

.leaderboardTable th:nth-child(2),
.leaderboardTable td:nth-child(2) {
  text-align: left;
}

.leaderboardTable tr.currentUser {
  background: rgba(59, 130, 246, 0.12);
  font-weight: 700;
}

.leaderboardEmpty {
  text-align: center !important;
  opacity: 0.75;
}
