/* ==========================================================================
   Retro ROM showcase — dark theme
   Tile = black clamshell case (assets/case.webp, alpha) with the box art
   laid into the case window. Geometry is measured from the source artwork;
   see tools/make_case.py for how the constants below were derived.
   ========================================================================== */

:root {
  --bg:          #0a0d13;
  --bg-soft:     #111722;
  --panel:       #151c29;
  --panel-2:     #1b2433;
  --line:        #26303f;
  --text:        #e7edf7;
  --muted:       #8d9ab0;
  --muted-dim:   #5f6b7e;
  --accent:      #4da3ff;
  --accent-soft: #1d4b7d;

  /* case window, as a fraction of the trimmed case image (734 x 1104) */
  --win-left:   3.542%;
  --win-top:   11.866%;
  --win-width: 92.643%;
  --win-height:85.688%;

  --cols: 6;
  --gap: 20px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  /* The neon grid sits on top of the gradients, not under them: its dark cells
     are transparent (see tools/make_background.py), so the gradients read
     through and only the glowing lines are added. The tile is seamless in both
     axes - it is built from mirrored copies, so every seam meets its own
     reflection. */
  background-color: var(--bg);
  background-image:
    url(assets/bg-grid.webp),
    radial-gradient(1200px 620px at 50% -180px, #16233a 0%, transparent 70%),
    radial-gradient(900px 500px at 100% 0%, #1a1630 0%, transparent 60%);
  background-repeat: repeat, no-repeat, no-repeat;
  min-height: 100vh;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------- header */

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(10, 13, 19, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.top__inner {
  max-width: 1780px;
  margin: 0 auto;
  padding: 14px 26px;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.brand {
  display: block;
  flex: 0 0 auto;
  line-height: 0;
  text-decoration: none;
  border-radius: 8px;
  transition: filter .18s, transform .18s;
}

.brand img {
  display: block;
  height: 42px;
  width: auto;
}

.brand:hover { filter: brightness(1.12); transform: translateY(-1px); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }

/* the same lockup, larger, at the top of the home view */
.hero {
  max-width: 1780px;
  margin: 0 auto;
  padding: 20px 26px 0;
  display: flex;
  justify-content: center;
}

/* attribute selector outranks the .hero class, so no !important is needed */
.hero[hidden] { display: none; }

.hero a {
  display: block;
  line-height: 0;
  border-radius: 14px;
  transition: filter .2s, transform .2s;
}

.hero img {
  display: block;
  width: 100%;
  max-width: 560px;
  height: auto;
  filter: drop-shadow(0 20px 36px rgba(0, 0, 0, .55));
}

.hero a:hover { filter: brightness(1.1); transform: translateY(-2px); }
.hero a:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .16s, color .16s, border-color .16s;
}

.tab:hover { color: var(--text); border-color: #33415a; }

.tab[aria-selected="true"] {
  background: linear-gradient(180deg, #21538c, #1a3f6d);
  border-color: #2f6cb0;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(77, 163, 255, .25), 0 6px 18px -8px rgba(77, 163, 255, .7);
}

.tab__count {
  color: var(--muted-dim);
  font-weight: 500;
  margin-left: 7px;
  font-size: 12px;
}

.tab[aria-selected="true"] .tab__count { color: #b7d6f7; }

.adminlink {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  text-decoration: none;
  font-size: 17px;
  transition: color .16s, border-color .16s;
}
.adminlink:hover { color: #fff; border-color: #3a4a63; }

/* ------------------------------------------------------------- alphabet bar */

.alpha {
  max-width: 1780px;
  margin: 0 auto;
  padding: 0 26px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.alpha[hidden] { display: none; }

.alpha__btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  min-width: 34px;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121824;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  transition: background .14s, color .14s, border-color .14s;
}

.alpha__btn i {
  font-style: normal;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted-dim);
}

.alpha__btn:hover { color: #fff; border-color: #3a4a63; background: #18202e; }

.alpha__btn.is-on {
  background: linear-gradient(180deg, #21538c, #1a3f6d);
  border-color: #2f6cb0;
  color: #fff;
}
.alpha__btn.is-on i { color: #b7d6f7; }

/* ------------------------------------------------------------------ star */

.star {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  line-height: 0;
  color: #7d8798;
  transition: color .16s, transform .16s, opacity .16s;
}

.star svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
  fill: rgba(8, 11, 16, .55);
}

.star:hover { color: #ffd479; transform: scale(1.14); }

.star.is-on { color: #ffc83d; }
.star.is-on svg { fill: #ffc83d; }

.star--tile {
  position: absolute;
  top: 5%;
  right: 5%;
  z-index: 7;
  opacity: 0;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .8));
}

/* always show stars already set, reveal the rest on hover so the case art
   is not covered by chrome in the default view */
.tile:hover .star--tile,
.tile:focus-within .star--tile,
.star--tile.is-on { opacity: 1; }

.star--detail {
  vertical-align: -3px;
  margin-left: 8px;
}

/* --------------------------------------------------------------- detail */

.chip--edited {
  color: #ffd479;
  border-color: #6b5220;
  background: #241c0d;
}

.search {
  margin-left: auto;
  position: relative;
  min-width: 260px;
  flex: 1 1 260px;
  max-width: 420px;
}

.search input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}

.search input:focus {
  border-color: #2f6cb0;
  box-shadow: 0 0 0 3px rgba(77, 163, 255, .14);
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--muted-dim);
  fill: none;
  stroke-width: 2;
  pointer-events: none;
}

/* ------------------------------------------------------------- statusbar */

.status {
  max-width: 1780px;
  margin: 0 auto;
  padding: 14px 26px 0;
  color: var(--muted-dim);
  font-size: 13px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

/* ------------------------------------------------------------------ grid */

.grid {
  max-width: 1780px;
  margin: 0 auto;
  padding: 18px 26px 90px;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
}

@media (max-width: 1700px) { :root { --cols: 6; } }
@media (max-width: 1500px) { :root { --cols: 5; } }
@media (max-width: 1240px) { :root { --cols: 4; } }
@media (max-width: 960px)  { :root { --cols: 3; } }
@media (max-width: 700px)  { :root { --cols: 2; } }

/* ------------------------------------------------------------------ tile */

.tile {
  display: flex;
  flex-direction: column;
  gap: 9px;
  position: relative;
  transition: transform .26s cubic-bezier(.2, .7, .3, 1);
  will-change: transform;
}

.tile:hover, .tile:focus-within { transform: translateY(-4px) scale(1.035); z-index: 5; }
.tile:active { transform: translateY(-1px) scale(1.012); }

/* the whole case is the "open details" target; kept as a separate element
   because a star button lives inside the same box */
.tile__open {
  position: absolute;
  inset: 0;
  z-index: 5;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 8px;
}
.tile__open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* the case itself */
.case {
  position: relative;
  aspect-ratio: 734 / 1104;
  filter: drop-shadow(0 14px 20px rgba(0, 0, 0, .6));
}

.case__shell {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  user-select: none;
  -webkit-user-drag: none;
}

/* window where the printed insert sits */
.case__win {
  position: absolute;
  left: var(--win-left);
  top: var(--win-top);
  width: var(--win-width);
  height: var(--win-height);
  overflow: hidden;
  z-index: 2;
  background: #07090d;
  /* the insert sits slightly recessed under the plastic lip */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .85),
              inset 0 2px 10px rgba(0, 0, 0, .55);
}

.case__art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

/* placeholder for games libretro has no box art for */
.case__none {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10%;
  text-align: center;
  background:
    repeating-linear-gradient(45deg, #12171f 0 9px, #0e131a 9px 18px);
  color: #46536a;
}

.case__none svg {
  width: 34px;
  height: 34px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  opacity: .8;
}

.case__none i {
  font-style: normal;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

/* ------------------------------------------------------- gloss / plastic */

/* broad moving highlight = the reflection off the shrink-wrap */
.case__gloss {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}

/* Clip both highlight layers to the case silhouette. The case asset carries a
   real alpha channel, so its alpha doubles as the mask and the sheen never
   spills onto the page background. */
.case__gloss,
.case__sheen {
  -webkit-mask-image: url(assets/case.webp);
          mask-image: url(assets/case.webp);
  -webkit-mask-size: 100% 100%;
          mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
}

.case__gloss::before {
  content: "";
  position: absolute;
  top: -35%;
  left: -85%;
  width: 62%;
  height: 170%;
  background: linear-gradient(
    100deg,
    rgba(255, 255, 255, 0)    0%,
    rgba(255, 255, 255, .10) 34%,
    rgba(255, 255, 255, .38) 50%,
    rgba(255, 255, 255, .10) 66%,
    rgba(255, 255, 255, 0)  100%);
  transform: rotate(8deg) translateX(0);
  transition: transform .82s cubic-bezier(.25, .55, .3, 1);
  mix-blend-mode: screen;
}

/* a tighter secondary glint, slightly out of phase */
.case__gloss::after {
  content: "";
  position: absolute;
  top: -40%;
  left: -40%;
  width: 22%;
  height: 180%;
  background: linear-gradient(
    100deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, .22) 48%,
    rgba(255, 255, 255, 0) 100%);
  transform: rotate(8deg);
  opacity: 0;
  transition: transform .95s cubic-bezier(.25, .55, .3, 1) .06s, opacity .3s;
  mix-blend-mode: screen;
}

.tile:hover .case__gloss::before,
.tile:focus-visible .case__gloss::before {
  transform: rotate(8deg) translateX(400%);
}

.tile:hover .case__gloss::after,
.tile:focus-visible .case__gloss::after {
  opacity: 1;
  transform: rotate(8deg) translateX(560%);
}

/* permanent faint sheen so the plastic reads even at rest */
.case__sheen {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(
    118deg,
    rgba(255, 255, 255, .075) 0%,
    rgba(255, 255, 255, .015) 26%,
    rgba(255, 255, 255, 0)    45%,
    rgba(255, 255, 255, .028) 72%,
    rgba(255, 255, 255, .06) 100%);
  mix-blend-mode: screen;
}

/* ----------------------------------------------------------- tile title */

.tile__meta { display: flex; flex-direction: column; gap: 2px; padding: 0 2px; }

.tile__title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: #dbe4f2;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}

.tile__sub {
  font-size: 11px;
  color: var(--muted-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile__rus {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #7fe0a8;
  border: 1px solid #2c6b47;
  background: #10281c;
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 6px;
  vertical-align: 1px;
}

/* --------------------------------------------------------------- detail */

.detail {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  background: rgba(4, 6, 10, .78);
  backdrop-filter: blur(8px);
  overflow-y: auto;
  padding: 40px 20px 60px;
}

.detail[data-open="1"] { display: block; }

.detail__box {
  max-width: 1100px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--panel), #10151f);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 40px 90px -30px #000;
  overflow: hidden;
  animation: pop .22s cubic-bezier(.2, .8, .3, 1);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

.detail__top {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 28px;
  padding: 28px;
}

@media (max-width: 780px) {
  .detail__top { grid-template-columns: 1fr; }
  .detail__casewrap { max-width: 260px; margin: 0 auto; }
}

.detail__casewrap { position: relative; }

.detail__body h2 {
  margin: 0 0 4px;
  font-size: 25px;
  line-height: 1.2;
}

.detail__slugline {
  color: var(--muted-dim);
  font-size: 12.5px;
  margin-bottom: 14px;
}

.detail__facts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.chip {
  font-size: 11.5px;
  color: #a9b8cd;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 11px;
}

.detail__desc {
  color: #c3cddd;
  font-size: 14.5px;
  white-space: pre-line;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 8px;
  margin-bottom: 18px;
}

.detail__dl {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e1420;
}

.btn-dl {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(180deg, #2a72bd, #1d548f);
  border: 1px solid #3a82cc;
  padding: 12px 20px;
  border-radius: 10px;
  transition: filter .15s, transform .15s;
}

.btn-dl:hover { filter: brightness(1.14); }
.btn-dl:active { transform: translateY(1px); }

.btn-dl svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2.2; }

.dl__meta { font-size: 12.5px; color: var(--muted); }
.dl__meta b { color: #cfdaea; font-weight: 600; }

.detail__files {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail__files li { font-size: 13px; }

.detail__files a {
  text-decoration: none;
  color: #b9cbe2;
  display: flex;
  gap: 10px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.detail__files a:hover { background: var(--panel-2); border-color: var(--line); color: #fff; }
.detail__files .sz { margin-left: auto; color: var(--muted-dim); font-variant-numeric: tabular-nums; }

.detail__shots {
  padding: 0 28px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.shot {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #070a10;
}

.shot img { display: block; width: 100%; height: auto; image-rendering: pixelated; }

.shot figcaption {
  font-size: 11px;
  color: var(--muted-dim);
  padding: 7px 10px;
  border-top: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.detail__close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(12, 16, 24, .85);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.detail__close:hover { color: #fff; border-color: #3a4a63; }

.detail__box { position: relative; }

.note {
  padding: 0 28px 26px;
  color: var(--muted-dim);
  font-size: 12px;
}

.note a { color: #7ea9d8; }

/* --------------------------------------------------------------- text page */

/* the grid is a display:grid element, so [hidden] needs outranking by class */
.grid[hidden] { display: none; }

.page {
  max-width: 840px;
  margin: 0 auto;
  padding: 32px 26px 90px;
  color: #c3cddd;
  font-size: 15px;
  line-height: 1.72;
}

.page[hidden] { display: none; }

.page h1 {
  margin: 0 0 22px;
  font-size: 30px;
  line-height: 1.2;
  color: var(--text);
}

.page h2 {
  margin: 36px 0 14px;
  font-size: 18px;
  color: #e7edf7;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.page p { margin: 0 0 14px; }
.page b { color: #e2eaf6; font-weight: 600; }
.page a { color: var(--accent); }

.page ul { margin: 0 0 16px; padding-left: 22px; }
.page li { margin-bottom: 6px; }

.page__lead {
  padding: 15px 19px;
  border-left: 3px solid #2f6cb0;
  background: #101823;
  border-radius: 0 10px 10px 0;
}

.page__src {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 14px;
}

.page__src td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.page__src td:first-child { color: var(--muted); width: 56%; }

.page__en { margin-top: 48px; border-bottom: 0; }

.page__en-text {
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e131b;
  color: #8d9ab0;
  font-size: 13.5px;
  line-height: 1.7;
}

.page__en-text p { margin: 0 0 10px; }
.page__en-text p:last-child { margin-bottom: 0; }

.legal {
  color: var(--muted-dim);
  text-decoration: none;
  border-bottom: 1px dotted #3a4a63;
}

.legal:hover { color: #b9cbe2; }

/* -------------------------------------------------------------- loading */

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted-dim);
  padding: 70px 20px;
  font-size: 15px;
  line-height: 1.7;
}

.empty__hint {
  color: #4e5a6e;
  font-size: 13px;
}
