/* Game page layout - sidebars with leaderboard and other games */
body:has(.game-page-layout) {
  display: block;
  height: auto;
  min-height: 100vh;
}
.game-page-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-width: 0;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
.game-sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  background: rgba(0,0,0,0.15);
  border-right: 1px solid rgba(255,255,255,0.1);
}
.game-sidebar-left {
  padding-top: 5rem;
}
.game-sidebar-right {
  border-right: none;
  border-left: 1px solid rgba(255,255,255,0.1);
}
.game-sidebar h3 {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255,255,255,0.2);
}
.game-sidebar-leaderboard .gl-row {
  display: flex;
  align-items: center;
  padding: 0.35rem 0;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.95);
}
.game-sidebar-leaderboard .gl-rank {
  width: 28px;
  font-weight: 800;
  color: #fbbf24;
  flex-shrink: 0;
}
.game-sidebar-leaderboard .gl-rank.gold { color: #fbbf24; }
.game-sidebar-leaderboard .gl-rank.silver { color: #94a3b8; }
.game-sidebar-leaderboard .gl-rank.bronze { color: #d97706; }
.game-sidebar-leaderboard .gl-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-sidebar-leaderboard .gl-score {
  font-weight: 800;
  color: #fbbf24;
  font-size: 0.75rem;
}
.game-sidebar-leaderboard .gl-empty {
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
  padding: 0.5rem 0;
}
.game-sidebar-games .gl-game-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.35rem;
  border-radius: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.08);
  transition: background 0.2s;
}
.game-sidebar-games .gl-game-link:hover {
  background: rgba(255,255,255,0.18);
}
.game-sidebar-games .gl-game-emoji {
  font-size: 1.1rem;
  flex-shrink: 0;
}
.game-sidebar-games .gl-game-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gl-leaderboard-link {
  display: block;
  margin-top: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: rgba(251,191,36,0.25);
  color: #fbbf24;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
  transition: background 0.2s;
}
.gl-leaderboard-link:hover {
  background: rgba(251,191,36,0.4);
}
@media (max-width: 900px) {
  .game-sidebar {
    display: none;
  }
  .game-main {
    padding: 1rem;
    padding-top: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Mobile: fit game + buttons on screen without scrolling, smaller controls */
@media (max-width: 768px) {
  .game-main {
    padding: 0.4rem;
    padding-top: 0.4rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    justify-content: flex-start;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  .game-page-layout .back-link {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    top: max(0.4rem, env(safe-area-inset-top));
    left: max(0.4rem, env(safe-area-inset-left));
  }

  .game-page-layout .game-wrapper {
    padding: 0.25rem 0.2rem 0.5rem;
    width: 100%;
    max-width: 100%;
  }

  .game-page-layout .game-title {
    font-size: 1.25rem;
    margin-bottom: 0.1rem;
  }

  .game-page-layout .game-tagline {
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
  }

  .game-page-layout .stats-row,
  .game-page-layout .score-row,
  .game-page-layout .stages-row {
    gap: 0.4rem;
    margin-bottom: 0.4rem;
  }

  .game-page-layout .stat-pill {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  .game-page-layout .difficulty {
    margin-bottom: 0.4rem;
  }

  .game-page-layout .btn,
  .game-page-layout .stage-btn,
  .game-page-layout .difficulty .btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  .game-page-layout .message {
    font-size: 0.9rem;
    min-height: 1.25rem;
    margin-bottom: 0.4rem;
  }

  .game-page-layout .canvas-wrap {
    padding: 6px;
    margin-bottom: 0.4rem;
    max-height: min(52vh, 380px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .game-page-layout .canvas-wrap #gameCanvas {
    max-width: 100%;
    max-height: 100%;
  }

  .game-page-layout .board-wrap {
    padding: 8px;
    margin-bottom: 0.4rem;
  }

  .game-page-layout .hint {
    font-size: 0.75rem;
    padding: 0.35rem 0.6rem;
    margin-top: 0.4rem;
  }

  .game-page-layout .hint kbd {
    padding: 0.1rem 0.25rem;
    font-size: 0.7em;
  }

  .game-page-layout .actions-row {
    margin-bottom: 0.4rem;
  }
}

/* Prevent horizontal overflow on small screens */
.game-page-layout {
  overflow-x: hidden;
}

/* Mobile game pages: no scroll (no left/right/up/down), title top right, max canvas, buttons fit */
@media (max-width: 768px) {
  html:has(.game-page-layout) {
    overflow: hidden !important;
    height: 100%;
    width: 100%;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
  }

  body:has(.game-page-layout) {
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    position: relative;
    margin: 0;
    -webkit-overflow-scrolling: auto;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
  }

  .game-page-layout {
    overflow: hidden;
    overflow-x: hidden;
    overflow-y: hidden;
    height: 100dvh;
    max-height: 100dvh;
    width: 100%;
    max-width: 100vw;
  }

  .game-main {
    overflow: hidden;
    overflow-x: hidden;
    overflow-y: hidden;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    max-width: 100vw;
  }

  .game-page-layout .game-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden;
    overflow-y: hidden;
    padding-top: 2rem;
    position: relative;
    width: 100%;
    max-width: 100vw;
  }

  .game-page-layout .game-wrapper > .stats-row {
    margin-top: 0.6rem;
  }

  .game-page-layout .game-title,
  .game-page-layout .game-wrapper > h1 {
    position: absolute;
    top: max(0.35rem, env(safe-area-inset-top));
    right: max(0.4rem, env(safe-area-inset-right));
    left: auto;
    margin: 0;
    font-size: 0.9rem;
    max-width: 48%;
    text-align: right;
    line-height: 1.2;
    z-index: 5;
  }

  .game-page-layout .game-tagline {
    display: none;
  }

  .game-page-layout .canvas-wrap {
    flex: 1;
    min-height: 0;
    max-height: none;
    margin-bottom: 0.25rem;
    padding: 4px;
  }

  .game-page-layout .board-wrap,
  .game-page-layout .board-container {
    flex: 1;
    min-height: 0;
    max-height: none;
    margin-bottom: 0.25rem;
    padding: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .game-page-layout .board-wrap .board,
  .game-page-layout .board-wrap .game-container,
  .game-page-layout .board-container .board {
    max-width: 100%;
    max-height: 100%;
  }

  .game-page-layout .game-wrapper > .game-container {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    max-width: 100%;
  }

  .game-page-layout .stats-row,
  .game-page-layout .score-row,
  .game-page-layout .stages-row,
  .game-page-layout .score-panel,
  .game-page-layout .difficulty {
    margin-bottom: 0.25rem;
    flex-shrink: 0;
  }

  .game-page-layout .stat-pill,
  .game-page-layout .score-panel {
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
  }

  .game-page-layout .btn,
  .game-page-layout .stage-btn,
  .game-page-layout .difficulty .btn,
  .game-page-layout .btn-restart,
  .game-page-layout .controls-row .btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    min-height: 36px;
  }

  .game-page-layout .actions-row {
    margin-bottom: 0.25rem;
    flex-shrink: 0;
  }

  .game-page-layout .message {
    font-size: 0.8rem;
    min-height: 1.1rem;
    margin-bottom: 0.25rem;
  }

  .game-page-layout .hint {
    font-size: 0.65rem;
    padding: 0.25rem 0.4rem;
    margin-top: 0.25rem;
    flex-shrink: 0;
  }

  .game-page-layout .hint kbd {
    padding: 0.08rem 0.2rem;
    font-size: 0.65em;
  }

  .game-page-layout .dpad {
    flex-shrink: 0;
    margin-top: 0.25rem;
  }

  .game-page-layout .ui {
    flex-shrink: 0;
    margin-top: 0.35rem;
    font-size: 0.7rem;
  }
}
