/* ---------------------------------------------------------------------------
   Demos — house palette. These eight are the token set; every value below is
   var()-bound or color-mix()-derived from them. No raw hex outside :root.
--------------------------------------------------------------------------- */
:root {
  --bg:     #04060a;
  --white:  #dfe8f0;
  --cyan:   #3fe0d0;
  --grey:   #5d6f80;
  --green:  #6ee787;
  --red:    #ff6b6b;
  --violet: #a98bff;
  --orange: #ffb44d;

  /* derived — --grey alone is 3.96:1 on --bg, under AA for small text, so it
     is used for hairlines and fills only. Real copy uses these two. */
  --dim:    color-mix(in srgb, var(--grey) 55%, var(--white));   /* 8.1:1 */
  --dim-2:  color-mix(in srgb, var(--grey) 72%, var(--white));   /* 6.2:1 */
  --line:   color-mix(in srgb, var(--grey) 34%, transparent);
  --line-2: color-mix(in srgb, var(--grey) 18%, transparent);
  --raise:  color-mix(in srgb, var(--grey) 9%, transparent);

  --game:   var(--violet);
  --world:  var(--cyan);
  --accent: var(--cyan);        /* cards override per category */

  /* motion */
  --d-fast:   150ms;
  --d-base:   250ms;
  --d-slow:   420ms;
  --ease:     cubic-bezier(0.22, 1, 0.36, 1);

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, sans-serif;

  --gutter: clamp(16px, 4vw, 48px);
  --maxw: 1320px;
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--white);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;                 /* body never scrolls sideways */
}

/* one soft cold light source, top-left. no parallax, no second focal point. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120vw 70vh at 8% -12%, color-mix(in srgb, var(--cyan) 7%, transparent), transparent 62%),
    radial-gradient(90vw 60vh at 100% 108%, color-mix(in srgb, var(--violet) 5%, transparent), transparent 60%);
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: 3px;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg);
  color: var(--cyan);
  padding: 10px 16px;
  border: 1px solid var(--cyan);
  z-index: 99;
}
.skip:focus { left: var(--gutter); top: 12px; }

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

.top {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: clamp(40px, 8vh, 88px) 0 6px;
}

.mark {
  font-family: var(--mono);
  font-size: clamp(28px, 4.4vw, 46px);
  letter-spacing: 0.14em;
  font-weight: 500;
  margin: 0;
  color: var(--white);
}
.mark .dot { color: var(--cyan); }

.count {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--dim-2);
  text-transform: uppercase;
}

.tagline {
  max-width: 62ch;
  color: var(--dim);
  margin: 8px 0 0;
  font-size: clamp(15px, 1.6vw, 17px);
}

.rule {
  height: 1px;
  border: 0;
  margin: 30px 0 0;
  background: linear-gradient(90deg, var(--line), transparent 70%);
}

/* --- filters ------------------------------------------------------------ */

.filters {
  display: flex;
  gap: 6px;
  padding: 22px 0 26px;
  flex-wrap: wrap;
}

.filter {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 8px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: color var(--d-fast) var(--ease),
              border-color var(--d-fast) var(--ease),
              background-color var(--d-fast) var(--ease);
}
.filter:hover { color: var(--white); border-color: var(--line); }
.filter[aria-pressed="true"] {
  color: var(--cyan);
  border-color: color-mix(in srgb, var(--cyan) 46%, transparent);
  background: color-mix(in srgb, var(--cyan) 8%, transparent);
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(288px, 1fr));
  gap: 20px;
  padding-bottom: 96px;
  list-style: none;
  margin: 0;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;          /* fill the grid row so bottoms align across a row */
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--raise);
  overflow: hidden;
  color: inherit;
  transition: transform var(--d-base) var(--ease),
              border-color var(--d-base) var(--ease),
              background-color var(--d-base) var(--ease);
}
.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent) 52%, transparent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  text-decoration: none;
}
.card::after {           /* one hairline that lights on hover — the whole flourish */
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--d-base) var(--ease);
}
.card:hover::after, .card:focus-visible::after { opacity: 0.85; }

.card[data-cat="game"]  { --accent: var(--game); }
.card[data-cat="world"] { --accent: var(--world); }

.shot {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: color-mix(in srgb, var(--grey) 8%, var(--bg));
  border-bottom: 1px solid var(--line-2);
}
.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--d-slow) var(--ease), filter var(--d-slow) var(--ease);
  filter: saturate(0.88);
}
.card:hover .shot img, .card:focus-visible .shot img {
  transform: scale(1.035);
  filter: saturate(1);
}

/* poster not captured yet — an intentional plate, not a broken image */
.plate {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    repeating-linear-gradient(
      -45deg,
      color-mix(in srgb, var(--accent) 5%, transparent) 0 1px,
      transparent 1px 9px
    ),
    radial-gradient(80% 80% at 50% 120%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%);
}
.plate span {
  font-family: var(--mono);
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: 0.22em;
  color: color-mix(in srgb, var(--accent) 62%, transparent);
  text-indent: 0.22em;
}

.meta { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 7px; flex: 1; }

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.005em;
}

.chip {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.blurb { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.5; }

.keys {
  margin: auto 0 0;
  padding-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--dim-2);
  border-top: 1px solid var(--line-2);
  overflow-wrap: anywhere;
}

.weight { color: var(--dim-2); font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; }

/* --- entrance stagger --------------------------------------------------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.grid > li { animation: rise var(--d-slow) var(--ease) both; }
.grid > li:nth-child(1)  { animation-delay:  20ms; }
.grid > li:nth-child(2)  { animation-delay:  55ms; }
.grid > li:nth-child(3)  { animation-delay:  90ms; }
.grid > li:nth-child(4)  { animation-delay: 125ms; }
.grid > li:nth-child(5)  { animation-delay: 160ms; }
.grid > li:nth-child(6)  { animation-delay: 195ms; }
.grid > li:nth-child(7)  { animation-delay: 230ms; }
.grid > li:nth-child(8)  { animation-delay: 265ms; }
.grid > li:nth-child(9)  { animation-delay: 300ms; }
.grid > li:nth-child(10) { animation-delay: 335ms; }
.grid > li:nth-child(11) { animation-delay: 370ms; }
.grid > li:nth-child(12) { animation-delay: 405ms; }
.grid > li:nth-child(n+13) { animation-delay: 440ms; }

.head-in { animation: rise var(--d-slow) var(--ease) both; }

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

.back {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 30px 0 0;
}
.back:hover { color: var(--cyan); text-decoration: none; }
.back .arrow { transition: transform var(--d-fast) var(--ease); display: inline-block; }
.back:hover .arrow { transform: translateX(-4px); }

.detail-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 20px 0 18px;
}
.detail-head h1 {
  margin: 0;
  font-size: clamp(24px, 3.4vw, 34px);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.detail-head .blurb { max-width: 66ch; margin-top: 7px; font-size: 15px; }

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

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: color var(--d-fast) var(--ease),
              border-color var(--d-fast) var(--ease),
              background-color var(--d-fast) var(--ease);
}
.btn:hover { color: var(--white); border-color: var(--line); text-decoration: none; }
.btn-key {
  color: var(--cyan);
  border-color: color-mix(in srgb, var(--cyan) 40%, transparent);
}
.btn-key:hover {
  background: color-mix(in srgb, var(--cyan) 10%, transparent);
  border-color: var(--cyan);
  color: var(--cyan);
}

.stage {
  position: relative;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--grey) 6%, var(--bg));
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 220px);
  min-height: 380px;
}
.stage:fullscreen { aspect-ratio: auto; max-height: none; border: 0; border-radius: 0; }

.stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg);
  opacity: 0;
  transition: opacity var(--d-slow) var(--ease);
}
.stage[data-state="ready"] iframe { opacity: 1; }

/* --- loader ------------------------------------------------------------- */

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  transition: opacity var(--d-slow) var(--ease), visibility var(--d-slow);
}
.stage[data-state="ready"] .loader { opacity: 0; visibility: hidden; }
.loader[hidden] { display: none; }

.loader .phase {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}

.meter {
  width: min(340px, 62vw);
  height: 2px;
  background: color-mix(in srgb, var(--grey) 26%, transparent);
  border-radius: 2px;
  overflow: hidden;
}
.meter .fill {
  height: 100%;
  width: 0%;
  background: var(--cyan);
  transform-origin: left;
  transition: width 90ms linear;
}
/* only used when Content-Length is genuinely unavailable — an honest unknown */
.meter[data-indeterminate] .fill {
  width: 34%;
  animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(320%); }
}

.loader .bytes {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--dim-2);
  font-variant-numeric: tabular-nums;
}

.loader .fail { color: var(--red); font-family: var(--mono); font-size: 12px; }

.hint {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: baseline;
  padding: 14px 2px 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--dim);
}
.hint .lbl {
  color: var(--dim-2);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 10px;
}
.hint .lock { color: var(--orange); }

.detail-foot { padding: 26px 0 80px; }

/* --- desktop gate ------------------------------------------------------- */

.gate { display: none; }
.gate .note {
  border: 1px solid color-mix(in srgb, var(--orange) 34%, transparent);
  background: color-mix(in srgb, var(--orange) 7%, transparent);
  border-radius: 12px;
  padding: 18px 20px;
  margin-top: 16px;
}
.gate h2 {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange);
}
.gate p { margin: 0; color: var(--dim); font-size: 14px; }
.gate .anyway { display: inline-block; margin-top: 12px; font-size: 13px; }
.gate .still {
  position: relative;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--grey) 8%, var(--bg));
}
.gate .still img { width: 100%; height: 100%; object-fit: cover; display: block; }

.gate[data-cat="game"]  { --accent: var(--game); }
.gate[data-cat="world"] { --accent: var(--world); }

body[data-coarse] .gate  { display: block; }
body[data-coarse] .stage { display: none; }
body[data-coarse] .hint  { display: none; }
/* Restart and Fullscreen drive the stage. With no stage they are dead controls. */
body[data-coarse] .actions [data-act] { display: none; }

/* --- footer ------------------------------------------------------------- */

.foot {
  border-top: 1px solid var(--line-2);
  padding: 22px 0 60px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--dim-2);
}

/* --- responsive --------------------------------------------------------- */

@media (max-width: 780px) {
  .stage { aspect-ratio: 4 / 3; min-height: 320px; }
  .detail-head { align-items: flex-start; }
}
@media (max-width: 460px) {
  .grid { grid-template-columns: 1fr; gap: 16px; }
  .stage { min-height: 260px; }
  .actions { width: 100%; }
  .btn { flex: 1 1 auto; justify-content: center; }
}

/* --- motion off --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover, .card:focus-visible { transform: none; }
  .card:hover .shot img, .card:focus-visible .shot img { transform: none; }
  .meter[data-indeterminate] .fill { animation: none; width: 100%; opacity: 0.4; }
}

/* cross-document transition into the detail view. native, no library. */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}
