:root {
  color-scheme: dark;
  --bg-0: #04070f;
  --bg-1: #081424;
  --bg-2: #11253a;
  --panel: rgba(7, 14, 28, 0.8);
  --panel-strong: rgba(9, 18, 34, 0.92);
  --panel-border: rgba(167, 194, 255, 0.22);
  --text-main: #f7f9ff;
  --text-soft: #c6d0ea;
  --text-faint: #95a4c7;
  --accent-hot: #ff7a18;
  --accent-gold: #ffbe55;
  --accent-cool: #22d3b6;
  --danger: #ff5d7d;
  --success: #2fdd85;
  --board-light: #efe3c5;
  --board-dark: #ad683f;
  --board-frame: #2a527e;
  --board-glow: rgba(255, 140, 51, 0.62);
  --board-size: clamp(250px, 50vw, 560px);
  --piece-white: #ffffff;
  --piece-black: #111522;
  --piece-white-filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.42));
  --piece-black-filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
  --piece-font: "Segoe UI Symbol", "Noto Sans Symbols 2", "Arial Unicode MS", sans-serif;
  --piece-emboss: 0 2px 0 rgba(0, 0, 0, 0.32);
  --radius-panel: 22px;
  --radius-card: 16px;
  --shadow-xl: 0 28px 70px rgba(0, 0, 0, 0.5);
}

body[data-board-theme="classic"] {
  --board-light: #efe3c5;
  --board-dark: #ad683f;
  --board-glow: rgba(255, 140, 51, 0.62);
}

body[data-board-theme="emerald"] {
  --board-light: #dbe8d2;
  --board-dark: #3f6a4e;
  --board-glow: rgba(80, 209, 160, 0.66);
}

body[data-board-theme="royal"] {
  --board-light: #e5ecfa;
  --board-dark: #4d669f;
  --board-glow: rgba(104, 151, 255, 0.66);
}

body[data-board-theme="carbon"] {
  --board-light: #cad2df;
  --board-dark: #4b576a;
  --board-glow: rgba(182, 203, 246, 0.74);
}

body[data-board-theme="sunset"] {
  --board-light: #f7d8be;
  --board-dark: #92525e;
  --board-glow: rgba(255, 168, 122, 0.68);
}

body[data-piece-theme="classic"] {
  --piece-white: #ffffff;
  --piece-black: #111522;
  --piece-white-filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.42));
  --piece-black-filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
  --piece-emboss: 0 2px 0 rgba(0, 0, 0, 0.32);
}

body[data-piece-theme="ivory"] {
  --piece-white: #fff4d2;
  --piece-black: #5b3d2f;
  --piece-white-filter: drop-shadow(0 1px 2px rgba(84, 54, 24, 0.44));
  --piece-black-filter: drop-shadow(0 1px 2px rgba(27, 18, 11, 0.45));
  --piece-emboss: 0 2px 0 rgba(54, 36, 17, 0.26);
}

body[data-piece-theme="steel"] {
  --piece-white: #ecf4ff;
  --piece-black: #394556;
  --piece-white-filter: drop-shadow(0 1px 2px rgba(50, 71, 102, 0.4));
  --piece-black-filter: drop-shadow(0 1px 2px rgba(22, 29, 39, 0.44));
  --piece-emboss: 0 2px 0 rgba(26, 35, 47, 0.24);
}

body[data-piece-theme="neon"] {
  --piece-white: #d7fff9;
  --piece-black: #061a29;
  --piece-white-filter: drop-shadow(0 0 6px rgba(80, 255, 225, 0.55));
  --piece-black-filter: drop-shadow(0 0 5px rgba(88, 157, 255, 0.4));
  --piece-emboss: 0 2px 0 rgba(0, 0, 0, 0.24);
}

body[data-piece-theme="obsidian"] {
  --piece-white: #f3f7ff;
  --piece-black: #0a0d12;
  --piece-white-filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.38));
  --piece-black-filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.52));
  --piece-emboss: 0 2px 0 rgba(0, 0, 0, 0.32);
}

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

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

html {
  scrollbar-gutter: stable both-edges;
}

body {
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(900px 620px at -10% -15%, rgba(46, 204, 255, 0.16), transparent 64%),
    radial-gradient(760px 420px at 102% 0%, rgba(255, 151, 53, 0.17), transparent 62%),
    linear-gradient(145deg, var(--bg-0) 0%, var(--bg-1) 46%, var(--bg-2) 100%);
  overflow-x: clip;
  line-height: 1.4;
  padding-left: max(0.45rem, env(safe-area-inset-left));
  padding-right: max(0.45rem, env(safe-area-inset-right));
}

body.is-fullscreen {
  padding-left: max(0.2rem, env(safe-area-inset-left));
  padding-right: max(0.2rem, env(safe-area-inset-right));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -6;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 88%);
  opacity: 0.38;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(110px);
  pointer-events: none;
  z-index: -5;
}

.orb-a {
  width: 360px;
  height: 360px;
  right: -110px;
  top: -90px;
  background: rgba(255, 122, 24, 0.58);
  animation: orb-float 16s ease-in-out infinite;
}

.orb-b {
  width: 420px;
  height: 420px;
  left: -160px;
  bottom: -180px;
  background: rgba(26, 203, 174, 0.44);
  animation: orb-float 19s ease-in-out infinite reverse;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -7;
  background:
    linear-gradient(transparent, rgba(7, 13, 24, 0.6)),
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.08), transparent 42%);
}

.app-shell {
  width: min(1480px, 100%);
  margin-inline: auto;
  padding: 1rem 0 calc(2.4rem + env(safe-area-inset-bottom));
}

.game-shell,
.game-grid,
.board-panel,
.side-column,
.top-bar,
.player-strip,
.panel {
  min-width: 0;
}

.panel {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-panel);
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(130deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 34%),
    var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-xl);
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.07), transparent 30%);
  opacity: 0.5;
}

.lobby-panel {
  padding: 1.2rem 1rem 1.15rem;
  animation: rise 450ms ease-out;
}

.eyebrow {
  margin: 0;
  color: var(--accent-gold);
  letter-spacing: 0.34em;
  text-transform: uppercase;
  font-size: 0.71rem;
  font-weight: 800;
}

.lobby-panel h1 {
  margin: 0.75rem 0 0.48rem;
  font-family: "Bebas Neue", Impact, sans-serif;
  font-size: clamp(2.2rem, 7vw, 4.1rem);
  line-height: 0.92;
  letter-spacing: 0.03em;
}

.subtext {
  margin: 0;
  max-width: 68ch;
  color: var(--text-soft);
  font-size: clamp(0.9rem, 2.4vw, 1.02rem);
}

.lobby-highlights {
  margin-top: 0.95rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.highlight-card {
  border-radius: 13px;
  border: 1px solid rgba(171, 196, 243, 0.28);
  background:
    linear-gradient(130deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 50%),
    rgba(8, 17, 34, 0.7);
  padding: 0.55rem 0.62rem;
  display: grid;
  gap: 0.12rem;
}

.highlight-card strong {
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.highlight-card span {
  color: var(--text-soft);
  font-size: 0.73rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
}

.field span {
  color: var(--text-faint);
  font-size: 0.81rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
}

.field input {
  width: 100%;
  border: 1px solid rgba(164, 188, 238, 0.25);
  border-radius: 13px;
  background: rgba(11, 22, 42, 0.64);
  color: var(--text-main);
  padding: 0.78rem 0.9rem;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.field input::placeholder {
  color: rgba(205, 218, 247, 0.5);
}

.field input:focus {
  border-color: rgba(255, 190, 85, 0.78);
  box-shadow:
    0 0 0 3px rgba(255, 190, 85, 0.17),
    0 8px 20px rgba(0, 0, 0, 0.28);
  background: rgba(10, 23, 45, 0.85);
}

.lobby-actions {
  margin-top: 1rem;
  display: grid;
  gap: 0.85rem;
}

.action-card {
  border-radius: var(--radius-card);
  border: 1px solid rgba(152, 180, 235, 0.26);
  background:
    radial-gradient(circle at 100% 0%, rgba(255, 180, 70, 0.16), transparent 46%),
    rgba(7, 16, 31, 0.72);
  padding: 1rem;
  display: grid;
  gap: 0.65rem;
}

.action-card h2 {
  margin: 0;
  font-family: "Bebas Neue", Impact, sans-serif;
  font-size: 1.85rem;
  letter-spacing: 0.06em;
}

.action-card p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.66rem 0.95rem;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 130ms ease, filter 130ms ease, box-shadow 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.48;
  filter: grayscale(0.22);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(120deg, #ff7a18 0%, #ffbe55 100%);
  box-shadow: 0 14px 26px rgba(255, 122, 24, 0.36);
}

.btn-secondary {
  background: linear-gradient(120deg, #12a88f 0%, #1fd1bb 100%);
  box-shadow: 0 12px 24px rgba(21, 177, 152, 0.35);
}

.btn-ghost {
  border: 1px solid rgba(192, 210, 247, 0.28);
  background: rgba(11, 20, 38, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn-danger {
  background: linear-gradient(120deg, #ff446f 0%, #ff7a99 100%);
  box-shadow: 0 12px 24px rgba(255, 80, 118, 0.34);
}

.tips {
  margin-top: 1rem;
  border-radius: 14px;
  border: 1px solid rgba(159, 185, 234, 0.24);
  background: rgba(8, 18, 36, 0.74);
  padding: 0.75rem 0.85rem;
}

.tips p {
  margin: 0.25rem 0;
  color: var(--text-soft);
  font-size: 0.86rem;
}

.game-shell {
  display: none;
  gap: 0.9rem;
  animation: rise 320ms ease-out;
}

body.in-game .lobby-panel {
  display: none;
}

body.in-game .game-shell {
  display: grid;
}

.top-bar {
  padding: 0.8rem;
  display: grid;
  gap: 0.7rem;
  background: var(--panel-strong);
}

.room-chip {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 0.54rem;
  padding: 0.5rem 0.64rem;
  border-radius: 11px;
  border: 1px solid rgba(154, 184, 235, 0.3);
  background: rgba(13, 24, 46, 0.74);
}

.room-chip .label {
  color: var(--text-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.67rem;
  font-weight: 700;
}

.room-chip strong {
  letter-spacing: 0.14em;
  font-size: 0.96rem;
}

.chip-btn {
  border: 1px solid rgba(181, 203, 247, 0.32);
  border-radius: 8px;
  padding: 0.28rem 0.54rem;
  color: #fff;
  background: rgba(13, 24, 46, 0.86);
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.chip-btn:hover {
  border-color: rgba(255, 190, 85, 0.72);
  background: rgba(24, 40, 70, 0.92);
}

.role-pill {
  width: fit-content;
  padding: 0.44rem 0.72rem;
  border-radius: 999px;
  border: 1px solid rgba(159, 186, 240, 0.3);
  background: rgba(14, 26, 48, 0.85);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  font-weight: 800;
}

.status-text {
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 1.4rem;
  color: #fdfefe;
  overflow-wrap: anywhere;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-start;
}

.top-actions .btn {
  min-width: 92px;
  white-space: nowrap;
}

#fullscreen-btn {
  min-width: 52px;
  padding-inline: 0.4rem;
}

.top-settings {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.setting-field {
  display: grid;
  gap: 0.24rem;
}

.setting-field span {
  color: var(--text-faint);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.setting-field select {
  width: 100%;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid rgba(170, 195, 241, 0.34);
  background: rgba(10, 20, 38, 0.82);
  color: #fff;
  padding: 0.46rem 0.5rem;
  font-size: 0.82rem;
  outline: none;
}

.setting-field select:focus {
  border-color: rgba(255, 190, 85, 0.8);
  box-shadow: 0 0 0 2px rgba(255, 190, 85, 0.15);
}

.game-grid {
  display: grid;
  gap: 0.9rem;
}

.board-panel {
  padding: 0.82rem;
  display: grid;
  gap: 0.8rem;
  background:
    radial-gradient(circle at 50% 0%, rgba(39, 220, 188, 0.08), transparent 36%),
    radial-gradient(circle at 90% 100%, rgba(255, 170, 83, 0.12), transparent 48%),
    var(--panel-strong);
}

.player-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.62rem;
}

.player-card {
  position: relative;
  border-radius: 13px;
  border: 1px solid rgba(155, 182, 231, 0.28);
  background: rgba(11, 22, 42, 0.84);
  padding: 0.62rem 0.66rem;
  min-width: 0;
}

.player-card h3 {
  margin: 0;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
}

.player-card p {
  margin: 0.35rem 0 0;
  font-size: 0.94rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.connection-dot {
  position: absolute;
  right: 0.6rem;
  top: 0.6rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.connection-dot.online {
  background: var(--success);
  box-shadow: 0 0 13px rgba(47, 221, 133, 0.86);
}

.connection-dot.offline {
  background: rgba(204, 216, 240, 0.26);
}

.board {
  width: min(100%, var(--board-size));
  margin-inline: auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: 20px;
  overflow: hidden;
  border: 3px solid rgba(119, 164, 225, 0.46);
  outline: 1px solid rgba(255, 190, 85, 0.4);
  outline-offset: 0;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.13),
    0 28px 58px rgba(0, 0, 0, 0.5),
    0 0 0 4px rgba(18, 34, 61, 0.85),
    0 0 42px rgba(44, 141, 219, 0.34);
  isolation: isolate;
  contain: layout paint;
}

.game-shell:fullscreen {
  display: grid;
  gap: 0.72rem;
  padding: 0.72rem;
  overflow: auto;
  align-content: start;
  background: radial-gradient(circle at 0% 0%, #112844 0%, #070d16 62%);
}

.game-shell:fullscreen::backdrop {
  background: radial-gradient(circle at 20% 20%, #122a47 0%, #070d16 66%);
}

.game-shell:fullscreen .top-bar {
  position: sticky;
  top: 0;
  z-index: 24;
}

.game-shell:fullscreen .game-grid {
  gap: 0.72rem;
}

.game-shell:fullscreen .board {
  width: min(88vmin, 900px);
  max-width: 100%;
  margin-inline: auto;
}

@media (orientation: landscape) {
  .game-shell:fullscreen .game-grid {
    grid-template-columns: minmax(0, 1fr) clamp(280px, 27vw, 430px);
    align-items: start;
  }
}

@media (orientation: portrait) {
  .game-shell:fullscreen .game-grid {
    grid-template-columns: 1fr;
  }

  .game-shell:fullscreen .board {
    width: min(94vw, calc(100dvh - 220px));
  }
}

.square {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: filter 100ms ease;
}

.square::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.2), transparent 64%);
  transition: opacity 120ms ease;
}

.square:hover::before {
  opacity: 0.56;
}

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

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

.square.selected {
  box-shadow: inset 0 0 0 4px var(--board-glow);
  z-index: 2;
}

.square.legal::after,
.square.capture::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
}

.square.legal::after {
  width: 28%;
  height: 28%;
  background: rgba(29, 202, 174, 0.56);
  box-shadow: 0 0 14px rgba(29, 202, 174, 0.42);
}

.square.capture::after {
  width: 84%;
  height: 84%;
  border: 3px solid rgba(255, 98, 128, 0.78);
  background: rgba(255, 98, 128, 0.09);
}

.square.last-move {
  box-shadow: inset 0 0 0 4px rgba(255, 170, 84, 0.55);
}

.square.check {
  box-shadow: inset 0 0 0 4px rgba(255, 92, 123, 0.72);
  animation: king-danger 980ms ease-in-out infinite;
}

.coord {
  position: absolute;
  pointer-events: none;
  user-select: none;
  color: rgba(17, 24, 35, 0.52);
  font-size: clamp(0.5rem, 1.2vw, 0.66rem);
  line-height: 1;
  font-weight: 900;
}

.coord.file {
  right: 4px;
  bottom: 3px;
}

.coord.rank {
  left: 4px;
  top: 3px;
}

.piece {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  user-select: none;
  pointer-events: none;
  line-height: 1;
  font-family: var(--piece-font);
  font-size: clamp(1.4rem, 4.9vw, 2.8rem);
  text-shadow: var(--piece-emboss);
  transform: translateZ(0);
}

.piece.white-piece {
  color: var(--piece-white);
  filter: var(--piece-white-filter);
}

.piece.black-piece {
  color: var(--piece-black);
  filter: var(--piece-black-filter);
}

body[data-piece-mode="2d"] .piece {
  text-shadow: none;
}

body[data-piece-mode="2d"] .piece.white-piece,
body[data-piece-mode="2d"] .piece.black-piece {
  filter: none;
}

body[data-piece-mode="3d"] .piece {
  transform: translateY(-1px) translateZ(0);
}

.turn-hint {
  margin: 0;
  min-height: 1.5rem;
  text-align: center;
  color: var(--text-soft);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.side-column {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
}

.capture-panel,
.moves-panel,
.chat-panel {
  padding: 0.82rem;
  background: var(--panel-strong);
}

.capture-panel h3,
.moves-panel h3,
.chat-panel h3 {
  margin: 0 0 0.65rem;
  font-family: "Bebas Neue", Impact, sans-serif;
  font-size: 1.58rem;
  letter-spacing: 0.05em;
}

.capture-line {
  display: grid;
  gap: 0.38rem;
  margin-bottom: 0.68rem;
}

.capture-line span {
  color: var(--text-faint);
  font-size: 0.79rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.capture-pieces {
  min-height: 40px;
  border-radius: 10px;
  border: 1px dashed rgba(166, 190, 235, 0.38);
  background: rgba(9, 18, 35, 0.74);
  display: flex;
  align-items: center;
  gap: 0.32rem;
  flex-wrap: wrap;
  padding: 0.36rem 0.42rem;
}

.capture-piece {
  width: 27px;
  height: 27px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  font-size: 1.03rem;
  background: rgba(255, 255, 255, 0.12);
}

.moves-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.56rem;
  margin-bottom: 0.58rem;
}

.spectator-chip {
  border-radius: 999px;
  border: 1px solid rgba(161, 185, 236, 0.36);
  background: rgba(12, 22, 40, 0.84);
  padding: 0.22rem 0.56rem;
  color: var(--text-soft);
  font-size: 0.72rem;
}

.move-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.move-nav .btn {
  padding: 0.5rem 0.3rem;
  font-size: 0.79rem;
}

.move-review-text {
  margin: 0 0 0.55rem;
  font-size: 0.76rem;
  color: var(--text-faint);
}

.move-review-text.active {
  color: #ffd89d;
}

.move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 250px;
  overflow-y: auto;
  display: grid;
  gap: 0.44rem;
}

.move-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.44rem;
  border-radius: 9px;
  border: 1px solid rgba(161, 186, 236, 0.24);
  background: rgba(11, 21, 40, 0.78);
  padding: 0.42rem 0.5rem;
  font-size: 0.87rem;
  font-weight: 600;
}

.move-index {
  color: var(--text-faint);
  font-size: 0.78rem;
}

.move-cell {
  border: 1px solid rgba(161, 186, 236, 0.24);
  background: rgba(9, 18, 34, 0.68);
  color: #eaf0ff;
  border-radius: 8px;
  min-height: 30px;
  font-size: 0.83rem;
  cursor: pointer;
  transition: border-color 110ms ease, background 110ms ease;
}

.move-cell:hover {
  border-color: rgba(255, 190, 85, 0.62);
  background: rgba(16, 29, 52, 0.82);
}

.move-cell.active {
  border-color: rgba(255, 190, 85, 0.82);
  background: rgba(255, 190, 85, 0.2);
  color: #fff5df;
}

.move-cell.recent {
  border-color: rgba(44, 211, 181, 0.72);
  background: rgba(44, 211, 181, 0.2);
}

.move-cell.empty {
  opacity: 0.52;
}

.chat-log {
  min-height: 190px;
  max-height: 300px;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid rgba(159, 185, 236, 0.28);
  background: rgba(7, 16, 32, 0.72);
  padding: 0.58rem;
  display: grid;
  gap: 0.42rem;
}

.chat-item {
  border-radius: 11px;
  padding: 0.42rem 0.55rem;
  background: rgba(255, 255, 255, 0.08);
  word-break: break-word;
  font-size: 0.84rem;
}

.chat-item strong {
  display: block;
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.69rem;
  color: var(--text-faint);
}

.chat-item.self {
  border: 1px solid rgba(30, 214, 181, 0.4);
  background: rgba(30, 214, 181, 0.15);
}

.chat-item.system {
  border: 1px solid rgba(255, 166, 76, 0.4);
  background: rgba(255, 166, 76, 0.15);
}

.chat-form {
  margin-top: 0.65rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.46rem;
}

.chat-form input {
  min-width: 0;
  border-radius: 10px;
  border: 1px solid rgba(165, 190, 238, 0.32);
  background: rgba(11, 21, 40, 0.82);
  color: #fff;
  padding: 0.58rem 0.64rem;
  outline: none;
}

.chat-form input:focus {
  border-color: rgba(255, 190, 85, 0.8);
  box-shadow: 0 0 0 3px rgba(255, 190, 85, 0.15);
}

.promotion-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(3, 8, 18, 0.76);
  backdrop-filter: blur(6px);
  z-index: 50;
}

.promotion-modal.hidden {
  display: none;
}

.promotion-card {
  width: min(430px, 100%);
  padding: 1rem;
  background: var(--panel-strong);
}

.promotion-card h3 {
  margin: 0;
  font-size: 1.5rem;
  font-family: "Bebas Neue", Impact, sans-serif;
  letter-spacing: 0.06em;
}

.promotion-card p {
  margin: 0.38rem 0 0.7rem;
  color: var(--text-soft);
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.74rem;
}

.promotion-btn {
  height: 58px;
  border-radius: 10px;
  border: 1px solid rgba(164, 190, 238, 0.3);
  background: rgba(11, 21, 40, 0.86);
  color: #fff;
  font-size: 1.78rem;
  cursor: pointer;
  transition: border-color 130ms ease, transform 130ms ease;
}

.promotion-btn:hover {
  border-color: rgba(255, 190, 85, 0.78);
  transform: translateY(-1px);
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 9, 19, 0.74);
  backdrop-filter: blur(7px);
}

.result-modal.hidden {
  display: none;
}

.result-card {
  width: min(480px, 100%);
  padding: 1rem;
  background: var(--panel-strong);
  border: 1px solid rgba(173, 198, 246, 0.38);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.result-eyebrow {
  margin: 0;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.67rem;
  font-weight: 800;
}

.result-card h3 {
  margin: 0.42rem 0 0;
  font-family: "Bebas Neue", Impact, sans-serif;
  letter-spacing: 0.04em;
  font-size: 2rem;
}

.result-summary {
  margin: 0.45rem 0 0;
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.result-detail {
  margin: 0.3rem 0 0;
  color: var(--text-soft);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.result-actions {
  margin-top: 0.88rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(18px);
  pointer-events: none;
  opacity: 0;
  z-index: 60;
  border-radius: 999px;
  border: 1px solid rgba(165, 189, 237, 0.36);
  background: rgba(8, 17, 35, 0.95);
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.46);
  padding: 0.58rem 0.9rem;
  font-size: 0.85rem;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.move-list::-webkit-scrollbar,
.chat-log::-webkit-scrollbar {
  width: 9px;
}

.move-list::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb {
  background: rgba(166, 191, 236, 0.4);
  border-radius: 999px;
}

.move-list::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track {
  background: rgba(7, 15, 28, 0.46);
}

@media (min-width: 760px) {
  .app-shell {
    padding-top: 1.5rem;
  }

  .lobby-panel {
    padding: 1.55rem;
  }

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

@media (min-width: 980px) {
  .top-bar {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.8rem;
    padding: 0.9rem;
  }

  .top-actions {
    justify-content: flex-end;
  }
}

@media (min-width: 1120px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr) minmax(350px, 430px);
    align-items: start;
  }

  .board-panel {
    padding: 1rem;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: 100%;
    padding-top: 0.72rem;
    padding-bottom: 1.3rem;
  }

  .lobby-panel h1 {
    font-size: clamp(1.9rem, 10vw, 2.8rem);
  }

  .lobby-highlights {
    grid-template-columns: 1fr;
  }

  .panel {
    border-radius: 18px;
  }

  .top-bar {
    padding: 0.68rem;
    gap: 0.56rem;
  }

  .room-chip {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    row-gap: 0.34rem;
  }

  .room-chip strong {
    font-size: 0.92rem;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 0.4rem;
  }

  .top-actions .btn {
    min-width: 0;
    padding: 0.58rem 0.25rem;
    font-size: 0.9rem;
  }

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

  .top-settings .setting-field:last-child {
    grid-column: 1 / -1;
  }

  .board-panel {
    padding: 0.62rem;
    gap: 0.62rem;
  }

  .board {
    width: min(100%, calc(100vw - 2.2rem));
    border-radius: 15px;
    border-width: 2px;
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.13),
      0 18px 34px rgba(0, 0, 0, 0.42),
      0 0 0 3px rgba(18, 34, 61, 0.85),
      0 0 28px rgba(44, 141, 219, 0.24);
  }

  .piece {
    font-size: clamp(1.28rem, 7.8vw, 2.15rem);
  }

  .capture-panel,
  .moves-panel,
  .chat-panel {
    padding: 0.68rem;
  }

  .move-list {
    max-height: 210px;
  }

  .chat-log {
    min-height: 160px;
    max-height: 240px;
  }

  .result-card {
    padding: 0.86rem;
  }

  .result-card h3 {
    font-size: 1.72rem;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  #rematch-btn {
    grid-column: 1 / -1;
  }

  #leave-room-btn {
    grid-column: 1 / -1;
  }

  .top-settings {
    grid-template-columns: 1fr;
  }

  .top-settings .setting-field:last-child {
    grid-column: auto;
  }

  .room-chip .label {
    font-size: 0.62rem;
  }

  .room-chip strong {
    letter-spacing: 0.08em;
    font-size: 0.88rem;
  }

  .role-pill {
    font-size: 0.63rem;
    padding: 0.38rem 0.56rem;
  }

  .status-text {
    font-size: 0.88rem;
  }

  .board {
    width: min(100%, calc(100vw - 1.5rem));
  }

  .player-card {
    padding: 0.54rem 0.56rem;
  }

  .player-card p {
    font-size: 0.86rem;
  }

  .turn-hint {
    font-size: 0.84rem;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-form .btn {
    width: 100%;
  }
}

@media (max-width: 360px) {
  .board {
    width: min(100%, calc(100vw - 1rem));
  }

  .piece {
    font-size: clamp(1.08rem, 8.5vw, 1.84rem);
  }

  .top-actions .btn {
    font-size: 0.82rem;
    padding: 0.5rem 0.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes orb-float {
  0% {
    transform: translate(0, 0) scale(1);
  }

  50% {
    transform: translate(20px, -18px) scale(1.06);
  }

  100% {
    transform: translate(0, 0) scale(1);
  }
}

@keyframes king-danger {
  0%,
  100% {
    filter: saturate(1);
  }

  50% {
    filter: saturate(1.24);
  }
}
