:root {
  color-scheme: dark;
  --pink: #ff2e63;
  --gold: #ffd166;
  --ink: #09090d;
  --panel: #15151d;
  --line: #323240;
  --muted: #9292a3;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 46, 99, 0.08), transparent 28rem),
    radial-gradient(ellipse at center, #17171f 0%, #101014 56%, var(--ink) 100%);
  color: #f2f2f5;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  overflow-x: hidden;
}

#stage {
  position: relative;
  width: min(calc(100vw - 32px), calc((100vh - 104px) * 5 / 3), 1000px);
  aspect-ratio: 5 / 3;
  flex: 0 0 auto;
  overflow: hidden;
  line-height: 0;
  border: 1px solid #3a3a49;
  border-radius: 14px;
  background: #101014;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.68),
    0 0 0 5px rgba(255, 255, 255, 0.025),
    0 0 44px rgba(255, 46, 99, 0.08);
}

#stage::after {
  /* Never layer a CSS compositor surface over KAPLAY's WebGL canvas. Mobile
     Safari/Chrome can promote this pseudo-element into a growing opaque tile
     after a resize or toolbar/orientation change. The in-canvas CRT shader
     already supplies the intended scanlines and vignette. */
  content: none;
  display: none;
}

@supports (height: 100dvh) {
  #stage {
    width: min(calc(100vw - 32px), calc((100dvh - 104px) * 5 / 3), 1000px);
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.arcade-footer {
  width: min(calc(100vw - 32px), 1000px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.025em;
}

.arcade-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arcade-title b {
  color: var(--pink);
  font-weight: 750;
}

.arcade-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.arcade-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  color: #d8d8e0;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.arcade-nav a:hover,
.arcade-nav a:focus-visible {
  border-color: var(--gold);
  background: rgba(255, 209, 102, 0.08);
  color: var(--gold);
  outline: none;
}

.arcade-nav a[aria-current="page"] {
  border-color: rgba(255, 46, 99, 0.72);
  background: rgba(255, 46, 99, 0.12);
  color: #fff;
}

kbd {
  padding: 1px 4px;
  border: 1px solid #454555;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #20202a;
  color: #e8e8ed;
  font: inherit;
  font-size: 0.92em;
}

@media (max-width: 760px) {
  body {
    gap: 10px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  #stage {
    width: min(calc(100vw - 20px), calc((100vh - 126px) * 5 / 3));
    border-radius: 10px;
  }

  .arcade-footer {
    width: min(calc(100vw - 20px), 1000px);
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .arcade-title { white-space: normal; }
  .arcade-nav { justify-content: flex-start; }
}

@supports (height: 100dvh) {
  @media (max-width: 760px) {
    #stage {
      width: min(calc(100vw - 20px), calc((100dvh - 126px) * 5 / 3));
    }
  }
}

/* Short mobile landscape viewports need a one-line footer and a frame sized
   from the *visible* viewport.  `flex: 0 0 auto` above keeps KAPLAY's 5:3
   surface from being squashed, while dvh avoids Safari's retracting toolbar. */
@media (orientation: landscape) and (max-height: 520px) {
  body {
    gap: 8px;
    justify-content: center;
    padding:
      max(8px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  #stage {
    width: min(
      calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100vh - 54px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 5 / 3),
      1000px
    );
  }

  .arcade-footer {
    width: min(
      calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)),
      1000px
    );
    min-height: 28px;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .arcade-title { display: none; }

  .arcade-nav {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: center;
  }

  .arcade-nav a {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 11px;
  }
}

@supports (height: 100dvh) {
  @media (orientation: landscape) and (max-height: 520px) {
    #stage {
      width: min(
        calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)),
        calc((100dvh - 54px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 5 / 3),
        1000px
      );
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .arcade-nav a { transition: none; }
}
