/* Portal styles. Mobile first. System fonts only (no downloads). */
:root {
  --bg: #f4f1ff;
  --surface: #ffffff;
  --ink: #1d1640;
  --muted: #5b537e;
  --brand: #3b2a8f;
  --brand-ink: #ffffff;
  --accent: #ffcf3f;
  --accent-ink: #2a1d00;
  --line: #e2dcf7;
  --chip: #ffffff;
  --chip-on: #3b2a8f;
  --shadow: 0 2px 0 rgba(59, 42, 143, 0.08), 0 6px 18px rgba(59, 42, 143, 0.08);
  --radius: 16px;
  --focus: #1d1640;
  --focus-gap: #ffcf3f;
  --tw: clamp(136px, 38vw, 188px); /* tile width in scrolling rows */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14102b; --surface: #1f1a40; --ink: #f1eeff; --muted: #b7afd9; --line: #2f2860;
    --chip: #1f1a40; --chip-on: #ffcf3f; --brand-ink: #ffffff; --focus: #ffcf3f; --focus-gap: #14102b;
    --shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.3);
  }
  .chip[aria-current="page"] { color: #2a1d00 !important; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.5;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }
.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; z-index: 10; }
.skip:focus { left: 8px; }

/* header */
.top { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 5; padding-top: env(safe-area-inset-top); }
.top .wrap { display: flex; align-items: center; gap: 10px; height: 64px; }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 1.2rem; min-height: 44px; flex: none; }
.logo img { width: 36px; height: 36px; border-radius: 10px; }
.search { flex: 1; display: flex; min-width: 0; max-width: 460px; margin-left: auto; }
.search input {
  flex: 1; min-width: 0; height: 44px; border: 0; border-radius: 22px 0 0 22px; padding: 0 16px;
  font: inherit; font-size: 1rem; background: #fff; color: #1d1640;
}
.search button {
  width: 48px; height: 44px; border: 0; border-radius: 0 22px 22px 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer;
}
.search button svg { width: 22px; height: 22px; }
@media (max-width: 420px) {
  .logo { gap: 8px; font-size: 1rem; }
  .logo img { width: 32px; height: 32px; }
  .search input { padding: 0 12px; }
  .search button { width: 44px; }
}
@media (max-width: 300px) { .logo span { display: none; } }

/* category chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 5px 8px; margin: 0 -5px; scrollbar-width: none; overscroll-behavior-x: contain;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
.chips.at-end { -webkit-mask-image: none; mask-image: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 22px;
  background: var(--chip); box-shadow: var(--shadow); text-decoration: none; font-weight: 700; white-space: nowrap;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip[aria-current="page"] { background: var(--chip-on); color: #fff; }

main { flex: 1; }
h1, h2 { line-height: 1.2; }
.page-h { font-size: 1.5rem; margin: 14px 0 10px; }
.section-h { font-size: 1.2rem; margin: 22px 0 10px; }

/* game grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 0; margin: 0; list-style: none; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1120px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tile {
  position: relative; display: block; text-decoration: none; background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: transform 0.15s ease;
}
.tile img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
/* fixed height (name + 2-line hook) so every tile is the same size: no shift, rows can reserve space */
.tile .meta { display: block; padding: 8px 12px 10px; height: calc(18px + 3.6rem); overflow: hidden; }
.tile .name { display: block; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.5rem; }
.tile .short, .mini .short {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 0.8rem; line-height: 1.3; color: var(--muted);
}
.tile:active { transform: scale(0.97); }
.tile .badge {
  position: absolute; top: 8px; left: 8px; padding: 3px 9px; border-radius: 12px; font-size: 0.8rem; font-weight: 800;
  background: rgba(20, 14, 50, 0.72); color: #fff;
}
@media (hover: hover) { .tile:hover { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .tile, .tile:hover, .tile:active { transition: none; transform: none; } }
.grid li[hidden] { display: none; }
.empty { padding: 24px 0; color: var(--muted); font-weight: 600; }
.empty[hidden] { display: none; }
.results-h { display: none; align-items: center; gap: 12px; flex-wrap: wrap; }
.results-h h2 { min-height: 1.2em; }
/* search state is a class on <html> (set before first paint when the page opens with ?q=) */
.searching .results-h { display: flex; }
.searching [data-hide-on-search] { display: none !important; }
.searching.noresults #row-new-sec { display: block !important; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 22px; border: 0; font: inherit; font-weight: 800; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); font-size: 1.2rem; min-height: 56px; padding: 0 30px; box-shadow: 0 4px 0 #c99a00; }
.btn svg { width: 22px; height: 22px; }

/* game page */
.crumbs { font-size: 0.9rem; color: var(--muted); padding-top: 12px; }
.crumbs a { display: inline-block; padding: 10px 0; }
.player {
  position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: max(320px, calc(100vh - 250px)); background: #120d2c;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin: 6px 0 12px;
}
@media (max-width: 759px) { .player { aspect-ratio: 4 / 3; } }
.player .cover { position: absolute; inset: 0; display: grid; place-items: center; text-decoration: none; }
.player .cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(16px) brightness(0.6); transform: scale(1.15); }
.player .cover .inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; color: #fff; text-align: center; padding: 16px; }
.player .cover .thumb { width: 120px; height: 120px; border-radius: 24px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); position: static; filter: none; transform: none; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.player-bar { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-bottom: 8px; min-height: 44px; }
.player-bar h1 { margin: 0; font-size: 1.5rem; flex: 1; }
.player-bar .btn[hidden] { display: none; }
.player:fullscreen { border-radius: 0; max-height: none; aspect-ratio: auto; }
.info { display: grid; gap: 4px 32px; }
@media (min-width: 860px) { .info { grid-template-columns: 1.4fr 1fr; } }
.info p, .info ol { margin: 0 0 12px; }
.info ol { padding-left: 1.3em; }
.info li { margin-bottom: 6px; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; padding: 0; list-style: none; }
.prose { max-width: 70ch; }

/* footer */
.foot { margin-top: 40px; padding: 24px 0 calc(24px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); color: var(--muted); }
.foot nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.foot nav a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; color: var(--ink); }
.foot p { margin: 8px 0 0; font-size: 0.9rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }

/* featured hero (fixed aspect: no layout shift) */
.hero { margin: 4px 0 8px; }
.hero-card {
  display: grid; grid-template-columns: minmax(110px, 34%) 1fr; gap: 16px; align-items: center; text-decoration: none;
  background: #2a1f6b; /* fallback without color-mix */
  background: linear-gradient(135deg, color-mix(in srgb, var(--hero) 60%, #1d1640), color-mix(in srgb, var(--hero) 32%, #1d1640));
  color: #fff; border-radius: 20px; padding: 14px; box-shadow: var(--shadow); min-height: 150px;
}
.hero-card img { width: 100%; aspect-ratio: 1 / 1; border-radius: 16px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); }
.hero-text { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.hero .kicker { font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.hero-title { font-size: 1.5rem; font-weight: 800; line-height: 1.1; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.hero-short { font-size: 0.95rem; }
.hero .btn.primary { font-size: 1rem; min-height: 48px; padding: 0 20px; margin-top: 4px; }
@media (min-width: 760px) {
  .hero-card { grid-template-columns: 220px 1fr; padding: 20px; gap: 28px; }
  .hero-title { font-size: 2.2rem; }
  .hero-short { font-size: 1.1rem; }
}
.hero[hidden], .section-h[hidden], section[hidden] { display: none; }

/* "New" badge, opposite corner from the best-score badge */
.tile .new {
  position: absolute; top: 8px; right: 8px; padding: 3px 9px; border-radius: 12px; font-size: 0.75rem; font-weight: 800;
  background: #c8143f; color: #fff; text-transform: uppercase; letter-spacing: 0.04em;
}
.chip svg { flex: none; }

/* category intro */
.intro { max-width: 70ch; margin: 0 0 16px; color: var(--muted); }

/* horizontally scrolling rows (touch swipe + snap; arrow buttons only for fine pointers) */
.row-sec { margin-top: 6px; }
.row-h { display: flex; align-items: center; gap: 6px; margin: 18px 0 4px; }
.row-h .section-h { margin: 0; flex: 1; min-width: 0; }
.row-h .section-h a { text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }
.see-all { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 6px 0 12px; font-weight: 800; text-decoration: none; color: var(--brand); border-radius: 22px; }
.see-all svg { width: 18px; height: 18px; }
.arrow { display: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); cursor: pointer; place-items: center; flex: none; }
.arrow svg { width: 22px; height: 22px; }
@media (hover: hover) and (pointer: fine) { .arrow { display: grid; } }
.row-sec[data-fits] .arrow { visibility: hidden; }
.row {
  display: flex; gap: 12px; margin: 0 -16px; padding: 6px 16px 14px; list-style: none; overflow-x: auto;
  scroll-snap-type: x mandatory; scroll-padding-inline: 16px; overscroll-behavior-x: contain; scrollbar-width: none;
}
.row::-webkit-scrollbar { display: none; }
.row > li { flex: 0 0 var(--tw); min-width: 0; scroll-snap-align: start; }
@media (min-width: 1272px) { .row { margin: 0; padding-inline: 0; scroll-padding-inline: 0; } }
/* "Continue playing" / "Favourites": hidden unless the inline head script found entries; height reserved */
.row-sec.dyn { display: none; }
.has-recent #row-recent-sec, .has-fav #row-fav-sec { display: block; }
.dyn .row { min-height: calc(var(--tw) + 18px + 3.6rem + 20px); }
@media (prefers-color-scheme: dark) { .see-all { color: var(--accent); } }

/* game page: player + up-next row, desktop side rail */
.game-layout { display: block; }
.rail { display: none; }
@media (min-width: 760px) {
  .row.fit4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: visible; margin: 0; padding: 4px 0 8px; }
  .fit4 .arrow { display: none; }
}
.game-main .row-h { margin-top: 4px; }
@media (min-width: 1100px) {
  .game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 272px; gap: 24px; align-items: start; }
  .rail { display: block; }
  .rail .section-h { margin-top: 52px; }
  .rail ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
}
.mini { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); text-decoration: none; min-height: 80px; }
.mini img { width: 64px; height: 64px; border-radius: 12px; flex: none; }
.mini > span { min-width: 0; }
.mini .name { display: block; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .mini:hover { transform: translateX(2px); } }
.btn.icon { width: 44px; padding: 0; flex: none; }
.fav svg { fill: none; }
.fav[aria-pressed="true"] { color: #c8143f; }
.fav[aria-pressed="true"] svg { fill: currentColor; }
@media (prefers-color-scheme: dark) { .fav[aria-pressed="true"] { color: #ff7a93; } }
@media (max-width: 420px) { .player-bar h1 { font-size: 1.25rem; } }

/* focus last so it wins over component shadows. Two-tone ring: dark ring + yellow gap on light backgrounds,
   yellow ring + dark gap on dark ones (header, hero, player) */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-gap); }
.top :focus-visible, .hero :focus-visible, .player :focus-visible { outline-color: #ffcf3f; box-shadow: 0 0 0 2px #1d1640; }
.hero-card:focus-visible { outline-color: var(--focus); box-shadow: 0 0 0 2px var(--focus-gap); }
.player .cover:focus-visible { outline-offset: -7px; box-shadow: inset 0 0 0 4px #1d1640; }
