/* JoyPanel — console shell (the public web-console site).
 *
 * Split from style.css: everything page-specific lives here.
 * Shared foundation (tokens, base, .pill) lives in ui.css —
 * load ui.css FIRST, then this file. Rules below are unchanged.
 */

/* ---------- console viewport shell ---------- */
body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body[data-grid="1"] { --card: 128px; }
body[data-grid="2"] { --card: 256px; }
body[data-grid="3"] { --card: 384px; }
body[data-grid="4"] { --card: 512px; }

/* ---------- topbar ---------- */
/* (.topbar/.brand/.brand-logo live in ui.css — shared with admin) */
:root:fullscreen { background: var(--bg); }
.pad-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--sub);
  font-size: var(--fs-s);
  white-space: nowrap;
}
.pad-status.on { color: var(--focus); }
#padIcon { width: var(--ico); height: var(--ico); opacity: 1; image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- shoulders: see css/hints.css (button + icon colors live there) ---------- */
/* ---------- main split ---------- */
.shelf-layout { flex: 1 1 auto; display: flex; align-items: stretch; min-height: 0; min-width: 0; }
.shelf-wrap { flex: 1 1 auto; min-width: 0; min-height: 0; padding: var(--gutter); overflow-y: auto; }

/* ---------- grid + cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--card));
  /* centered: equal air on both sides (last row centers too) */
  justify-content: center;
  gap: 20px var(--card-gap);
}
.card {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  /* content starts at the top: every thumb is 1:1, so the thumbs drive the
     row alignment — a 3-line title never pushes a card's image down
     (a button otherwise centers its content vertically) */
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  /* nav uses scrollIntoView({block:"nearest"}): keep the shelf's gutter
     around the focused card, so the top row still shows its air + focus
     outline and the bottom stops at the padding — never past it. */
  scroll-margin-block: var(--gutter);
}
.card-thumb {
  display: block;
  position: relative;
  isolation: isolate;
  line-height: 0;
}
.card-thumb .thumb-main {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  position: relative;
  z-index: 1;
  background: var(--line);
}
/* glow copy: same image behind with a saturated, bright glow.
   Only visible on the selected card — picks up the image's own colors. */
.card-thumb .thumb-glow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 0;
  pointer-events: none;
  image-rendering: auto;
  filter: brightness(2) saturate(20) blur(30px);
  opacity: 0;
  visibility: hidden;
  transform: scale(1.1);
  /* slow fade-out when selection leaves the card —
     visibility flips only once opacity hits bottom,
     otherwise the fade-out is cut off instantly */
  transition: opacity 1s ease, visibility 0s linear 1s;
}
.card.focused { position: relative; z-index: 2; }
.card.focused .thumb-glow {
  opacity: 0.4;
  visibility: visible;
  /* fast fade-in when the card is selected (your tuned 0.1s),
     visibility flips immediately */
  transition: opacity 0.1s ease, visibility 0s;
}
/* selected image: raw accent outline (same true genre color as PLAY/pills,
   not the white-lifted accent-ink the text uses) + 1px radius */
.card.focused .thumb-main {
  outline: 4px solid var(--accent);
  outline-offset: 4px;
  border-radius: 1px;
}
.card-meta { padding: 14px 6px 16px; }
.card-title { font-size: var(--fs-m); line-height: var(--lh-loose); overflow-wrap: anywhere; }
.card-author { color: var(--sub); font-size: var(--fs-m); }
/* 1x thumbs (128px): only the text under the thumbnails steps down a size,
   so the small cards stay readable without crowding the image. */
body[data-grid="1"] .card-title,
body[data-grid="1"] .card-author { font-size: var(--fs-s); }

/* hover is visual only — never moves focus/preview.
   Selected card = glow copy behind the image, no background on text. */
.sentinel { height: 2px; }

/* ---------- empty genre ---------- */
.empty { padding: 80px 20px; text-align: center; }
.empty-title { font-family: var(--font-pixel); font-size: var(--fs-s); color: var(--sub); }
.empty-sub { color: var(--faint); }

/* ---------- preview ---------- */
.preview {
  flex: 0 0 var(--preview-w);
  width: var(--preview-w);
  min-width: 384px;
  max-width: min(720px, 50vw);
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-self: stretch;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* splitter between shelf and preview (JS writes px into --preview-w).
   The splitter line is the only divider here. */
.preview-splitter {
  flex: none;
  width: 14px;
  margin-left: -7px;
  margin-right: -7px;
  z-index: 5;
  cursor: ew-resize;
  touch-action: none;
  position: relative;
  background: transparent;
}
.preview-splitter::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 6px;
  width: 1px;
  background: var(--line);
}
.preview-splitter:hover::before,
.preview-splitter.dragging::before,
.preview-splitter:focus-visible::before { background: var(--action); }

.preview-media {
  line-height: 0;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 0;
}
.preview-media img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: transparent;
  will-change: opacity;
  cursor: pointer;
}
/* soft gradient at the bottom of the image — appears on scroll (JS sets --pv-shade 0..1) */
.preview-media::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--bg) 90%, transparent));
  opacity: var(--pv-shade, 0);
  pointer-events: none;
}

/* text layer slides up over the pinned image — no box, no border */
.preview-body {
  position: relative;
  z-index: 1;
  background: transparent;
  border-top: 0;
  padding-bottom: var(--gutter);
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
}

/* all text below the image keeps its indent — one place */
.preview-title, .preview-by, .preview-pills, .preview-desc, .preview-thread, .preview-socials, #adminEdit { margin-inline: var(--gutter); }
.preview-pills, .preview-desc { margin-top: 12px; }
.preview-thread { margin-top: auto; padding-top: var(--fs-s); }
/* social links: stacked one per line under the thread link, same style */
.preview-socials { display: flex; flex-direction: column; gap: var(--fs-xs); margin-top: var(--fs-s); }
.preview-socials:empty { margin-top: 0; }

/* PLAY: standard .btn + preview placement (bottom-right over the
   image). All visuals come from .btn — position only here; icon colors
   live in css/hints.css. */
.preview .play-btn {
  z-index: 2;
  position: relative;
  align-self: flex-end;
  margin: -24px calc(var(--gutter) / 2) 12px 0;
}

.preview-title {
}
@media (min-width: 1400px) {
  .preview-title { font-size: var(--fs-xl); }
}
.preview-by { color: var(--accent-ink); font-size: var(--fs-m); }
/* by-line links (author + license) inherit the line's genre color — no inline styles. */
.by-link { color: inherit; text-decoration: none; }
.preview-pills { display: flex; flex-wrap: wrap; gap: 10px; }
.preview-desc { font-size: var(--fs-m); line-height: var(--lh-body); }
.preview-thread, .social-link { color: var(--link); font-size: var(--fs-m); }
/* icon+label links: underline on the text itself — not under the icon/gap.
   The ↗ arrow sits outside the span, so it never underlines. Hover drops
   the underline (same feel as the hint links). */
.preview-thread, .player-thread, .social-link { text-decoration: none; }
.preview-thread span, .player-thread span, .social-link span, .by-link span { text-decoration: underline; }
.preview-thread:hover span, .player-thread:hover span, .social-link:hover span, .by-link:hover span { text-decoration: none; }

/* empty shelf: preview collapses to a single message */
.preview.is-empty { justify-content: center; }
.preview.is-empty :is(.preview-media, .play-btn, .preview-by, .preview-pills, .preview-desc, .preview-thread, .preview-socials, #adminEdit) { display: none; }
.preview.is-empty .preview-body { background: transparent; border-top: 0; padding-bottom: 0; }
.preview.is-empty .preview-title { text-align: center; font-size: var(--fs-s); line-height: var(--lh-loose); color: var(--sub); }

/* ---------- helpbar: see css/hints.css (all hint rows live there) ---------- */

/* ---------- player overlay: game left, minimal side right ---------- */
.player {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: row;
  overflow: hidden;
  z-index: 50;
}
.player.hidden { display: none; }
.player-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
}
.player-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.player-stage .loading {
  color: var(--sub);
  font-family: var(--font-pixel);
  font-size: var(--fs-s);
  letter-spacing: 1px;
  position: absolute;
}
/* The game runs in same-origin player.html — the iframe fills the stage,
   and the parent page never navigates (fullscreen survives cart switches). */
.game-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg);
  cursor: none;
}
/* side panel: info top, guides bottom */
.player-side {
  flex: 0 0 360px;
  width: 360px;
  max-width: 32vw;
  border-left: var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.player-side-top {
  padding: 0 0 var(--gutter);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.player-media { line-height: 0; background: var(--bg); position: relative; }
.player-media img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--bg);
  image-rendering: pixelated;
}
/* close button: top-right, left of the edge, over the thumbnail */
.player-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  font-family: var(--font-pixel);
  font-size: var(--fs-s);
  line-height: 1;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--ink);
  border: var(--border);
  cursor: pointer;
}
.player-close:hover { background: var(--ink); color: var(--bg); }
.player-title { font-family: var(--font-pixel); font-size: var(--fs-m); line-height: var(--lh-tight); margin: var(--gutter) var(--gutter) 0; overflow-wrap: anywhere; }
.player-by { color: var(--sub); font-size: var(--fs-s); margin: 12px var(--gutter) 0; }
.player-pills { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px var(--gutter) 0; }
.player-thread { margin: 12px var(--gutter) 0; }
.player-side-bottom {
  margin-top: auto;
  border-top: var(--border);
  padding: var(--gutter);
}
/* (stacked hint rows: see css/hints.css — .helpbar--stacked lives there) */

/* ---------- responsive ---------- */
/* The shelf ALWAYS stays side-by-side (grid left, preview right) —
   even in narrow windows. The touch-warn banner is the "mobile sign",
   not a stacked layout. The splitter stays visible so the preview
   can shrink to 384px; JS temporarily shrinks thumbs on resize
   when space runs out (the user's 1-4 choice is preserved). */
@media (max-width: 1100px) {
  /* player stacks: game on top, side below */
  .player { flex-direction: column; overflow-y: auto; }
  .player-main { min-height: 62vh; flex: none; }
  .player-side { flex: none; width: auto; max-width: none; border-left: 0; border-top: var(--border); }
  .player-media img { max-width: 320px; }
}
@media (max-width: 760px) {
  :root { --gutter: 20px; --card-gap: 24px; }
  /* Thumbs are ALWAYS driven by --card (128px is the floor) — no fluid
     columns here; if the shelf is narrower than one card, it scrolls. */
}
@media (prefers-reduced-motion: reduce) {
  .card-thumb .thumb-glow,
  .card.focused .thumb-glow { transition: none; }
  .genre-nav-inner { transition: none; }
  .genre-nav .genre, .genre-icon { transition: none; }
  .genre-nav .genre:hover .genre-icon, .genre-nav .genre.active .genre-icon { transform: none; }
}

/* ============================================================
   RAIL NAVIGATION (active in index.php)
   Collapsible genre rail: icon column in flow (var(--rail-w)), expanded
   text-wide drawer as overlay with dropshadow. Icons sit 100% in the
   same spot in both states (left, --rail-pad).
   ============================================================ */
:root {
  --rail-w: 64px;
  --rail-open-w: 272px; /* min width; longest label wins via max-content */
  --rail-ico: 16px; /* icon box (square — position measured on the edge) */
  --rail-pad: calc((var(--rail-w) - var(--rail-ico)) / 2); /* icon indent, both states */
}

/* ---------- touch/small-screen warning: hidden on desktop ---------- */
.touch-warn {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--fs-s) var(--gutter);
  background: var(--pico-orange);
  color: var(--pico-black);
  font-family: var(--font-pixel);
  font-size: var(--fs-s);
  line-height: var(--lh-loose);
  cursor: pointer;
}
/* coarse pointer (touch) or narrow viewport = show the warning */
@media (pointer: coarse), (max-width: 760px) {
  .touch-warn { display: flex; }
}

/* ---------- main row: rail + layout side by side ---------- */
.main-row {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  min-height: 0;
  min-width: 0;
  position: relative;
}
/* (inner layout uses base .shelf-layout — no override needed) */

/* ---------- rail: 60px in flow, open menu is an overlay over the shelf ---------- */
/* (overlay with dropshadow — the shelf never reflows, the shelf gutter is
   untouched; the drawer only covers the left side while open) */
.genre-nav {
  flex: none;
  width: var(--rail-w);
  position: relative;
  z-index: 30;
  background: var(--bg);
}
.genre-nav-inner {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: var(--border);
  overflow: hidden;
  transition: width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.22s ease;
}
.genre-nav.open .genre-nav-inner,
.genre-nav.peek .genre-nav-inner {
  /* width follows the text (longest label wins), min = old
     drawer, max = guard against absurd widths */
  width: max-content;
  min-width: var(--rail-open-w);
  max-width: min(480px, 72vw);
  box-shadow: 12px 0 0 color-mix(in srgb, var(--pico-black) 55%, transparent);
}

/* shoulders in rail: up/down instead of left/right, accent hint.
   Q/E always aligns left with the genre icons (same indent).
   The chip inherits the accent color but keeps the footer size (10px):
   hint buttons measure the same everywhere — the footer is the reference. */
.genre-nav .shoulder {
  min-height: 44px;
  align-self: stretch;
  justify-content: flex-start;
  padding-left: var(--rail-pad);
}

/* genre buttons: flex-distributed across the rail height so all 15 stay visible */
.genre-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--fs-s) 0;
}
.genre-nav .genre {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--fs-s);
  padding: 4px var(--rail-pad);
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--font-pixel);
  font-size: var(--fs-m);
  /* base .genre.active has a 4px underline — it doesn't belong in the rail */
  text-decoration: none;
  color: var(--gc, var(--faint));
  transition: background-color 0.18s ease, color 0.18s ease;
}
.genre-nav .genre:hover { color: var(--accent); text-decoration: none; }
.genre-nav .genre.active {
  color: var(--accent);
  text-decoration: none;
  background: transparent;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.genre-nav .genre.active .genre-icon { opacity: 1; }
/* keyboard focus in the rail: same genre color as active — no white inversion.
   (Open rail + active marker already show where you are.) */
.genre-icon {
  flex: none;
  width: var(--rail-ico);
  height: var(--rail-ico);
  object-fit: contain;
  object-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  opacity: 1;
  transition: transform 0.18s ease;
}
/* label + count only visible when the rail is open/peek */
.genre-nav .genre-label,
.genre-nav .genre-count { display: none; }
.genre-nav.open .genre-label,
.genre-nav.peek .genre-label { display: inline; overflow: hidden; text-overflow: ellipsis; }
.genre-nav.open .genre-count,
.genre-nav.peek .genre-count {
  display: inline;
  margin-left: auto;
  /* body font with normal smoothing: base .genre disables smoothing,
     and it inherits down — otherwise the numbers render pixelated. */
  font-family: var(--font-body);
  font-size: var(--fs-s);
  -webkit-font-smoothing: antialiased;
  font-smooth: auto;
  color: var(--sub);
}
.genre-nav .genre.active .genre-count { color: var(--accent); }

/* Genre colors: PICO-8 standard palette in order across the
   alphabetical list. Black is the background, so slot 0 (all) renders
   as white instead. Hover/active stays white for legibility. */
.genre-nav .genre[data-gen="all"] { --gc: var(--pico-white); }
.genre-nav .genre[data-gen="adventure"] { --gc: var(--pico-dark-blue); }
.genre-nav .genre[data-gen="arcade"] { --gc: var(--pico-dark-purple); }
.genre-nav .genre[data-gen="cozy"] { --gc: var(--pico-pink); }
.genre-nav .genre[data-gen="fighting"] { --gc: var(--pico-brown); }
.genre-nav .genre[data-gen="platformer"] { --gc: var(--pico-light-grey); }
.genre-nav .genre[data-gen="puzzle"] { --gc: var(--pico-white); }
.genre-nav .genre[data-gen="racing"] { --gc: var(--pico-red); }
.genre-nav .genre[data-gen="roguelike"] { --gc: var(--pico-orange); }
.genre-nav .genre[data-gen="rpg"] { --gc: var(--pico-yellow); }
.genre-nav .genre[data-gen="shooter"] { --gc: var(--pico-green); }
.genre-nav .genre[data-gen="simulator"] { --gc: var(--pico-blue); }
.genre-nav .genre[data-gen="sports"] { --gc: var(--pico-indigo); }
.genre-nav .genre[data-gen="strategy"] { --gc: var(--pico-dark-green); }
.genre-nav .genre[data-gen="survivors"] { --gc: var(--pico-peach); }

/* short windows: internal scroll instead of squeezed buttons.
   Icons go from 3x to 2x so all 15 buttons can still show. */
@media (max-height: 720px) {
  :root { --rail-ico: 16px; }
  .genre-list { overflow-y: auto; }
  .genre-nav .genre { flex: none; min-height: 44px; }
}

/* ============================================================
   FULL ACCENT: all text + hints follow the active genre via
   accent-ink (accent lifted toward white so dark genres stay legible).
   Focus (ring, outline, inversion) stays deliberately white.
   ============================================================ */
.brand,
.card-title, .card-author,
.preview-title, .preview-by, .preview-desc,
.player-title, .player-by,
.helpbar, .helpbar .hint-link, .hint-label,
.pad-status, .pad-status.on,
.empty-title, .empty-sub,
.player-stage .loading,
.nav-link, .preview-thread, .player-thread, .social-link { color: var(--accent-ink); }
.player-close { color: var(--accent-ink); }
.player-close:hover { background: var(--accent); color: var(--on-accent); }

/* --- embed mode: only the preview panel (used by /prep.php iframe) --- */
body:not(.game-admin).is-embed .genre-nav,
body:not(.game-admin).is-embed .shelf-wrap,
body:not(.game-admin).is-embed .preview-splitter { display: none; }
body:not(.game-admin).is-embed .shelf-layout { display: block; }
body:not(.game-admin).is-embed .main-row { display: block; }
body:not(.game-admin).is-embed .preview { width: 100%; max-width: none; border-left: 0; }
