/**
 * Chess Royale — Game styles
 * Used only by index.html (loading, menu, game screens)
 * Documentation styles are in css/documentation.css
 */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --sky-top: #5bb8f5;
  --sky-bottom: #a8dff8;
  --grass: #5cb85c;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-border: #8b6914;
  --player-blue: #3b7dd8;
  --player-blue-dark: #2563b8;
  --opponent-red: #e74c5c;
  --opponent-red-dark: #c0392b;
  --btn-blue: #4a90e2;
  --btn-blue-dark: #357abd;
  --btn-yellow: #f5a623;
  --btn-yellow-dark: #d4891a;
  --highlight-move: rgba(155, 199, 0, 0.5);
  --highlight-select: rgba(255, 255, 0, 0.5);
  --highlight-check: rgba(255, 0, 0, 0.6);
  --highlight-last: rgba(155, 199, 0, 0.35);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  --radius: 16px;
  --font: 'Fredoka', 'Nunito', sans-serif;
  --game-font: var(--font);
  --stroke-blue: #1d4f91;
  --stroke-blue-deep: #12386b;
  --stroke-red: #9b2335;
  --stroke-red-deep: #6b1825;
  --stroke-brown: #5c3a18;
  --stroke-dark: #1a1a2e;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 60%, var(--grass) 100%);
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  z-index: 1;
}

.screen.active {
  display: flex;
}

/* ========== LOADING ========== */
.loading-bg, .menu-bg, .game-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.loading-bg::before,
.menu-bg::before,
.game-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    url('../assets/game-bg-pattern.svg') repeat,
    linear-gradient(180deg, #6ecff5 0%, #3d9fd9 55%, #2a7fbe 100%);
  background-size: 112px 112px, 100% 100%;
}

.loading-bg::after,
.menu-bg::after,
.game-bg::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24%;
  background: linear-gradient(180deg, transparent 0%, rgba(72, 160, 72, 0.45) 55%, rgba(46, 125, 50, 0.75) 100%);
  pointer-events: none;
}

#loading-screen .loading-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px 24px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

#loading-screen .loading-header {
  text-align: center;
  margin-bottom: 20px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#loading-screen .loading-logo {
  width: clamp(120px, 36vw, 168px);
  height: clamp(120px, 36vw, 168px);
  object-fit: contain;
  margin-bottom: 14px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(92, 58, 24, 0.3));
  animation: loading-logo-pulse 1.8s ease-in-out infinite;
}

@keyframes loading-logo-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

#loading-screen .loading-header h1 {
  font-family: var(--game-font);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.03em;
  -webkit-text-stroke: 2px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--stroke-brown), 0 5px 12px rgba(92, 58, 24, 0.35);
}

#loading-screen .loading-panel {
  width: 100%;
  background: linear-gradient(180deg, rgba(255, 248, 228, 0.95) 0%, rgba(255, 232, 178, 0.92) 100%);
  border: 3px solid var(--stroke-brown);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow:
    0 6px 0 var(--stroke-brown),
    0 12px 28px rgba(92, 58, 24, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

#loading-screen .loading-bar-wrap {
  width: 100%;
  height: 14px;
  padding: 3px;
  background: rgba(92, 58, 24, 0.14);
  border: 2px solid rgba(92, 58, 24, 0.28);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(92, 58, 24, 0.12);
}

#loading-screen .loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-radius: 9px;
  transition: width 0.3s ease;
  box-shadow:
    0 2px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#loading-screen .loading-text {
  color: var(--stroke-brown);
  font-family: var(--game-font);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
}

#loading-screen.ready {
  cursor: pointer;
}

#loading-screen.ready .loading-text {
  animation: loading-tap-hint 1.2s ease-in-out infinite;
}

@keyframes loading-tap-hint {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ========== MENU ========== */
#menu-screen .menu-content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

#menu-screen .menu-header {
  text-align: center;
  margin-bottom: 22px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#menu-screen .menu-logo {
  width: clamp(148px, 42vw, 200px);
  height: clamp(148px, 42vw, 200px);
  object-fit: contain;
  margin-bottom: 12px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(92, 58, 24, 0.3));
}

#menu-screen .menu-header h1 {
  font-family: var(--game-font);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.03em;
  -webkit-text-stroke: 2px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--stroke-brown), 0 5px 12px rgba(92, 58, 24, 0.35);
}

#menu-screen .menu-panel {
  background: linear-gradient(180deg, rgba(255, 248, 228, 0.95) 0%, rgba(255, 232, 178, 0.92) 100%);
  border: 3px solid var(--stroke-brown);
  border-radius: 20px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow:
    0 6px 0 var(--stroke-brown),
    0 12px 28px rgba(92, 58, 24, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

#menu-screen .menu-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#menu-screen .menu-label {
  font-family: var(--game-font);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stroke-brown);
  padding-left: 4px;
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
}

#menu-screen .segmented {
  display: flex;
  gap: 5px;
  padding: 5px;
  background: rgba(92, 58, 24, 0.14);
  border: 2px solid rgba(92, 58, 24, 0.28);
  border-radius: 14px;
  box-shadow: inset 0 2px 5px rgba(92, 58, 24, 0.12);
}

#menu-screen .diff-card,
#menu-screen .time-card,
#menu-screen .color-card {
  flex: 1;
  border: 2px solid rgba(92, 58, 24, 0.2);
  border-radius: 11px;
  padding: 11px 6px;
  background: rgba(255, 255, 255, 0.45);
  font-family: var(--game-font);
  font-weight: 700;
  font-size: 0.82rem;
  color: rgba(92, 58, 24, 0.82);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  text-align: center;
  -webkit-text-stroke: 0;
  text-shadow: none;
}

#menu-screen .color-card {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#menu-screen .diff-card:hover,
#menu-screen .time-card:hover,
#menu-screen .color-card:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.65);
  border-color: rgba(92, 58, 24, 0.35);
}

#menu-screen .diff-card.selected,
#menu-screen .time-card.selected,
#menu-screen #setting-color:checked ~ .color-grid .pick-white,
#menu-screen #setting-color:not(:checked) ~ .color-grid .pick-black {
  color: #fff;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
  box-shadow:
    0 3px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  -webkit-text-stroke: 0.8px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.4);
}

#menu-screen .diff-card:active,
#menu-screen .time-card:active,
#menu-screen .color-card:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--stroke-brown);
}

.settings-list {
  background: rgba(92, 58, 24, 0.1);
  border: 2px solid rgba(92, 58, 24, 0.22);
  border-radius: 14px;
  padding: 8px 14px;
  box-shadow: inset 0 2px 5px rgba(92, 58, 24, 0.08);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(92, 58, 24, 0.15);
  cursor: pointer;
  font-family: var(--game-font);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--stroke-brown);
  gap: 8px;
}

.setting-row:last-child { border-bottom: none; }

.setting-row input { display: none; }

.toggle {
  width: 48px;
  height: 26px;
  background: rgba(92, 58, 24, 0.18);
  border: 1px solid rgba(92, 58, 24, 0.28);
  border-radius: 13px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  top: 1px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(92, 58, 24, 0.35);
}

.setting-row input:checked + .toggle {
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
}

.setting-row input:checked + .toggle::after {
  transform: translateX(22px);
}

#menu-screen .btn-play {
  width: 100%;
  padding: 18px 16px;
  margin-top: 28px;
  flex-shrink: 0;
  border: 3px solid var(--stroke-brown);
  border-radius: 16px;
  font-family: var(--game-font);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  box-shadow:
    0 5px 0 var(--stroke-brown),
    0 8px 22px rgba(92, 58, 24, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  -webkit-text-stroke: 1.2px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 rgba(92, 58, 24, 0.45);
  position: relative;
  overflow: hidden;
}

#menu-screen .btn-play::before {
  content: '';
  position: absolute;
  inset: 0 0 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.38) 0%, transparent 100%);
  border-radius: 12px 12px 50% 50%;
  pointer-events: none;
}

#menu-screen .btn-play:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow:
    0 7px 0 var(--stroke-brown),
    0 12px 26px rgba(92, 58, 24, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#menu-screen .btn-play:active {
  transform: translateY(3px);
  filter: brightness(0.98);
  box-shadow:
    0 2px 0 var(--stroke-brown),
    0 4px 10px rgba(92, 58, 24, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* ========== GAME ========== */
#game-screen {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--game-font);
}

#game-screen.active .game-container {
  flex: 1;
  min-height: 0;
}

#game-screen .game-container {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
}

#game-screen .game-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 8px;
  position: relative;
  margin-bottom: 8px;
  flex-shrink: 0;
}

#game-screen .player-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 248, 228, 0.95) 0%, rgba(255, 232, 178, 0.92) 100%);
  border: 2px solid var(--stroke-brown);
  box-shadow:
    0 4px 0 var(--stroke-brown),
    0 6px 16px rgba(92, 58, 24, 0.22);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

#game-screen .player-card.active-turn {
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
  box-shadow:
    0 4px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 16px rgba(92, 58, 24, 0.28);
}

#game-screen .player-card.opponent,
#game-screen .player-card.player {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#game-screen .player-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 2px solid var(--stroke-brown);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#game-screen .player-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#game-screen .player-info {
  min-width: 0;
  flex: 1;
}

#game-screen .player-name {
  display: block;
  color: var(--stroke-brown);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-screen .player-card.active-turn .player-name {
  color: #fff;
  -webkit-text-stroke: 0.8px var(--stroke-brown);
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.4);
}

#game-screen .player-card.player .player-name,
#game-screen .player-card.opponent .player-name {
  -webkit-text-stroke-color: rgba(92, 58, 24, 0.35);
}

#game-screen .player-stats {
  display: flex;
  gap: 2px;
  margin-top: 2px;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: flex-start;
}

#game-screen .stat {
  color: var(--stroke-brown);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  flex: 0 1 auto;
}

#game-screen .stat.rating,
#game-screen .stat.timer {
  flex: 0 1 auto;
}

#game-screen .stat #player-rating,
#game-screen .stat #opponent-rating,
#game-screen .stat #player-timer,
#game-screen .stat #opponent-timer {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-screen .stat.rating #player-rating,
#game-screen .stat.rating #opponent-rating {
  color: #c8860a;
  -webkit-text-stroke: 0.6px #8b6914;
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(139, 105, 20, 0.25);
}

#game-screen .stat.timer #player-timer,
#game-screen .stat.timer #opponent-timer {
  color: var(--stroke-brown);
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
}

#game-screen .player-card.active-turn .stat.rating #player-rating,
#game-screen .player-card.active-turn .stat.rating #opponent-rating {
  color: #fff;
  -webkit-text-stroke: 0.6px var(--stroke-brown);
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.35);
}

#game-screen .player-card.active-turn .stat.timer #player-timer,
#game-screen .player-card.active-turn .stat.timer #opponent-timer {
  color: #fff;
  -webkit-text-stroke: 0.6px var(--stroke-brown);
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.35);
}

#game-screen .player-card.opponent .stat.timer #opponent-timer {
  -webkit-text-stroke-color: rgba(92, 58, 24, 0.35);
  text-shadow: none;
}

#game-screen .stat-icon {
  font-size: 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

#game-screen .stat-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#game-screen .vs-badge {
  position: relative;
  justify-self: center;
  align-self: center;
  flex-shrink: 0;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 55%, #ff9f2e 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 5px 11px;
  border-radius: 10px;
  border: 2px solid var(--stroke-brown);
  letter-spacing: 0.08em;
  white-space: nowrap;
  -webkit-text-stroke: 1.5px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 rgba(92, 58, 24, 0.45);
  box-shadow: 0 3px 0 var(--stroke-brown), 0 4px 10px rgba(92, 58, 24, 0.28);
}

#game-screen .btn-settings {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border: 2px solid var(--stroke-brown);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
  align-self: center;
  justify-self: end;
  box-shadow:
    0 3px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

#game-screen .btn-settings img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  object-position: center;
  display: block;
}

#game-screen .btn-settings:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

#game-screen .btn-settings:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--stroke-brown);
}

#game-screen .status-bar {
  text-align: center;
  padding: 9px 14px;
  margin-bottom: 8px;
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(255, 248, 228, 0.95) 0%, rgba(255, 232, 178, 0.92) 100%);
  border: 2px solid var(--stroke-brown);
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--stroke-brown);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: all 0.3s ease;
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
  box-shadow: 0 3px 0 var(--stroke-brown);
}

#game-screen .status-bar.check {
  background: linear-gradient(180deg, #ffd6d6 0%, #ffb4b4 100%);
  border-color: #8b2020;
  color: #6b1515;
  box-shadow: 0 3px 0 #6b1515;
  -webkit-text-stroke-color: rgba(107, 21, 21, 0.35);
  animation: pulse-check 1s ease infinite;
}

#game-screen .status-bar.checkmate {
  background: linear-gradient(180deg, #ffe08a 0%, #ffc857 100%);
  border-color: #8b6914;
  color: #6b4f10;
  box-shadow: 0 3px 0 #8b6914;
  -webkit-text-stroke-color: rgba(107, 79, 16, 0.35);
}

@keyframes pulse-check {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#game-screen .board-wrapper {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

#game-screen .board-layout {
  --board-size: min(calc(100cqw - 23px), calc(100cqh - 26px), 440px);
  --coord-font: clamp(0.42rem, calc(var(--board-size) / 8 * 0.38), 0.72rem);
  width: min(100%, 463px);
  height: 100%;
  min-height: 0;
  container-type: size;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 5px;
  row-gap: 4px;
  align-content: center;
  align-self: center;
}

#game-screen .board-coords-left {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  align-self: stretch;
  font-size: var(--coord-font);
  font-weight: 700;
  font-family: var(--game-font);
  color: #e8c99a;
  -webkit-text-stroke: 0.6px #5c3a18;
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(60, 30, 0, 0.35);
  pointer-events: none;
  user-select: none;
}

#game-screen .board-coords-bottom {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  width: var(--board-size);
  justify-self: center;
  font-size: var(--coord-font);
  font-weight: 700;
  font-family: var(--game-font);
  color: #e8c99a;
  -webkit-text-stroke: 0.6px #5c3a18;
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(60, 30, 0, 0.35);
  pointer-events: none;
  user-select: none;
}

#game-screen .coord-label {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  width: 100%;
  height: 100%;
}

#game-screen .board-area {
  grid-column: 2;
  grid-row: 1;
  width: var(--board-size);
  aspect-ratio: 1;
  height: auto;
  justify-self: center;
  align-self: start;
  container-type: size;
}

#game-screen .chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 3px solid var(--stroke-brown);
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 6px 0 var(--stroke-brown),
    0 10px 28px rgba(92, 58, 24, 0.35);
  background: var(--board-light);
}

#game-screen .square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

#game-screen .square.light { background: var(--board-light); }
#game-screen .square.dark { background: var(--board-dark); }

#game-screen .square.selected { background: var(--highlight-select) !important; }
#game-screen .square.legal-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(120, 180, 255, 0.55);
}
#game-screen .square.legal-capture::after {
  content: '';
  position: absolute;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  border: 3px solid rgba(120, 180, 255, 0.55);
  background: transparent;
}
#game-screen .square.last-move { background: rgba(120, 180, 255, 0.25) !important; }
#game-screen .square.in-check { background: rgba(255, 80, 80, 0.45) !important; }
#game-screen .square.hint-from,
#game-screen .square.hint-to {
  background: rgba(100, 200, 255, 0.4) !important;
}

#game-screen .piece {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 11cqmin;
  line-height: 1;
  z-index: 2;
  transition: transform 0.15s ease;
  filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.5));
  pointer-events: none;
}

#game-screen .piece img,
#game-screen .piece-img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  display: block;
}

#game-screen .piece.moving {
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
  z-index: 10;
}

#game-screen .square:hover:not(.disabled) .piece.moving {
  transform: translate(0, 0);
}

#game-screen .piece.white {
  color: #fff;
  -webkit-text-stroke: 1.5px #333;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#game-screen .piece.black {
  color: #222;
  -webkit-text-stroke: 1px #555;
}

#game-screen .square:hover:not(.disabled) .piece {
  transform: scale(1.06);
}

#game-screen .game-controls {
  display: flex;
  gap: 5px;
  padding: 5px;
  margin-top: 8px;
  flex-shrink: 0;
  background: rgba(92, 58, 24, 0.14);
  border: 2px solid rgba(92, 58, 24, 0.28);
  border-radius: 14px;
  align-items: stretch;
  width: 100%;
  box-shadow: inset 0 2px 5px rgba(92, 58, 24, 0.12);
}

#game-screen .ctrl-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 2px;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(92, 58, 24, 0.2);
  border-radius: 11px;
  color: rgba(92, 58, 24, 0.82);
  cursor: pointer;
  font-family: var(--game-font);
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

#game-screen .ctrl-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.65);
  border-color: rgba(92, 58, 24, 0.35);
  transform: translateY(-1px);
}

#game-screen .ctrl-btn:active:not(:disabled) {
  transform: translateY(1px);
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
  box-shadow: 0 1px 0 var(--stroke-brown);
  color: #fff;
}

#game-screen .ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#game-screen .ctrl-btn-main {
  flex: 1.1;
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
  box-shadow:
    0 2px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: #fff;
}

#game-screen .ctrl-icon {
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

#game-screen .ctrl-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#game-screen .ctrl-label {
  font-size: 0.52rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(92, 58, 24, 0.82);
  -webkit-text-stroke: 0;
  text-shadow: none;
}

#game-screen .ctrl-btn-main .ctrl-label,
#game-screen .ctrl-btn:active:not(:disabled) .ctrl-label {
  color: #fff;
  -webkit-text-stroke: 0.6px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.4);
}

#game-screen .hint-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ffdc4a;
  color: #5c3a18;
  font-size: 0.55rem;
  font-weight: 700;
  font-family: var(--game-font);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #8b6914;
  box-shadow: 0 1px 0 #8b6914;
}

/* ========== MODALS ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: linear-gradient(180deg, rgba(255, 248, 228, 0.98) 0%, rgba(255, 232, 178, 0.96) 100%);
  border: 3px solid var(--stroke-brown);
  border-radius: 20px;
  padding: 26px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 6px 0 var(--stroke-brown),
    0 12px 32px rgba(92, 58, 24, 0.35);
  animation: modal-in 0.3s ease;
  font-family: var(--game-font);
}

@keyframes modal-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--stroke-brown);
  margin-bottom: 8px;
  -webkit-text-stroke: 0.6px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
}

.modal h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--stroke-brown);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  -webkit-text-stroke: 0.5px rgba(92, 58, 24, 0.35);
  paint-order: stroke fill;
  text-shadow: none;
}

.modal p {
  color: rgba(92, 58, 24, 0.88);
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 20px;
  line-height: 1.45;
}

.gameover-icon {
  font-size: 72px;
  margin-bottom: 8px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gameover-icon img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
}

.gameover-actions {
  display: flex;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  font-family: var(--game-font);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  letter-spacing: 0.04em;
}

.btn-primary {
  border: 2px solid var(--stroke-brown);
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  color: #fff;
  box-shadow:
    0 4px 0 var(--stroke-brown),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  -webkit-text-stroke: 1px var(--stroke-brown);
  paint-order: stroke fill;
  text-shadow: 0 1px 0 rgba(92, 58, 24, 0.4);
}

.btn-primary:hover {
  filter: brightness(1.04);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--stroke-brown);
}

.btn-secondary {
  border: 2px solid rgba(92, 58, 24, 0.35);
  background: rgba(255, 255, 255, 0.55);
  color: var(--stroke-brown);
  box-shadow: 0 3px 0 rgba(92, 58, 24, 0.22);
  -webkit-text-stroke: 0;
  text-shadow: none;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.72);
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(92, 58, 24, 0.22);
}

.promotion-pieces {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.promo-piece {
  font-size: 48px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(92, 58, 24, 0.3);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(92, 58, 24, 0.2);
}

.promo-piece img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
}

.promo-piece:hover {
  transform: translateY(-2px) scale(1.04);
  background: linear-gradient(180deg, #ffe566 0%, #ffb347 48%, #ff9f2e 100%);
  border-color: var(--stroke-brown);
  box-shadow: 0 4px 0 var(--stroke-brown);
}

.settings-modal .settings-list {
  margin-bottom: 16px;
}

.settings-modal .btn-primary {
  width: 100%;
}

/* AI thinking indicator */
.thinking .opponent-avatar {
  animation: think-pulse 0.8s ease infinite;
  will-change: transform;
}

#game-screen.ai-thinking .status-bar {
  color: var(--stroke-brown);
  animation: pulse-check 1.2s ease infinite;
}

#game-screen.ai-thinking .chess-board {
  opacity: 0.92;
  transition: opacity 0.2s ease;
}

@keyframes think-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Responsive — game screen */
@media (max-width: 480px) {
  #game-screen .game-header {
    gap: 4px 5px;
  }

  #game-screen .player-card {
    padding: 7px 8px;
    gap: 5px;
  }

  #game-screen .player-avatar {
    width: 38px;
    height: 38px;
  }

  #game-screen .player-name {
    font-size: 0.72rem;
  }

  #game-screen .player-stats {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
  }

  #game-screen .stat {
    font-size: 0.62rem;
    gap: 2px;
    flex: none;
    width: 100%;
  }

  #game-screen .stat-icon {
    width: 16px;
    height: 16px;
  }

  #game-screen .vs-badge {
    font-size: 0.68rem;
    padding: 4px 7px;
  }

  #game-screen .btn-settings {
    width: 38px;
    height: 38px;
  }

  #game-screen .btn-settings img {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 400px) {
  #game-screen .ctrl-label { display: none; }
  #game-screen .ctrl-btn { padding: 10px 2px; }
  #game-screen .player-card { padding: 6px 7px; gap: 4px; }
  #game-screen .player-avatar { width: 34px; height: 34px; font-size: 16px; }
  #game-screen .stat { font-size: 0.58rem; }
  #game-screen .stat-icon { width: 14px; height: 14px; }
}

@media (max-height: 700px) {
  #game-screen .game-container { padding: 6px 10px 8px; }
  #game-screen .game-header { margin-bottom: 6px; }
  #game-screen .status-bar { padding: 6px 10px; margin-bottom: 6px; font-size: 0.62rem; }
  #game-screen .player-card { padding: 7px 8px; }
  #game-screen .player-avatar { width: 40px; height: 40px; font-size: 15px; }
  #game-screen .player-name { font-size: 0.72rem; }
  #game-screen .stat { font-size: 0.62rem; }
  #game-screen .game-controls { margin-top: 6px; }
  #game-screen .ctrl-btn { padding: 8px 2px; }
}

@media (max-height: 520px) {
  #game-screen .status-bar { padding: 4px 8px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #game-screen .game-container {
    max-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 0 12px;
    padding: 6px 12px;
  }

  #game-screen .game-header {
    order: 1;
    width: 100%;
    margin-bottom: 4px;
  }

  #game-screen .status-bar {
    order: 2;
    width: 100%;
    margin-bottom: 4px;
  }

  #game-screen .board-wrapper {
    order: 3;
    flex: 1 1 55%;
    min-width: 0;
    min-height: 180px;
    max-width: calc(100% - 190px);
    align-self: stretch;
  }

  #game-screen .board-layout {
    width: min(100%, 463px);
    height: 100%;
  }

  #game-screen .game-controls {
    order: 4;
    flex: 0 0 180px;
    flex-direction: column;
    margin-top: 0;
    align-self: center;
    max-height: calc(100dvh - 24px);
  }

  #game-screen .ctrl-btn {
    flex: 1;
    flex-direction: row;
    gap: 6px;
    padding: 8px 10px;
  }

  #game-screen .ctrl-label { display: inline; }
}

@media (min-width: 600px) and (min-height: 700px) {
  #game-screen .game-container { max-width: 540px; }
}

@supports not (container-type: size) {
  #game-screen .board-layout {
    --board-size: min(calc(100vw - 52px), calc(100dvh - 210px), 440px);
  }

  #game-screen .piece {
    font-size: clamp(20px, 9vw, 46px);
  }
}

@media (min-width: 600px) {
  #menu-screen .menu-content { padding: 40px 32px; max-width: 420px; }
  #menu-screen .menu-panel { padding: 28px 24px; }
}
