:root {
  --bg: #0b0d10;
  --panel: #151922;
  --panel-2: #1d2330;
  --text: #f5f7fb;
  --muted: #a8b0c2;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --border: rgba(255,255,255,0.11);
  --shadow: 0 20px 55px rgba(0,0,0,0.42);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(56,189,248,0.12), transparent 36rem),
    radial-gradient(circle at bottom right, rgba(34,197,94,0.08), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.45rem);
  letter-spacing: 0.04em;
}

h2, h3 { margin: 0 0 12px; }
.subtitle { margin: 6px 0 0; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.hidden { display: none !important; }

.connection-pill {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  font-size: 0.9rem;
}
.connection-pill.ok { color: #bbf7d0; border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.1); }
.connection-pill.bad { color: #fecaca; border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.1); }

.panel, .side-panel, .board-frame {
  background: linear-gradient(180deg, rgba(255,255,255,0.055), rgba(255,255,255,0.025));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.start-panel { padding: 18px; }
.start-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.start-card {
  padding: 20px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.primary-card {
  background: linear-gradient(180deg, rgba(56,189,248,0.10), rgba(255,255,255,0.035));
}

label {
  display: block;
  margin: 13px 0 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}
input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(0,0,0,0.22);
  color: var(--text);
  padding: 0 13px;
  outline: none;
}
input:focus { border-color: rgba(56,189,248,0.7); box-shadow: 0 0 0 3px rgba(56,189,248,0.15); }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.code-input {
  text-align: center;
  font-size: 1.8rem;
  letter-spacing: 0.28em;
  font-weight: 800;
}

button {
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 800;
  color: var(--text);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
.big-btn { width: 100%; min-height: 48px; margin-top: 16px; }
.primary { background: linear-gradient(135deg, #0ea5e9, #22c55e); }
.secondary { background: rgba(255,255,255,0.09); border: 1px solid var(--border); }
.danger-btn { background: var(--danger); }
.danger-outline { background: var(--danger-soft); color: #fecaca; border: 1px solid rgba(239,68,68,0.45); }
.tiny-btn { padding: 6px 9px; border-radius: 10px; background: rgba(255,255,255,0.09); border: 1px solid var(--border); font-size: 0.82rem; }

.created-code-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid rgba(56,189,248,0.25);
  background: rgba(56,189,248,0.08);
  border-radius: 16px;
  text-align: center;
}
.big-code {
  margin: 10px auto;
  font-size: clamp(2.4rem, 10vw, 5rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: 0.16em;
  font-variant-numeric: tabular-nums;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(310px, 560px) minmax(220px, 300px);
  gap: 18px;
  align-items: start;
}
.side-panel { padding: 16px; background-color: var(--panel); }
.room-code-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(0,0,0,0.22);
  margin-bottom: 14px;
}
.room-code-line strong { font-size: 1.5rem; letter-spacing: 0.14em; font-variant-numeric: tabular-nums; }

.players { display: grid; gap: 10px; }
.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.045);
}
.player-card.active {
  border-color: rgba(56,189,248,0.7);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.13);
}
.piece-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); flex: 0 0 auto; }
.white-dot { background: #f8fafc; }
.black-dot { background: #111827; }
.player-name { font-weight: 800; }
.clock {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #dbeafe;
  font-size: 1.35rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.status-line {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.45;
  min-height: 42px;
}

.board-section { min-width: 0; }
.board-frame {
  padding: clamp(8px, 1.6vw, 16px);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.025)),
    #111827;
}
#board {
  width: min(74vmin, 560px);
  max-width: 100%;
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
}

/* chessboard.js professional-looking board tweaks */
.white-1e1d7 { background-color: #f0d9b5 !important; }
.black-3c85d { background-color: #b58863 !important; }
.highlight-last {
  box-shadow: inset 0 0 0 9999px rgba(255, 235, 59, 0.34) !important;
}
.highlight-selected {
  box-shadow: inset 0 0 0 4px rgba(14, 165, 233, 0.85) !important;
}

.move-history {
  min-height: 265px;
  max-height: 430px;
  overflow: auto;
  padding: 12px;
  border-radius: 14px;
  background: rgba(0,0,0,0.24);
  color: #d1d5db;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.75;
  white-space: pre-wrap;
}
.controls { display: grid; gap: 9px; margin-top: 14px; }

.move-history-toggle,
.move-history-close {
  display: none;
}

.move-history-sheet-header h3 {
  margin: 0 0 12px;
}

.disconnect-notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 15px;
  background: rgba(245,158,11,0.14);
  color: #fde68a;
  border: 1px solid rgba(245,158,11,0.35);
  text-align: center;
  font-weight: 800;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,0.62);
  backdrop-filter: blur(6px);
}
.modal-box {
  width: min(440px, 100%);
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #151922;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-box p { color: var(--muted); line-height: 1.55; }
.modal-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.promotion-options button {
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  padding: 10px;
}
.promotion-options img { width: 54px; height: 54px; object-fit: contain; }


/* Generic blink kept for existing uses such as rematch. */
.blink {
  animation: blink 0.7s infinite alternate;
}

@keyframes blink {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.7);
  }
}





/* Strong visible draw-offer alert. */



#drawBtn.blink {
  opacity: 1 !important;
  position: relative !important;
  z-index: 3 !important;
  color: #111827 !important;
  background: #facc15 !important;
  border: 2px solid #ffffff !important;
  box-shadow:
    0 0 0 4px rgba(250, 204, 21, 0.28),
    0 0 14px rgba(250, 204, 21, 0.55) !important;
  text-shadow: none !important;
  animation: draw-offer-alert-once 1s 1 forwards !important;
}

#drawBtn.blink::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 17px;
  border: 3px solid rgba(250, 204, 21, 0.95);
  pointer-events: none;
  animation: draw-offer-ring-once 1s 1 forwards;
}

@keyframes draw-offer-alert-once {
  0% {
    background: #fde047;
    transform: scale(1);
    filter: brightness(1);
  }
  20% {
    background: #eab308;
    transform: scale(1.04);
    filter: brightness(1.10);
  }
  40% {
    background: #fde047;
    transform: scale(1);
    filter: brightness(1);
  }
  60% {
    background: #eab308;
    transform: scale(1.03);
    filter: brightness(1.08);
  }
  100% {
    background: #facc15;
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes draw-offer-ring-once {
  0% {
    opacity: 0.20;
    transform: scale(1);
  }
  20% {
    opacity: 0.95;
    transform: scale(1.06);
  }
  40% {
    opacity: 0.20;
    transform: scale(1);
  }
  60% {
    opacity: 0.80;
    transform: scale(1.05);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}





@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; }
  .top-side { order: 1; }
  .board-section { order: 2; }
  .bottom-side { order: 3; }
  #board { width: min(94vw, 560px); }
  .move-history { min-height: 110px; max-height: 150px; }
  .players { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 16px, 1240px); padding-top: 10px; }
  .topbar { align-items: flex-start; }
  .subtitle { font-size: 0.9rem; }
  .start-grid { grid-template-columns: 1fr; }
  .start-panel { padding: 10px; }
  .start-card { padding: 14px; }
  .players { grid-template-columns: 1fr; }
  .room-code-line strong { font-size: 1.25rem; }
  .clock { font-size: 1.15rem; }
  .side-panel { padding: 12px; }
  .board-frame { padding: 7px; }
  #board { width: min(96vw, calc(100vh - 320px)); min-width: 300px; }
}

@media (max-width: 420px) {
  .topbar { flex-direction: column; gap: 8px; }
  .connection-pill { align-self: flex-start; }
  #board { min-width: 286px; }
  .modal-buttons { justify-content: stretch; }
  .modal-buttons button { flex: 1 1 auto; }
}

/* Final simplified 4-digit code start screen */
.simple-code-panel {
  width: min(94vw, 560px);
  margin: 0 auto;
}

.simple-code-card {
  width: 100%;
  background:
    radial-gradient(circle at top left, rgba(76, 175, 80, 0.18), transparent 32%),
    linear-gradient(145deg, rgba(35,35,35,0.98), rgba(18,18,18,0.98));
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 28px;
  padding: clamp(22px, 4vw, 38px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  text-align: center;
}

.brand-mark {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 22px;
  background: rgba(76,175,80,0.14);
  border: 1px solid rgba(76,175,80,0.35);
  font-size: 42px;
}

.simple-code-card h2 {
  margin: 0 0 8px;
  font-size: clamp(26px, 5vw, 38px);
}

.clean-time-grid {
  margin: 24px 0 20px;
}

.clean-time-grid input {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.your-code-box {
  margin: 22px auto;
  padding: 22px;
  border-radius: 24px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
}

.code-label {
  color: #aaa;
  font-size: 15px;
  margin-bottom: 8px;
}

.big-code {
  font-size: clamp(46px, 12vw, 72px);
  font-weight: 900;
  letter-spacing: 0.16em;
  line-height: 1;
  font-family: "Courier New", monospace;
  color: #fff;
  text-shadow: 0 0 24px rgba(76,175,80,0.35);
}

.join-clean-box {
  margin-top: 20px;
}

.join-clean-box label {
  display: block;
  margin-bottom: 10px;
  color: #ddd;
  font-weight: 700;
}

.join-clean-box .code-input {
  width: min(100%, 300px);
  margin: 0 auto 14px;
  text-align: center;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.18em;
  font-family: "Courier New", monospace;
}

.note-line {
  margin-top: 14px;
}

@media (max-width: 640px) {
  .simple-code-card {
    padding: 20px;
    border-radius: 22px;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
    font-size: 34px;
  }

  .join-clean-box .code-input {
    font-size: 30px;
  }
}

/* Pilapila inherited animated tile background */
body.pilapila-chess-bg {
  background:
    radial-gradient(circle at top left, rgba(250, 211, 144, 0.50), transparent 34%),
    radial-gradient(circle at bottom right, rgba(231, 127, 103, 0.28), transparent 34%),
    #f0f0f0 !important;
  color: #202124;
}

body.pilapila-chess-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,0.16), rgba(255,255,255,0));
}

#tile-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.tile {
  position: absolute;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  border-radius: 18px;
  opacity: 0.72;
  will-change: transform;
  transform: translateZ(0);
  filter: saturate(1.04);
}

.app-shell,
.modal-overlay,
.promotion-overlay {
  position: relative;
  z-index: 2;
}

.simple-code-card,
.panel,
.board-card,
.side-panel {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    display: none;
  }
}

/* Z-index fix: keep Pilapila animated tiles behind chess UI */
html,
body.pilapila-chess-bg {
  min-height: 100%;
}

body.pilapila-chess-bg {
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
}

/* Background layer only */
body.pilapila-chess-bg::before {
  z-index: 0 !important;
}

/* Tiles must stay behind all UI */
body.pilapila-chess-bg #tile-container {
  position: fixed !important;
  inset: 0 !important;
  z-index: 0 !important;
  pointer-events: none !important;
  overflow: hidden !important;
}

/* Individual tiles should never create a higher layer */
body.pilapila-chess-bg #tile-container .tile {
  z-index: 0 !important;
  pointer-events: none !important;
}

/* Main chess application above the background */
body.pilapila-chess-bg .app-shell,
body.pilapila-chess-bg main,
body.pilapila-chess-bg .panel,
body.pilapila-chess-bg .start-panel,
body.pilapila-chess-bg .simple-code-panel,
body.pilapila-chess-bg .simple-code-card,
body.pilapila-chess-bg .game-panel,
body.pilapila-chess-bg .board-card,
body.pilapila-chess-bg .side-panel {
  position: relative !important;
  z-index: 10 !important;
}

/* Popups must be above everything */
body.pilapila-chess-bg .modal-overlay,
body.pilapila-chess-bg .promotion-overlay {
  position: fixed !important;
  z-index: 9999 !important;
}

/* Dragged chess pieces should remain above board/background */
body.pilapila-chess-bg .dragging-piece,
body.pilapila-chess-bg img.chess-piece,
body.pilapila-chess-bg .piece-417db {
  z-index: 50 !important;
}

/* --------------------------------------------------------------------------
   Mobile chessboard fixes + responsive game UI
   Added 2026-05-24.
   Purpose:
   - Desktop keeps chessboard.js drag/drop.
   - Mobile/coarse-pointer devices get stable tap-to-move from app.js.
   - Touching the board must not scroll the page.
   - Dark backgrounds always use bright text; light backgrounds use dark text.
-------------------------------------------------------------------------- */

body.chess-dragging,
body.pilapila-chess-bg.chess-dragging {
  overflow: hidden;
  overscroll-behavior: none;
}

/* The board itself is an interactive surface, not a scroll surface. */
#board,
#board .board-b72b1,
#board [class*="square-"],
.board-section,
.board-frame {
  -ms-touch-action: none !important;
  touch-action: none !important;
}

#board,
#board * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

#board img {
  display: block;
  max-width: 100%;
  height: auto;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
}

/* Keep the chess board in LTR coordinates even when the page language is RTL. */
#board,
#board *,
.board-section,
.board-frame {
  direction: ltr !important;
}

/* Game panels are dark, so text inside them must be bright. */
.game-panel,
.game-panel .side-panel,
.game-panel .board-frame {
  color: #f8fafc;
}

.game-panel .side-panel {
  background: rgba(17, 24, 39, 0.94);
  border-color: rgba(255, 255, 255, 0.16);
}

.game-panel .room-code-line,
.game-panel .player-card,
.game-panel .move-history {
  background: rgba(2, 6, 23, 0.46);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.14);
}

.game-panel .room-code-line span,
.game-panel .room-code-line strong,
.game-panel .player-name,
.game-panel .clock,
.game-panel h3 {
  color: #f8fafc;
}

.game-panel .status-line {
  color: #dbeafe;
}

.game-panel .move-history {
  color: #e5e7eb;
}

.game-panel .secondary,
.game-panel .tiny-btn {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.game-panel .secondary:hover,
.game-panel .tiny-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.game-panel .danger-outline {
  color: #fee2e2;
  background: rgba(127, 29, 29, 0.48);
  border: 1px solid rgba(248, 113, 113, 0.48);
}

.modal-box {
  color: #f8fafc;
  background: #151922;
}

.modal-box p {
  color: #d1d5db;
}

.modal-box .secondary {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* On mobile, app.js disables chessboard.js dragging and uses tap-to-move.
   Disable image hit-testing so the square receives taps reliably. */
@media (pointer: coarse), (max-width: 980px) {
  #board img {
    pointer-events: none;
  }

  #board [class*="square-"] {
    cursor: pointer;
  }
}

/* Tablet and narrow desktop: stack the game, but keep information compact. */
@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr !important;
    gap: 12px;
    align-items: stretch;
  }

  .top-side {
    order: 1;
  }

  .board-section {
    order: 2;
  }

  .bottom-side {
    order: 3;
  }

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

  #board {
    width: min(92vw, 560px) !important;
    min-width: 0 !important;
  }

  .move-history {
    min-height: 90px;
    max-height: 135px;
  }
}

/* Phone portrait: board-first feel with compact clocks and controls. */
@media (max-width: 760px) {
  .shell {
    width: min(100% - 14px, 1240px);
    padding-top: 8px;
    padding-bottom: 12px;
  }

  .game-layout {
    gap: 9px;
  }

  .topbar {
    margin-bottom: 7px;
  }

  .connection-pill {
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .side-panel {
    padding: 10px;
    border-radius: 16px;
  }

  .top-side {
    display: grid;
    gap: 8px;
  }

  .room-code-line {
    min-height: 38px;
    margin-bottom: 0;
    padding: 8px 10px;
  }

  .room-code-line strong {
    font-size: 1.12rem;
    letter-spacing: 0.12em;
  }

  .players {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }

  .player-card {
    min-width: 0;
    gap: 8px;
    padding: 8px;
    border-radius: 13px;
  }

  .piece-dot {
    width: 18px;
    height: 18px;
  }

  .player-name {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.86rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .clock {
    font-size: 1.06rem;
  }

  .status-line {
    min-height: 0;
    margin-top: 0;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(2, 6, 23, 0.36);
    text-align: center;
    font-size: 0.9rem;
  }

  .board-frame {
    padding: 6px;
    border-radius: 16px;
  }

  #board {
    width: min(calc(100vw - 28px), calc(100svh - 264px), 560px) !important;
    min-width: 0 !important;
    max-width: 100% !important;
    aspect-ratio: 1 / 1;
    border-radius: 9px;
  }

  .bottom-side {
    padding: 10px;
  }

  .bottom-side h3 {
    margin-bottom: 7px;
    font-size: 0.95rem;
  }

  .move-history {
    min-height: 58px;
    max-height: 86px;
    padding: 9px;
    font-size: 0.82rem;
    line-height: 1.55;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 9px;
  }

  .controls button {
    min-height: 42px;
    padding: 9px 8px;
    border-radius: 12px;
    font-size: 0.88rem;
  }
}

/* Very small phones. */
@media (max-width: 420px) {
  .shell {
    width: min(100% - 10px, 1240px);
  }

  .players {
    gap: 6px;
  }

  .player-card {
    padding: 7px;
  }

  .clock {
    font-size: 1rem;
  }

  #board {
    width: min(calc(100vw - 18px), calc(100svh - 258px), 520px) !important;
  }

  .controls {
    gap: 7px;
  }

  .controls button {
    font-size: 0.82rem;
  }
}

/* Mobile landscape: use a real landscape layout instead of a tall stacked page. */
@media (max-height: 560px) and (orientation: landscape) {
  .shell {
    width: min(100% - 16px, 1240px);
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .topbar {
    min-height: 28px;
    margin-bottom: 6px;
  }

  .game-layout {
    grid-template-columns: minmax(170px, 0.75fr) minmax(240px, 1.05fr) minmax(170px, 0.8fr) !important;
    gap: 10px;
    align-items: center;
  }

  .top-side,
  .board-section,
  .bottom-side {
    order: initial;
  }

  .side-panel {
    max-height: calc(100svh - 58px);
    overflow: auto;
    padding: 9px;
  }

  .players {
    grid-template-columns: 1fr !important;
  }

  .player-card {
    padding: 7px 8px;
  }

  .status-line {
    font-size: 0.82rem;
  }

  .board-frame {
    padding: 5px;
  }

  #board {
    width: min(calc(100svh - 74px), 46vw, 500px) !important;
    min-width: 230px !important;
  }

  .move-history {
    min-height: 58px;
    max-height: 96px;
    font-size: 0.78rem;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .controls button {
    min-height: 36px;
    padding: 7px 8px;
    font-size: 0.8rem;
  }
}

/* Large desktop keeps the original spacious three-column design. */
@media (min-width: 981px) {
  .game-layout {
    grid-template-columns: minmax(230px, 280px) minmax(380px, 560px) minmax(230px, 300px);
  }
}


/* --------------------------------------------------------------------------
   Mobile touch/tap chessboard hard fix v2
   The board is not allowed to become a scroll/drag surface on phones.
   app.js handles mobile moves by tap source square -> tap destination square.
-------------------------------------------------------------------------- */
body.chess-touch-mode #board,
body.chess-touch-mode #board *,
body.chess-touch-mode .board-frame,
body.chess-touch-mode .board-section {
  -ms-touch-action: none !important;
  touch-action: none !important;
  overscroll-behavior: contain !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

body.chess-touch-mode #board img,
body.chess-touch-mode #board [draggable="true"] {
  pointer-events: none !important;
  -webkit-user-drag: none !important;
  user-drag: none !important;
}

body.chess-touch-mode #board [class*="square-"] {
  cursor: pointer !important;
}

body.chess-touch-mode.chess-dragging,
body.chess-touch-mode.chess-dragging html {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

/* Keep both clocks next to each other on all phone/tablet layouts. */
@media (max-width: 980px) {
  .players {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .player-card {
    min-width: 0 !important;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .game-layout {
    grid-template-columns: minmax(225px, 0.95fr) minmax(230px, 1fr) minmax(175px, 0.78fr) !important;
  }

  .players {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .player-card {
    padding: 6px !important;
    gap: 6px !important;
  }

  .piece-dot {
    width: 14px !important;
    height: 14px !important;
  }

  .player-name {
    font-size: 0.74rem !important;
  }

  .clock {
    font-size: 0.88rem !important;
  }
}

/* Extra contrast guard: dark cards/panels always keep bright text. */
.game-panel .side-panel,
.game-panel .side-panel *,
.game-panel .board-frame,
.game-panel .move-history,
.game-panel .room-code-line,
.game-panel .player-card {
  color: #f8fafc;
}

.game-panel .status-line {
  color: #dbeafe !important;
}

.game-panel input,
.start-panel input,
.compact-start-card input {
  color: #111827;
  background: rgba(255, 255, 255, 0.88);
}

/* --------------------------------------------------------------------------
   Language + game UI polish v3
   - Game room code row is hidden after game starts.
   - Connection pill is placed in a stable floating top-center position.
   - Disconnect notice is solid/non-transparent and bilingual text comes from app.js.
   - Persian language uses Persian digits in app.js, while move history stays LTR.
-------------------------------------------------------------------------- */

/* Better place for the connection pill: centered at the top, not inside the game panels. */
body.pilapila-chess-bg .topbar {
  position: fixed !important;
  top: max(10px, env(safe-area-inset-top)) !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  z-index: 5002 !important;
  width: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  pointer-events: none !important;
  direction: ltr !important;
}

body.pilapila-chess-bg .topbar > * {
  pointer-events: auto !important;
}

body.pilapila-chess-bg .topbar > div:first-child {
  display: none !important;
}

body.pilapila-chess-bg .connection-pill {
  min-height: 38px !important;
  padding: 8px 14px !important;
  border-radius: 999px !important;
  border: 2px solid #475569 !important;
  color: #f8fafc !important;
  background: #334155 !important;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28) !important;
  font-size: 0.86rem !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  opacity: 1 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.pilapila-chess-bg .connection-pill.ok {
  color: #052e16 !important;
  border-color: #16a34a !important;
  background: #86efac !important;
}

body.pilapila-chess-bg .connection-pill.bad {
  color: #450a0a !important;
  border-color: #dc2626 !important;
  background: #fca5a5 !important;
}

/* Leave enough breathing room for the floating top controls. */
body.pilapila-chess-bg .shell {
  padding-top: max(64px, calc(env(safe-area-inset-top) + 58px)) !important;
}

/* B. The in-game code row is no longer needed once the game starts. */
body.pilapila-chess-bg #gamePanel .room-code-line {
  display: none !important;
}

/* C. Disconnect notice must be solid, readable, and never transparent. */
body.pilapila-chess-bg .disconnect-notice {
  background: #f59e0b !important;
  color: #111827 !important;
  border: 2px solid #92400e !important;
  box-shadow: 0 10px 24px rgba(146, 64, 14, 0.24) !important;
  opacity: 1 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Moves are the single exception requested by the user: always English/LTR. */
body.pilapila-chess-bg #moveHistory {
  direction: ltr !important;
  unicode-bidi: plaintext !important;
  text-align: left !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace !important;
}

/* Clocks/codes are formatted by app.js; keep their visual direction stable. */
body.pilapila-chess-bg .clock,
body.pilapila-chess-bg #createdCode,
body.pilapila-chess-bg #roomCodeLabel {
  direction: ltr !important;
  unicode-bidi: plaintext !important;
}

/* Dark backgrounds => bright text. */
body.pilapila-chess-bg .game-panel .side-panel,
body.pilapila-chess-bg .game-panel .board-frame,
body.pilapila-chess-bg .modal-box {
  color: #f8fafc !important;
}

body.pilapila-chess-bg .game-panel .side-panel *,
body.pilapila-chess-bg .game-panel .board-frame *,
body.pilapila-chess-bg .modal-box h2,
body.pilapila-chess-bg .modal-box p {
  color: inherit;
}

body.pilapila-chess-bg .game-panel .status-line,
body.pilapila-chess-bg .game-panel .move-history,
body.pilapila-chess-bg .modal-box p {
  color: #e5e7eb !important;
}

/* Light start card => dark text. */
body.pilapila-chess-bg .compact-start-card,
body.pilapila-chess-bg .compact-start-card label,
body.pilapila-chess-bg .compact-start-card .code-label,
body.pilapila-chess-bg .compact-start-card .note-line {
  color: #111827 !important;
}

/* Responsive refinements after hiding the code row. */
@media (max-width: 980px) {
  body.pilapila-chess-bg #gamePanel .top-side {
    padding-top: 10px !important;
  }

  body.pilapila-chess-bg #gamePanel .players {
    grid-template-columns: 1fr 1fr !important;
  }
}

@media (max-width: 760px) {
  body.pilapila-chess-bg .shell {
    padding-top: max(58px, calc(env(safe-area-inset-top) + 52px)) !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 34px !important;
    padding: 7px 10px !important;
    font-size: 0.78rem !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side {
    padding: 8px !important;
  }

  body.pilapila-chess-bg #gamePanel .players {
    grid-template-columns: 1fr 1fr !important;
    gap: 7px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-card {
    min-width: 0 !important;
    padding: 8px !important;
  }
}

@media (max-width: 430px) {
  body.pilapila-chess-bg .connection-pill {
    font-size: 0.74rem !important;
    padding: 7px 9px !important;
  }
}

@media (max-width: 360px) {
  body.pilapila-chess-bg .connection-pill {
    font-size: 0.70rem !important;
    padding: 6px 8px !important;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  body.pilapila-chess-bg .topbar {
    top: max(7px, env(safe-area-inset-top)) !important;
  }

  body.pilapila-chess-bg .shell {
    padding-top: max(48px, calc(env(safe-area-inset-top) + 42px)) !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 32px !important;
    padding: 6px 10px !important;
  }
}

/* Takeback action: compact controls beside the turn/status text in the clocks area. */
.turn-action-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
}

.turn-action-row .status-line {
  width: 100%;
  min-width: 0;
  min-height: 30px;
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.takeback-controls {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(248, 250, 252, 0.18);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
  white-space: nowrap;
  direction: inherit;
}

.takeback-segment-btn {
  min-height: 30px;
  height: 30px;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 950;
  line-height: 1;
  touch-action: manipulation;
  transition: background-color 0.16s ease, color 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}

.takeback-accept-btn {
  min-width: 48px;
  padding: 0 10px;
  color: #052e16;
  background: #bbf7d0;
  border-inline-end: 1px solid rgba(15, 23, 42, 0.20);
}

.takeback-main-btn {
  min-width: 112px;
  padding: 0 13px;
  color: #111827;
  background: #fef3c7;
  border-inline-end: 1px solid rgba(15, 23, 42, 0.20);
}

.takeback-decline-btn {
  min-width: 44px;
  padding: 0 10px;
  color: #ffffff;
  background: #334155;
}

.takeback-accept-btn:hover:not(:disabled) {
  background: #86efac;
}

.takeback-main-btn:hover:not(:disabled) {
  background: #fde68a;
}

.takeback-decline-btn:hover:not(:disabled) {
  background: #1e293b;
}

.takeback-segment-btn:focus-visible {
  position: relative;
  z-index: 2;
  outline: 3px solid rgba(56, 189, 248, 0.35);
  outline-offset: -2px;
}

.takeback-segment-btn:disabled {
  cursor: not-allowed;
}

.takeback-accept-btn:disabled,
.takeback-decline-btn:disabled {
  opacity: 0.42;
  color: #cbd5e1;
  background: rgba(30, 41, 59, 0.78);
}

.takeback-main-btn:disabled {
  opacity: 0.58;
  color: #475569;
  background: rgba(226, 232, 240, 0.90);
}

.takeback-controls.is-incoming .takeback-main-btn,
.takeback-main-btn.is-pending-incoming {
  opacity: 1;
  color: #ffffff;
  background: #dc2626;
  animation: takeback-alert-blink 0.62s infinite alternate;
}

.takeback-controls.is-outgoing .takeback-main-btn,
.takeback-main-btn.is-pending-outgoing {
  opacity: 1;
  color: #7f1d1d;
  background: #fee2e2;
}

@keyframes takeback-alert-blink {
  from {
    background: #dc2626;
    color: #ffffff;
    filter: brightness(1);
  }
  to {
    background: #7f1d1d;
    color: #ffffff;
    filter: brightness(1.28);
  }
}

body.pilapila-chess-bg .takeback-controls {
  background: rgba(255, 255, 255, 0.92) !important;
  border-color: rgba(17, 24, 39, 0.13) !important;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16) !important;
}

body.pilapila-chess-bg .takeback-accept-btn {
  color: #052e16 !important;
  background: #bbf7d0 !important;
}

body.pilapila-chess-bg .takeback-main-btn {
  color: #111827 !important;
  background: #fef3c7 !important;
}

body.pilapila-chess-bg .takeback-decline-btn {
  color: #ffffff !important;
  background: #334155 !important;
}

body.pilapila-chess-bg .takeback-accept-btn:disabled,
body.pilapila-chess-bg .takeback-decline-btn:disabled {
  color: #64748b !important;
  background: rgba(241, 245, 249, 0.92) !important;
}

body.pilapila-chess-bg .takeback-main-btn:disabled {
  color: #64748b !important;
  background: rgba(241, 245, 249, 0.92) !important;
}

body.pilapila-chess-bg .takeback-controls.is-incoming .takeback-main-btn,
body.pilapila-chess-bg .takeback-main-btn.is-pending-incoming {
  color: #ffffff !important;
  background: #dc2626 !important;
}

body.pilapila-chess-bg .takeback-controls.is-outgoing .takeback-main-btn,
body.pilapila-chess-bg .takeback-main-btn.is-pending-outgoing {
  color: #7f1d1d !important;
  background: #fee2e2 !important;
}

@media (max-width: 760px) {
  .turn-action-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 7px;
    margin-top: 8px;
  }

  .turn-action-row .status-line {
    flex: 1 1 auto;
    width: auto;
    min-height: 30px;
    justify-content: flex-start;
    text-align: start;
  }

  .takeback-controls {
    flex: 0 0 auto;
  }

  .takeback-segment-btn {
    height: 28px;
    min-height: 28px;
    font-size: 0.70rem;
  }

  .takeback-accept-btn {
    min-width: 40px;
    padding: 0 7px;
  }

  .takeback-main-btn {
    min-width: 92px;
    padding: 0 9px;
  }

  .takeback-decline-btn {
    min-width: 36px;
    padding: 0 7px;
  }
}

@media (max-width: 420px) {
  .turn-action-row {
    gap: 5px;
  }

  .takeback-segment-btn {
    height: 26px;
    min-height: 26px;
    font-size: 0.66rem;
  }

  .takeback-accept-btn {
    min-width: 36px;
    padding: 0 6px;
  }

  .takeback-main-btn {
    min-width: 82px;
    padding: 0 7px;
  }

  .takeback-decline-btn {
    min-width: 32px;
    padding: 0 6px;
  }
}

/* --------------------------------------------------------------------------
   Takeback visibility patch v5
   Purpose: prevent the compact takeback segmented control from disappearing
   on narrower iPhone layouts, especially iPhone 13 portrait width.
   Server/game logic is unchanged.
-------------------------------------------------------------------------- */
#gamePanel .top-side,
#gamePanel .turn-action-row {
  overflow: visible !important;
}

.takeback-controls:not(.hidden) {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

@media (max-width: 430px) {
  .turn-action-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    justify-content: stretch !important;
    gap: 5px !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
  }

  .turn-action-row .status-line {
    min-width: 0 !important;
    width: auto !important;
    padding: 6px 7px !important;
    font-size: 0.80rem !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .takeback-controls {
    justify-self: end !important;
    max-width: calc(100vw - 18px) !important;
    min-width: 0 !important;
    transform: translateZ(0);
  }

  .takeback-segment-btn {
    height: 26px !important;
    min-height: 26px !important;
    font-size: 0.62rem !important;
    letter-spacing: -0.01em !important;
  }

  .takeback-accept-btn {
    min-width: 32px !important;
    padding: 0 5px !important;
  }

  .takeback-main-btn {
    min-width: 72px !important;
    padding: 0 6px !important;
  }

  .takeback-decline-btn {
    min-width: 28px !important;
    padding: 0 5px !important;
  }
}

@media (max-width: 380px) {
  .turn-action-row {
    gap: 4px !important;
  }

  .turn-action-row .status-line {
    padding: 5px 6px !important;
    font-size: 0.76rem !important;
  }

  .takeback-segment-btn {
    height: 25px !important;
    min-height: 25px !important;
    font-size: 0.58rem !important;
  }

  .takeback-accept-btn {
    min-width: 30px !important;
    padding: 0 4px !important;
  }

  .takeback-main-btn {
    min-width: 66px !important;
    padding: 0 5px !important;
  }

  .takeback-decline-btn {
    min-width: 26px !important;
    padding: 0 4px !important;
  }
}


/* --------------------------------------------------------------------------
   Mobile hero layout v1
   Desktop remains controlled by the original three-column rules above.
   Mobile is intentionally centralized here to replace the older scattered phone
   overrides with one predictable layout:
   1) compact clock/status/takeback bar
   2) board-first hero area
   3) sticky action bar
   4) collapsed move-history bottom sheet
-------------------------------------------------------------------------- */
:root {
  --chita-mobile-board-vw: 80vw;
  --chita-mobile-bottom-gap: 10px;
  --chita-mobile-action-min-height: 56px;
  --chita-mobile-action-bar-space: calc(var(--chita-mobile-action-min-height) + var(--chita-mobile-bottom-gap) + env(safe-area-inset-bottom));
}

@media (max-width: 760px) {
  html,
  body.pilapila-chess-bg {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
  }

  body.pilapila-chess-bg .shell {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100svh !important;
    padding-left: max(6px, env(safe-area-inset-left)) !important;
    padding-right: max(6px, env(safe-area-inset-right)) !important;
    padding-top: max(52px, calc(env(safe-area-inset-top) + 46px)) !important;
    padding-bottom: calc(var(--chita-mobile-action-bar-space) + 12px) !important;
  }

  body.pilapila-chess-bg .top-actions {
    top: max(6px, env(safe-area-inset-top)) !important;
    left: max(6px, env(safe-area-inset-left)) !important;
    right: max(6px, env(safe-area-inset-right)) !important;
    gap: 6px !important;
  }

  body.pilapila-chess-bg .language-switcher button,
  body.pilapila-chess-bg .back-home-btn {
    min-height: 34px !important;
    padding: 6px 10px !important;
    font-size: 0.76rem !important;
    border-radius: 14px !important;
  }

  body.pilapila-chess-bg .topbar {
    top: max(46px, calc(env(safe-area-inset-top) + 40px)) !important;
    transform: translateX(-50%) scale(0.86) !important;
    transform-origin: top center !important;
  }

  body.pilapila-chess-bg #gamePanel {
    width: 100% !important;
  }

  body.pilapila-chess-bg #gamePanel .disconnect-notice {
    width: min(100% - 8px, 560px) !important;
    margin: 0 auto 8px !important;
    padding: 9px 10px !important;
    font-size: 0.82rem !important;
    border-radius: 14px !important;
  }

  body.pilapila-chess-bg #gamePanel .game-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas:
      "mobile-top"
      "mobile-board"
      "mobile-bottom" !important;
    align-items: center !important;
    justify-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side {
    grid-area: mobile-top !important;
    width: min(100% - 8px, 620px) !important;
    display: grid !important;
    grid-template-columns: minmax(72px, 1fr) minmax(118px, 1.08fr) minmax(72px, 1fr) !important;
    grid-template-areas: "white-clock turn-box black-clock" !important;
    gap: 6px !important;
    align-items: stretch !important;
    margin: 0 auto !important;
    padding: 6px !important;
    border-radius: 18px !important;
    background: rgba(15, 23, 42, 0.90) !important;
    border: 1px solid rgba(255, 255, 255, 0.16) !important;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.20) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    direction: ltr !important;
    overflow: visible !important;
    z-index: 30 !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side .room-code-line {
    display: none !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side .players {
    display: contents !important;
  }

  body.pilapila-chess-bg #gamePanel #whitePlayer {
    grid-area: white-clock !important;
  }

  body.pilapila-chess-bg #gamePanel #blackPlayer {
    grid-area: black-clock !important;
  }

  body.pilapila-chess-bg #gamePanel .player-card {
    min-width: 0 !important;
    width: 100% !important;
    min-height: 48px !important;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 7px 6px !important;
    border-radius: 14px !important;
    background: rgba(2, 6, 23, 0.52) !important;
    direction: ltr !important;
  }

  body.pilapila-chess-bg #gamePanel .piece-dot {
    width: 14px !important;
    height: 14px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-name {
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.70rem !important;
    font-weight: 900 !important;
    line-height: 1.1 !important;
    opacity: 0.92 !important;
  }

  body.pilapila-chess-bg #gamePanel .clock {
    margin-top: 2px !important;
    color: #dbeafe !important;
    font-size: clamp(0.94rem, 4.7vw, 1.18rem) !important;
    line-height: 1 !important;
  }

  body.pilapila-chess-bg #gamePanel .turn-action-row {
    grid-area: turn-box !important;
    min-width: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: center !important;
    gap: 4px !important;
    margin: 0 !important;
    direction: inherit !important;
    overflow: visible !important;
  }

  html[dir="rtl"] body.pilapila-chess-bg #gamePanel .turn-action-row {
    direction: rtl !important;
  }

  body.pilapila-chess-bg #gamePanel .turn-action-row .status-line {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 22px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 4px 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 11px !important;
    background: rgba(255, 255, 255, 0.10) !important;
    color: #e0f2fe !important;
    font-size: clamp(0.68rem, 3.3vw, 0.82rem) !important;
    font-weight: 900 !important;
    line-height: 1.12 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-controls:not(.hidden) {
    width: 100% !important;
    max-width: 100% !important;
    display: grid !important;
    grid-template-columns: minmax(30px, 0.7fr) minmax(58px, 1.45fr) minmax(30px, 0.7fr) !important;
    border-radius: 999px !important;
    overflow: hidden !important;
    transform: translateZ(0) !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-segment-btn {
    min-width: 0 !important;
    width: 100% !important;
    height: 24px !important;
    min-height: 24px !important;
    padding: 0 4px !important;
    font-size: clamp(0.54rem, 2.7vw, 0.66rem) !important;
    line-height: 1 !important;
  }

  body.pilapila-chess-bg #gamePanel .board-section {
    grid-area: mobile-board !important;
    width: 100% !important;
    min-width: 0 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 20 !important;
  }

  body.pilapila-chess-bg #gamePanel .board-frame {
    width: fit-content !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 6px !important;
    border-radius: 18px !important;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.025)),
      #111827 !important;
  }

  body.pilapila-chess-bg #gamePanel #board {
    width: min(var(--chita-mobile-board-vw), calc(100svh - 186px - var(--chita-mobile-action-bar-space)), 560px) !important;
    min-width: 0 !important;
    max-width: calc(100vw - 24px) !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    margin: 0 auto !important;
  }

  body.pilapila-chess-bg #gamePanel .bottom-side {
    grid-area: mobile-bottom !important;
    width: 100% !important;
    max-width: 100% !important;
    display: contents !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-toggle {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: min(100% - 28px, 360px) !important;
    min-height: 34px !important;
    margin: 0 auto !important;
    padding: 7px 14px !important;
    border-radius: 999px !important;
    color: #f8fafc !important;
    background: rgba(15, 23, 42, 0.88) !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18) !important;
    font-size: 0.82rem !important;
    font-weight: 950 !important;
    line-height: 1 !important;
    touch-action: manipulation !important;
    z-index: 70 !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-toggle::before {
    content: "⌃";
    display: inline-block;
    margin-inline-end: 7px;
    font-size: 0.90rem;
    line-height: 1;
    transform: translateY(1px);
  }

  body.move-history-open.pilapila-chess-bg #gamePanel .move-history-toggle::before {
    content: "⌄";
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet {
    position: fixed !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    bottom: calc(var(--chita-mobile-action-bar-space) + 10px) !important;
    z-index: 1200 !important;
    max-height: min(42svh, 340px) !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: 10px !important;
    border-radius: 20px !important;
    background: rgba(15, 23, 42, 0.97) !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    box-shadow: 0 22px 60px rgba(2, 6, 23, 0.45) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    transform: translateY(calc(100% + var(--chita-mobile-action-bar-space) + 24px)) !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: transform 0.22s ease, opacity 0.18s ease, visibility 0.18s ease !important;
  }

  body.move-history-open.pilapila-chess-bg #gamePanel .move-history-sheet {
    transform: translateY(0) !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet-header h3 {
    margin: 0 !important;
    color: #f8fafc !important;
    font-size: 0.98rem !important;
    font-weight: 950 !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-close {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 30px !important;
    padding: 5px 11px !important;
    border-radius: 999px !important;
    color: #f8fafc !important;
    background: rgba(255, 255, 255, 0.10) !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    font-size: 0.78rem !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history {
    min-height: 128px !important;
    max-height: calc(min(42svh, 340px) - 64px) !important;
    overflow: auto !important;
    padding: 10px !important;
    border-radius: 14px !important;
    background: rgba(2, 6, 23, 0.58) !important;
    -webkit-overflow-scrolling: touch !important;
    font-size: 0.84rem !important;
    line-height: 1.62 !important;
  }

  body.pilapila-chess-bg #gamePanel .controls {
    position: sticky !important;
    bottom: max(var(--chita-mobile-bottom-gap), env(safe-area-inset-bottom)) !important;
    z-index: 1000 !important;
    width: min(100% - 16px, 620px) !important;
    min-height: var(--chita-mobile-action-min-height) !important;
    display: flex !important;
    align-items: stretch !important;
    justify-content: center !important;
    gap: 8px !important;
    margin: 2px auto 0 !important;
    padding: 8px !important;
    border-radius: 20px !important;
    background: rgba(15, 23, 42, 0.94) !important;
    border: 1px solid rgba(255, 255, 255, 0.16) !important;
    box-shadow: 0 14px 36px rgba(2, 6, 23, 0.34) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
  }

  body.pilapila-chess-bg #gamePanel .controls button {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    min-height: 42px !important;
    margin: 0 !important;
    padding: 8px 6px !important;
    border-radius: 14px !important;
    font-size: clamp(0.74rem, 3.4vw, 0.88rem) !important;
    font-weight: 950 !important;
    line-height: 1.08 !important;
    touch-action: manipulation !important;
  }

  body.pilapila-chess-bg #gamePanel .controls button.hidden {
    display: none !important;
  }
}

@media (max-width: 390px) {
  :root {
    --chita-mobile-board-vw: 82vw;
  }

  body.pilapila-chess-bg #gamePanel .top-side {
    grid-template-columns: minmax(66px, 0.88fr) minmax(112px, 1.12fr) minmax(66px, 0.88fr) !important;
    gap: 5px !important;
    padding: 5px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-card {
    min-height: 44px !important;
    padding: 6px 5px !important;
    gap: 5px !important;
  }

  body.pilapila-chess-bg #gamePanel .piece-dot {
    width: 12px !important;
    height: 12px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-name {
    font-size: 0.64rem !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-segment-btn {
    height: 22px !important;
    min-height: 22px !important;
    font-size: 0.54rem !important;
  }

  body.pilapila-chess-bg #gamePanel .controls {
    width: min(100% - 10px, 620px) !important;
    gap: 6px !important;
    padding: 7px !important;
  }

  body.pilapila-chess-bg #gamePanel .controls button {
    min-height: 40px !important;
    font-size: 0.74rem !important;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  :root {
    --chita-mobile-board-vw: 46vw;
    --chita-mobile-action-min-height: 46px;
    --chita-mobile-bottom-gap: 6px;
  }

  body.pilapila-chess-bg .shell {
    width: 100% !important;
    min-height: 100svh !important;
    padding-top: max(42px, calc(env(safe-area-inset-top) + 36px)) !important;
    padding-left: max(6px, env(safe-area-inset-left)) !important;
    padding-right: max(6px, env(safe-area-inset-right)) !important;
    padding-bottom: 6px !important;
  }

  body.pilapila-chess-bg .top-actions {
    top: max(5px, env(safe-area-inset-top)) !important;
  }

  body.pilapila-chess-bg .language-switcher button,
  body.pilapila-chess-bg .back-home-btn {
    min-height: 31px !important;
    padding: 5px 9px !important;
    font-size: 0.70rem !important;
  }

  body.pilapila-chess-bg .topbar {
    top: max(5px, env(safe-area-inset-top)) !important;
    transform: translateX(-50%) scale(0.78) !important;
  }

  body.pilapila-chess-bg #gamePanel .game-layout {
    grid-template-columns: minmax(132px, 0.78fr) minmax(230px, auto) minmax(126px, 0.72fr) !important;
    grid-template-areas: "mobile-top mobile-board mobile-bottom" !important;
    gap: 8px !important;
    align-items: center !important;
    justify-items: stretch !important;
    min-height: calc(100svh - 50px) !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side {
    width: 100% !important;
    height: auto !important;
    grid-template-columns: 1fr !important;
    grid-template-areas:
      "white-clock"
      "turn-box"
      "black-clock" !important;
    align-self: center !important;
    padding: 6px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-card {
    min-height: 40px !important;
  }

  body.pilapila-chess-bg #gamePanel .clock {
    font-size: 0.92rem !important;
  }

  body.pilapila-chess-bg #gamePanel .turn-action-row .status-line {
    min-height: 22px !important;
    font-size: 0.64rem !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-segment-btn {
    height: 22px !important;
    min-height: 22px !important;
    font-size: 0.52rem !important;
  }

  body.pilapila-chess-bg #gamePanel .board-frame {
    padding: 5px !important;
  }

  body.pilapila-chess-bg #gamePanel #board {
    width: min(var(--chita-mobile-board-vw), calc(100svh - 62px), 500px) !important;
    max-width: 100% !important;
  }

  body.pilapila-chess-bg #gamePanel .bottom-side {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: center !important;
    gap: 7px !important;
    width: 100% !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-toggle {
    width: 100% !important;
    min-height: 32px !important;
    margin: 0 !important;
    padding: 6px 10px !important;
    font-size: 0.72rem !important;
  }

  body.pilapila-chess-bg #gamePanel .controls {
    position: static !important;
    width: 100% !important;
    min-height: 0 !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin: 0 !important;
    padding: 7px !important;
    border-radius: 16px !important;
  }

  body.pilapila-chess-bg #gamePanel .controls button {
    min-height: 34px !important;
    padding: 6px !important;
    font-size: 0.72rem !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet {
    left: auto !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    bottom: max(8px, env(safe-area-inset-bottom)) !important;
    width: min(42vw, 310px) !important;
    max-height: calc(100svh - 20px) !important;
    transform: translateX(calc(100% + 28px)) !important;
  }

  body.move-history-open.pilapila-chess-bg #gamePanel .move-history-sheet {
    transform: translateX(0) !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history {
    min-height: 86px !important;
    max-height: calc(100svh - 78px) !important;
    font-size: 0.76rem !important;
  }
}

@media (min-width: 761px) and (max-width: 980px) {
  body.pilapila-chess-bg #gamePanel .game-layout {
    grid-template-columns: 1fr !important;
    justify-items: center !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side,
  body.pilapila-chess-bg #gamePanel .bottom-side {
    width: min(100%, 620px) !important;
  }

  body.pilapila-chess-bg #gamePanel #board {
    width: min(80vw, 560px) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.pilapila-chess-bg #gamePanel .move-history-sheet {
    transition: none !important;
  }
}


/* --------------------------------------------------------------------------
   Mobile hero layout v3 fixes
   - Connection pill no longer floats over the mobile status/card.
   - Connection pill UI is restyled globally.
   - Landscape phones use a compact desktop-like three-column layout.
-------------------------------------------------------------------------- */
body.pilapila-chess-bg .connection-pill {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  min-height: 38px !important;
  padding: 8px 14px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  color: #f8fafc !important;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(15, 23, 42, 0.72)) !important;
  box-shadow:
    0 10px 26px rgba(2, 6, 23, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.14) !important;
  font-size: 0.84rem !important;
  font-weight: 950 !important;
  line-height: 1 !important;
  letter-spacing: -0.01em !important;
  white-space: nowrap !important;
  opacity: 1 !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
}

body.pilapila-chess-bg .connection-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.18);
}

body.pilapila-chess-bg .connection-pill.ok {
  color: #ecfdf5 !important;
  border-color: rgba(34, 197, 94, 0.46) !important;
  background:
    linear-gradient(180deg, rgba(20, 83, 45, 0.88), rgba(15, 23, 42, 0.76)) !important;
}

body.pilapila-chess-bg .connection-pill.ok::before {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22), 0 0 16px rgba(34, 197, 94, 0.52);
}

body.pilapila-chess-bg .connection-pill.bad {
  color: #fff1f2 !important;
  border-color: rgba(248, 113, 113, 0.50) !important;
  background:
    linear-gradient(180deg, rgba(127, 29, 29, 0.88), rgba(15, 23, 42, 0.78)) !important;
}

body.pilapila-chess-bg .connection-pill.bad::before {
  background: #fb7185;
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.22), 0 0 16px rgba(251, 113, 133, 0.48);
}

@media (max-width: 760px) {
  body.pilapila-chess-bg .shell {
    padding-top: max(46px, calc(env(safe-area-inset-top) + 40px)) !important;
  }

  body.pilapila-chess-bg .topbar {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
    transform-origin: center !important;
    z-index: 45 !important;
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 auto 8px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    pointer-events: auto !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 30px !important;
    padding: 6px 11px !important;
    font-size: 0.74rem !important;
    box-shadow:
      0 8px 20px rgba(2, 6, 23, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.12) !important;
  }

  body.pilapila-chess-bg .connection-pill::before {
    width: 7px;
    height: 7px;
    flex-basis: 7px;
  }

  body.pilapila-chess-bg #startPanel.start-panel {
    margin-top: 0 !important;
  }

  body.pilapila-chess-bg #gamePanel .game-layout {
    margin-top: 0 !important;
  }
}

@media (max-width: 390px) and (orientation: portrait) {
  body.pilapila-chess-bg .shell {
    padding-top: max(44px, calc(env(safe-area-inset-top) + 38px)) !important;
  }

  body.pilapila-chess-bg .topbar {
    margin-bottom: 7px !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 28px !important;
    padding: 6px 10px !important;
    font-size: 0.70rem !important;
  }
}

/* Phone landscape: compact desktop-like layout. */
@media (max-height: 560px) and (orientation: landscape) {
  body.pilapila-chess-bg .shell {
    width: min(100% - 12px, 980px) !important;
    max-width: 980px !important;
    min-height: 100svh !important;
    padding-top: max(38px, calc(env(safe-area-inset-top) + 32px)) !important;
    padding-left: max(6px, env(safe-area-inset-left)) !important;
    padding-right: max(6px, env(safe-area-inset-right)) !important;
    padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
  }

  body.pilapila-chess-bg .topbar {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
    z-index: 45 !important;
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 auto 6px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 27px !important;
    padding: 5px 10px !important;
    font-size: 0.68rem !important;
  }

  body.pilapila-chess-bg #startPanel.start-panel {
    width: min(100%, 760px) !important;
    margin-top: 0 !important;
  }

  body.pilapila-chess-bg #startPanel .compact-start-card {
    display: grid !important;
    grid-template-columns: minmax(170px, 0.9fr) minmax(205px, 1fr) minmax(220px, 1.05fr) !important;
    gap: 10px !important;
    align-items: end !important;
    padding: 12px !important;
    border-radius: 18px !important;
  }

  body.pilapila-chess-bg #startPanel .compact-start-card .note-line {
    grid-column: 1 / -1 !important;
    margin: 0 !important;
  }

  body.pilapila-chess-bg #gamePanel .game-layout {
    display: grid !important;
    grid-template-columns: minmax(145px, 0.72fr) minmax(260px, auto) minmax(150px, 0.74fr) !important;
    grid-template-areas: "mobile-top mobile-board mobile-bottom" !important;
    gap: 8px !important;
    align-items: start !important;
    justify-items: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    margin: 0 auto !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side {
    grid-area: mobile-top !important;
    display: block !important;
    width: 100% !important;
    max-height: calc(100svh - 78px) !important;
    overflow: auto !important;
    padding: 8px !important;
    border-radius: 16px !important;
    background: rgba(15, 23, 42, 0.90) !important;
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    box-shadow: 0 12px 30px rgba(2, 6, 23, 0.22) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    direction: inherit !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side .players {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 7px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-card {
    min-height: 42px !important;
    padding: 7px !important;
    border-radius: 13px !important;
  }

  body.pilapila-chess-bg #gamePanel .player-name {
    font-size: 0.66rem !important;
  }

  body.pilapila-chess-bg #gamePanel .clock {
    font-size: clamp(0.80rem, 2.5vw, 0.98rem) !important;
  }

  body.pilapila-chess-bg #gamePanel .turn-action-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin-top: 8px !important;
  }

  body.pilapila-chess-bg #gamePanel .turn-action-row .status-line {
    min-height: 34px !important;
    padding: 7px 8px !important;
    white-space: normal !important;
    font-size: 0.70rem !important;
    line-height: 1.25 !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-controls:not(.hidden) {
    display: grid !important;
    grid-template-columns: minmax(32px, 0.7fr) minmax(62px, 1.5fr) minmax(32px, 0.7fr) !important;
  }

  body.pilapila-chess-bg #gamePanel .takeback-segment-btn {
    height: 24px !important;
    min-height: 24px !important;
    font-size: 0.54rem !important;
  }

  body.pilapila-chess-bg #gamePanel .board-section {
    grid-area: mobile-board !important;
    align-self: start !important;
    display: flex !important;
    align-items: flex-start !important;
    justify-content: center !important;
    min-width: 0 !important;
    padding: 0 !important;
  }

  body.pilapila-chess-bg #gamePanel .board-frame {
    width: fit-content !important;
    max-width: 100% !important;
    padding: 5px !important;
    border-radius: 16px !important;
  }

  body.pilapila-chess-bg #gamePanel #board {
    width: min(50vw, calc(100svh - 78px), 430px) !important;
    min-width: 0 !important;
    max-width: 100% !important;
    aspect-ratio: 1 / 1 !important;
  }

  body.pilapila-chess-bg #gamePanel .bottom-side {
    grid-area: mobile-bottom !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 7px !important;
    width: 100% !important;
    max-height: calc(100svh - 78px) !important;
    overflow: hidden !important;
    padding: 8px !important;
    border-radius: 16px !important;
    background: rgba(15, 23, 42, 0.90) !important;
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    box-shadow: 0 12px 30px rgba(2, 6, 23, 0.22) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-toggle {
    display: none !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet {
    position: static !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-close {
    display: none !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history-sheet-header h3 {
    margin: 0 !important;
    font-size: 0.78rem !important;
    line-height: 1 !important;
  }

  body.pilapila-chess-bg #gamePanel .move-history {
    flex: 1 1 auto !important;
    min-height: 72px !important;
    max-height: calc(100svh - 192px) !important;
    padding: 8px !important;
    border-radius: 12px !important;
    font-size: 0.70rem !important;
    line-height: 1.45 !important;
  }

  body.pilapila-chess-bg #gamePanel .controls {
    position: static !important;
    bottom: auto !important;
    width: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  body.pilapila-chess-bg #gamePanel .controls button {
    min-height: 31px !important;
    padding: 5px 7px !important;
    border-radius: 11px !important;
    font-size: 0.68rem !important;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  body.pilapila-chess-bg .shell {
    padding-top: max(34px, calc(env(safe-area-inset-top) + 28px)) !important;
  }

  body.pilapila-chess-bg .topbar {
    margin-bottom: 5px !important;
  }

  body.pilapila-chess-bg .connection-pill {
    min-height: 25px !important;
    padding: 4px 9px !important;
    font-size: 0.64rem !important;
  }

  body.pilapila-chess-bg #gamePanel .game-layout {
    grid-template-columns: minmax(138px, 0.72fr) minmax(238px, auto) minmax(142px, 0.72fr) !important;
    gap: 7px !important;
  }

  body.pilapila-chess-bg #gamePanel #board {
    width: min(48vw, calc(100svh - 66px), 410px) !important;
  }

  body.pilapila-chess-bg #gamePanel .top-side,
  body.pilapila-chess-bg #gamePanel .bottom-side {
    max-height: calc(100svh - 68px) !important;
  }
}
