/* Opening Explorer styles — page-specific stylesheet.
   Loaded only on the Opening Explorer page (extra_head), NOT in base.html, so
   it is a page asset the async shell re-syncs on in-site navigation. Keep OE
   CSS here (not in global style.css) so tweaks appear without a hard refresh —
   style.css is in main.ts GLOBAL_HEAD_LINK_PATHS and is never re-fetched by the
   shell. See docs/memory/frontend.md. */

body.opening-explorer-page .page {
  --oe-panel-edge: clamp(18px, 3.6vw, 64px);
  --oe-panel-pad: clamp(16px, 1.9vw, 28px);
  --oe-layout-gap: clamp(18px, 2.4vw, 34px);
  --oe-board-min: 320px;
  --oe-board-size: clamp(var(--oe-board-min), min(34vw, calc(100vh - 314px)), 600px);

  max-width: none;
  width: 100%;
  padding-left: 0;
  padding-right: 0;
}

@supports (height: 100svh) {
  body.opening-explorer-page .page {
    --oe-board-size: clamp(var(--oe-board-min), min(34vw, calc(100svh - 314px)), 600px);
  }
}

@media (max-height: 680px) {
  body.opening-explorer-page .page {
    --oe-board-min: 280px;
    --oe-board-size: clamp(var(--oe-board-min), min(34vw, calc(100vh - 286px)), 520px);
  }
}

@supports (height: 100svh) {
  @media (max-height: 680px) {
    body.opening-explorer-page .page {
      --oe-board-size: clamp(var(--oe-board-min), min(34vw, calc(100svh - 286px)), 520px);
    }
  }
}

body.opening-explorer-page .oe-panel {
  width: min(1500px, calc(100vw - var(--oe-panel-edge) - var(--oe-panel-edge)));
  max-width: none;
  padding: var(--oe-panel-pad);
}

/* Opening Explorer: small move-input board + player + click-to-cycle colour */
.oe-layout {
  display: grid;
  grid-template-columns: var(--oe-board-size) minmax(360px, 1fr);
  gap: var(--oe-layout-gap);
  align-items: start;
}
@media (max-width: 900px) {
  .oe-layout {
    grid-template-columns: 1fr;
  }
  .oe-board-col {
    align-items: center;
  }
}
.oe-board-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.oe-results-col {
  min-width: 0;
}
/* Size the shared game-viewer board from one responsive page scale. */
.opening-explorer-page #board-skin {
  width: min(var(--oe-board-size), 100%) !important;
  max-width: var(--oe-board-size);
}
/* The board needs the game-viewer's player/move/nav/fen nodes to init, but we
   only surface the board + our own results, so hide that scaffolding. */
.oe-gv-scaffold,
.opening-explorer-page .player-tag,
.opening-explorer-page .board-resize-handle {
  display: none !important;
}
/* Query row: compact player input + colour swatch + player-relative result. */
.oe-query {
  display: flex;
  align-items: center;
  gap: 10px;
}
.oe-player-input {
  flex: 0 1 300px;
  width: min(300px, 100%);
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(0, 200, 255, 0.35);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.28);
  color: var(--white);
  padding: 0 12px;
  font: 0.95rem 'Inter', sans-serif;
}
.oe-result-select {
  flex: 0 0 88px;
  width: 88px;
  min-height: 42px;
  border: 1px solid rgba(0, 200, 255, 0.35);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.55);
  color: var(--white);
  padding: 0 24px 0 8px;
  font: 0.9rem 'Inter', sans-serif;
  cursor: pointer;
}
.oe-reset-button {
  flex: 0 0 36px;
  width: 36px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(0, 200, 255, 0.35);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.42);
  color: var(--cyan);
  font: 1.25rem/1 'Share Tech Mono', monospace;
  cursor: pointer;
}
.oe-reset-button:hover,
.oe-reset-button:focus-visible {
  outline: none;
  border-color: rgba(0, 200, 255, 0.78);
  color: var(--white);
  box-shadow: 0 0 14px rgba(0, 200, 255, 0.2);
}
.oe-result-select:hover,
.oe-result-select:focus-visible {
  outline: none;
  border-color: rgba(0, 200, 255, 0.78);
  box-shadow: 0 0 16px rgba(0, 200, 255, 0.16);
}
.oe-player-input:focus {
  outline: none;
  border-color: rgba(0, 200, 255, 0.78);
  box-shadow: 0 0 16px rgba(0, 200, 255, 0.16);
}
/* Colour toggle as a small swatch: white / black / diagonal split (both). */
.oe-color-swatch {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(0, 200, 255, 0.5);
  border-radius: 3px;
  cursor: pointer;
  background: #1b2733;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.oe-color-swatch:hover,
.oe-color-swatch:focus-visible {
  border-color: rgba(0, 200, 255, 0.85);
  box-shadow: 0 0 14px rgba(0, 200, 255, 0.22);
  outline: none;
}
.oe-color-swatch[data-color="white"] { background: #eef2f6; }
.oe-color-swatch[data-color="black"] { background: #0b0f14; }
.oe-color-swatch[data-color="both"] {
  background: linear-gradient(135deg, #eef2f6 0 50%, #0b0f14 50% 100%);
}
/* Meta block on the top toolbar row (never below the search box): game count
   stacked directly above the page count, with the nav buttons beside them. */
.opening-explorer-page .oe-meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  /* Reserve the meta's populated width so the search box keeps the same size
     whether or not there are results (empty state just shows blank here). */
  min-width: 190px;
}
@media (max-width: 560px) {
  .opening-explorer-page .oe-meta {
    min-width: 0;
  }
}
.opening-explorer-page .oe-meta-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.opening-explorer-page .oe-count {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  color: var(--gold);
  white-space: nowrap;
}
.opening-explorer-page .oe-count[hidden] {
  display: none;
}
.opening-explorer-page .oe-pagenum {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: var(--muted);
  white-space: nowrap;
}
.opening-explorer-page .oe-pagenum[hidden] {
  display: none;
}
.opening-explorer-page .oe-pager {
  flex: 0 0 auto;
}
.opening-explorer-page .oe-pager .oe-pagination {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.opening-explorer-page .oe-pager .games-page-side {
  display: inline-flex;
  gap: 6px;
}
.opening-explorer-page .oe-pager .games-page-status {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 2px;
}
.opening-explorer-page .oe-pager .games-page-link {
  min-width: 30px;
  min-height: 30px;
  padding: 0 6px;
}
/* Compact games list: a lighter, Lichess-style view (players + result · year,
   click a row for full detail) instead of the wide /game-search table. The list
   is a bounded scroll box so results never run the whole page down. */
.opening-explorer-page #oe-results {
  margin-top: 18px;
  padding-top: 0;
  border-top: 0;
}
.opening-explorer-page #oe-results:empty {
  display: none;
}
/* Status line is only for transient/empty messages now (Searching…, errors);
   collapse it when blank so it never eats a row above the results. */
.opening-explorer-page #oe-status:empty {
  display: none;
  margin: 0;
}
.opening-explorer-page .oe-games {
  max-height: min(460px, 62vh);
  overflow-y: auto;
  border: 1px solid rgba(0, 200, 255, 0.22);
  background: rgba(0, 12, 22, 0.35);
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 200, 255, 0.4) transparent;
}
.opening-explorer-page .oe-games::-webkit-scrollbar {
  width: 9px;
}
.opening-explorer-page .oe-games::-webkit-scrollbar-thumb {
  background: rgba(0, 200, 255, 0.3);
}
.opening-explorer-page .oe-games::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 200, 255, 0.5);
}
/* Two-column layout: keep the results column level with the fixed board so its
   bottom lines up with the board's instead of running taller and leaving a gap
   underneath. The board itself is untouched. Stacked layout (<=900px) keeps
   the taller scroll list. */
@media (min-width: 901px) {
  .opening-explorer-page .oe-results-col {
    display: flex;
    flex-direction: column;
    height: var(--oe-board-size);
    /* Height is pinned to the board's real height in JS (syncHeight) so the
       games box fills exactly, whatever size the board renders at. */
  }
  .opening-explorer-page .oe-results-col #oe-results {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }
  .opening-explorer-page .oe-results-col .oe-games {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
  .opening-explorer-page .oe-results-col .oe-pagination {
    flex: 0 0 auto;
  }
}
.oe-game {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  border-bottom: 1px solid rgba(0, 200, 255, 0.1);
  text-decoration: none;
  font-family: 'Share Tech Mono', monospace;
  transition: background 0.14s ease;
}
.oe-game:last-child {
  border-bottom: 0;
}
.oe-game:hover,
.oe-game:focus-visible {
  background: rgba(0, 200, 255, 0.07);
  outline: none;
}
.oe-game-players {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}
.oe-game-name {
  color: var(--cyan);
}
.oe-game:hover .oe-game-name {
  color: var(--white);
}
.oe-game-vs {
  color: var(--muted);
  margin: 0 6px;
}
.oe-game-meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  white-space: nowrap;
}
.oe-game-result {
  color: var(--data-secondary);
}
.oe-game-dot {
  color: var(--muted);
}
.oe-game-year {
  color: var(--gold);
}
/* Skeleton loader: shown in the games box while a player/position query is in
   flight so a slow lookup reads as loading, not broken. Mirrors the real
   .oe-games row geometry; clips overflow so the filler rows never scroll. */
.oe-games--skeleton {
  overflow: hidden;
}
.oe-game--skeleton {
  pointer-events: none;
  align-items: center;
}
.oe-skel {
  display: inline-block;
  height: 0.82rem;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    rgba(0, 200, 255, 0.08) 0%,
    rgba(0, 200, 255, 0.2) 50%,
    rgba(0, 200, 255, 0.08) 100%
  );
  background-size: 200% 100%;
  animation: oe-skel-shimmer 1.2s ease-in-out infinite;
}
.oe-skel-players {
  flex: 1 1 auto;
  max-width: 62%;
}
.oe-game--skeleton:nth-child(3n) .oe-skel-players {
  max-width: 50%;
}
.oe-game--skeleton:nth-child(3n + 1) .oe-skel-players {
  max-width: 70%;
}
.oe-skel-meta {
  flex: 0 0 auto;
  width: 58px;
}
@keyframes oe-skel-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .oe-skel {
    animation: none;
  }
}
.opening-explorer-page .oe-pagination {
  /* Pager now sits as a toolbar row above the games box. */
  margin: 0 0 12px;
}
.opening-explorer-page .oe-pagination .games-page-link {
  background: rgba(2, 8, 13, 0.82);
  cursor: pointer;
}
.opening-explorer-page .header-name {
  font-size: clamp(2.2rem, 6vw, 4.3rem);
}
@media (min-width: 600px) {
  .opening-explorer-page .header-name {
    white-space: nowrap;
  }
}
/* ============================================================================
   Opening Explorer — mobile layout (Android/iOS user agents only)
   Gated on the server-set body.oe-mobile class, NOT a viewport width query, so
   none of these rules can ever reach the desktop layout: a Windows/Mac/Linux
   UA never carries the class, at any window size. The board stays finger-sized,
   the search + colour toolbar lifts above it (moved in JS), and the results
   live in a Maps-style bottom sheet that drags up over the board.
   ========================================================================== */
/* Trim the page chrome so the board clears the half-open sheet. */
body.oe-mobile .stats-header { margin-bottom: 6px; }
body.oe-mobile .opening-explorer-page.header-name,
body.oe-mobile .opening-explorer-page .header-name { font-size: 1.85rem; }
body.oe-mobile.opening-explorer-page .page {
  --oe-board-min: 300px;
  --oe-board-size: min(340px, calc(100vw - 24px));
}
/* Stack the (JS-reordered) toolbar above the board; the old results column is
   now empty because its contents moved into the sheet. */
body.oe-mobile .oe-layout { display: block; }
body.oe-mobile .oe-results-col { display: none; }
body.oe-mobile .oe-board-col { align-items: center; margin-top: 4px; }
body.oe-mobile .oe-query { margin: 0 0 12px; }
body.oe-mobile .oe-player-input { flex: 1 1 auto; width: auto; }
body.oe-mobile .oe-result-select { flex-basis: 78px; width: 78px; padding-left: 7px; }
/* Move-navigation arrows below the board. The game-viewer's first/prev/next/last
   buttons are moved here from the hidden scaffold (opening-explorer-board.ts) so
   a phone user can step through the line with no keyboard. Spans the board width;
   buttons flex to fill and are finger-sized. */
body.oe-mobile .oe-move-nav {
  display: flex;
  gap: 8px;
  width: min(340px, calc(100vw - 24px));
  margin-top: 10px;
}
body.oe-mobile .oe-move-nav .btn-node {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  font-size: 20px;
}
body.oe-mobile .oe-move-nav .oe-reset-button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
}
/* Drop the panel's framed box on mobile: with the results in the sheet the
   panel only wraps the toolbar + board, and the desktop border/background would
   otherwise run the full page height behind the fixed sheet. */
body.oe-mobile .oe-panel {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 6px 12px 16px;
}

/* ---- the sheet ---- */
body.oe-mobile .oe-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200; /* above page content, below the site nav (1000+) */
  height: 88vh;
  display: flex;
  flex-direction: column;
  background: rgba(3, 10, 16, 0.97);
  border-top: 1px solid rgba(0, 200, 255, 0.4);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.55);
  /* Default collapsed to a peek (grip + count row stay on-screen, ~64px) so the
     sheet is always grabbable. The controller opens it to half when results
     arrive; the user can drag between peek, half, and full either way. The 64px
     here must match SHEET_PEEK_PX in opening-explorer-board.ts. */
  transform: translateY(calc(100% - 64px));
  transition: transform 0.28s ease;
  will-change: transform;
}
body.oe-mobile .oe-sheet[data-snap="peek"] { transform: translateY(calc(100% - 64px)); }
body.oe-mobile .oe-sheet[data-snap="half"] { transform: translateY(50%); }
body.oe-mobile .oe-sheet[data-snap="full"] { transform: translateY(0); }
/* Grip + head own the drag; the body scrolls the list independently. */
body.oe-mobile .oe-sheet-grip {
  flex: 0 0 auto;
  height: 24px;
  position: relative;
  cursor: grab;
  touch-action: none;
}
body.oe-mobile .oe-sheet-grip::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  width: 42px;
  height: 4px;
  margin-left: -21px;
  border-radius: 2px;
  background: rgba(0, 200, 255, 0.55);
}
body.oe-mobile .oe-sheet-head {
  flex: 0 0 auto;
  padding: 0 14px 10px;
  touch-action: none;
}
body.oe-mobile .oe-sheet-head .oe-meta {
  min-width: 0;
  width: 100%;
  justify-content: space-between;
}
body.oe-mobile .oe-sheet-head .oe-meta-text { align-items: flex-start; }
body.oe-mobile .oe-sheet-head .games-page-link { min-width: 40px; min-height: 40px; }
body.oe-mobile .oe-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 24px;
}
/* Inside the sheet the games box fills and scrolls with the body — drop the
   desktop inner-scroll cap so there's no nested scroll trap. */
body.oe-mobile .oe-sheet-body #oe-results { margin-top: 0; }
body.oe-mobile .oe-sheet-body .oe-games {
  max-height: none;
  border: 0;
  background: transparent;
}
@media (prefers-reduced-motion: reduce) {
  body.oe-mobile .oe-sheet { transition: none; }
}
