:root {
  --bg: #050813;
  --surface: #0b1020;
  --surface-2: #10172b;
  --ink: #e9e4d4;
  --muted: #b6c0d2;
  --nav: #b9c0d0;
  --gold: #d9b45a;
  --gold-bright: #f0d488;
  --gold-dim: #8a7038;
  --rose: #f09ec7;
  --line: rgba(255, 255, 255, .09);
  --radius: 16px;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Lato", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .brand {
  font-family: var(--serif);
  letter-spacing: -0.01em;
}
h1, h2 { font-weight: 300; }
h3 { font-weight: 400; }
h1 { color: #fff; }
p { color: var(--muted); }

a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

/* ---------- Space background (drawn by assets/space.js) ---------- */
#space {
  position: fixed; inset: 0; z-index: 0;
  display: block; pointer-events: none;
}
.hero, .wrap, footer { position: relative; z-index: 1; }

/* ---------- Portal header ---------- */
.hero {
  background: radial-gradient(ellipse 70% 60% at 50% 0%, rgba(217, 180, 90, .14), transparent 70%);
  padding: 24px 20px 40px;
  text-align: center;
  min-height: min(46vh, 420px);
  display: flex; flex-direction: column;
}
.hero-inner {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  transform-origin: 50% 35%;
  will-change: transform, opacity;
}
.hero-inner > * { animation: rise 1s cubic-bezier(.16, .8, .2, 1) both; }
.hero-inner > :nth-child(2) { animation-delay: .15s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(.96); filter: blur(4px); }
  to   { opacity: 1; transform: none; filter: none; }
}
.topbar {
  width: 100%; max-width: 1100px; margin: 0 auto 48px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; }
.brand-logo { display: block; height: 68px; width: auto; }

.hero h1 { font-size: clamp(38px, 7vw, 68px); line-height: 1.05; }
.hero h1 em {
  font-style: italic; color: var(--gold-bright);
  padding-right: .08em;
  background: linear-gradient(100deg, var(--gold) 20%, #fff6d8 42%, var(--gold-bright) 58%, var(--gold) 80%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 6s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 100% { background-position: 100% 0; }
  50%      { background-position: 0% 0; }
}
.hero p {
  margin: 16px auto 0; max-width: 560px;
  font-size: clamp(15px, 2.2vw, 17px);
}

/* ---------- Game grid ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 40px 20px 56px; }

.section-title {
  font-size: 32px; margin: 0 0 22px; color: var(--ink);
  transform: scale(calc(1 - var(--sink, 0) * .2));
  transform-origin: left center;
  opacity: calc(1 - var(--sink, 0));
}

/* App Store style list: icon, title, description, story line, Play pill, then a big screenshot */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 28px;
}

/* --lift (hover) and --sink (set by space.js as a card leaves the top) combine into one transform */
.card {
  --lift: 0px;
  --icon: 84px;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px;
  border: 1px solid transparent;
  border-radius: 22px;
  transform: translate3d(0, var(--lift), 0) scale(calc(1 - var(--sink, 0) * .18));
  opacity: calc(1 - var(--sink, 0) * .85);
  transition: transform .25s ease-out, opacity .25s ease-out, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.card:hover, .card:focus-visible {
  --lift: -4px;
  background: rgba(11, 16, 32, .62);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-color: rgba(217, 180, 90, .35);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35), 0 0 30px rgba(217, 180, 90, .08);
}
.card:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 3px; }
.card:active { transform: scale(.98); }

/* Fly in from deep space (classes added and removed by space.js) */
.space-motion .card.reveal {
  opacity: 0;
  transform: perspective(900px) translate3d(0, 60px, -420px) rotateX(14deg);
  filter: blur(6px);
  transition: opacity .9s ease var(--d, 0ms), transform 1.1s cubic-bezier(.16, .8, .2, 1) var(--d, 0ms), filter .9s ease var(--d, 0ms);
}
.space-motion .card.reveal.in {
  opacity: 1;
  transform: perspective(900px) translate3d(0, 0, 0) rotateX(0deg);
  filter: blur(0);
}

.app-head {
  display: grid;
  grid-template-columns: var(--icon) minmax(0, 1fr) auto;
  align-items: center; gap: 18px;
}

/* App icon: icons/<game-id>.png, or a placeholder tile until one is added */
.app-icon {
  position: relative;
  width: var(--icon); height: var(--icon);
  border-radius: 22%;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.app-icon img { display: block; width: 100%; height: 100%; object-fit: cover; }
.app-icon.placeholder {
  display: grid; place-items: center;
  font-size: calc(var(--icon) * .44);
  border: 1.5px dashed rgba(217, 180, 90, .5);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
}
.app-icon.placeholder::before {
  content: "";
  position: absolute; inset: -30%;
  background: radial-gradient(closest-side, var(--c, var(--gold)), transparent);
  opacity: .35;
}
.app-icon.placeholder > span { position: relative; }

.app-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card h3 {
  font-size: 26px; line-height: 1.1; color: #fff;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.desc {
  font-size: 15px; line-height: 1.4; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.story { font-size: 13.5px; color: #7d879b; }

.app-cta { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.play {
  font-weight: 700; font-size: 14px; letter-spacing: 0.06em;
  color: var(--bg); background: var(--gold);
  padding: 8px 24px; border-radius: 99px;
  transition: background .18s ease;
}
.card:hover .play, .card:focus-visible .play { background: var(--gold-bright); }
.age {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: #7d879b;
}
.age:empty { display: none; }

/* Screenshot, lined up under the text like a store listing */
.thumb {
  position: relative;
  margin-left: calc(var(--icon) + 18px);
  aspect-ratio: 16 / 10;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 64px;
}
.thumb .shot {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: transform .6s cubic-bezier(.16, .8, .2, 1);
}
.card:hover .shot, .card:focus-visible .shot { transform: scale(1.05); }
/* Fallback screenshot: dark panel with a soft glow in the game's colour (--c) */
.thumb.no-thumb::before {
  content: "";
  position: absolute; inset: -20%;
  background: radial-gradient(closest-side, var(--c, var(--gold)), transparent);
  opacity: .32;
}
.thumb.no-thumb > span { position: relative; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .card { --icon: 64px; padding: 14px 4px; gap: 14px; }
  .app-head { gap: 14px; }
  .card h3 { font-size: 22px; }
  .desc { font-size: 14px; }
  .story { font-size: 12.5px; }
  .play { padding: 7px 18px; font-size: 13px; }
  .thumb { margin-left: 0; }
}

.empty { text-align: center; padding: 60px 20px; color: var(--muted); font-size: 17px; }

footer {
  text-align: center; padding: 28px 20px 40px;
  background: linear-gradient(to bottom, transparent, rgba(5, 8, 19, .7));
  color: var(--muted); font-size: 14px;
  border-top: 1px solid var(--line);
}
footer a { color: var(--gold); }
footer a:hover { color: var(--gold-bright); }

/* ---------- Player page ---------- */
body.player { display: flex; flex-direction: column; height: 100dvh; background: var(--bg); }

.player-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  flex: 0 0 auto;
}
.player-bar .title {
  flex: 1; min-width: 0;
  font-family: var(--serif); font-size: 22px; font-weight: 400;
  letter-spacing: -0.01em; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn {
  display: inline-block; text-decoration: none;
  cursor: pointer; font-family: var(--sans); font-weight: 700;
  font-size: 13px; letter-spacing: 0.06em; line-height: 1.2;
  padding: 8px 16px; border-radius: 99px;
  border: 1px solid var(--gold); background: transparent; color: var(--gold);
  white-space: nowrap;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.btn:hover { background: rgba(217, 180, 90, .12); color: var(--gold-bright); border-color: var(--gold-bright); }
.btn.primary { background: var(--gold); color: var(--bg); }
.btn.primary:hover { background: var(--gold-bright); border-color: var(--gold-bright); color: var(--bg); }

#frame { flex: 1 1 auto; width: 100%; border: 0; background: #fff; }

.msg {
  flex: 1; display: grid; place-items: center; text-align: center;
  color: var(--ink); padding: 24px; font-size: 18px;
}
.msg a { color: var(--gold); font-weight: 700; }
.msg a:hover { color: var(--gold-bright); }

@media (max-width: 480px) {
  .btn .label { display: none; }
  .btn { padding: 8px 12px; }
  .player-bar .title { font-size: 19px; }
  .topbar { margin-bottom: 36px; }
  .brand-logo { height: 56px; }
  .topbar .btn { font-size: 12px; padding: 7px 12px; }
}

@media (max-width: 400px) {
  .topbar { gap: 10px; }
  .brand-logo { height: 48px; }
  .topbar .btn { font-size: 11px; letter-spacing: 0.04em; padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
  .card:hover, .card:focus-visible, .card:active { transform: none; }
  .card:hover .shot, .card:focus-visible .shot { transform: none; }
}
