:root {
  --bar: 52px;
  --bg: #140d2b;
  --bg-2: #1d1340;
  --bar-bg: #0e0920;
  --line: rgba(255, 255, 255, .1);
  --text: #f3efff;
  --muted: #a99fd0;
  --accent: #38e0ff;
  --hot: #ff4f7b;
  --gold: #ffd23f;
  --font: 'Fredoka', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bar-bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout: bar on the short edge, play area gets the rest ---------- */
.arcade {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
}

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--bar) + var(--safe-t));
  padding: var(--safe-t) max(8px, var(--safe-r)) 0 max(8px, var(--safe-l));
  background: var(--bar-bg);
  border-bottom: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  z-index: 2;
}

.bar-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-actions { display: flex; gap: 6px; align-items: center; }

.bar-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.bar-btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; }
.bar-btn:hover { background: rgba(255, 255, 255, .14); }
.bar-btn:active { transform: scale(.94); }
.bar-btn:focus-visible, .tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.home-btn { color: var(--accent); }
.arcade[data-view="home"] .home-btn { color: var(--muted); }
.arcade[data-view="home"] .play-only { display: none; }

@media (orientation: landscape) {
  .arcade {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: auto minmax(0, 1fr);
  }
  .bar {
    flex-direction: column;
    width: calc(var(--bar) + var(--safe-l));
    height: auto;
    padding: max(8px, var(--safe-t)) 0 max(8px, var(--safe-b)) var(--safe-l);
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  .bar-title {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
  }
  .bar-title span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    max-height: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bar-actions { flex-direction: column; }
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%);
}

/* ---------- Home: tile grid ---------- */
.home {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px max(16px, var(--safe-r)) max(24px, var(--safe-b)) max(16px, var(--safe-l));
}
@media (orientation: landscape) {
  .home { padding-left: 20px; padding-top: max(20px, var(--safe-t)); }
}

.home-head { max-width: 1100px; margin: 0 auto 18px; }
.home-head h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 700;
  letter-spacing: .03em;
  background: linear-gradient(90deg, var(--accent), var(--hot) 60%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.home-head p { margin: 2px 0 0; color: var(--muted); font-size: 16px; }

.grid {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 1100px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.tile {
  --tile: #5d4bb0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--tile) 38%, transparent), transparent 70%),
    rgba(255, 255, 255, .04);
  text-align: left;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.tile:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--tile) 70%, white 10%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35), 0 0 0 1px color-mix(in srgb, var(--tile) 50%, transparent);
}
.tile:active { transform: scale(.97); }

.tile-icon {
  aspect-ratio: 1;
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: var(--tile);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
}
.tile-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-icon .letter { font-size: 64px; font-weight: 700; color: rgba(255, 255, 255, .9); }

.tile-name { font-weight: 600; font-size: 17px; line-height: 1.2; }
.tile-desc {
  margin-top: -4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status { max-width: 1100px; margin: 24px auto 0; color: var(--muted); text-align: center; }
.status:empty { display: none; }
.status code { color: var(--text); }

/* ---------- Play area ---------- */
.play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
}
@media (orientation: landscape) {
  .play { padding: var(--safe-t) var(--safe-r) var(--safe-b) 0; }
}

.play iframe {
  display: block;
  flex: none;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--game-bg, #000);
}

/* Games that declare an orientation keep a sensible shape when the screen is the other way round. */
@media (orientation: landscape) {
  .play.wants-portrait iframe { width: auto; max-width: 100%; aspect-ratio: 9 / 16; }
}
@media (orientation: portrait) {
  .play.wants-landscape iframe { height: auto; max-height: 100%; aspect-ratio: 16 / 9; }
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity .25s;
}
.loading img { width: 96px; height: 96px; border-radius: 22px; animation: pulse 1s ease-in-out infinite alternate; }
.loading.done { opacity: 0; }
@keyframes pulse { from { transform: scale(.92); opacity: .7; } to { transform: scale(1); opacity: 1; } }

/* ---------- Free trial and full access ---------- */
.chip {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 224, 255, .12);
  border: 1px solid rgba(56, 224, 255, .35);
  color: var(--accent);
  font-size: 13px;
  white-space: nowrap;
}
.chip b { font-size: 15px; }
@media (orientation: landscape) {
  .chip { flex-direction: column; align-items: center; gap: 0; padding: 4px 0; width: 40px; border-radius: 12px; line-height: 1.1; }
  .chip small { font-size: 10px; }
  .chip-extra { display: none; }
}

.buy-btn { color: var(--gold); }
.buy-btn.urgent { background: var(--gold); color: #2a1a00; border-color: transparent; }

.banner {
  max-width: 1100px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(56, 224, 255, .08);
  border: 1px solid rgba(56, 224, 255, .25);
}
.banner p { margin: 0; flex: 1 1 220px; line-height: 1.35; }
.banner.ended { background: rgba(255, 210, 63, .1); border-color: rgba(255, 210, 63, .4); }

.btn {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn.primary { background: var(--gold); color: #2a1a00; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible, .link-btn:focus-visible, .paywall a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.tile-icon { position: relative; }
.tile-lock { display: none; }
.grid.locked .tile-icon img, .grid.locked .tile-icon .letter { filter: grayscale(.7) brightness(.6); }
.grid.locked .tile-lock {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
}
.grid.locked .tile-lock svg {
  width: 38%;
  height: 38%;
  fill: #fff;
  stroke: #fff;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5));
}

.home-foot {
  max-width: 1100px;
  margin: 32px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: center;
  font-size: 14px;
}
.home-foot a, .link-btn { color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; font-size: inherit; }

.paywall {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px 22px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--bg-2);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.paywall::backdrop { background: rgba(5, 3, 15, .7); backdrop-filter: blur(3px); }
.paywall h2 { margin: 0 0 8px; font-size: 24px; }
.paywall p { margin: 0 0 14px; line-height: 1.4; }
.pw-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
}
.pw-x:hover { background: rgba(255, 255, 255, .08); }
.pw-form { display: grid; gap: 10px; }
.pw-form label { color: var(--muted); }
.pw-form input {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}
.pw-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pw-points { margin: 0 0 16px; padding-left: 20px; line-height: 1.6; }
.pw-small { color: var(--muted); font-size: 13px; margin-top: 8px !important; }
.pw-restore { margin: 4px 0 14px; }
.pw-restore summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
.pw-restore .pw-form { margin-top: 8px; }
.pw-legal { font-size: 13px; color: var(--muted); text-align: center; margin: 0 !important; }
.pw-legal a { color: var(--muted); }
.pw-key {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px 10px 10px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .3);
  border: 1px dashed rgba(255, 210, 63, .5);
}
.pw-key code {
  flex: 1;
  font: 600 17px/1.3 ui-monospace, 'Cascadia Mono', Consolas, monospace;
  letter-spacing: .04em;
  color: var(--gold);
  user-select: all;
  word-break: break-all;
}
.pw-msg { margin: 12px 0 0 !important; color: var(--gold); min-height: 1.2em; }
.pw-msg:empty { display: none; }

.turnstile-box { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
