:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --ink: #18201f;
  --muted: #69746f;
  --line: #d7ded9;
  --panel: #ffffff;
  --panel-soft: #fbfcfb;
  --green: #227a5b;
  --green-dark: #155b45;
  --gold: #c47a2c;
  --red: #b63838;
  --light-square: #e8dcc4;
  --dark-square: #57836e;
  --target: #f2c94c;
  --selected: #2d6cdf;
  --shadow: 0 18px 40px rgba(21, 35, 31, 0.12);
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --button-bg: var(--ink);
  --button-text: #fff;
  --ghost-bg: #fff;
  --pieces-url: url("/assets/pieces-classic-grid.png");
}

body[data-theme="gold"] {
  color-scheme: dark;
  --bg: #100d09;
  --ink: #fff3d0;
  --muted: #bcae8c;
  --line: rgba(222, 177, 83, 0.34);
  --panel: #1c1710;
  --panel-soft: #141008;
  --green: #d8ad54;
  --green-dark: #f0cd78;
  --gold: #f4c76b;
  --red: #d76657;
  --light-square: #e7c071;
  --dark-square: #3b2718;
  --target: #ffe08a;
  --selected: #f5ce73;
  --shadow: 0 20px 46px rgba(0, 0, 0, 0.42);
  --topbar-bg: rgba(24, 18, 10, 0.92);
  --button-bg: linear-gradient(180deg, #f2cd7b, #a96f22);
  --button-text: #16100a;
  --ghost-bg: #17120b;
  --pieces-url: url("/assets/pieces-gold-grid.png");
}

body[data-theme="flat"] {
  color-scheme: light;
  --bg: #fbfaf3;
  --ink: #151515;
  --muted: #65645e;
  --line: #151515;
  --panel: #fffef7;
  --panel-soft: #f3f1e8;
  --green: #18b6d4;
  --green-dark: #008fac;
  --gold: #ffd71a;
  --red: #ff2647;
  --light-square: #f9f6e8;
  --dark-square: #f7d91d;
  --target: #00d2ff;
  --selected: #ff2647;
  --shadow: 10px 10px 0 #151515;
  --topbar-bg: rgba(255, 254, 247, 0.94);
  --button-bg: #151515;
  --button-text: #fffef7;
  --ghost-bg: #fffef7;
  --pieces-url: url("/assets/pieces-flat-grid.png");
}

body[data-theme="neon"] {
  color-scheme: dark;
  --bg: #060712;
  --ink: #e8fbff;
  --muted: #93a9bf;
  --line: rgba(91, 232, 255, 0.34);
  --panel: rgba(8, 13, 30, 0.94);
  --panel-soft: rgba(13, 21, 44, 0.92);
  --green: #25f4ff;
  --green-dark: #ff3df2;
  --gold: #b7ff3d;
  --red: #ff3d72;
  --light-square: #111b3d;
  --dark-square: #071021;
  --target: #b7ff3d;
  --selected: #ff3df2;
  --shadow: 0 22px 56px rgba(0, 0, 0, 0.5), 0 0 26px rgba(37, 244, 255, 0.16);
  --topbar-bg: rgba(5, 8, 22, 0.9);
  --button-bg: linear-gradient(135deg, #25f4ff, #ff3df2);
  --button-text: #050711;
  --ghost-bg: rgba(9, 16, 34, 0.92);
  --pieces-url: url("/assets/pieces-neon-grid.png");
}

body[data-theme="wood"] {
  color-scheme: light;
  --bg: #f3eadb;
  --ink: #2a1a10;
  --muted: #7a6656;
  --line: rgba(92, 55, 28, 0.26);
  --panel: rgba(255, 250, 240, 0.94);
  --panel-soft: #f7eddc;
  --green: #6f8f4d;
  --green-dark: #4d6d35;
  --gold: #c48942;
  --red: #a84632;
  --light-square: #edd0a2;
  --dark-square: #8a5a33;
  --target: #d8a84b;
  --selected: #4f7f9c;
  --shadow: 0 22px 46px rgba(77, 45, 21, 0.2);
  --topbar-bg: rgba(255, 248, 236, 0.92);
  --button-bg: linear-gradient(180deg, #b87939, #6c3f20);
  --button-text: #fff8ec;
  --ghost-bg: #fff8ec;
  --pieces-url: url("/assets/pieces-wood-grid.png");
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="gold"] {
  background:
    radial-gradient(circle at 18% 0%, rgba(232, 179, 83, 0.18), transparent 34%),
    linear-gradient(180deg, #171107, #0d0a07 60%, #151008);
}

body[data-theme="flat"] {
  background:
    linear-gradient(104deg, transparent 0 13%, rgba(255, 38, 71, 0.92) 13% 24%, transparent 24% 100%),
    linear-gradient(176deg, transparent 0 58%, rgba(255, 215, 26, 0.88) 58% 69%, transparent 69% 100%),
    linear-gradient(90deg, rgba(0, 210, 255, 0.16) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(0, 210, 255, 0.16) 0 1px, transparent 1px 100%),
    #fbfaf3;
  background-size: auto, auto, 64px 64px, 64px 64px, auto;
}

body[data-theme="neon"] {
  background:
    linear-gradient(116deg, transparent 0 10%, rgba(255, 61, 242, 0.16) 10% 12%, transparent 12% 100%),
    linear-gradient(68deg, transparent 0 60%, rgba(37, 244, 255, 0.12) 60% 62%, transparent 62% 100%),
    linear-gradient(90deg, rgba(37, 244, 255, 0.08) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(255, 61, 242, 0.07) 0 1px, transparent 1px 100%),
    #060712;
  background-size: auto, auto, 72px 72px, 72px 72px, auto;
}

body[data-theme="wood"] {
  background:
    linear-gradient(90deg, rgba(90, 52, 26, 0.08) 0 1px, transparent 1px 100%),
    radial-gradient(circle at 18% 8%, rgba(196, 137, 66, 0.2), transparent 32%),
    linear-gradient(135deg, #f7eddc, #e9d3b3 62%, #d8b381);
  background-size: 46px 46px, auto, auto;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 120ms ease,
    background 120ms ease,
    opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

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

button.accent {
  background: var(--green);
}

button.accent:hover {
  background: var(--green-dark);
}

button.ghost {
  border: 1px solid var(--line);
  background: var(--ghost-bg);
  color: var(--ink);
}

button.danger {
  background: var(--red);
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 122, 91, 0.15);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
}

.brand,
.accountbar,
.account-chip,
.matchbar,
.join-box,
.room-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.accountbar {
  justify-content: flex-end;
}

.account-chip {
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--ghost-bg);
  color: var(--ink);
}

.avatar {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background:
    linear-gradient(135deg, var(--green), var(--gold));
  color: var(--button-text);
  font-size: 13px;
  font-weight: 900;
  background-position: center;
  background-size: cover;
}

.avatar.large {
  width: 58px;
  height: 58px;
  font-size: 24px;
}

.avatar.image-avatar {
  color: transparent;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--ghost-bg);
  color: var(--ink);
  font-size: 20px;
}

.mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #0f1715;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 10px 22px rgba(21, 35, 31, 0.2);
  overflow: hidden;
}

.mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.connection::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
}

.connection.online::before {
  background: var(--green);
}

.connection.offline::before {
  background: var(--red);
}

.layout {
  width: min(1500px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 390px;
  gap: clamp(18px, 3vw, 34px);
  padding: clamp(16px, 3vw, 34px);
}

.layout:has(.ad-rail) {
  width: min(1720px, 100%);
  grid-template-columns: minmax(420px, 1fr) 390px minmax(160px, 220px);
}

.play-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.matchbar {
  flex-wrap: wrap;
}

.join-box {
  min-width: min(320px, 100%);
}

.join-box input {
  width: 150px;
  text-transform: uppercase;
}

.board-shell {
  align-self: start;
  display: grid;
  gap: 12px;
}

.player-strip {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px;
  color: var(--ink);
}

.player-strip span {
  display: inline-flex;
  min-width: 34px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.player-strip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-strip.active strong {
  color: var(--green-dark);
}

.player-strip.muted {
  color: var(--muted);
}

.board {
  position: relative;
  width: min(78vh, 100%);
  max-width: 760px;
  min-width: 320px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 8px solid color-mix(in srgb, var(--dark-square) 64%, #111);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  background: color-mix(in srgb, var(--dark-square) 64%, #111);
}

.board.in-check {
  animation: board-check 680ms ease;
}

.board.checkmate::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(246, 199, 91, 0.42), transparent 28%),
    radial-gradient(circle at 50% 50%, transparent 32%, rgba(182, 56, 56, 0.34) 56%, transparent 72%);
  animation: mate-flare 1200ms ease both;
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  display: grid;
  place-items: center;
  color: #17201d;
  font-size: clamp(28px, 6.3vmin, 60px);
  font-weight: 500;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35);
  overflow: hidden;
}

.square:hover {
  transform: none;
  filter: brightness(1.04);
}

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

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

.square.selected::after,
.square.target::after,
.square.last::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 7px;
  pointer-events: none;
  z-index: 3;
}

.square.selected::after {
  border: 4px solid var(--selected);
}

.square.target::after {
  width: 24%;
  height: 24%;
  inset: auto;
  background: rgba(242, 201, 76, 0.78);
  border-radius: 50%;
}

.square.capture.target::after {
  width: auto;
  height: auto;
  inset: 10%;
  border: 5px solid rgba(242, 201, 76, 0.72);
  background: transparent;
}

.square.last::after {
  background: rgba(196, 122, 44, 0.25);
  z-index: 1;
}

.square.premove-origin {
  box-shadow: inset 0 0 0 4px rgba(255, 38, 71, 0.42);
}

.square.premove-to {
  box-shadow: inset 0 -10px 0 rgba(255, 38, 71, 0.72);
}

.square.premove-from:not(.premove-to) {
  box-shadow: inset 0 0 0 4px rgba(255, 38, 71, 0.24);
}

.square.king-check {
  animation: king-square-warning 900ms ease-in-out infinite;
}

.square.king-mate {
  animation: king-square-mate 780ms ease-in-out infinite;
}

.piece {
  position: relative;
  z-index: 2;
  display: block;
  width: 94%;
  height: 94%;
  background-image: var(--pieces-url);
  background-repeat: no-repeat;
  background-size: 600% 200%;
  filter: drop-shadow(0 8px 7px rgba(20, 29, 27, 0.32));
  pointer-events: none;
  transform-origin: 50% 86%;
  will-change: transform, filter;
}

.piece-wk {
  background-position: 0% 0%;
}

.piece-wq {
  background-position: 20% 0%;
}

.piece-wr {
  background-position: 40% 0%;
}

.piece-wb {
  background-position: 60% 0%;
}

.piece-wn {
  background-position: 80% 0%;
}

.piece-wp {
  background-position: 100% 0%;
}

.piece-bk {
  background-position: 0% 100%;
}

.piece-bq {
  background-position: 20% 100%;
}

.piece-br {
  background-position: 40% 100%;
}

.piece-bb {
  background-position: 60% 100%;
}

.piece-bn {
  background-position: 80% 100%;
}

.piece-bp {
  background-position: 100% 100%;
}

.piece.move-in {
  animation: piece-slide 340ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.drag-piece {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 60;
  width: min(74px, 11vmin);
  height: min(74px, 11vmin);
  pointer-events: none;
  filter: drop-shadow(0 16px 15px rgba(20, 29, 27, 0.24));
}

.king-check .piece {
  animation: king-piece-warning 900ms ease-in-out infinite;
}

.king-mate .piece {
  animation: king-piece-mate 780ms ease-in-out infinite;
}

.coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  color: rgba(24, 32, 31, 0.62);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.side-panel {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 16px;
}

.ad-slot {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(21, 35, 31, 0.07);
  overflow: hidden;
}

.ad-slot .adsbygoogle {
  width: 100%;
}

.ad-rail {
  position: sticky;
  top: 98px;
  align-self: start;
  min-height: 600px;
}

.ad-rail .adsbygoogle {
  min-height: 600px;
}

.desktop-bottom-ad {
  width: min(970px, calc(100% - clamp(32px, 6vw, 68px)));
  min-height: 96px;
  margin: 0 auto clamp(18px, 3vw, 34px);
}

.desktop-bottom-ad .adsbygoogle {
  min-height: 96px;
}

.mobile-anchor-ad {
  display: none;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 10px 24px rgba(21, 35, 31, 0.07);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-line {
  min-height: 42px;
  display: flex;
  align-items: center;
  border-block: 1px solid var(--line);
  color: var(--ink);
  font-weight: 800;
}

.room-actions {
  flex-wrap: wrap;
  margin-top: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-soft);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.move-list {
  min-height: 110px;
  max-height: 190px;
  overflow: auto;
  margin: 0;
  padding-left: 28px;
}

.move-list li {
  padding: 5px 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
}

.stack-list,
.friend-form {
  display: grid;
  gap: 8px;
}

.friend-form {
  grid-template-columns: 1fr auto;
  margin-bottom: 10px;
}

.stack-item {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
}

.stack-item:hover {
  transform: none;
}

.stack-item.static {
  cursor: default;
}

.stack-info {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.stack-item strong,
.stack-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stack-item small,
.stack-info small,
.empty-list {
  color: var(--muted);
  font-size: 12px;
}

.stack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.stack-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.empty-list {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: var(--panel-soft);
}

.avatar.small {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  font-size: 13px;
}

.pgn-view {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: var(--panel-soft);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.chat-panel {
  display: grid;
  gap: 12px;
}

.chat-log {
  height: 210px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-soft);
}

.chat-message {
  margin: 0 0 9px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.chat-message:last-child {
  margin-bottom: 0;
}

.chat-message.system {
  color: var(--muted);
  font-style: italic;
}

.chat-name {
  color: var(--green-dark);
  font-weight: 800;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.promotion {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(16, 23, 22, 0.42);
}

.promotion-box {
  width: min(360px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
}

.promotion-box span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.promotion-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promotion-choices button {
  height: 64px;
  padding: 0;
  background: var(--panel-soft);
  color: var(--ink);
  display: grid;
  place-items: center;
}

.premove-queue {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.premove-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 12px;
}

.square.premove-to::before {
  content: attr(data-premove);
  position: absolute;
  right: 5px;
  top: 5px;
  z-index: 4;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: var(--button-text);
  font-size: 10px;
  font-weight: 900;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 13, 12, 0.56);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-header,
.tabs,
.toggle-row,
.profile-preview,
.account-actions,
.social-login {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.tabs {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  border-radius: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--green);
}

.settings-section {
  display: grid;
  gap: 16px;
}

.toggle-row {
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.toggle-row small,
.profile-preview small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.field-block,
.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.auth-form h3 {
  margin: 0 0 4px;
}

.social-login,
.account-actions {
  flex-wrap: wrap;
}

.profile-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

body[data-theme="gold"] .panel,
body[data-theme="gold"] .ad-slot,
body[data-theme="gold"] .modal-panel,
body[data-theme="gold"] .board {
  box-shadow:
    0 0 0 1px rgba(244, 199, 107, 0.16),
    var(--shadow);
}

body[data-theme="gold"] .square.light {
  background:
    linear-gradient(135deg, rgba(255, 238, 184, 0.16), transparent),
    var(--light-square);
}

body[data-theme="gold"] .square.dark {
  background:
    linear-gradient(135deg, rgba(0, 0, 0, 0.14), transparent),
    var(--dark-square);
}

body[data-theme="flat"] .topbar,
body[data-theme="flat"] .panel,
body[data-theme="flat"] .ad-slot,
body[data-theme="flat"] .modal-panel,
body[data-theme="flat"] .board,
body[data-theme="flat"] input,
body[data-theme="flat"] select,
body[data-theme="flat"] .avatar,
body[data-theme="flat"] .player-strip {
  border-color: #151515;
  box-shadow: var(--shadow);
}

body[data-theme="flat"] .panel,
body[data-theme="flat"] .ad-slot,
body[data-theme="flat"] .modal-panel {
  background:
    linear-gradient(90deg, rgba(255, 38, 71, 0.08) 0 6px, transparent 6px),
    var(--panel);
}

body[data-theme="flat"] button {
  border: 2px solid #151515;
  box-shadow: 4px 4px 0 #151515;
}

body[data-theme="flat"] button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 #151515;
}

body[data-theme="flat"] button:disabled {
  transform: none;
  box-shadow: 4px 4px 0 #151515;
}

body[data-theme="flat"] button.accent {
  background: #ff2647;
  color: #fffef7;
}

body[data-theme="flat"] button.ghost {
  background: #fffef7;
  color: #151515;
}

body[data-theme="flat"] .board {
  border-color: #151515;
  background: #151515;
}

body[data-theme="flat"] .square.light {
  background:
    linear-gradient(135deg, rgba(0, 210, 255, 0.12), transparent 42%),
    var(--light-square);
}

body[data-theme="flat"] .square.dark {
  background:
    linear-gradient(135deg, rgba(255, 38, 71, 0.18), transparent 40%),
    var(--dark-square);
}

body[data-theme="flat"] .piece {
  filter:
    drop-shadow(2px 0 0 #00d2ff)
    drop-shadow(-2px 0 0 #ff2647)
    drop-shadow(0 8px 0 rgba(21, 21, 21, 0.18));
}

body[data-theme="neon"] .topbar,
body[data-theme="neon"] .panel,
body[data-theme="neon"] .ad-slot,
body[data-theme="neon"] .modal-panel,
body[data-theme="neon"] .board,
body[data-theme="neon"] input,
body[data-theme="neon"] select,
body[data-theme="neon"] .player-strip,
body[data-theme="neon"] .stack-item,
body[data-theme="neon"] .empty-list,
body[data-theme="neon"] .pgn-view,
body[data-theme="neon"] .auth-form,
body[data-theme="neon"] .toggle-row,
body[data-theme="neon"] .profile-preview {
  border-color: rgba(91, 232, 255, 0.38);
  box-shadow:
    inset 0 0 0 1px rgba(255, 61, 242, 0.08),
    0 0 22px rgba(37, 244, 255, 0.12),
    var(--shadow);
}

body[data-theme="neon"] .panel,
body[data-theme="neon"] .ad-slot,
body[data-theme="neon"] .modal-panel,
body[data-theme="neon"] .stack-item,
body[data-theme="neon"] .empty-list,
body[data-theme="neon"] .pgn-view,
body[data-theme="neon"] .auth-form,
body[data-theme="neon"] .toggle-row,
body[data-theme="neon"] .profile-preview {
  background:
    linear-gradient(90deg, rgba(37, 244, 255, 0.08) 0 2px, transparent 2px),
    linear-gradient(180deg, rgba(255, 61, 242, 0.08), transparent 42%),
    var(--panel);
}

body[data-theme="neon"] .topbar {
  background:
    linear-gradient(90deg, rgba(37, 244, 255, 0.18), rgba(255, 61, 242, 0.12)),
    var(--topbar-bg);
}

body[data-theme="neon"] button {
  border: 1px solid rgba(91, 232, 255, 0.48);
  box-shadow:
    0 0 18px rgba(37, 244, 255, 0.2),
    0 0 30px rgba(255, 61, 242, 0.12);
}

body[data-theme="neon"] button:hover {
  box-shadow:
    0 0 22px rgba(37, 244, 255, 0.28),
    0 0 34px rgba(255, 61, 242, 0.18);
}

body[data-theme="neon"] button.ghost {
  color: var(--ink);
}

body[data-theme="neon"] .board {
  background: #02040e;
  border-color: rgba(183, 255, 61, 0.5);
}

body[data-theme="neon"] .square.light {
  background:
    linear-gradient(135deg, rgba(37, 244, 255, 0.18), transparent 48%),
    var(--light-square);
}

body[data-theme="neon"] .square.dark {
  background:
    linear-gradient(135deg, rgba(255, 61, 242, 0.16), transparent 46%),
    var(--dark-square);
}

body[data-theme="neon"] .square.selected,
body[data-theme="neon"] .square.target {
  box-shadow: inset 0 0 0 4px rgba(183, 255, 61, 0.45), inset 0 0 22px rgba(37, 244, 255, 0.24);
}

body[data-theme="neon"] .square.premove-to::after {
  background: #ff3df2;
  color: #050711;
  box-shadow: 0 0 16px rgba(255, 61, 242, 0.7);
}

body[data-theme="neon"] .piece {
  filter:
    drop-shadow(0 0 8px rgba(37, 244, 255, 0.58))
    drop-shadow(0 0 12px rgba(255, 61, 242, 0.45))
    drop-shadow(0 10px 10px rgba(0, 0, 0, 0.38));
}

body[data-theme="wood"] .topbar,
body[data-theme="wood"] .panel,
body[data-theme="wood"] .ad-slot,
body[data-theme="wood"] .modal-panel,
body[data-theme="wood"] .board,
body[data-theme="wood"] input,
body[data-theme="wood"] select,
body[data-theme="wood"] .player-strip,
body[data-theme="wood"] .stack-item,
body[data-theme="wood"] .empty-list,
body[data-theme="wood"] .pgn-view,
body[data-theme="wood"] .auth-form,
body[data-theme="wood"] .toggle-row,
body[data-theme="wood"] .profile-preview {
  border-color: rgba(92, 55, 28, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    var(--shadow);
}

body[data-theme="wood"] .panel,
body[data-theme="wood"] .ad-slot,
body[data-theme="wood"] .modal-panel,
body[data-theme="wood"] .stack-item,
body[data-theme="wood"] .empty-list,
body[data-theme="wood"] .pgn-view,
body[data-theme="wood"] .auth-form,
body[data-theme="wood"] .toggle-row,
body[data-theme="wood"] .profile-preview {
  background:
    linear-gradient(90deg, rgba(122, 76, 36, 0.06) 0 1px, transparent 1px 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), transparent 46%),
    var(--panel);
}

body[data-theme="wood"] .topbar {
  background:
    linear-gradient(90deg, rgba(196, 137, 66, 0.12), rgba(111, 143, 77, 0.1)),
    var(--topbar-bg);
}

body[data-theme="wood"] .board {
  background: #5f391e;
  border-color: rgba(92, 55, 28, 0.44);
}

body[data-theme="wood"] .square.light {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 44%),
    var(--light-square);
}

body[data-theme="wood"] .square.dark {
  background:
    linear-gradient(135deg, rgba(60, 32, 16, 0.22), transparent 46%),
    var(--dark-square);
}

body[data-theme="wood"] .piece {
  filter:
    drop-shadow(0 8px 7px rgba(51, 27, 13, 0.36))
    drop-shadow(0 1px 0 rgba(255, 247, 231, 0.22));
}

.promotion-choices .piece {
  width: 58px;
  height: 58px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.modal-panel.compact {
  width: min(420px, 100%);
}

.modal-copy {
  margin: 0 0 18px;
  color: var(--ink);
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .layout:has(.ad-rail) {
    width: min(1500px, 100%);
    grid-template-columns: minmax(420px, 1fr) 390px;
  }

  .ad-rail {
    display: none;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .layout:has(.ad-rail) {
    grid-template-columns: 1fr;
  }

  .board {
    width: min(100%, 720px);
    justify-self: center;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-panel {
    grid-column: 1 / -1;
  }

  .desktop-bottom-ad {
    display: none;
  }
}

@media (max-width: 680px) {
  body:has(.mobile-anchor-ad) {
    padding-bottom: 126px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .accountbar {
    width: 100%;
    justify-content: space-between;
  }

  .account-chip {
    min-width: 0;
  }

  .matchbar,
  .join-box {
    width: 100%;
  }

  .matchbar > button,
  .join-box button,
  .join-box input {
    flex: 1 1 auto;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .board {
    min-width: 0;
    border-width: 5px;
  }

  .square {
    font-size: clamp(26px, 9vw, 48px);
  }

  .mobile-anchor-ad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    display: block;
    min-height: 106px;
    border-inline: 0;
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    box-shadow: 0 -14px 30px rgba(21, 35, 31, 0.16);
  }

  .mobile-anchor-ad .adsbygoogle {
    min-height: 106px;
  }
}

@keyframes piece-slide {
  from {
    transform: translate(var(--move-x), var(--move-y));
    filter: drop-shadow(0 18px 13px rgba(20, 29, 27, 0.2));
  }

  to {
    transform: translate(0, 0);
    filter: drop-shadow(0 8px 7px rgba(20, 29, 27, 0.32));
  }
}

@keyframes board-check {
  0%,
  100% {
    box-shadow: var(--shadow);
  }

  45% {
    box-shadow:
      0 0 0 8px rgba(182, 56, 56, 0.2),
      0 22px 48px rgba(182, 56, 56, 0.26);
  }
}

@keyframes king-square-warning {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 rgba(182, 56, 56, 0);
  }

  50% {
    box-shadow: inset 0 0 0 8px rgba(182, 56, 56, 0.62);
  }
}

@keyframes king-square-mate {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.18) saturate(1.2);
  }
}

@keyframes king-piece-warning {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-4%) scale(1.06);
  }
}

@keyframes king-piece-mate {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }

  25% {
    transform: rotate(-3deg) scale(1.08);
  }

  75% {
    transform: rotate(3deg) scale(1.08);
  }
}

@keyframes mate-flare {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }

  32% {
    opacity: 1;
  }

  100% {
    opacity: 0.3;
    transform: scale(1.18);
  }
}
