:root {
  --bg: #130f26;
  --panel: #1b1535;
  --panel-2: #251d49;
  --line: #2f2658;
  --text: #f1eeff;
  --muted: #a89fd0;
  --accent: #6c3fe0;
  --accent-hi: #8a63f5;
  --radius: 14px;
  --topbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; text-decoration: none; }
h1, h2 { margin: 0; }
h2 { font-size: 18px; margin-bottom: 12px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: .2px; white-space: nowrap; }
.search {
  margin-left: auto; flex: 0 1 420px; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent-hi); color: var(--text); }
.search input {
  flex: 1; min-width: 0; background: none; border: 0; outline: 0;
  color: var(--text); font: inherit;
}
.search input::placeholder { color: var(--muted); }
.back { margin-left: auto; color: var(--muted); font-weight: 600; }
.back:hover { color: var(--text); }

/* Shell: rail + content */
.shell { flex: 1; display: flex; gap: 24px; padding: 20px 20px 32px; max-width: 1400px; width: 100%; margin: 0 auto; }
.rail { flex: 0 0 180px; position: sticky; top: calc(var(--topbar-h) + 20px); align-self: flex-start; display: flex; flex-direction: column; gap: 4px; }
.rail button {
  text-align: left; background: none; border: 0; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 14px; border-radius: 10px; cursor: pointer;
}
.rail button:hover { background: var(--panel); color: var(--text); }
.rail button[aria-current="true"] { background: var(--accent); color: #fff; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 28px; }

/* Cards */
.card {
  position: relative; display: block; overflow: hidden;
  border-radius: var(--radius); background: var(--panel-2);
  aspect-ratio: 1; isolation: isolate;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .label {
  position: absolute; inset: auto 0 0 0; padding: 28px 12px 10px;
  background: linear-gradient(transparent, rgba(8, 5, 22, .88));
  font-weight: 700; font-size: 15px;
}
.card .label small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.card:hover, .card:focus-visible { transform: translateY(-3px) scale(1.02); box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 0 0 2px var(--accent-hi); outline: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.hero-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.hero-row .card .label { font-size: 18px; }
.empty { color: var(--muted); }
.empty a { color: var(--accent-hi); text-decoration: underline; }

/* Game page */
.play { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px 16px 32px; display: flex; flex-direction: column; gap: 28px; }
.stage { display: flex; flex-direction: column; gap: 12px; width: 100%; margin: 0 auto; }
/* Portrait: the stage is as wide as a 9:16 frame that fits the viewport height. */
.stage[data-orientation="portrait"] { max-width: calc(min(100dvh - var(--topbar-h) - 150px, 760px) * 9 / 16); }
.frame {
  position: relative; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
}
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
.frame[data-orientation="portrait"] { aspect-ratio: 9 / 16; }
.frame[data-orientation="landscape"] { aspect-ratio: 16 / 9; max-height: calc(100dvh - var(--topbar-h) - 150px); }
.bar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bar h1 { font-size: 22px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 18px; font: inherit; font-weight: 700; cursor: pointer;
}
.btn:hover { background: var(--accent-hi); }
.desc { margin: 0; color: var(--muted); max-width: 70ch; }

/* Pseudo fullscreen (iOS Safari has no element fullscreen) */
.frame.pseudo-fs {
  position: fixed; inset: 0; z-index: 100; width: 100vw; height: 100dvh; max-height: none;
  aspect-ratio: auto; border: 0; border-radius: 0;
}
.fs-exit {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
}

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

/* Phones: rail becomes a chip row */
@media (max-width: 760px) {
  .logo span { display: none; }
  .search { flex: 1; }
  .shell { flex-direction: column; gap: 14px; padding: 14px 16px 24px; }
  .rail {
    position: static; flex: none; flex-direction: row; gap: 8px;
    overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail button { flex: none; background: var(--panel); border-radius: 999px; padding: 8px 16px; white-space: nowrap; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .hero-row { grid-template-columns: 1fr; }
  .hero-row .card { aspect-ratio: 16 / 10; }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover, .card:focus-visible { transform: none; }
}
