/* legacy-adapt.css — γεφυρώνει το markup που παράγει το content.php (tpl4
   data path) με το design του Σταύρου (styles.css). Το tpl4 renderer βγάζει
   κάρτες ".gll > a.li.gthli > img + .ti(.rdr.rd2 + .na)"· εδώ τις κάνουμε να
   μοιάζουν με τις ".card" του Σταύρου, χωρίς να αγγίξουμε PHP. Χρησιμοποιεί τα
   :root variables του styles.css. (Βάση tpl4 — τα game links δουλεύουν σωστά.) */

/* ---------- Responsive game grid (tpl4 .gll cards) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  padding: 8px 2px 4px;
}
.grid.similar { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

/* Game cards (.gll) inside a horizontal .rail (home category / new-games rails):
   fixed width so they scroll horizontally like Stavros's .card rails. */
.rail > .gll { width: 180px; flex-shrink: 0; }

/* Hide the top leaderboard banner ONLY on the home page (index.php is shared by
   home + category + newgames + popular). data-home is set pre-paint by the header
   inline script when pathname is '/'. */
:root[data-home="1"] .ad-leaderboard { display: none; }

/* Plain list pages (/newgames/, /popular/): hide the top leaderboard banner and
   show 8 games per row, like the category pages. (data-plainlist set pre-paint.) */
:root[data-plainlist] .ad-leaderboard { display: none; }
:root[data-plainlist] .home-all-games .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
@media (max-width: 1100px) { :root[data-plainlist] .home-all-games .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 820px)  { :root[data-plainlist] .home-all-games .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 540px)  { :root[data-plainlist] .home-all-games .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Home: the flat "All Games" grid is redundant (the rails cover it). Hide on home
   only; category/newgames/popular (shared index.php) keep it. The top-grid JS still
   reads its cards (display:none stays in the DOM). */
:root[data-home="1"] .home-all-games { display: none; }

/* ---------- Rail scroll arrows: always visible when scrollable (not hover-only),
   positioned just inside the edges so they're never clipped. .hidden = at edge.
   Applies to game rails, the category-tiles rail AND the top-grid. ---------- */
/* ---------- Pagination (.pgr — engine createPagingTPL4) ----------
   The engine marks the current page with a.sel; give the pager real styling
   so you can SEE which page you're on (accent pill) at a glance. */
.pgr {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 26px 0 12px;
}
.pgr span { display: contents; }
.pgr a {
  min-width: 40px; height: 40px; padding: 2px 12px 0;   /* +2px: digits have no
  descenders, so true centring reads as "too high" — nudge them down optically */
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid #ffffff14; border-radius: 12px;
  color: var(--text); font-size: 14px; font-weight: 700; line-height: 1;
  transition: background .15s;
}
.pgr a:hover { background: var(--surface-3); }
.pgr a.sel {
  background: var(--accent); border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px -6px var(--accent); pointer-events: none;
}

.rail-arrow { opacity: 1; top: 44%; width: 40px; height: 40px; }
.rail-wrap:hover .rail-arrow { opacity: 1; }
.rail-arrow.left { left: 4px; }
.rail-arrow.right { right: 4px; }
.rail-arrow.hidden { opacity: 0 !important; pointer-events: none; }
.rail-arrow svg { width: 20px; height: 20px; fill: none; }
.top-grid + .rail-arrow, .rail-wrap > .top-grid { }  /* top-grid uses the same .rail-wrap */

/* ---------- Back to top (floating, appears on scroll) ---------- */
.to-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  width: 50px; height: 50px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer;
  box-shadow: 0 12px 28px -6px var(--accent), 0 4px 12px #00000066;
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(.85);
  transition: opacity .25s ease, transform .25s ease, visibility .25s, box-shadow .2s;
}
.to-top.show { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { transform: translateY(-4px) scale(1.08); box-shadow: 0 18px 38px -6px var(--accent), 0 8px 16px #00000077; }
.to-top:active { transform: translateY(-1px) scale(1.02); }
.to-top svg { width: 24px; height: 24px; fill: #fff; }
@media (max-width: 560px) { .to-top { right: 14px; bottom: 14px; width: 46px; height: 46px; } }

/* Sidebar open = PUSH the content right, don't SHRINK it. The main column keeps a
   fixed width (flex-basis = space next to the collapsed rail, flex-shrink:0), so
   when the sidebar widens it pushes main right instead of squeezing the cards; the
   overflow is clipped (overflow-x:clip keeps position:sticky working, unlike hidden). */
.layout { overflow-x: clip; }
.main { flex: 0 0 calc(100% - var(--rail-w)); min-width: 0; }

.gll { width: auto; list-style: none; }
.gll > a.li {
  display: block; color: inherit; text-decoration: none;
  position: relative;
  /* round only the TOP corners: the title sits inside a.li, so rounding the
     bottom corners + overflow:hidden was clipping the first/last letters. */
  border-radius: var(--radius) var(--radius) 0 0; overflow: hidden;
}
/* thumbnail — all four corners rounded (title sits below the img, not affected) */
.gll > a.li > img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px -10px #00000080;
  transition: transform .28s ease;
}
.gll:hover > a.li > img { transform: scale(1.08); }
/* hover overlay + play glyph (no extra markup). It tracks the IMAGE box exactly:
   same aspect-ratio as the img (not "100% minus a fixed title height", which
   left an undarkened strip at the image bottom — visible now that all four
   corners are rounded) and the same full border-radius. */
.gll > a.li::after {
  content: "";
  position: absolute; left: 0; top: 0; width: 100%;
  aspect-ratio: 4 / 3; height: auto;
  background: rgba(10, 6, 24, .40)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E")
    center / 46px 46px no-repeat;
  opacity: 0; transition: opacity .2s ease, transform .28s ease; pointer-events: none;
  border-radius: var(--radius);
}
/* The img zooms (scale 1.08) on hover — the overlay must zoom WITH it, or the
   scaled image pokes out below the darkening (the "gap" under the photo). */
.gll:hover > a.li::after { opacity: 1; transform: scale(1.08); }
/* title bar */
.gll .ti { display: block; margin-top: 9px; padding: 0 3px; }
.gll .ti .na {
  display: block; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
/* rating pill (top-right on the thumb) */
.gll .ti .rdr {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: rgba(10,6,24,.72); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 999px;
}

/* ---------- Sidebar categories from [%TPL4_SIDE_CATS%] (<li><a>) ---------- */
.side-cats { list-style: none; margin: 0; padding: 0; }
.side-cats li { list-style: none; }
.side-cats li > a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 2px 0; border-radius: 10px;
  color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden;
}
.side-cats li > a:hover { background: var(--surface); color: var(--text); }
.side-cats li p { margin: 0; }   /* subcat rows */
.side-cats li p a { color: var(--muted); font-size: 13px; }
/* category icon (added by app.js) — always visible, incl. collapsed rail */
.side-cats li > a .cat-ic { min-width: 22px; width: 22px; text-align: center; font-size: 17px; line-height: 1; flex-shrink: 0; }
.sidebar:not(.open) .side-cats li > a { justify-content: center; }
.sidebar:not(.open) .side-cats li > a span:not(.cat-ic) { display: none; }

/* Category page (.crumbs / .cat-hero / .toolbar / .sort-chip) uses Stavros's
   styles.css verbatim — no overrides here (an old override used to fight it and
   broke the spacing above/below the sort filters). */

/* Subcategory pills (moved out of the sidebar) — sit just below the sort filters. */
.subcat-bar { display: flex; flex-wrap: wrap; gap: 9px; margin: 0 0 24px; }
.subcat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid #ffffff14;
  color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 8px 15px; border-radius: 999px; white-space: nowrap;
  transition: color .16s ease, background .16s ease, border-color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.subcat-chip::before { content: "#"; opacity: .55; font-weight: 800; }
.subcat-chip:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  transform: translateY(-2px); box-shadow: 0 9px 22px -8px var(--accent);
}
.subcat-chip:hover::before { opacity: .85; color: #fff; }
:root[data-theme="light"] .subcat-chip { border-color: #00000014; }

/* Category grid: exactly 8 games per row. minmax(0,1fr) (not 1fr) so long nowrap
   game titles can't blow out the column widths / clip the last card off-screen. */
.grid.cat-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.cat-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 820px)  { .grid.cat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 540px)  { .grid.cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Paging (createPagingTPL4 = .pgr > span > a) ---------- */
.pgr, .pager .pgr { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 20px 0 8px; }
.pgr span { list-style: none; }
.pgr span a, .pgr a {
  display: inline-block; min-width: 38px; text-align: center;
  padding: 8px 12px; border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px;
}
.pgr span a:hover { background: var(--surface-3); }
.pgr .active a, .pgr span.sel a { background: var(--accent); }

/* ---------- Game stage mount (faithful tpl4 #gmfr inside styles.css .player) ----------
   styles.css already defines .game-layout / .player / .game-bar / .about / .game-side.
   Here we only make the legacy tpl4 game markup fill the .player box. game.js.php's
   showGame() injects the game into #gmfr; we force it (and its iframe/embed) to 100%. */
/* Sizing model = NATIVE game height. #gmfr gets its per-game height in px from
   [%GAME_OBJ_DETAILS%] (e.g. height:704px); .player wraps it (no aspect-ratio,
   no percentage-height chain — those break under aspect-ratio boxes). The game
   iframe/embed then fills #gmfr full-width. */
.player { aspect-ratio: auto !important; height: auto !important; background: #000; }
.player #game-wrapper, .player #gamearea, .player #gamearea-inner {
  position: static !important; width: 100% !important; height: auto !important;
  margin: 0 !important; padding: 0 !important; min-width: 0 !important; float: none !important; display: block;
}
.player #gmfr {                 /* height supplied inline by GAME_OBJ_DETAILS */
  width: 100% !important; margin: 0 auto !important; background: #000; display: block; min-height: 360px;
}
.player #gmfr > div { width: 100% !important; height: 100% !important; margin: 0 !important; }
.player #gmfr iframe, .player #gmfr embed, .player #gmfr object,
.player #gmfr canvas, .player #gmfr ruffle-player {
  width: 100% !important; height: 100% !important; border: 0; display: block;
}
.player #afg { position: static; z-index: 4; }

/* Desktop: hold the game's NATIVE aspect ratio so narrowing the window scales the
   game down proportionally instead of clipping its sides. Fixed-pixel-height games
   (e.g. Coral Mystery 1024x576) otherwise keep rendering at native width and get
   cropped once the column is narrower than that. --gw/--gh are set by app10.js from
   the per-game data-gw/data-gh; the .has-aspect flag is only added when both are
   valid, so games without dimensions keep the native-height model. Scoped to
   >1024px — mobile has its own play-cover + fullscreen letterbox model. */
@media (min-width: 1025px) {
  .player.has-aspect #gmfr {
    aspect-ratio: var(--gw) / var(--gh);
    height: auto !important; min-height: 0 !important;
    /* Cap the stage to the VIEWPORT height too: 4:3 / portrait games at full
       column width came out taller than short laptop screens (e.g. mob-rush
       800x600 on a MacBook). min() picks the height-capped width when the
       full-width stage wouldn't fit vertically (~200px = header + game bar). */
    width: min(100%, calc((100dvh - 200px) * var(--gw, 16) / var(--gh, 9))) !important;
    margin: 0 auto !important;
  }
  /* Fixed-canvas games (fs=2, e.g. Hidden4Fun) REFUSE to play below their
     native size — under a threshold they hide the game behind a logo splash.
     So the iframe stays at NATIVE px (the game always "sees" e.g. 1024×576)
     and we shrink it VISUALLY with transform:scale (set as --gscale by
     app10.js from the stage width). Pointer coordinates map through CSS
     transforms, so the game stays fully playable at any window size. */
  .player[data-fs="2"] #gmfr { overflow: hidden; }
  .player[data-fs="2"] #gmfr iframe,
  .player[data-fs="2"] #gmfr embed,
  .player[data-fs="2"] #gmfr object,
  .player[data-fs="2"] #gmfr canvas,
  .player[data-fs="2"] #gmfr ruffle-player {
    width: calc(var(--gw, 16) * 1px) !important;
    height: calc(var(--gh, 9) * 1px) !important;
    transform: scale(var(--gscale, 1));
    transform-origin: 0 0;
  }
}

/* Pre-game splash (AFG video-ad path) — fills the stage, styled play button */
.player .pr-sp {
  position: absolute; inset: 0; width: 100% !important; height: 100% !important;
  display: flex; align-items: center; justify-content: center; z-index: 6; cursor: pointer;
}
.player .pr-sp-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(4px) brightness(.5); }
.player .pr-sp-bg-op { position: absolute; inset: 0; background: rgba(10, 6, 24, .55); }
.player .pr-sp-btn-c-bg { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; padding: 20px; }
.player .pr-sp-btn-c-bg .left img { width: 92px; height: 92px; border-radius: 20px; object-fit: cover; box-shadow: 0 12px 30px -8px #000; }
.player .pr-sp-btn-c-bg .right p { color: #fff; font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.player .js-pr-sp-play {
  display: inline-flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 16px; padding: 14px 34px; border-radius: 999px;
  box-shadow: 0 14px 34px -10px var(--accent);
}

/* Description / instructions / category pills inside styles.css .about */
.about .about-desc { color: #ded5ff; line-height: 1.7; font-size: 14.5px; }
.about .about-desc a, .about .pills a { color: var(--accent-2); }
.about .pills { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.about .pills a { background: var(--surface-2); border: 1px solid #ffffff14; padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.gb-btn.fs svg, .gb-btn svg { width: 17px; height: 17px; fill: currentColor; }
.gb-btn strong { color: var(--text); }
/* game title is now an <h1> (SEO) — keep the .gb-title look, drop default h1 margin */
h1.gb-title { margin: 0; }

/* ---------- Static pages / ads / misc ---------- */
.static-box { background: var(--surface); border-radius: var(--radius); padding: 22px; color: var(--text); line-height: 1.6; }
.static-box.center { text-align: center; }
.static-box.legal { color: var(--muted); }
.btn-more { display: inline-block; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 700; margin-top: 10px; }
.ad-slot { display: flex; align-items: center; justify-content: center; min-height: 90px; margin: 14px 0; background: #ffffff08; border: 1px dashed #ffffff1f; border-radius: 12px; color: var(--muted); font-size: 13px; overflow: hidden; }
.ad-slot:empty { display: none; }
.sr-title { position: absolute; left: -9999px; }
.foot-cats { }
.foot-cats li { list-style: none; }
.foot-cats li > a { display: block; color: var(--muted); padding: 3px 0; font-size: 14px; }
.foot-cats li > a:hover { color: var(--text); }

/* ============================================================
   THEME TOGGLE (dark = default blue/purple, light = white)
   Button in header; JS (app.js) sets data-theme="light" on <html>
   and persists to localStorage. Inline head script applies it pre-paint.
   ============================================================ */
.theme-btn { color: var(--text); }
.theme-btn .ic-sun { display: none; }
.theme-btn .ic-moon { display: block; }
:root[data-theme="light"] .theme-btn .ic-moon { display: none; }
:root[data-theme="light"] .theme-btn .ic-sun  { display: block; }
.theme-btn svg { width: 21px; height: 21px; }

/* ---- Light palette: override the :root variables ---- */
:root[data-theme="light"] {
  --bg-top:    #efe9fb;
  --bg-mid:    #e7dff7;
  --bg-bottom: #f1ecfb;
  --surface:   #ffffff;
  --surface-2: #f2eefb;
  --surface-3: #e7dff7;
  --text:      #221741;
  --muted:     #6a6291;
  --accent:    #7c3aed;
  --accent-2:  #8b5cf6;
  --new:       #0284c7;
  --top:       #d97706;
}

/* ---- Light: fix the hardcoded dark-assuming colours (header/footer/borders/
        subtle whites) that styles.css bakes in ---- */
:root[data-theme="light"] body { color: var(--text); }
:root[data-theme="light"] .header { background: rgba(255,255,255,.88); border-bottom-color: #0000000f; }
:root[data-theme="light"] .menu-btn,
:root[data-theme="light"] .icon-btn,
:root[data-theme="light"] .gb-btn,
:root[data-theme="light"] .btn-load,
:root[data-theme="light"] .sort-chip,
:root[data-theme="light"] .chip { background: #0000000a; }
:root[data-theme="light"] .menu-btn:hover,
:root[data-theme="light"] .icon-btn:hover { background: #00000014; }
:root[data-theme="light"] .menu-btn svg,
:root[data-theme="light"] .icon-btn svg,
:root[data-theme="light"] .theme-btn { fill: var(--text); color: var(--text); }
:root[data-theme="light"] .search { background: #00000008; border-color: #0000001c; }
:root[data-theme="light"] .search:focus-within { background: #0000000d; box-shadow: 0 0 0 3px #7c3aed33; }
:root[data-theme="light"] .search input { color: var(--text); }
:root[data-theme="light"] .search svg { fill: var(--muted); }
:root[data-theme="light"] .sidebar { border-right-color: #00000012; }
:root[data-theme="light"] .nav-item:hover { background: var(--surface-2); }
:root[data-theme="light"] .chip, :root[data-theme="light"] .sort-chip { border-color: #00000014; }
:root[data-theme="light"] .footer { background: #f2eefb; border-top-color: #00000010; }
:root[data-theme="light"] .footer .cols { border-bottom-color: #0000000f; }
:root[data-theme="light"] .about,
:root[data-theme="light"] .game-bar,
:root[data-theme="light"] .side-card { border-color: #0000000f; }
:root[data-theme="light"] .about .pills a { border-color: #00000014; }
:root[data-theme="light"] .card .thumb,
:root[data-theme="light"] .gll > a.li > img { background: var(--surface-2); }
:root[data-theme="light"] .ad-slot { border-color: #00000018; color: var(--muted); }
:root[data-theme="light"] .gll .ti .rdr { background: rgba(34,23,65,.72); }
