:root {
  --bg: #10131a;
  --panel: #171b25;
  --panel-2: #1d2430;
  --text: #f6f4ec;
  --muted: #aeb6c3;
  --line: #2b3240;
  --accent: #f4c95d;
  --danger: #ec6f70;
  --square-light: #d4c0a2;
  --square-dark: #705b4a;
  --square-ring: #ffef99;
  --move: rgba(44, 143, 113, 0.78);
  --capture: rgba(209, 72, 72, 0.82);
  --white-piece: #f8f7f2;
  --black-piece: #262a31;
  --red-piece: #d94e4e;
  --blue-piece: #4b8fe8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(244, 201, 93, 0.16), transparent 30rem),
    radial-gradient(circle at bottom right, rgba(75, 143, 232, 0.15), transparent 34rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1520px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.76rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 3.2vw, 3.1rem);
  line-height: 1;
}

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

.connection-pill {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(23, 27, 37, 0.82);
  color: var(--muted);
  white-space: nowrap;
}

.connection-pill.online {
  color: #9be2c5;
}

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

.game-layout {
  display: grid;
  grid-template-columns: 285px minmax(0, 1fr) 325px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: rgba(23, 27, 37, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
}

.name-row {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.name-row input {
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
  outline: none;
}

.name-row input:focus {
  border-color: var(--accent);
}

.seat-grid {
  display: grid;
  gap: 10px;
}

.seat-button {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 4px 10px;
  text-align: left;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
}

.seat-button:hover,
.seat-button.mine {
  border-color: var(--accent);
}

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

.seat-button .seat-color {
  grid-row: span 2;
  width: 14px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.seat-button strong {
  text-transform: capitalize;
}

.seat-button small {
  color: var(--muted);
}

.white-bg { background: var(--white-piece); }
.red-bg { background: var(--red-piece); }
.black-bg { background: var(--black-piece); }
.blue-bg { background: var(--blue-piece); }

.secondary,
.danger {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
}

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

.danger {
  background: rgba(236, 111, 112, 0.13);
  border-color: rgba(236, 111, 112, 0.38);
}

.danger:hover {
  border-color: var(--danger);
}

.turn-card {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(244, 201, 93, 0.10), rgba(255, 255, 255, 0.02));
}

.turn-card span,
.turn-card small {
  display: block;
  color: var(--muted);
}

.turn-card strong {
  display: block;
  margin: 3px 0;
  font-size: 1.5rem;
  text-transform: capitalize;
}

.board-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: auto;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.message-box {
  min-height: 42px;
  flex: 1;
  display: flex;
  align-items: center;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(23, 27, 37, 0.92);
  color: var(--muted);
}

.message-box.success { color: #9be2c5; }
.message-box.error { color: var(--danger); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  justify-content: flex-end;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  border-radius: 999px;
  background: rgba(23, 27, 37, 0.82);
  border: 1px solid var(--line);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot.white { background: var(--white-piece); }
.dot.red { background: var(--red-piece); }
.dot.black { background: var(--black-piece); }
.dot.blue { background: var(--blue-piece); }

.board {
  width: min(65vw, 760px);
  max-width: 100%;
  aspect-ratio: 1;
 
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(12, 1fr);
  border: 10px solid #27202a;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.42);
  margin: 0 auto;
  background: #27202a;
}

.square {
  position: relative;
  border: 0;
  padding: 0;
  background: var(--square-light);
  display: grid;
  place-items: center;
  isolation: isolate;
}

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

.square.selected::after {
  content: '';
  position: absolute;
  inset: 7%;
  border: 3px solid var(--square-ring);
  border-radius: 10px;
  z-index: 2;
  pointer-events: none;
}

.square.move::before,
.square.capture::before {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  z-index: 1;
  background: var(--move);
  pointer-events: none;
}

.square.capture::before {
  width: 72%;
  height: 72%;
  border: 4px solid var(--capture);
  background: transparent;
}

.coord {
  position: absolute;
  left: 4px;
  bottom: 3px;
  color: rgba(16, 19, 26, 0.52);
  font-size: clamp(0.42rem, 0.88vw, 0.64rem);
  font-weight: 700;
  z-index: 0;
}

.dark .coord {
  color: rgba(246, 244, 236, 0.42);
}

.piece {
  position: relative;
  z-index: 3;
  width: 78%;
  height: 78%;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-weight: 900;
  font-size: clamp(1rem, 2.75vw, 2.25rem);
  line-height: 1;
  user-select: none;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.piece.white {
  background: var(--white-piece);
  color: #2f3138;
}

.piece.black {
  background: var(--black-piece);
  color: #f5f1e8;
}

.piece.red {
  background: var(--red-piece);
  color: #fff7f7;
}

.piece.blue {
  background: var(--blue-piece);
  color: #f8fbff;
}

.piece.inactive {
  opacity: 0.28;
}

.rules {
  margin: 0 0 18px;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.48;
}

.move-log {
  display: grid;
  gap: 8px;
  max-height: min(570px, calc(100vh - 350px));
  overflow: auto;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
}

.move-log li::marker {
  color: var(--accent);
}

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

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

  .move-log {
    max-height: 260px;
  }
}

@media (max-width: 820px) {
  .topbar,
  .board-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .board {
    width: 100%;
    border-width: 6px;
  }
}

.primary {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(244, 201, 93, 0.62);
  color: #17120a;
  background: var(--accent);
  font-weight: 800;
}

.primary:hover {
  filter: brightness(1.06);
}

.primary:disabled,
.secondary:disabled,
.danger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.compact {
  margin-top: 8px;
}

.room-card,
.team-card,
.ai-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(244, 201, 93, 0.25);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(244, 201, 93, 0.10), rgba(75, 143, 232, 0.08));
}

.room-card h2,
.team-card h2,
.ai-card h2 {
  margin-bottom: 10px;
}

.room-card small,
.team-card small,
.ai-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.room-row,
.team-row,
.ai-row {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.room-row input,
.team-row select,
.ai-row select {
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
  outline: none;
}

.room-row input:focus,
.team-row select:focus,
.ai-row select:focus {
  border-color: var(--accent);
}

.seat-button.ai-seat {
  border-color: rgba(244, 201, 93, 0.34);
  background: linear-gradient(135deg, rgba(244, 201, 93, 0.08), var(--panel-2));
}

.piece.ai-piece::after {
  content: 'AI';
  position: absolute;
  right: -5px;
  top: -6px;
  padding: 2px 4px;
  border-radius: 999px;
  font-size: 0.42rem;
  line-height: 1;
  letter-spacing: 0.03em;
  color: #17120a;
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.16);
}

.square.king-check::after {
  content: '';
  position: absolute;
  inset: 4%;
  border: 4px solid var(--danger);
  border-radius: 12px;
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 0 18px rgba(236, 111, 112, 0.7);
}

.confirm-checkmate {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
  box-shadow: 0 0 0 3px rgba(244, 201, 93, 0.15);
}

.piece.pending-mate {
  outline: 3px solid var(--danger);
  box-shadow: 0 0 18px rgba(236, 111, 112, 0.55), 0 8px 14px rgba(0, 0, 0, 0.24);
}
