/* ChessApp v2.1 compact viewport layout */

:root {
  --header-h: 62px;
  --layout-gap: 12px;
  --board-size: min(520px, calc(100dvh - 170px), calc(100vw - 660px));
  --play-height: calc(var(--board-size) + 88px);
}

html,
body {
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
}

.site-header {
  min-height: var(--header-h);
  height: var(--header-h);
  padding: 8px 18px;
}

.brand {
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 24px;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  font-size: 11px;
}

.icon-button,
.theme-toggle {
  min-height: 40px;
}

.app-shell {
  width: min(1280px, calc(100% - 16px));
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 0 24px;
}

.hero-copy,
#topAdSlot,
.feature-grid {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.game-layout {
  width: 100%;
  display: grid;
  grid-template-columns: var(--board-size) 300px 300px;
  justify-content: center;
  align-items: start;
  gap: var(--layout-gap);
}

.board-panel,
.control-panel,
.ad-rail {
  min-width: 0;
}

.board-panel {
  width: var(--board-size);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.player-strip {
  min-height: 44px;
  height: 44px;
  padding: 2px 3px 5px;
  gap: 8px;
}

.player-strip:last-child {
  padding: 5px 3px 2px;
}

.avatar {
  width: 34px;
  height: 34px;
  font-size: 19px;
}

.player-strip strong {
  font-size: 14px;
  line-height: 1.1;
}

.player-strip span {
  font-size: 10px;
  line-height: 1.1;
}

.player-details {
  min-width: 0;
}

.material-row {
  min-height: 15px;
  height: 15px;
  margin-top: 1px;
  gap: 4px;
}

.captured-piece {
  width: 14px;
  height: 15px;
  margin-right: -3px;
}

.captured-piece .piece-shell,
.captured-piece .piece-svg {
  width: 15px !important;
  height: 15px !important;
}

.material-empty {
  font-size: 9px !important;
  line-height: 15px;
}

.advantage-badge {
  min-width: 25px;
  height: 17px;
  padding: 0 6px;
  font-size: 9px !important;
}

.turn-dot {
  width: 8px;
  height: 8px;
}

.turn-dot.active {
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.board-wrap {
  width: var(--board-size);
  max-width: var(--board-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  box-shadow: none;
}

.chessboard {
  width: var(--board-size);
  height: var(--board-size);
  max-width: none;
  border-radius: 4px;
  border: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

.control-panel {
  width: 300px;
  height: var(--play-height);
  position: sticky;
  top: calc(var(--header-h) + 10px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: none;
}

.status-card {
  flex: 0 0 auto;
  padding: 13px;
  border-radius: 12px;
}

.status-card strong {
  margin: 4px 0;
  font-size: 22px;
}

.status-card span:last-child {
  font-size: 12px;
  line-height: 1.35;
}

.setup-grid {
  flex: 0 0 auto;
  gap: 8px;
}

.setup-grid label {
  gap: 5px;
  font-size: 11px;
}

select,
input {
  min-height: 39px;
  padding: 8px 10px;
  border-radius: 9px;
}

.primary-actions {
  flex: 0 0 auto;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 7px;
}

.button {
  min-height: 46px;
  padding: 7px 9px;
  border-radius: 9px;
  font-size: 13px;
}

.moves-card {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
}

.section-heading {
  flex: 0 0 auto;
  padding: 9px 11px;
}

.move-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 8px 10px 8px 34px;
  gap: 3px 12px;
  overflow-y: auto;
}

.move-list li {
  padding: 4px 2px;
  font-size: 13px;
}

.small-actions {
  flex: 0 0 auto;
  gap: 7px;
}

.switch-row {
  font-size: 11px;
}

.switch-row input {
  width: 38px;
  height: 20px;
}

.ad-rail {
  width: 300px;
  height: var(--play-height);
  position: sticky;
  top: calc(var(--header-h) + 10px);
}

.ad-creative {
  width: 300px;
  height: var(--play-height);
  min-height: 0;
  padding: 16px;
  gap: 12px;
  border-radius: 6px;
}

.ad-chess-art {
  min-height: 120px;
  font-size: clamp(82px, 8vw, 116px);
}

.ad-copy h2 {
  font-size: clamp(27px, 2.4vw, 35px);
}

.ad-copy p {
  font-size: 13px;
  line-height: 1.45;
}

.ad-cta {
  min-height: 48px;
  border-radius: 10px;
}

footer {
  padding: 13px 18px;
  font-size: 11px;
}

/* Compact desktop: keep the ad rail, slightly reduce each column. */
@media (min-width: 1100px) and (max-width: 1249px) {
  :root {
    --board-size: min(490px, calc(100dvh - 170px), calc(100vw - 610px));
  }

  .game-layout {
    grid-template-columns: var(--board-size) 286px 270px;
    gap: 10px;
  }

  .control-panel {
    width: 286px;
  }

  .ad-rail,
  .ad-creative {
    width: 270px;
  }
}

/* Tablet and narrow laptop: board and controls only. */
@media (max-width: 1099px) {
  :root {
    --board-size: min(560px, calc(100dvh - 165px), calc(100vw - 340px));
  }

  .app-shell {
    width: min(940px, calc(100% - 12px));
  }

  .game-layout {
    grid-template-columns: var(--board-size) minmax(280px, 320px);
    gap: 10px;
  }

  .control-panel {
    width: 100%;
  }

  .ad-rail {
    display: none;
  }
}

/* Mobile: full-width board first, controls underneath. */
@media (max-width: 799px) {
  :root {
    --header-h: 58px;
    --board-size: min(620px, calc(100vw - 12px));
    --play-height: auto;
  }

  .site-header {
    height: var(--header-h);
    min-height: var(--header-h);
    padding: 7px 8px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 21px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand small,
  .theme-label {
    display: none;
  }

  .header-actions {
    gap: 6px;
  }

  .icon-button,
  .theme-toggle {
    min-height: 38px;
  }

  .app-shell {
    width: 100%;
    padding: 6px 6px 20px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .board-panel,
  .control-panel {
    width: var(--board-size);
    max-width: 620px;
    margin-inline: auto;
  }

  .player-strip {
    height: 40px;
    min-height: 40px;
  }

  .avatar {
    width: 31px;
    height: 31px;
    font-size: 17px;
  }

  .board-wrap,
  .chessboard {
    width: var(--board-size);
    height: var(--board-size);
  }

  .control-panel {
    height: auto;
    position: static;
    overflow: visible;
    padding: 10px;
    gap: 9px;
  }

  .status-card {
    padding: 12px;
  }

  .status-card strong {
    font-size: 20px;
  }

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

  .moves-card {
    min-height: 190px;
    max-height: 300px;
  }

  .move-list {
    min-height: 140px;
    max-height: 240px;
  }

  .ad-rail,
  footer {
    display: none;
  }
}

@media (max-width: 430px) {
  :root {
    --board-size: calc(100vw - 8px);
  }

  .app-shell {
    padding-inline: 4px;
  }

  .board-panel,
  .control-panel {
    max-width: none;
  }

  .setup-grid {
    grid-template-columns: 1fr 1fr;
  }

  .button {
    min-height: 43px;
    font-size: 12px;
  }

  .coordinate {
    font-size: 8px;
  }
}
