/* Game screen layout: score left · map centre · build right · hand and dice below. */

.game-layout:not([hidden]) {
  display: grid; gap: 14px; align-items: start;
  grid-template-columns: minmax(230px, 270px) minmax(0, 1fr) minmax(230px, 270px);
  /* the side columns run alongside both the map and the hand, so the hand sits right under the map */
  grid-template-areas: "left centre right" "left bottom right";
  grid-template-rows: auto 1fr;
}
.gl-left, .gl-right { align-self: start; }
.gl-left { grid-area: left; }
.gl-centre { grid-area: centre; }
.gl-right { grid-area: right; }
.gl-bottom { grid-area: bottom; display: flex; gap: 18px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.gl-left, .gl-right { padding: 14px; }
.gl-left h2 { margin-bottom: 4px; }
.gl-left p { margin: 0; }
.gl-centre .prompt { margin: 0 0 6px; min-height: 1.6em; }
.gl-centre .action-bar { margin: 0 0 8px; }
.gl-centre .action-bar:empty { display: none; }
.gl-bottom .hand-area { margin: 0; flex: 1 1 520px; min-width: 0; }
.gl-dice { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
body.in-game #g-endturn { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; justify-content: center; min-height: 34px; }
body.in-game #g-endturn.is-placeholder { visibility: hidden; }

/* scoreboard */
.vp-bar { display: block; height: 4px; border-radius: 2px; background: var(--border); margin-top: 4px; overflow: hidden; }
.vp-bar > span { display: block; height: 100%; border-radius: 2px; }
.player .vp small { color: var(--muted); font-size: 0.72rem; font-weight: 500; }

@media (max-width: 1150px) {
  .game-layout:not([hidden]) {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
    grid-template-areas: "centre right" "bottom bottom" "left left";
  }
}

/* ---------------------------------------------------------------- fit to the window
 * While a game is open (body.in-game) the page is exactly one window tall at every
 * resolution: hand and dice keep their row, the map scales into the space left,
 * side columns scroll inside themselves. Players never scroll the page.
 * Full screen (body.is-fullscreen) is the same layout with the browser bars gone.
 */
.fullscreen-btn, .drawer-btn { margin-left: 8px; }
.drawer-btn { display: none; }
html:has(body.in-game), body.in-game { overflow: hidden; overflow: clip; }
body.in-game .shell { max-width: none; height: 100vh; height: 100dvh; padding: 8px 12px; display: flex; flex-direction: column; }
body.in-game .top { padding: 0 2px 6px; margin-bottom: 8px; }
/* Table name and win conditions sit beside the wordmark, so the score column starts at the players. */
.top-lead { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; min-width: 0; }
.table-id { display: none; }
body.in-game .table-id {
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  flex: 1 1 auto; min-width: 0; padding: 0 16px 0 14px; border-left: 1px solid var(--border);
}
body.in-game .table-id h2 {
  margin: 0; font-size: 0.95rem; line-height: 1.2; font-weight: 650; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
body.in-game .table-id p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.in-game .gl-score > h3:first-child { margin-top: 0; }
body.in-game .top nav { flex: 0 0 auto; }
body.in-game .err { margin: 0 0 8px; }
body.in-game .game-layout:not([hidden]) { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; gap: 10px; }
body.in-game .gl-left, body.in-game .gl-right { align-self: stretch; overflow-x: hidden; overflow-y: auto; min-width: 0; min-height: 0; }
body.in-game .gl-centre { align-self: stretch; display: flex; flex-direction: column; min-height: 0; padding: 6px; }
body.in-game .gl-status {
  margin: 12px 0 0; padding-top: 8px; border-top: 1px solid var(--border);
}
body.in-game .gl-status .turnbar { min-height: 0; margin-bottom: 4px; gap: 6px; }
#game-tools { display: none; }
body.in-game #game-tools { display: inline-flex; align-items: center; gap: 8px; }
body.in-game .top .fullscreen-btn, body.in-game .top .drawer-btn { margin-left: 0; }
/* The map sits inside its box, so the box's size comes from the free space only. */
body.in-game .gl-centre .board-wrap.big { flex: 1; min-height: 120px; position: relative; padding: 0; }
body.in-game .gl-centre .board-wrap.big .board { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); max-height: none; }
body.in-game .gl-bottom { padding: 10px 14px; flex-wrap: nowrap; }
body.in-game .gl-bottom .hand-area { flex: 1 1 auto; }
body.in-game .cards-fan { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; min-height: 100px; padding: 16px 2px 2px; }
body.in-game .log { max-height: none; }

/* The turn and the prompt live in the left column, so they never resize the map. */
body.in-game .prompt-row {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin: 0;
  max-height: 9em; overflow: auto;
}
body.in-game .prompt-row .prompt { margin: 0; min-width: 0; overflow-wrap: anywhere; }
body.in-game .prompt-row .prompt p { margin: 0; }
body.in-game .prompt-row .action-bar { margin: 0; flex-wrap: wrap; }
body.in-game .prompt-row .action-bar:empty { display: none; }
body.in-game .hand-head { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0; }
body.in-game .suggestions {
  height: auto; min-height: 36px; margin-top: 6px; flex-wrap: nowrap; align-items: center;
  overflow: hidden; white-space: nowrap;
}
body.in-game #g-suggest.is-placeholder { visibility: hidden; }

/* Short windows: a more compact hand row. */
@media (max-height: 820px) {
  body.in-game .gl-centre .prompt { font-size: 0.9rem; }
  body.in-game .pcard { width: 50px; height: 70px; }
  body.in-game .pcard-art { width: 30px; height: 30px; }
  body.in-game .pgroup .pcard + .pcard { margin-left: -26px; }
  body.in-game .cards-fan { min-height: 84px; padding-top: 14px; }
  body.in-game .die-cube { --s: 34px; }
  body.in-game .dice-tray { padding: 8px 12px; }
  body.in-game .suggestions { margin-top: 4px; min-height: 32px; }
}

/* Narrower windows: score and build become slide-out panels, the map keeps its room. */
@media (max-width: 1150px) {
  body.in-game .game-layout:not([hidden]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "centre" "bottom";
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  body.in-game .drawer-btn { display: inline-block; }
  body.in-game .gl-left { display: contents; }
  body.in-game .gl-status { grid-area: status; position: static; margin: 0; padding: 0 0 6px; border-bottom: 0; }
  body.in-game .gl-score, body.in-game .gl-right {
    position: fixed; top: 0; bottom: 0; z-index: 50; width: min(320px, 88vw); border-radius: 0;
    transition: transform 0.2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
    background: var(--surface); overflow: auto; padding: 14px;
  }
  /* Closed drawers are hidden outright, so they never widen the page on phones. */
  body.in-game .gl-score { left: 0; transform: translateX(-105%); visibility: hidden; }
  body.in-game .gl-right { right: 0; transform: translateX(105%); visibility: hidden; }
  body.in-game.show-left .gl-score, body.in-game.show-right .gl-right { transform: none; visibility: visible; }
}
@media (prefers-reduced-motion: reduce) { body.in-game .gl-left, body.in-game .gl-right { transition: none; } }

/* scoreboard: city-improvement levels per player (scoreboard.js) */
.sb-improve { display: flex; gap: 8px; margin-top: 3px; }
.sb-track { display: inline-flex; gap: 2px; align-items: center; }
.sb-track i { width: 7px; height: 9px; border-radius: 2px; background: var(--border); }
.sb-track i.on { background: var(--t); }
.sb-metro { font-size: 0.7rem; margin-left: 2px; }
/* Progress-card backs: the colour is the type (trade, politics, science), the name stays hidden. */
.sb-progress { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: -2px; }
.sb-progress i { width: 8px; height: 11px; border-radius: 2px; background: var(--t); border: 1px solid rgba(0, 0, 0, 0.45); }

/* right column: each block folds with the arrow on the heading (app.js Folds) */
.fold-head { display: flex; align-items: center; gap: 2px; width: 100%; }
.fold-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  flex: 1 1 auto; min-width: 0; width: auto; margin: 0; padding: 12px 0 4px; border: 0; border-radius: 0;
  background: transparent; color: var(--orange-dim); cursor: pointer;
  font: inherit; font-size: 0.78rem; font-weight: 650; letter-spacing: 0.08em;
  text-transform: uppercase; text-align: left;
}
.fold-toggle:hover { background: transparent; color: var(--text); border-color: transparent; }
.fold-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-arrow { flex: 0 0 auto; }
.fold-arrow::before { content: "▾"; }
.fold.open .fold-arrow::before { content: "▴"; }
.fold:not(.open) > .fold-body { display: none; }
.fold.near > .fold-head .fold-toggle { color: var(--pending); }
.fold.imminent > .fold-head .fold-toggle { color: var(--missing); }
.fold-float {
  flex: 0 0 auto; width: 26px; height: 26px; margin: 0; padding: 0;
  display: grid; place-items: center; border-radius: 6px;
  background: transparent; color: var(--orange-dim); border: 1px solid var(--border);
}
.fold-float:hover { background: transparent; color: var(--text); border-color: var(--text); }
.fold-float .icon-back { display: none; }
.fold.floated .fold-float .icon-out { display: none; }
.fold.floated .fold-float .icon-back { display: block; }
/* Unhooked: a card on the board, dragged by the title, same idea as chat. */
.fold.floated {
  position: fixed; z-index: 60; width: min(280px, calc(100vw - 24px));
  max-height: min(70vh, 640px); overflow: hidden;
  display: flex; flex-direction: column;
  margin: 0; padding: 2px 12px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.fold.floated > .fold-body { overflow: auto; min-height: 0; }
.fold.floated .fold-head { cursor: grab; touch-action: none; user-select: none; }
.fold.floated.is-dragging .fold-head { cursor: grabbing; }
.fold.floated .fold-float { cursor: pointer; touch-action: auto; }
.fold.floated .fold-toggle::before {
  content: ""; width: 10px; height: 14px; flex: 0 0 auto; opacity: 0.55;
  background-image: radial-gradient(circle, var(--muted) 1.2px, transparent 1.45px);
  background-size: 5px 5px; background-repeat: repeat;
}
.fold.floated[data-fold="score"],
.fold.floated[data-fold="improve"],
.fold.floated[data-fold="turn"] { width: min(340px, calc(100vw - 24px)); }
.fold.floated[data-fold="tray"] {
  width: max-content; max-width: calc(100vw - 24px);
  align-items: stretch; justify-content: flex-start; padding: 2px 12px 10px;
}
.fold.floated[data-fold="tray"] .fold-toggle { justify-content: flex-start; gap: 8px; }
.fold.floated[data-fold="tray"] .fold-arrow { margin-left: auto; }
/* Lifted panels are moved onto the page, so without this they stay up in the lobby. */
body:not(.in-game) .fold.floated { display: none; }

/* Nothing left in the bottom row: the map takes that height too. */
body.in-game .game-layout.no-bottom .gl-bottom { display: none; }
body.in-game .game-layout.no-bottom { row-gap: 0; }

/* A column with nothing docked gives its space to the map. The turn box lifts with the rest. */
@media (min-width: 1151px) {
  body.in-game .game-layout.no-left:not([hidden]) { grid-template-columns: 0px minmax(0, 1fr) minmax(230px, 270px); }
  body.in-game .game-layout.no-right:not([hidden]) { grid-template-columns: minmax(230px, 270px) minmax(0, 1fr) 0px; }
  body.in-game .game-layout.no-left.no-right:not([hidden]) { grid-template-columns: 0px minmax(0, 1fr) 0px; }
  body.in-game .game-layout.no-right .gl-right { display: none; }
  body.in-game .game-layout.no-left .gl-left { display: contents; }
  body.in-game .game-layout.no-left .gl-score { display: none; }
  body.in-game .game-layout.no-left .gl-status {
    grid-area: centre; align-self: end; justify-self: stretch; z-index: 6;
    margin: 0 8px 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    max-height: 34%; overflow: auto; pointer-events: none;
  }
  body.in-game .game-layout.no-left .gl-status :is(button, a, input, select, label) { pointer-events: auto; }
}
.gl-right .log { margin-top: 4px; }

/* benefits under each city-improvement track (benefits.js) */
.benefits { list-style: none; margin: 2px 0 4px; padding: 0; font-size: 0.74rem; line-height: 1.35; }
.benefits li.have { color: var(--text); }
.benefits li.have::before { content: "✓ "; color: var(--t); font-weight: 700; }
.benefits li:not(.have) { color: var(--muted); }

/* progress cards sit right of the resource cards (filled once progress cards exist) */
.progress-hand { flex: 0 0 auto; min-width: 140px; padding-left: 14px; border-left: 1px solid var(--border); }
body.in-game .progress-hand .cards-fan { min-height: 0; align-items: flex-start; }

/* settings page (settings.js) */
.settings-view:not([hidden]) { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; max-width: 980px; }
.settings-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 10px; }
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.settings-grid .menu-switch { flex-direction: row; align-items: center; gap: 6px; margin-top: 6px; }
.settings-grid .menu-switch input { margin: 0; }
.ok-note { color: var(--found); font-weight: 600; margin: 0; }
nav:not(.guest) .guest-only { display: none; }

/* colour picker in the waiting room (app.js renderColorPicker): only free colours */
.color-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.color-choice { width: 30px; height: 30px; padding: 0; border-radius: 50%; background: var(--c); border: 2px solid var(--border); }
.color-choice:hover { background: var(--c); border-color: var(--text); }
.color-choice.on { border: 3px solid var(--text); box-shadow: 0 0 0 3px var(--accent-faint); }

/* One tray: dice, then cards, then progress. The lift control sits in the corner
   while it is docked, so those three keep the row they had. The title shows once lifted. */
body.in-game .gl-bottom:not(.floated) { display: block; position: relative; }
body.in-game .gl-bottom:not(.floated) > .fold-head {
  position: absolute; top: 6px; right: 8px; z-index: 4; width: auto;
}
body.in-game .gl-bottom:not(.floated) > .fold-head .fold-title {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
body.in-game .gl-bottom:not(.floated) > .fold-head .fold-toggle {
  flex: 0 0 auto; width: auto; padding: 0; gap: 0;
}
body.in-game .gl-bottom:not(.open):not(.floated) { min-height: 40px; }
body.in-game .gl-bottom.open:not(.floated) > .fold-body {
  display: grid; width: 100%; grid-template-columns: max-content minmax(0, 1fr) auto; grid-template-rows: auto auto auto;
  gap: 8px 14px; align-items: start; min-width: 0;
}
.fold.floated.open[data-fold="tray"] > .fold-body {
  display: grid; grid-template-columns: max-content max-content max-content; grid-template-rows: auto auto auto;
  gap: 8px 14px; align-items: start; width: max-content; max-width: 100%;
}
body.in-game .gl-bottom > .fold-body > .hand-area,
body.in-game .gl-bottom > .fold-body > .progress-hand,
body.in-game .gl-bottom > .fold-body > .gl-dice {
  display: grid; grid-template-rows: subgrid; grid-row: 1 / span 3; align-items: start; min-width: 0;
}
body.in-game .gl-bottom:not(.floated) .hand-head { padding-right: 52px; }
body.in-game .gl-score > .fold:first-child .fold-toggle { padding-top: 0; }
body.in-game .gl-bottom > .fold-body > .gl-dice { grid-column: 1; }
body.in-game .gl-bottom > .fold-body > .hand-area { grid-column: 2; }
/* Five is the most you can hold (discard back to four at the end of the turn).
   The column keeps that width with fewer cards, so the fifth never opens a scrollbar. */
body.in-game .gl-bottom > .fold-body > .progress-hand {
  grid-column: 3;
  width: calc(14px + 4px + 5 * 58px + 4 * 6px + 2px);
}
body.in-game .gl-bottom .progress-hand { padding-left: 14px; border-left: 1px solid var(--border); }
body.in-game .gl-bottom .gl-dice {
  padding-right: 14px; border-right: 1px solid var(--border); justify-items: stretch;
  /* Same width whether or not it is your roll, so the hand does not slide. */
  width: calc(36px * 2 + 48px * 3 + 8px * 2 + 2px);
}
body.in-game .gl-dice { align-items: stretch; }
body.in-game #g-dice { display: flex; justify-content: center; align-items: center; }
body.in-game .gl-dice .dice-tray,
body.in-game .gl-dice button.dice-tray:hover:not(:disabled) {
  flex-direction: column; align-items: center; justify-content: center; width: 100%; box-sizing: border-box;
  height: auto; gap: 12px; padding: 26px 36px 16px;
  background: none; border-color: transparent;
}
body.in-game .gl-dice .dice-row3d { gap: 8px; }
/* The line under the dice is always reserved. Only your roll shows the words. */
body.in-game .gl-dice .dice-total {
  display: block; width: 0; min-width: 100%; height: 1.15em; overflow: hidden; white-space: nowrap;
  visibility: hidden; text-align: center;
  font-family: var(--font); font-size: 0.95rem; font-weight: 700; line-height: 1.15;
}
body.in-game .gl-dice .die-cube { --s: 48px; }
body.in-game .gl-dice button.dice-tray.your-roll,
body.in-game .gl-dice button.dice-tray.your-roll:hover:not(:disabled) {
  background: color-mix(in srgb, var(--found) 28%, var(--surface-2));
  border-color: var(--found);
}
body.in-game .gl-dice button.dice-tray.your-roll .dice-total { visibility: visible; color: var(--found); }
.board-zoom {
  position: absolute; top: 8px; right: 8px; z-index: 4;
  display: none; flex-direction: column; gap: 4px;
}
body.in-game .board-zoom { display: flex; }
.board-zoom button {
  width: 32px; height: 32px; padding: 0; line-height: 1; font-size: 1.15rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.board-zoom button:hover { background: var(--surface-2); color: var(--text); border-color: var(--text); }
body.in-game #game-board.zoomed { cursor: grab; }
body.in-game #game-board.panning { cursor: grabbing; }
@media (max-height: 820px) {
  body.in-game .gl-dice .die-cube { --s: 40px; }
  body.in-game .gl-bottom:not(.floated) .gl-dice { width: calc(36px * 2 + 40px * 3 + 8px * 2 + 2px); }
}
/* Popped out, the columns are as wide as the pieces in them. The docked row still
   reserves room for five progress cards so the hand does not jump. */
.fold.floated[data-fold="tray"] > .fold-body > .gl-dice,
.fold.floated[data-fold="tray"] > .fold-body > .progress-hand,
.fold.floated[data-fold="tray"] > .fold-body > .hand-area { width: max-content; }
.fold.floated[data-fold="tray"] .gl-dice .dice-tray,
.fold.floated[data-fold="tray"] .gl-dice button.dice-tray:hover:not(:disabled) {
  width: auto; padding: 4px 8px 0;
}
