/* ============================================
   1. RESET + CUSTOM PROPERTIES
   ============================================ */
:root {
  /* Colors */
  --color-primary: #667eea;
  --color-primary-dark: #5a67d8;
  --color-primary-shadow: rgba(102, 126, 234, 0.4);
  --color-primary-highlight: rgba(102, 126, 234, 0.3);
  --color-primary-overlay: rgba(102, 126, 234, 0.8);
  --color-secondary: #764ba2;
  --color-danger: #dc3545;
  --color-danger-dark: #c82333;
  --color-muted: #6c757d;
  --color-muted-dark: #5a6268;
  --color-success: #28a745;
  --color-link: #007bff;
  --color-link-dark: #0056b3;
  --color-text: #333;
  --color-text-light: #666;
  --color-border: #ddd;
  --color-bg-light: #f0f2f5;
  --color-bg-input: #f8f9fa;
  --color-board-light: #f0d9b5;
  --color-board-dark: #b58863;
  --color-board-border: #8b4513;
  --color-last-move: rgba(155, 199, 0, 0.41); /* Lichess "brown" theme value, same board colours as ours */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  /* Layout */
  --side-panel-transition: 1.25s cubic-bezier(0.4, 0, 0.2, 1);
  /* Responsive breakpoints mirrored from public/js/main.js (LAYOUT_BREAKPOINTS). */
  --layout-breakpoint-overlay-max: 999px;
  --layout-breakpoint-full-min: 1370px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  height: 100dvh;
  min-height: 100svh; /* ensure stable viewport height on mobile */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--gradient-primary);
  height: 100vh;
  height: 100dvh;
  min-height: 100svh; /* better handling when browser UI appears */
  color: var(--color-text);
  margin: 0;
  padding: 0;
  overflow: hidden; /* prevent scrolling on mobile */
}

/* ============================================
   2. APP SHELL (header / main / footer)
   ============================================ */
.app-layout {
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  max-width: min(87.5rem, calc(100vw - clamp(0.5rem, 4vw, 2rem)));
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0 clamp(0.25rem, 2vw, 1rem);
  overflow: hidden;
}

.app-header {
  padding: clamp(0.2rem, 1vh, 0.5rem);
  text-align: center;
  color: white;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: clamp(1rem, max(4vw, calc(2vw + 1.5vh)), 2rem);
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
  font-size: clamp(0.6rem, max(2.2vw, calc(1.1vw + 0.8vh)), 0.9rem);
  opacity: 0.9;
  margin: 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  container-type: size;
}

.app-footer {
  padding: clamp(0.03rem, 0.45vmin, 0.25rem) clamp(0.12rem, 1vw, 0.5rem);
  text-align: center;
  color: white;
  opacity: 0.8;
  font-size: clamp(0.6rem, max(1.25vw, calc(0.6vw + 0.5vh)), 0.85rem);
  line-height: 1.15;
  flex-shrink: 0;
  margin-top: clamp(0.01rem, 0.35vmin, 0.3rem);
}

#stats {
  font-size: 1em;
  margin: 0;
  line-height: inherit;
}

/* ============================================
   3. SCREEN MANAGEMENT
   ============================================ */
.screen {
  display: none;
  width: 100%;
  text-align: center;
}

.screen.active {
  display: block;
}

#welcome-screen.active,
#waiting-screen.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
}

#game-screen.active {
  display: grid;
}

#game-screen:not(.active) {
  display: none !important;
}

/* ============================================
   4. WELCOME + WAITING SCREENS
   ============================================ */
#welcome-screen,
#waiting-screen {
  max-width: 100%;
  width: 100%;
  margin-top: auto;
  margin-bottom: auto;
}

.welcome-box,
.waiting-box {
  background: white;
  padding: clamp(1.2rem, 3vw, 2.5rem);
  border-radius: clamp(0.5rem, 1.5vw, 1.25rem);
  box-shadow: 0 clamp(0.3rem, 0.8vw, 0.7rem) clamp(0.5rem, 1.5vw, 1.25rem) rgba(0, 0, 0, 0.2);
  animation: slideUp 0.5s ease-out;
  max-width: min(clamp(31.25rem, 38vw, 56.25rem), 90vw);
  width: 100%;
  margin: 0 auto;
  container-type: inline-size;
}

.welcome-box h2,
.waiting-box h2 {
  margin-bottom: 4cqw;
  color: var(--color-text);
  font-size: 5.1cqw;
}

.welcome-box p,
.waiting-box p {
  margin-bottom: 4.8cqw;
  color: var(--color-text-light);
  font-size: 3.4cqw;
}

.input-group {
  display: flex;
  gap: 2.4cqw;
  margin-bottom: 4cqw;
  flex-wrap: wrap;
  box-sizing: border-box;
  width: 100%;
}

.input-group .btn-primary {
  flex: 1 0 auto;
  min-width: min-content;
}

#player-name {
  flex: 2 1 60%;
  min-width: 0;
  width: 100%;
  padding: 2.6cqw;
  border: 2px solid var(--color-border);
  border-radius: 2cqw;
  font-size: 3.4cqw;
  outline: none;
  transition: border-color 0.3s;
}
#player-name:focus {
  border-color: var(--color-primary);
}

/* Buttons (shared) */
.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 2.6cqw 5cqw;
  border: none;
  border-radius: 2cqw;
  font-size: 3.4cqw;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: bold;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px var(--color-primary-shadow);
}

.btn-secondary {
  background: var(--color-muted);
  color: white;
}

.btn-secondary:hover {
  background: var(--color-muted-dark);
  transform: translateY(-2px);
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-danger:hover {
  background: var(--color-danger-dark);
  transform: translateY(-2px);
}

/* Spinner */
.spinner {
  width: 10cqw;
  height: 10cqw;
  border: 1cqw solid #f3f3f3;
  border-top: 1cqw solid var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 4cqw;
}

/* ============================================
   5. GAME STAGE (grid, 3 columns)
   ============================================ */
#game-screen {
  /* Border-radius (cqh = main height, ~1000px → 1cqh ≈ 10px) */
  --radius-panel: 1cqh;      /* ~10px — player-info, chess-board, captured, chat */
  --radius-control: 0.7cqh;  /* ~7px  — buttons, inputs, color-indicator, chat messages */
  --radius-board: 0.35cqh;   /* ~3.5px — chessboard grid */
  /* Shadows */
  --shadow-panel: 0 0.3cqh 1cqh rgba(0, 0, 0, 0.1);  /* ~0 3px 10px */
  --shadow-board: 0 0.8cqh 2.5cqh rgba(0, 0, 0, 0.2); /* ~0 8px 25px */
  /* Borders */
  --border-input: 0.1cqh;    /* ~1px — input borders, chat separators */
  --border-accent: 0.2cqh;   /* ~2px — decorative underlines */
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: grid;
  grid-template-areas: "captured board chat";
  grid-template-columns: minmax(0, 25%) minmax(0, 1fr) minmax(0, 25%);
  grid-template-rows: auto;
  align-items: start;
  align-content: center;
  align-content: safe center;
  padding: 0.5cqh;
  gap: 2cqw;
  box-sizing: border-box;
  max-width: min(1350px, 100%, calc(100cqh * 1.63));
  margin: 0 auto;
  transition: grid-template-columns var(--side-panel-transition), gap var(--side-panel-transition);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#game-screen::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.captured-pieces-section { grid-area: captured; }
.game-center { grid-area: board; }
.chat-section { grid-area: chat; }

/* ============================================
   6. GAME CENTER + PLAYER INFO
   ============================================ */
.game-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(620px, 100%);
  width: 100%;
  height: auto;
  max-height: none;
  margin: 0 auto;
  min-height: 0;
  container-type: inline-size;
  justify-self: center;
  transition: max-width 1.05s cubic-bezier(0.16, 1, 0.3, 1), width 1.05s cubic-bezier(0.16, 1, 0.3, 1);
}

.game-center .player-info {
  margin: 0 auto 1.5cqw;
}

.player-info {
  background: white;
  padding: 1.5cqw 2.2cqw;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  width: 100%;
  margin-bottom: 1.5cqw;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#player-name-display {
  font-weight: bold;
  line-height: 1.1;
  font-size: 2.7cqw;
  min-width: 0;
}

#game-status {
  color: var(--color-primary);
  font-weight: bold;
  line-height: 1.1;
  font-size: 2.35cqw;
  min-width: 0;
  text-align: right;
}

/* ============================================
   7. CHESSBOARD + COORDINATES
   ============================================ */
#chess-board {
  background: white;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-board);
  container-type: inline-size;
  --coords-outset: 2.3cqw;
  --rank-left-buffer: 0.5cqw;
  --coord-font-size: calc((100cqw / 8) * 0.28);
  --coord-band-size: max(calc(var(--coord-font-size) * 1.2), calc(var(--coords-outset) - 0.05rem));
  padding: var(--coords-outset) calc(var(--coord-band-size) + var(--rank-left-buffer)) var(--coords-outset) calc(var(--coord-band-size) + var(--rank-left-buffer));
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
  box-sizing: border-box;
  flex: 0 0 auto;
  min-height: 0;
  display: block;
  overflow: hidden;
}

.chessboard-container {
  position: relative;
  width: 100%;
  margin-inline: auto;
  flex: 0 0 auto;
  min-height: 0;
  margin-bottom: calc(var(--coord-band-size) + 0.7cqw);
  container-type: inline-size;
}

.chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  --board-gap: 0.28cqw;
  --board-border: 0.35cqw;
  gap: var(--board-gap);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: var(--board-border) solid var(--color-board-border);
  border-radius: var(--radius-board);
  overflow: hidden;
  font-size: 12cqw;
  container-type: inline-size;
}

.square {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s;
}

.square.light {
  background-color: var(--color-board-light);
}

.square.dark {
  background-color: var(--color-board-dark);
}

.square:hover {
  opacity: 0.8;
}

.square.selected {
  box-shadow: inset 0 0 0 0.4cqw var(--color-primary);
}

/* From and to squares of the last move (as on Lichess/Chess.com): a tint laid over the square colour */
.square.last-move {
  background-image: linear-gradient(var(--color-last-move), var(--color-last-move));
}

.square.highlighted {
  background-color: var(--color-primary-highlight);
}

.square.highlighted::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--color-primary-overlay);
  transform: translate(-50%, -50%);
}

.piece {
  user-select: none;
  cursor: grab;
  line-height: 1;
}

.chessboard .piece {
  --x-offset: calc( calc(var(--board-border) * 2) + calc(var(--board-gap) * 7) );
  font-size: calc(((100cqw - var(--x-offset)) / 8) * 0.9);
}

.piece:active {
  cursor: pointer;
}

.coordinates {
  position: absolute;
  font-weight: bold;
  font-size: var(--coord-font-size);
  line-height: 1;
  color: var(--color-board-border);
  user-select: none;
  pointer-events: none;
}

.rank-coordinates {
  left: calc(var(--coord-band-size) * -1);
  width: var(--coord-band-size);
  top: 0;
  height: 100%;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  text-align: center;
}

.file-coordinates {
  bottom: calc(var(--coord-band-size) * -1);
  left: 0;
  width: 100%;
  height: var(--coord-band-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
}

.coordinates .coordinate {
  display: grid;
  place-items: center;
}

.color-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-bottom: 0.6cqw;
  padding: 1.4cqw 3cqw;
  background: var(--gradient-primary);
  color: white;
  border-radius: var(--radius-control);
  font-size: 3.2cqw;
  line-height: 1.2;
  flex-shrink: 0;
}

.color-indicator strong {
  display: inline-flex;
  align-items: center;
  font-size: 1em;
  margin-inline-start: 0.3em;
}

/* ============================================
   8. MOVE INPUT
   ============================================ */
.move-input {
  margin: 1.5cqw auto 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 1cqw;
  align-items: stretch;
  width: 100%;
  margin-inline: auto;
  box-sizing: border-box;
  flex-shrink: 0;
}

#move-input {
  flex: 1 1 60%;
  padding: 1.5cqw;
  border: var(--border-input) solid var(--color-border);
  border-radius: var(--radius-control);
  font-size: 2.5cqw;
  outline: none;
  transition: border-color 0.3s;
  min-width: 0;
}

#move-input:focus {
  border-color: var(--color-primary);
}

#move-input::placeholder {
  font-size: 2.2cqw;
}

#make-move-btn {
  flex: 1 1 auto;
  padding: 1.5cqw 3.5cqw;
  border-radius: var(--radius-control);
  font-size: 2.5cqw;
  min-width: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   9. CAPTURED PIECES PANEL
   ============================================ */
.captured-pieces-section {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  box-sizing: border-box;
  justify-content: space-between;
  container-type: inline-size;
  gap: 1.5cqw;
  flex-shrink: 0;
  align-self: start;
  transition: transform var(--side-panel-transition), opacity var(--side-panel-transition);
  transform: translate3d(0, 0, 0);
  opacity: 1;
  transform-origin: left center;
  backface-visibility: hidden;
}

.captured-pieces-section > .opponent-captured,
.captured-pieces-section > .player-captured {
  background: white;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  padding: 1.5cqw;
  flex: 1;
}

.captured-pieces-section > .opponent-captured h3,
.captured-pieces-section > .player-captured h3 {
  margin: 0 0 1.1cqw 0;
  font-size: 5cqw;
  line-height: 1.15;
  color: var(--color-text);
  text-align: center;
  padding-bottom: 1.1cqw;
  border-bottom: var(--border-accent) solid var(--color-primary);
}

.captured-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6cqw;
  justify-content: flex-start;
  min-height: 6.4cqw;
}

.captured-piece {
  --cp-size: 11cqw;
  width: var(--cp-size);
  height: var(--cp-size);
  font-size: calc(var(--cp-size) * 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

/* ============================================
   10. CHAT PANEL
   ============================================ */
.chat-section {
  position: static;
  width: 100%;
  max-width: 280px;
  height: auto;
  max-height: 100%;
  margin: 0 auto;
  display: flex;
  box-sizing: border-box;
  align-self: stretch;
  min-height: 0;
  contain: size;
  container-type: inline-size;
  transition: transform var(--side-panel-transition), opacity var(--side-panel-transition);
  transform: translate3d(0, 0, 0);
  opacity: 1;
  transform-origin: right center;
  backface-visibility: hidden;
}

.chat-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.chat-overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.chat-close-btn {
  display: none;
  position: absolute;
  right: 4cqw;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: white;
  font-size: 7cqw;
  cursor: pointer;
  padding: 0 2cqw;
  line-height: 1;
}

.side-overlay-chat-open .chat-close-btn,
.side-columns-collapsed .chat-close-btn {
  display: block;
}

.chat-container {
  background: white;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  background: var(--gradient-primary);
  color: white;
  padding: 4cqw 5.5cqw;
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  font-weight: bold;
  font-size: 5.7cqw;
  text-align: center;
  position: relative;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 4cqw;
  display: flex;
  flex-direction: column;
  gap: 3.2cqw;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-messages::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.chat-message {
  padding: 3.2cqw 4cqw;
  border-radius: var(--radius-control);
  max-width: 85%;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 5.1cqw;
  line-height: 1.3;
  box-sizing: border-box;
}

.chat-message.own {
  background: var(--color-primary);
  color: white;
  align-self: flex-end;
  text-align: left;
}

.chat-message.opponent {
  background: var(--color-bg-light);
  color: var(--color-text);
  align-self: flex-start;
  text-align: left;
}

.chat-message-author {
  font-weight: bold;
  font-size: 4.3cqw;
  margin-bottom: var(--border-accent);
  color: #000;
  opacity: 1;
}

.chat-message-time {
  font-size: 4cqw;
  opacity: 0.6;
  margin-top: var(--border-accent);
}

.chat-input-container {
  padding: 4cqw;
  border-top: var(--border-input) solid #e0e0e0;
  background: var(--color-bg-input);
  border-radius: 0 0 var(--radius-panel) var(--radius-panel);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1.2cqw;
}

.chat-input {
  width: 100%;
  padding: 3.2cqw 4cqw;
  border: var(--border-input) solid var(--color-border);
  border-radius: var(--radius-control);
  font-size: 4.2cqw;
  resize: none;
  min-height: 5cqw;
  max-height: 10cqw;
  box-sizing: border-box;
  margin: 0;
  line-height: 1.3;
}

.chat-input::placeholder {
  font-size: inherit !important;
  line-height: inherit;
}

.chat-input::-webkit-input-placeholder {
  font-size: inherit !important;
  line-height: inherit;
}

.chat-input::-moz-placeholder {
  font-size: inherit !important;
  line-height: inherit;
}

.chat-input:focus {
  border-color: var(--color-primary);
  outline: none;
}

.chat-message-text {
  white-space: pre-wrap;
}

.chat-error {
  color: var(--color-danger);
  font-size: 3.8cqw;
  padding: 0 4cqw;
  line-height: 1.3;
}

.chat-send-btn {
  background: var(--gradient-primary);
  color: white;
  border: none;
  padding: 1.5cqw 3.5cqw;
  border-radius: var(--radius-control);
  font-size: 4cqw;
  font-weight: bold;
  line-height: 1.2;
  cursor: pointer;
  margin-top: 0;
  transition: background 0.2s;
  width: 100%;
  text-align: center;
}

.chat-send-btn:hover {
  background: var(--color-primary-dark);
}

.chat-send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* ============================================
   11. GAME CONTROLS
   ============================================ */
.game-controls {
  display: flex;
  gap: 2cqw;
  width: 100%;
  margin: 1.5cqw auto 0;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.game-controls .btn-primary,
.game-controls .btn-danger {
  flex: 1 1 0;
  padding: 1.5cqw 3.5cqw;
  border-radius: var(--radius-control);
  font-size: 2.5cqw;
  line-height: 1.2;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-chat {
  display: none;
}

/* ============================================
   12. OVERLAYS + MODALS
   ============================================ */

/* Message Overlay */
.message-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 200;
  animation: fadeIn 0.3s ease-out;
  padding: clamp(0.5rem, 3vmin, 1.5rem);
  box-sizing: border-box;
}

.message-overlay.show {
  display: flex;
}

.message-box {
  background: white;
  padding: clamp(1.2rem, 2.5vw, 2.5rem);
  border-radius: clamp(0.5rem, 1.2vw, 1.25rem);
  text-align: center;
  max-width: min(clamp(25rem, 30vw, 43.75rem), 90vw);
  width: 100%;
  box-shadow: 0 clamp(0.3rem, 0.8vw, 0.7rem) clamp(0.5rem, 1.5vw, 1.5rem) rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
  position: relative;
  container-type: inline-size;
}

.message-box h3 {
  margin: 0 0 5cqw 0;
  font-size: 6cqw;
}

.message-box p {
  margin: 0 0 6cqw 0;
  font-size: 4.4cqw;
  line-height: 1.35;
}

.message-box.success h3 { color: var(--color-success); }
.message-box.error h3 { color: var(--color-danger); }
.message-box.info h3 { color: var(--color-primary); }

.message-close-btn {
  background: var(--gradient-primary);
  color: white;
  border: none;
  padding: 3cqw 6cqw;
  border-radius: 2cqw;
  font-size: 4cqw;
  cursor: pointer;
  transition: transform 0.2s;
}

.message-close-btn:hover {
  transform: translateY(-2px);
}

.message-buttons {
  display: flex;
  gap: 4cqw;
  justify-content: center;
  margin-top: 1.2cqw;
}

.btn-confirm {
  background: var(--color-danger);
  color: white;
  border: none;
  padding: 3cqw 5cqw;
  border-radius: 2cqw;
  font-size: 4cqw;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn-confirm:hover {
  background: var(--color-danger-dark);
  transform: translateY(-2px);
}

.btn-cancel {
  background: var(--color-muted);
  color: white;
  border: none;
  padding: 3cqw 5cqw;
  border-radius: 2cqw;
  font-size: 4cqw;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn-cancel:hover {
  background: var(--color-muted-dark);
  transform: translateY(-2px);
}

/* Game Selection Overlay */
.game-selection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.game-selection-modal {
  background: white;
  padding: clamp(1rem, 2.5vw, 2rem);
  border-radius: clamp(0.4rem, 1vw, 0.8rem);
  text-align: center;
  max-width: min(clamp(31.25rem, 38vw, 56.25rem), 92vw);
  max-height: 80vh;
  width: 90%;
  container-type: inline-size;
  box-shadow: 0 clamp(0.3rem, 0.8vw, 0.7rem) clamp(0.5rem, 1.5vw, 1.5rem) rgba(0, 0, 0, 0.3);
  overflow-y: scroll;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.game-selection-modal::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.game-selection-title {
  margin-bottom: 4cqw;
  color: var(--color-text);
  font-size: 4.8cqw;
}

.game-selection-subtitle {
  margin-bottom: 4cqw;
  color: var(--color-text-light);
  font-size: 3.2cqw;
}

.game-selection-list {
  margin: 4cqw 0;
}

.game-selection-item {
  border: 2px solid var(--color-border);
  border-radius: 2cqw;
  padding: 3cqw;
  margin: 2cqw 0;
  cursor: pointer;
  transition: all 0.3s ease;
}

.game-selection-item-your-turn {
  background: #e8f5e8;
}

.game-selection-item-opponent-turn {
  background: #f5f5f5;
}

.game-selection-item:hover {
  transform: scale(1.02);
}

.game-selection-opponent {
  margin: 0 0 2cqw 0;
  color: var(--color-text);
  font-size: 4cqw;
}

.game-selection-meta {
  margin: 1cqw 0;
  color: var(--color-text-light);
  font-size: 3.2cqw;
}

.game-selection-new-game-btn {
  background: var(--color-link);
  color: white;
  border: none;
  padding: 2.4cqw 4.8cqw;
  border-radius: 1.6cqw;
  cursor: pointer;
  margin-top: 4cqw;
  font-size: 3.2cqw;
  transition: background 0.3s ease;
}

.game-selection-new-game-btn:hover {
  background: var(--color-link-dark);
}

/* ============================================
   13. RESPONSIVE LAYOUT
   ============================================ */

/* --- Overlay mode baseline (0px - 999px) --- */
.chat-overlay {
  display: block;
}

.btn-chat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#open-captured-btn {
  display: inline-flex;
}

#game-screen {
  position: relative;
  grid-template-columns: 0fr minmax(0, 1fr) 0fr;
  gap: 0;
}

#game-screen .game-center {
  max-width: min(620px, 100%, calc((100cqh - clamp(4rem, 18cqh, 7.5rem)) * 0.88));
  width: 100%;
}

#game-screen .captured-pieces-section,
#game-screen .chat-section {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 95;
  width: min(84cqw, 300px);
  max-width: min(84cqw, 300px);
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

#game-screen .captured-pieces-section {
  left: 0;
  transform: translate3d(-105%, 0, 0);
}

#game-screen .chat-section {
  right: 0;
  transform: translate3d(105%, 0, 0);
}

#game-screen.side-overlay-captured-open .captured-pieces-section,
#game-screen.side-overlay-chat-open .chat-section {
  transform: translate3d(0, 0, 0);
  opacity: 1;
  pointer-events: auto;
}

/* --- Collapsed-capable mode (1000px - 1369px) --- */
@media (min-width: 1000px) {
  #open-captured-btn {
    display: none;
  }

  #game-screen {
    position: relative;
  }

  #game-screen.side-columns-collapsed {
    grid-template-columns: minmax(0, 0%) minmax(0, 1fr) minmax(0, 0%);
    gap: 0;
  }

  #game-screen.side-columns-collapsed .captured-pieces-section,
  #game-screen.side-columns-collapsed .chat-section {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 95;
    width: 100%;
    max-width: 280px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
  }

  #game-screen.side-columns-collapsed .captured-pieces-section {
    left: 0;
    transform: translate3d(-112%, 0, 0);
  }

  #game-screen.side-columns-collapsed .chat-section {
    right: 0;
    transform: translate3d(112%, 0, 0);
  }

  #game-screen.side-columns-collapsed.side-overlay-captured-open .captured-pieces-section,
  #game-screen.side-columns-collapsed.side-overlay-chat-open .chat-section {
    transform: translate3d(0, 0, 0);
    opacity: 1;
    pointer-events: auto;
  }

  #game-screen.side-columns-collapsed .game-center {
    max-width: min(620px, 100%, calc((100cqh - clamp(4rem, 18cqh, 7.5rem)) * 0.88));
    width: 100%;
  }

  .chat-overlay {
    display: none;
  }

  #game-screen {
    grid-template-columns: minmax(0, 25%) minmax(0, 1fr) minmax(0, 25%);
    gap: 2cqw;
  }

  #game-screen .captured-pieces-section,
  #game-screen .chat-section {
    position: static;
    top: auto;
    bottom: auto;
    left: auto;
    right: auto;
    z-index: auto;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(0, 0, 0);
  }
}

/* --- Full mode (>= 1370px) --- */
@media (min-width: 1370px) {
  .btn-chat {
    display: none;
  }

  #open-captured-btn {
    display: none;
  }
}

/* ============================================
   14. ANIMATIONS + UTILITIES
   ============================================ */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.square:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* ============================================
   15. PROMOTION DIALOG
   ============================================ */
.promotion-dialog {
  position: absolute;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 3px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.promotion-option {
  aspect-ratio: 1 / 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: white;
  cursor: pointer;
  padding: 0;
  font-size: calc((100cqw / 8) * 0.9);
  line-height: 1;
  transition: background-color 0.15s;
}

.promotion-option:hover {
  background-color: var(--color-primary-highlight);
}

.promotion-option:not(:last-child) {
  border-bottom: 1px solid var(--color-border);
}

.hidden {
  display: none !important;
}
