:root {
  --bg: #12141a;
  --panel: #1b1e27;
  --panel2: #232735;
  --ink: #e8eaf0;
  --ink-dim: #9aa0b0;
  --accent: #5b8def;
  --accent2: #3fb27f;
  --danger: #e2574c;
  --light-sq: #e9edf2;
  --dark-sq: #6f8199;
  --highlight: #f4d35e;
  --movehint: rgba(63, 178, 127, 0.55);
  --lastmove: rgba(244, 211, 94, 0.45);
  --checksq: rgba(226, 87, 76, 0.65);
  --opp: #8a93a6;
  --board-max: 640px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 15px;
}

#app { max-width: 1180px; margin: 0 auto; padding: 12px 18px 40px; }

#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 6px 0 14px; border-bottom: 1px solid #2a2e3b; margin-bottom: 16px;
}
#topbar h1 { font-size: 22px; margin: 0; letter-spacing: 0.5px; white-space: nowrap; }
#topActions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sizeCtl { display: flex; align-items: center; gap: 6px; color: var(--ink-dim); font-size: 13px; }
.iconBtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 30px; border-radius: 8px; cursor: pointer;
  background: var(--panel2); color: var(--ink); border: 1px solid #3a4152;
}
.iconBtn:hover { background: #2d3243; }
.iconBtn[aria-pressed="false"] { color: var(--ink-dim); }
.sizeCtl select {
  background: var(--panel2); color: var(--ink); border: 1px solid #3a4152;
  border-radius: 8px; padding: 5px 8px; font-size: 13px; cursor: pointer;
}
.inHand {
  margin-left: 4px; color: var(--ink-dim); font-size: 13px; min-height: 18px;
}
.inHand b { color: var(--accent2); }

.badge {
  background: var(--panel2); color: var(--ink-dim);
  padding: 4px 10px; border-radius: 20px; font-size: 13px; font-weight: 600;
}
#youAre.w { color: #12141a; background: var(--light-sq); }
#youAre.b { color: var(--ink); background: #3a4152; border: 1px solid #566; }

.hidden { display: none !important; }

/* connection / opponent-away banner */
.netBanner {
  margin: -6px 0 14px; padding: 10px 14px; border-radius: 8px;
  background: #3a3220; color: #f6dfa0; font-weight: 600; font-size: 14px;
  border-left: 4px solid var(--highlight);
}
.netBanner.err { background: #3b2322; color: #f5c2bd; border-left-color: var(--danger); }

/* join link + QR on the waiting screen */
.joinBox { margin-top: 18px; }
.joinLead { color: var(--ink-dim); line-height: 1.5; margin: 0 0 10px; }
.joinRow { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.joinUrl {
  font-family: "Consolas", monospace; font-size: 15px; color: #cfe0ff;
  background: var(--panel2); padding: 7px 10px; border-radius: 8px;
  word-break: break-all; text-decoration: none;
}
.joinQr {
  display: block; margin: 14px auto 6px; width: 180px; height: 180px;
  background: #fff; border-radius: 8px; padding: 6px;
}
.roomCode { font-family: "Consolas", monospace; letter-spacing: 2px; color: var(--ink); }

/* start screen: create a match / join with a code */
#screen-start h2 { margin: 0 0 10px; }
.bigBtn { font-size: 16px; padding: 12px 22px; margin: 8px 0 22px; }
.codeForm { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.codeInput {
  width: 150px; padding: 8px 10px; border-radius: 8px; font-size: 16px;
  font-family: "Consolas", monospace; letter-spacing: 2px; text-transform: uppercase; text-align: center;
  background: var(--panel2); color: var(--ink); border: 1px solid #3a4152;
}
#startMsg:empty { display: none; }
#rejectedCreateBtn { margin-top: 10px; }

/* screens */
.screen { display: none; }
body[data-screen="start"]    #screen-start,
body[data-screen="lobby"]    #screen-lobby,
body[data-screen="rejected"] #screen-rejected,
body[data-screen="config"]   #screen-config,
body[data-screen="setup"]    #screen-setup,
body[data-screen="game"]     #screen-game,
body[data-screen="end"]      #screen-end { display: block; }

#modeBadge.mode-chaos { color: #fff; background: #6a3ea1; }
#modeBadge.mode-classic { color: var(--ink); background: #2f7a52; }

.centerCard {
  max-width: 460px; margin: 12vh auto 0; text-align: center;
  background: var(--panel); padding: 40px 30px; border-radius: 14px;
}
.spinner {
  width: 42px; height: 42px; margin: 0 auto 20px;
  border: 4px solid #333a4a; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons */
.btn {
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px;
  font-weight: 600; cursor: pointer; color: var(--ink); background: var(--panel2);
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #2d3243; }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #4a7be0; }
.btn.primary:disabled { background: #384056; color: #6a7182; cursor: not-allowed; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #c8463c; }
.btn.ghost { background: transparent; border: 1px solid #3a4152; }

/* ===== board (shared) ===== */
.board {
  --cols: 8;                             /* overridden inline per boardDims */
  --rows: 8;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);   /* equal rows: a big glyph can't stretch its row */
  /* Fit the column, the chosen size AND the viewport height (minus the chrome
   * above/below the board), so "Large" still fits a 1280x860 laptop. */
  --board-chrome: 150px;
  width: min(100%, var(--board-max), max(260px, calc((100vh - var(--board-chrome)) * var(--cols) / var(--rows))));
  width: min(100%, var(--board-max), max(260px, calc((100dvh - var(--board-chrome)) * var(--cols) / var(--rows))));
  aspect-ratio: 1 / 1;
  border: 3px solid #2a2e3b; border-radius: 6px; overflow: hidden;
  user-select: none;
  container-type: inline-size;           /* glyphs scale with the board (cqw) */
}
#screen-game .board { --board-chrome: 140px; }
#screen-end .board { --board-chrome: 200px; }
/* the connection / opponent-away banner takes ~50px above the board */
body.has-banner #screen-game .board { --board-chrome: 195px; }
body.has-banner #screen-end .board { --board-chrome: 255px; }
.sq {
  position: relative;
  min-width: 0; min-height: 0;           /* let the grid track dictate size, not the glyph */
  display: flex; align-items: center; justify-content: center;
  /* scales down automatically for wider (10-col) boards via --cols */
  font-size: min(calc(50vw / var(--cols, 8)), calc(var(--board-max) / var(--cols, 8) * 0.72));
  font-size: calc(100cqw / var(--cols, 8) * 0.72);
  line-height: 1;
  overflow: hidden;
  cursor: default;
}
.sq .piece { max-width: 100%; }
.sq.light { background: var(--light-sq); }
.sq.dark  { background: var(--dark-sq); }
.sq .coord {
  position: absolute; bottom: 1px; right: 3px;
  font-size: 9px; color: rgba(0,0,0,0.4); pointer-events: none;
}
.sq.dark .coord { color: rgba(255,255,255,0.55); }

/* pieces */
.piece { pointer-events: none; }
/* White reads on BOTH light and dark squares via a solid dark outline. */
.piece.w {
  color: #fbfcfe;
  text-shadow:
    -1.2px -1.2px 0 #1a1d24, 1.2px -1.2px 0 #1a1d24,
    -1.2px  1.2px 0 #1a1d24, 1.2px  1.2px 0 #1a1d24,
     0 0 3px rgba(0,0,0,0.35);
}
.piece.b {
  color: #111318;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,0.55), 1px -1px 0 rgba(255,255,255,0.55),
    -1px  1px 0 rgba(255,255,255,0.55), 1px  1px 0 rgba(255,255,255,0.55);
}
/* Stronger halo where contrast is lowest: dark squares and dark UI panels. */
.sq.dark .piece.b, .trayItem .piece.b, .rosterIcon .piece.b, .promoBtn .piece.b, .inHand .piece.b {
  text-shadow:
    -1.2px -1.2px 0 #e9edf2, 1.2px -1.2px 0 #e9edf2,
    -1.2px  1.2px 0 #e9edf2, 1.2px  1.2px 0 #e9edf2,
     0 0 4px rgba(255,255,255,0.45);
}

/* ===== fairy pieces (OWN pieces + end-screen reveal only) =====
 * Distinct accent per fairy + uppercase letter. Opponent fairy pieces NEVER use
 * this — they render as the neutral .unknown token (fog), identical to standards. */
.piece.fairy {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; min-height: 1.5em; padding: 0 0.12em;
  border-radius: 0.34em;
  font-size: 0.5em; font-weight: 800; line-height: 1;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  letter-spacing: 0.5px;
}
/* owner ring: white = light ring, black = dark ring */
.piece.fairy.w { box-shadow: 0 0 0 2px #f4f6fb, 0 1px 4px rgba(0,0,0,0.5); }
.piece.fairy.b { box-shadow: 0 0 0 2px #0c0e12, 0 1px 4px rgba(0,0,0,0.5); }
/* distinct accent color per fairy type */
.fairy-a { background: #7c4dff; }  /* Amazon     — violet */
.fairy-c { background: #1aa79a; }  /* Chancellor — teal   */
.fairy-h { background: #e07b39; }  /* Archbishop — orange */
.fairy-i { background: #3d7bd6; }  /* Nightrider — blue   */
.fairy-m { background: #b8863b; }  /* Camel      — sand   */
.fairy-w { background: #d5459b; }  /* Wizard     — magenta*/

/* opponent hidden-piece marker — a glossy slate "veiled piece" token, no "?" */
.unknown {
  width: 72%; height: 72%; border-radius: 50%;
  background:
    radial-gradient(circle at 36% 28%, rgba(255,255,255,0.30), rgba(255,255,255,0) 46%),
    radial-gradient(circle at 50% 62%, #56607a, #2c3242 72%);
  box-shadow:
    inset 0 -3px 6px rgba(0,0,0,0.45),
    inset 0 2px 3px rgba(255,255,255,0.14),
    0 2px 5px rgba(0,0,0,0.4);
  position: relative;
  pointer-events: none;
}
.unknown::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 30%; height: 30%; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, rgba(255,255,255,0.18), rgba(0,0,0,0.28));
  box-shadow: inset 0 0 4px rgba(0,0,0,0.5);
}
.sq.selectable:hover .unknown { box-shadow:
  inset 0 -3px 6px rgba(0,0,0,0.45), inset 0 2px 3px rgba(255,255,255,0.14),
  0 0 0 2px var(--accent), 0 2px 6px rgba(0,0,0,0.5); }

/* interaction states */
.sq.selectable { cursor: pointer; }
.sq.selected { box-shadow: inset 0 0 0 4px var(--highlight); }
.sq.movehint { cursor: pointer; }
.sq.movehint::before {
  content: ""; position: absolute; width: 34%; height: 34%;
  border-radius: 50%; background: var(--movehint);
}
.sq.movehint.occupied::before {
  width: 88%; height: 88%; background: transparent;
  border: 5px solid var(--movehint); border-radius: 50%;
}
.sq.lastmove { background-image: linear-gradient(var(--lastmove), var(--lastmove)); }
.sq.checksq  { box-shadow: inset 0 0 0 4px var(--checksq); }
.sq.flash { animation: flash 0.6s ease; }
@keyframes flash {
  0% { background-image: linear-gradient(rgba(244,211,94,0.8), rgba(244,211,94,0.8)); }
  100% { background-image: none; }
}

/* pin overlay */
.pinTag {
  position: absolute; top: 2px; left: 3px;
  background: #6a3ea1; color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 4px; border-radius: 4px; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.pinTag.fade { animation: pinFade 0.6s ease forwards; }
@keyframes pinFade { to { opacity: 0; transform: scale(0.6); } }

/* ===== setup ===== */
.setupWrap { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; }
.setupLeft { flex: 1 1 560px; }
.setupRight { flex: 0 0 200px; }
.hint { color: var(--ink-dim); line-height: 1.5; max-width: 620px; }
.hint.small { font-size: 12px; }
.setupGrid {
  grid-template-rows: repeat(2, 1fr);
  aspect-ratio: 4 / 1;
  width: min(100%, var(--board-max));
  margin: 14px 0;
}
.setupControls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.statusLine { margin-top: 10px; min-height: 20px; font-size: 13px; }
.statusLine.err { color: var(--danger); }
.statusLine.ok  { color: var(--accent2); }

.tray {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: var(--panel); padding: 12px; border-radius: 10px; min-height: 120px;
}
.trayItem {
  aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center;
  font-size: 30px; background: var(--panel2); border-radius: 8px; cursor: pointer;
  position: relative; transition: box-shadow 0.12s, transform 0.05s;
  min-width: 0; overflow: hidden;
}
.trayItem:not(.empty):hover { box-shadow: inset 0 0 0 2px #3a4152; }
.trayItem.selected {
  box-shadow: inset 0 0 0 3px var(--accent2), 0 0 10px rgba(63,178,127,0.4);
  transform: translateY(-1px);
}
/* remaining-count pill, tucked into the corner so it never covers the glyph */
.trayItem .count {
  position: absolute; top: 2px; right: 2px;
  font-size: 10px; line-height: 14px; padding: 0 4px; border-radius: 7px;
  background: rgba(10, 12, 16, 0.75); color: #cfd5e2; font-weight: 700;
  pointer-events: none;
}
.trayItem.empty { opacity: 0.28; cursor: default; }
.sq.dropTarget { outline: 3px dashed var(--accent2); outline-offset: -3px; }
.sq .piece.draggable { pointer-events: auto; cursor: grab; }

/* ===== game / end layout ===== */
.gameWrap, .endWrap { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.boardCol { flex: 1 1 560px; min-width: 0; }
.sidePanel {
  flex: 1 1 300px; max-width: 380px; background: var(--panel);
  border-radius: 12px; padding: 14px 16px;
}
.panelHead { display: flex; align-items: center; justify-content: space-between; }
.panelHead h3 { margin: 4px 0 10px; }

.turnBar {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 10px;
  font-weight: 700; background: var(--panel2);
}
.turnBar.you { background: #234a34; color: #bff5d6; }
.turnBar.opp { background: #2a2e3b; color: var(--ink-dim); }
.checkBanner {
  padding: 8px 14px; border-radius: 8px; margin-bottom: 10px;
  background: var(--danger); color: #fff; font-weight: 700;
}

.moveLog {
  margin: 0; padding: 0; max-height: 300px; overflow-y: auto;
  font-size: 13px; line-height: 1.35;
}
.logRow {
  display: grid; grid-template-columns: 28px 1fr 1fr; gap: 8px;
  padding: 4px 6px; border-bottom: 1px solid #262b38;
}
.logHead {
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  color: var(--ink-dim); font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px;
}
.logNum { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.logCell { min-width: 0; overflow-wrap: anywhere; }
.logCell.own { color: var(--ink); }
.logCell.opp { color: var(--ink-dim); font-style: italic; }
.logCell.revealed { font-style: normal; }
.logCell.cap { color: var(--highlight); }
.logEmpty { color: var(--ink-dim); padding: 8px 6px; font-size: 13px; }

/* end screen */
.endTitle { margin: 4px 0 6px; }
.endTitle.win { color: #7fe0a8; }
.endTitle.loss { color: #f19a92; }
.endTitle.draw { color: var(--ink); }
.endReason { margin: 0 0 12px; color: var(--ink); line-height: 1.5; }
.endActions { display: flex; gap: 8px; flex-wrap: wrap; }

.pinLegend { margin-top: 16px; border-top: 1px solid #2a2e3b; padding-top: 12px; }
.pinLegend h4 { margin: 0 0 6px; }
.qmark {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  vertical-align: -3px;
  background:
    radial-gradient(circle at 36% 28%, rgba(255,255,255,0.30), rgba(255,255,255,0) 46%),
    radial-gradient(circle at 50% 62%, #56607a, #2c3242 72%);
  box-shadow: inset 0 -1px 2px rgba(0,0,0,0.45), inset 0 1px 1px rgba(255,255,255,0.14);
}
.pinList { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.pinList li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 3px 0; color: var(--ink-dim);
}
.pinList li .sqName { color: #b79ce0; font-weight: 700; }

/* ===== modals / toast ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modalCard {
  background: var(--panel); padding: 22px 26px; border-radius: 14px;
  min-width: 280px; max-width: 90vw; text-align: center;
}
.modalCard h3 { margin: 0 0 14px; }
.promoChoices, .pinChoices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pinChoices { margin-bottom: 12px; }
.promoBtn, .pinBtn {
  background: var(--panel2); color: var(--ink); border: none; border-radius: 8px;
  padding: 10px 12px; font-size: 15px; cursor: pointer;
}
.promoBtn:hover, .pinBtn:hover { background: var(--accent); color: #fff; }
.pinInput {
  width: 100%; margin: 4px 0 12px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid #3a4152; background: var(--panel2); color: var(--ink);
}
.modalActions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2a2e3b; color: var(--ink); padding: 12px 20px; border-radius: 10px;
  z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.5); font-weight: 600;
  border-left: 4px solid var(--accent);
}
.toast.err { border-left-color: var(--danger); }

/* ===== config / house-rules negotiation ===== */
.configWrap { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; }
.configMain { flex: 1 1 560px; }
.configSide {
  flex: 1 1 300px; max-width: 360px; background: var(--panel);
  border-radius: 12px; padding: 16px 18px; position: sticky; top: 12px;
}
.cfgGroup { margin: 18px 0; }
.cfgGroup h3 { margin: 0 0 8px; font-size: 15px; }

.modeToggle { display: flex; gap: 10px; }
.modeBtn {
  flex: 0 0 auto; padding: 10px 22px; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 700; color: var(--ink);
  background: var(--panel2); border: 2px solid transparent;
}
.modeBtn:hover { background: #2d3243; }
.modeBtn.active { border-color: var(--accent); background: #1f2c47; color: #cfe0ff; }

.dimsPicker { display: flex; gap: 8px; flex-wrap: wrap; }
.dimBtn {
  padding: 9px 16px; border-radius: 9px; cursor: pointer; font-weight: 700;
  background: var(--panel2); color: var(--ink); border: 2px solid transparent;
}
.dimBtn:hover { background: #2d3243; }
.dimBtn.active { border-color: var(--accent2); background: #1e3a2c; color: #bff5d6; }

.fairyToggles { display: flex; gap: 8px; flex-wrap: wrap; }
.fairyChip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 22px; cursor: pointer;
  background: var(--panel2); color: var(--ink-dim); border: 2px solid transparent;
  font-size: 13px; font-weight: 600;
}
.fairyChip:hover { background: #2d3243; }
.fairyChip.on { color: var(--ink); border-color: currentColor; }
.fairyChipBadge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; color: #fff;
  font-weight: 800; font-size: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.rosterEditor {
  display: grid; grid-template-columns: 1fr; gap: 6px;
  background: var(--panel); border-radius: 10px; padding: 4px 0;
}
.rosterRow {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px; border-bottom: 1px solid #262b38;
}
.rosterRow:last-child { border-bottom: none; }
.rosterRow.banned { opacity: 0.42; }
.rosterIcon {
  flex: 0 0 34px; font-size: 26px; text-align: center; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.rosterName { flex: 1 1 auto; font-weight: 600; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepBtn {
  width: 30px; height: 30px; border-radius: 7px; border: none; cursor: pointer;
  background: var(--panel2); color: var(--ink); font-size: 18px; font-weight: 700;
  line-height: 1; display: flex; align-items: center; justify-content: center;
}
.stepBtn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.stepBtn:disabled { opacity: 0.35; cursor: not-allowed; }
.stepCount { min-width: 26px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.banToggle {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px;
  color: var(--ink-dim); cursor: pointer; user-select: none;
}
.banToggle input { cursor: pointer; }

.cfgSummary {
  background: var(--panel2); border-radius: 9px; padding: 10px 12px; margin-bottom: 10px;
  font-size: 13px; line-height: 1.5;
}
.cfgSumHead { font-weight: 700; color: var(--ink); }
.cfgSumLine { color: var(--ink-dim); font-family: "Consolas", monospace; margin-top: 4px; word-spacing: 2px; }
.cfgSumBan { color: var(--danger); margin-top: 4px; }

.agreeRow { display: flex; gap: 8px; margin: 4px 0 8px; }
.agreeChip {
  flex: 1 1 auto; text-align: center; padding: 6px 8px; border-radius: 8px;
  background: var(--panel2); color: var(--ink-dim); font-size: 12px; font-weight: 700;
}
.agreeChip.ok { background: #234a34; color: #bff5d6; }
.configSide #agreeBtn { width: 100%; margin-top: 6px; }

/* promotion labels (dynamic buttons) */
.promoBtn { display: inline-flex; align-items: center; gap: 6px; }
.promoBtn .piece { font-size: 22px; }
.promoLbl { font-size: 14px; }
.trayGlyph { display: inline-flex; align-items: center; justify-content: center; }

/* ===== phones / narrow screens ===== */
@media (max-width: 640px) {
  html, body { font-size: 14px; }
  #app { padding: 8px 12px 28px; }
  #topbar { gap: 8px; padding-bottom: 10px; margin-bottom: 12px; flex-wrap: wrap; }
  #topbar h1 { font-size: 18px; }
  .badge { padding: 3px 8px; font-size: 12px; }
  /* On a phone the board is limited by the screen width, so the size picker
   * has no effect: hide it and keep the header on one line. */
  .sizeCtl { display: none; }
  #topbar { flex-wrap: nowrap; }

  .centerCard { margin-top: 4vh; padding: 26px 18px; }
  .setupWrap, .gameWrap, .endWrap, .configWrap { gap: 16px; }
  .setupLeft, .setupRight, .boardCol, .sidePanel, .configMain, .configSide {
    flex: 1 1 100%; max-width: 100%;
  }
  .configSide { position: static; }
  .tray { grid-template-columns: repeat(6, 1fr); padding: 8px; min-height: 0; }
  .trayItem { font-size: 26px; }
  .setupControls .btn { padding: 8px 12px; }
  .logRow { grid-template-columns: 24px 1fr 1fr; gap: 6px; }
}
