/* Pokémon Chess v2: the board, the game layout (ED 6.6, plan 10.4), the draft board and type
   picker (ED 6.7), the practice setup and the team builder, plus the online game's clocks, away
   countdown, draw bar, rematch and spectators (client spec §4.5-4.8). Tokens (--surface, --text,
   --muted, --accent, --radius...) and buttons, cards, pills, switches and dialogs come from app.css. */

/* The smallest viewport height where supported (iOS 15.4+), else vh. */
:root {
  --pc-vh: 1vh;
  --pc-warn-text: #f2c14e;                  /* app.css --warn, lightened for text on the dark surfaces */
}

@media (prefers-color-scheme: light) {
  :root {
    --pc-warn-text: #8a5a00;
  }
}

@supports (height: 1svh) {
  :root {
    --pc-vh: 1svh;
  }
}

/* ---------- Board ---------- */
/* board.js puts a square .board-wrap (canvas + gif overlay) inside this container. */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.board canvas {
  display: block;
  touch-action: manipulation;              /* no double-tap zoom delay; pinch zoom still works */
}

.board .fx-gif {
  pointer-events: none;
  max-width: 100%;
}

/* ---------- Game layout: phones first ----------
   Top to bottom: opponent bar, board (full width), player bar, controls, move log. The board's
   size keeps the controls row, and so "Skip extra move", on screen at 360x640 (A7). */
.game-layout {
  --bar-h: 56px;
  --controls-h: 52px;
  --board-size: min(100%, calc(100 * var(--pc-vh) - 2 * var(--bar-h) - var(--controls-h) - 16px));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "opponent" "board" "player" "controls" "log";
  row-gap: 4px;
  justify-items: center;
  min-width: 0;
}

.game-layout > .board {
  grid-area: board;
  width: var(--board-size);
}

.game-layout > .player-bar,
.game-layout > .game-actions,
.game-layout > .game-log {
  width: var(--board-size);
  min-width: 0;
}

/* ---------- Player bars ---------- */
.player-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: var(--bar-h, 56px);
  padding: 4px 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.player-bar.top {
  grid-area: opponent;
}

.player-bar.bottom {
  grid-area: player;
}

.player-bar.to-move {
  border-color: var(--brand-green, #779556);
  box-shadow: inset 4px 0 0 var(--brand-green, #779556);
}

.bar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* The name and its Guest / You pills: the part of the line that gives way when space is short. */
.bar-who {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bar-who > .pill {
  flex: none;
}

.bar-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bar-status {
  margin-left: auto;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--muted);
}

/* An online bar holds a name, pills, the status and a clock, so its status may shrink as well.
   Hot-seat bars keep the M1 rule above. */
.player-bar.online .bar-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.to-move .bar-status {
  color: var(--text);
  font-weight: 700;
}

.you-pill {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text);
}

/* Online clocks (client spec §4.4): the running side in the accent colour, under 20 s in red. */
.bar-clock {
  flex: none;
  padding: 1px 8px;
  border-radius: var(--radius-sm, 6px);
  background: var(--surface-2, var(--surface));
  box-shadow: inset 0 0 0 1px var(--border-soft);
  font-family: var(--font-mono, monospace);
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  white-space: nowrap;
}

.bar-clock.running {
  background: var(--accent);
  color: var(--accent-text, #fff);
}

.bar-clock.low {
  color: var(--danger-text);
}

.bar-clock.running.low {
  background: var(--danger);
  color: #fff;
}

/* A seat with no connection: "Disconnected · 1:47 to return" (PD 2.10); "Away 1:47" on phones. */
.player-bar.away {
  border-style: dashed;
  border-color: var(--warn);
}

.player-bar.away .bar-status {
  color: var(--pc-warn-text);
  font-weight: 700;
}

.away-short {
  display: none;
}

.away-time {
  font-variant-numeric: tabular-nums;
}

.side-pill.light {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.side-pill.dark {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

/* Up to 16 taken pieces fit on one line at 360 px. */
.captures {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  min-height: 20px;
}

/* A composited piece: the side's plain piece, then its type art on top (v1 client:1633-1654). */
.piece-icon {
  position: relative;
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
}

.piece-icon img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  pointer-events: none;
}

.piece-icon img.ov-pawn {                   /* v1 draws a pawn's type art 2% larger on each side */
  left: -2%;
  top: -2%;
  width: 104%;
  height: 104%;
}

/* ---------- Controls, skip hint, game over ---------- */
.game-actions {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-inline: 8px;
}

.game-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: var(--controls-h, 52px);
  padding-block: 4px;
}

.game-controls > .btn {
  flex: 1 1 auto;
  padding-inline: 12px;
}

/* During a bonus move Skip takes the whole first line, so it is never pushed off screen. */
.game-controls > .skip-btn {
  order: -1;
  flex-basis: 100%;
}

/* Online games keep the controls to one row (client spec §4.6). panels.js sets data-mode: during
   your own bonus only Skip and, if a draw was offered to you, Accept draw beside it; with a draw
   offered to you only the draw bar. */
.game-controls[data-mode="bonus"] > :not(.skip-btn):not(.accept-draw-btn),
.game-controls[data-mode="draw"] > :not(.draw-bar) {
  display: none;
}

.game-controls[data-mode="bonus"] > .skip-btn {
  flex: 1 1 55%;
}

.game-controls > .accept-draw-btn {
  flex: 1 1 35%;
}

.game-controls > .leave-btn {                /* after the view's Flip and Mute */
  order: 1;
}

.draw-bar {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.draw-text {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.draw-bar > .btn {
  flex: none;
  padding-inline: 14px;
}

.draw-hint {
  flex: 1 1 auto;
  text-align: center;
}

/* "Your opponent has 1:47 to come back, or you win" (client spec §4.7). */
.away-note {
  margin: 0;
  padding: 8px 12px;
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  background: var(--surface-2, var(--surface));
  font-weight: 600;
}

.skip-hint {
  margin: 0;
  padding: 8px 12px;
  border-left: 4px solid var(--focus, #3498db);
  border-radius: var(--radius);
  background: var(--surface-2, var(--surface));
  font-size: 0.95rem;
}

.game-over {
  padding: 12px 16px;
  border: 2px solid var(--brand-green, #779556);
  border-radius: var(--radius-lg, 14px);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.game-over-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.result-text {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
}

.game-over .btn-row {
  justify-content: center;
}

.login-nudge {                              /* PD's loginNudge() slot; empty in M2 */
  margin-top: 12px;
}

/* ---------- Spectators: "Watching: 3" and the names (client spec §4.8) ----------
   panels.js adds .with-spectators to the layout when it first shows this, so the hot-seat grid
   is unchanged. */
.game-layout.with-spectators {
  grid-template-areas: "opponent" "board" "player" "controls" "spectators" "log";
}

.game-spectators {
  grid-area: spectators;
  width: var(--board-size);
  min-width: 0;
  padding-inline: 8px;
}

.game-spectators > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap, 44px);
  list-style: none;
  font-weight: 700;
  cursor: pointer;
}

.game-spectators > summary::before {        /* our own marker: display: flex drops the built-in one */
  content: "\25B8";
  margin-right: 6px;
  color: var(--muted);
}

.game-spectators[open] > summary::before {
  content: "\25BE";
}

.game-spectators > summary::-webkit-details-marker {
  display: none;
}

.spectator-list {
  margin: 0;
  padding: 0 0 4px 1.25em;
  max-height: 10rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
}

.spectators-more {
  margin: 0 0 8px;
}

/* ---------- Move log (aria-live) ---------- */
.game-log {
  grid-area: log;
  padding-inline: 8px;
  padding-top: 4px;
}

.log-title {
  margin: 0 0 6px;
  font-size: 1rem;
}

.log-list {
  margin: 0;
  padding: 8px 12px 8px 2.5em;
  max-height: 14rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}

.log-list li + li {
  margin-top: 2px;
}

/* ---------- Promotion sheet: four big buttons (>= 72 px), not dismissible ---------- */
.promo-lead {
  margin: 0 0 12px;
}

.promo-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 6px;
}

.promo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 72px;
  min-height: 96px;
  padding: 6px 4px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--brand-cream, #ebecd0);
  color: #1f1e1c;
  font-weight: 700;
}

.promo-sheet[data-side="white"] .promo-btn {   /* white pieces read better on the green square */
  background: var(--brand-green, #779556);
  color: #fff;
}

.promo-btn img {
  width: 56px;
  height: 56px;
  max-width: 100%;
  object-fit: contain;
  pointer-events: none;
}

.promo-btn:disabled {
  opacity: 0.6;
}

@media (hover: hover) {
  .promo-btn:hover,
  .promo-sheet[data-side="white"] .promo-btn:hover {
    border-color: var(--focus, #3498db);
  }
}

/* ---------- Draft board and type picker ---------- */
.draft {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.draft > * {
  min-width: 0;
  margin: 0;
}

.draft .board {
  align-self: center;
  width: min(100%, 560px, max(300px, calc(100 * var(--pc-vh) - 300px)));
}

.draft-progress {
  color: var(--muted);
  text-align: center;
}

.draft-actions {
  justify-content: center;
}

/* After Ready (draft.js setLocked): the board and buttons are inert until Unready. */
.draft.locked .board {
  opacity: 0.8;
}

.draft.locked .draft-progress {
  color: var(--ok-text);
  font-weight: 700;
}

/* The online draft's status line, for views/game.js (client spec §4.5): the opponent's
   "Drafting…" / "Ready ✓" and the "2:47 to pick" countdown, red under 30 s. */
.draft-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.draft-countdown {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.draft-countdown.warn {
  color: var(--danger-text);
}

.saved-title {
  margin: 0 0 6px;
  font-size: 1rem;
}

/* One row of saved teams that scrolls sideways inside itself, never the page. */
.saved-strip {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  padding: 2px 2px 6px;
}

.saved-strip > p {
  margin: 0;
}

.saved-team {
  flex: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 13rem;
  min-height: var(--tap, 44px);
  padding: 8px 12px;
  border: 1px solid var(--border-soft);
  text-align: left;
  scroll-snap-align: start;
}

.saved-name {
  display: block;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The list of saved teams in the practice setup's sheet. */
.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.saved-team.wide {
  width: 100%;
  max-width: none;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.saved-team.wide .saved-name {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.empty-state {
  display: grid;
  gap: 12px;
  justify-items: start;
}

.empty-state > * {
  margin: 0;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.picker > * {
  margin: 0;
}

.picker-actions {
  justify-content: flex-end;
}

/* 18 types in a 6 x 3 grid of tiles at least 48 px, in each type's v1 colour (v1 client:1782-1791). */
.type-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.type-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 48px;
  aspect-ratio: 1 / 1;
  padding: 3px 2px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm, 6px);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}

.type-tile .piece-icon {
  display: block;
  width: 62%;
  height: auto;
  aspect-ratio: 1 / 1;
}

.type-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-tile.used {                          /* v1 client:1787-1788 */
  opacity: 0.3;
}

.type-tile.current {
  border-color: #fff;
  box-shadow: 0 0 0 2px #1f1e1c;
}

/* ---------- Team previews (two rows of 8, pawns above the back rank) ---------- */
.team-mini {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  vertical-align: middle;
}

.team-mini-row {
  display: flex;
  gap: 2px;
}

.team-mini .swatch {
  display: block;
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--surface-3, #524e49);
}

.team-mini .swatch.empty {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border, #625d56);
}

.side-card .team-mini .swatch {
  width: 22px;
  height: 22px;
}

.team-card .team-mini .swatch {
  width: 20px;
  height: 20px;
}

.saved-team .team-mini .swatch {
  width: 10px;
  height: 10px;
}

/* ---------- Page layouts: practice setup, practice draft, teams ---------- */
.practice,
.teams-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  max-width: 880px;
  margin-inline: auto;
}

.practice > *,
.teams-view > * {
  margin: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.side-cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}

.side-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.side-card > * {
  margin: 0;
}

.side-title {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 1.15rem;
}

.team-source {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.options {                                 /* a fieldset: kept as a block, grid on fieldsets is patchy in old Safari */
  display: block;
  min-width: 0;
  margin: 0;
}

.toggle-row {
  padding: 4px 0;
}

.options legend {
  padding: 0 6px;
  font-weight: 700;
}

.toggle-row + .toggle-row {
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
}

.toggle-label {
  font-weight: 600;
}

.toggle-help {
  margin: 0 0 4px;
}

.start-row {
  justify-content: center;
}

.start-btn {
  min-width: 220px;
}

.rules-help p {
  margin: var(--space-3, 12px) 0 0;
}

.team-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}

.team-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.team-card > * {
  margin: 0;
}

.team-name {
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.back-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap, 44px);
  font-weight: 600;
}

.editor-actions,
.end-row {
  justify-content: flex-end;
}

/* ---------- Phones (under 600 px) ---------- */
@media (max-width: 599px) {
  .btn-row > .btn {
    flex: 1 1 auto;
  }

  /* app.css hides the header and tab bar in a game; the board runs edge to edge. */
  .game-layout > .player-bar {
    border-inline: 0;
    border-radius: 0;
  }
}

/* Narrow phones: an online bar holds a side pill, a name, Guest and You pills and a clock, so
   the pills and clock get tighter, the running clock stands in for "To move", and the away
   status uses its short form. Hot-seat bars (no .online) are unchanged. */
@media (max-width: 479px) {
  .player-bar.online .pill {
    padding-inline: 6px;
    font-size: 0.72rem;
  }

  .player-bar.online .bar-clock {
    padding-inline: 5px;
    font-size: 0.9375rem;
  }

  .player-bar.online.has-clock .bar-status[data-kind="turn"] {
    display: none;
  }

  .player-bar.online .away-long {
    display: none;
  }

  .player-bar.online .away-short {
    display: inline;
  }
}

/* ---------- Tablets and desktops: the header stays, so the board allows for it ---------- */
@media (min-width: 600px) {
  .game-layout {
    --board-size: min(100%, max(320px, calc(100 * var(--pc-vh) - var(--header-h, 56px) - 2 * var(--bar-h) - var(--controls-h) - 72px)));
    row-gap: 8px;
  }
}

/* Desktop: the move log gets its own column. */
@media (min-width: 1024px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    grid-template-areas: "opponent log" "board log" "player log" "controls log";
    grid-template-rows: auto auto auto 1fr;
    column-gap: 16px;
    align-items: start;
  }

  .game-layout > .game-log {
    width: auto;
    justify-self: stretch;
    padding: 0;
  }

  .game-layout .log-list {
    max-height: calc(100 * var(--pc-vh) - var(--header-h, 56px) - 140px);
  }

  .game-layout.with-spectators {
    grid-template-areas: "opponent log" "board log" "player log" "controls log" "spectators log";
    grid-template-rows: auto auto auto auto 1fr;
  }
}

/* Phones on their side: board on the left, everything else on the right, no header. */
@media (orientation: landscape) and (max-height: 520px) {
  body.in-game {
    padding-bottom: 0;
  }

  body.in-game .app-header,
  body.in-game .tabbar,
  body.in-game .app-footer,
  body.in-game .notices {
    display: none;
  }

  body.in-game .view {
    width: calc(100% - 16px);
    margin: 8px auto;
  }

  .game-layout {
    --board-size: calc(100 * var(--pc-vh) - 16px);
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "board opponent" "board player" "board controls" "board log";
    grid-template-rows: auto auto auto 1fr;
    column-gap: 12px;
    row-gap: 6px;
    align-items: start;
    justify-items: stretch;
  }

  .game-layout > .board {
    width: var(--board-size);
    max-width: 60vw;
  }

  .game-layout > .player-bar,
  .game-layout > .game-actions,
  .game-layout > .game-log,
  .game-layout > .game-spectators {
    width: auto;
  }

  .game-layout > .game-actions,
  .game-layout > .game-log,
  .game-layout > .game-spectators {
    padding-inline: 0;
  }

  .game-layout.with-spectators {
    grid-template-areas: "board opponent" "board player" "board controls" "board spectators" "board log";
    grid-template-rows: auto auto auto auto 1fr;
  }

  .game-layout .log-list {
    max-height: max(80px, calc(100 * var(--pc-vh) - 250px));
  }
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .saved-strip,
  .log-list {
    scroll-behavior: auto;
  }

  .type-tile,
  .promo-btn,
  .saved-team {
    transition: none;
  }
}

/* M3: the flair badge (headers, lobby rows, player bars) and the Teams page's login card. */
.flair-badge {
  display: inline-flex;
  flex: none;
  align-items: center;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.6;
  text-transform: uppercase;
  white-space: nowrap;
}

.flair-developer {
  background: #5a4fcf;
}

.flair-creator {
  background: #b3471b;
}

.flair-community {
  background: #1f7a4d;
}

.bar-flair {
  display: inline-flex;
  flex: none;
}

.teams-login {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.teams-login > span {
  flex: 1 1 14rem;
}

/* ---------- Moves mode (WP-62): the move bar, the banners, the Fighting Spirit prompt ----------
   game.js adds .with-moves to the .game-layout of a Moves game, so a classic layout is untouched.
   The bar sits directly under the board. Tones: good, warn, bad, info, muted (text and a border, never colour alone:
   every chip and banner also says its state in words). */
.moves-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.moves-banners {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.moves-banners:empty {
  display: none;
}

.moves-banner {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.875rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  animation: moves-in 0.18s ease-out;
}

.moves-banner-weather.weather-sun {
  border-left-color: #e5a50a;
}

.moves-banner-weather.weather-rain {
  border-left-color: #3b82f6;
}

.moves-banner-weather.weather-snow {
  border-left-color: #cfe3f5;
}

.moves-banner-weather.weather-sand {
  border-left-color: #c8963c;
}

.moves-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  animation: moves-in 0.18s ease-out;
}

.moves-bar[hidden] {
  display: none;
}

.moves-bar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.moves-bar-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.moves-bar-text {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.moves-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.moves-bar .moves-btn {
  flex: 1 1 8rem;
  min-width: 0;
  min-height: 44px;
}

.moves-bar .moves-btn[hidden] {
  display: none;
}

.chip-moves {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-2);
  border: 1px solid currentColor;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.7;
  white-space: nowrap;
}

.chip-moves[hidden] {
  display: none;
}

.moves-tone-good {
  color: var(--ok-text);
}

.moves-tone-warn {
  color: var(--pc-warn-text);
}

.moves-tone-bad {
  color: var(--danger-text);
}

.moves-tone-info {
  color: var(--link);
}

.moves-tone-muted {
  color: var(--muted);
}

.moves-banner.moves-tone-warn {
  border-left-color: var(--warn);
  color: var(--text);
}

.moves-banner.moves-tone-info {
  color: var(--text);
}

@keyframes moves-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* The Fighting Spirit prompt: three pieces and a Keep button. */
.promo-fighting .promo-grid {
  grid-template-columns: repeat(3, minmax(72px, 1fr));
}

.promo-keep {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-2);
}

/* Layout areas for .with-moves. Phones: under the board, and the board gives up the bar's height. */
.game-layout.with-moves {
  --moves-h: 140px;
  --board-size: min(100%, calc(100 * var(--pc-vh) - 2 * var(--bar-h) - var(--controls-h) - var(--moves-h) - 16px));
  grid-template-areas: "opponent" "board" "moves" "player" "controls" "log";
}

/* The spectators row must survive: .with-moves comes later with the same specificity as .with-spectators. */
.game-layout.with-moves.with-spectators {
  grid-template-areas: "opponent" "board" "moves" "player" "controls" "spectators" "log";
}

.game-layout.with-moves > .moves-panel {
  grid-area: moves;
  width: var(--board-size);
}

@media (min-width: 600px) {
  .game-layout.with-moves {
    --board-size: min(100%, max(320px, calc(100 * var(--pc-vh) - var(--header-h, 56px) - 2 * var(--bar-h) - var(--controls-h) - var(--moves-h) - 72px)));
  }
}

@media (min-width: 1024px) {
  .game-layout.with-moves {
    grid-template-areas: "opponent log" "board log" "moves log" "player log" "controls log";
    grid-template-rows: auto auto auto auto 1fr;
  }

  .game-layout.with-moves.with-spectators {
    grid-template-areas: "opponent log" "board log" "moves log" "player log" "controls log" "spectators log";
    grid-template-rows: auto auto auto auto auto 1fr;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .game-layout.with-moves {
    --board-size: calc(100 * var(--pc-vh) - 16px);
    grid-template-areas: "board opponent" "board moves" "board player" "board controls" "board log";
    grid-template-rows: auto auto auto auto 1fr;
  }

  .game-layout.with-moves.with-spectators {
    grid-template-areas: "board opponent" "board moves" "board player" "board controls" "board spectators" "board log";
    grid-template-rows: auto auto auto auto auto 1fr;
  }

  .game-layout.with-moves > .moves-panel {
    width: auto;
  }
}

/* Under 700 px the bar is a single column and the buttons fill the width. */
@media (max-width: 699px) {
  .moves-bar .moves-btn {
    flex: 1 1 100%;
  }

  .moves-bar,
  .moves-banner {
    padding-inline: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .moves-bar,
  .moves-banner {
    animation: none;
  }
}
