/* aigames.one shared game shell — styles.
   Everything is namespaced under .arcade- so it won't collide with game CSS. */

/* Tokens use :where() (zero specificity) so a game's own rules always win. */
:where(:root) {
  --arcade-bg: #0e1020;
  --arcade-panel: #171a33;
  --arcade-panel-2: #22264a;
  --arcade-text: #f2f3ff;
  --arcade-muted: #a9aed6;
  --arcade-accent: #7c8cff;
  --arcade-accent-2: #ff6fb1;
  --arcade-focus: #ffd166;
  --arcade-header-h: 48px;
  --arcade-touch-h: 0px;
}

html.arcade-shell, html.arcade-shell body {
  margin: 0;
  background: var(--arcade-bg);
  color: var(--arcade-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.arcade-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--arcade-header-h);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--arcade-panel);
  border-bottom: 1px solid var(--arcade-panel-2);
  font-size: 15px;
}

.arcade-header a,
.arcade-header button {
  color: var(--arcade-text);
  font: inherit;
}

.arcade-back {
  text-decoration: none;
  white-space: nowrap;
  padding: 6px 8px;
  border-radius: 8px;
}
.arcade-back:hover { background: var(--arcade-panel-2); }

.arcade-title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.arcade-original {
  color: var(--arcade-muted) !important;
  font-size: 13px !important;
  white-space: nowrap;
  padding: 6px 8px;
}

.arcade-best {
  color: var(--arcade-muted);
  font-size: 13px;
  white-space: nowrap;
}

.arcade-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--arcade-panel-2);
  background: var(--arcade-panel-2);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 8px;
}
.arcade-btn:hover { border-color: var(--arcade-accent); }
.arcade-btn[aria-pressed="true"] { border-color: var(--arcade-accent-2); }

.arcade-header :focus-visible,
.arcade-overlay :focus-visible,
.arcade-touch :focus-visible {
  outline: 3px solid var(--arcade-focus);
  outline-offset: 2px;
}

@media (max-width: 560px) {
  .arcade-back .arcade-label,
  .arcade-best { display: none; }
  .arcade-original { font-size: 12px !important; padding: 6px 4px; }
}

/* Pause overlay */
.arcade-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 20, 0.78);
  backdrop-filter: blur(2px);
}
.arcade-overlay.is-open { display: flex; }

.arcade-overlay-card {
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-panel-2);
  border-radius: 16px;
  padding: 24px 28px;
  min-width: 240px;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.arcade-overlay-card h2 { margin: 0 0 8px; font-size: 26px; }
.arcade-overlay-card p { margin: 0 0 16px; color: var(--arcade-muted); font-size: 14px; }
.arcade-overlay-card .arcade-btn {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  height: 44px;
  font-size: 16px;
}
.arcade-overlay-card .arcade-primary {
  background: var(--arcade-accent);
  border-color: var(--arcade-accent);
  color: #0b0d1e;
  font-weight: 700;
}

/* On-screen touch controls.
   --arcade-touch-h is the height games reserve under their canvas for the pad.
   These rules use :where() (zero specificity) so a game's own
   `html.arcade-touch-on { --arcade-touch-h: ... }` always wins. */
:where(html.arcade-touch-on) { --arcade-touch-h: 96px; }
/* A full d-pad (with up/down) is 3 x 56 px + gaps + padding: about 200 px. */
:where(html.arcade-touch-on.arcade-touch-tall) {
  --arcade-touch-h: calc(188px + max(12px, env(safe-area-inset-bottom)));
}

.arcade-touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1050;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.arcade-touch.is-on { display: flex; }

.arcade-dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
}
.arcade-dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.arcade-dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.arcade-dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.arcade-dpad [data-dir="down"] { grid-column: 2; grid-row: 3; }

.arcade-actions {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.arcade-pad {
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(23, 26, 51, 0.55);
  color: var(--arcade-text);
  border-radius: 14px;
  font: 700 18px system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.arcade-actions .arcade-pad {
  width: 68px;
  height: 68px;
  border-radius: 50%;
}
.arcade-pad.is-down {
  background: rgba(124, 140, 255, 0.6);
  border-color: var(--arcade-accent);
}

/* Phones held sideways (short landscape screens): slim the header and let the
   touch pad float over the canvas edges instead of reserving a bottom bar. */
@media (orientation: landscape) and (max-height: 500px) {
  :where(html.arcade-shell) { --arcade-header-h: 36px; }
  :where(html.arcade-touch-on),
  :where(html.arcade-touch-on.arcade-touch-tall) { --arcade-touch-h: 0px; }
  .arcade-header { gap: 6px; padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); font-size: 14px; }
  .arcade-btn { min-width: 30px; height: 30px; font-size: 14px; }
  .arcade-back, .arcade-original { padding: 4px 6px; }
  .arcade-touch { padding: 6px max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .arcade-dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); }
  .arcade-dpad[style] .arcade-pad { width: 58px !important; height: 58px !important; }
  .arcade-actions { gap: 10px; }
  .arcade-actions .arcade-pad { width: 58px; height: 58px; font-size: 15px; }
  .arcade-pad { background: rgba(23, 26, 51, 0.38); border-color: rgba(255, 255, 255, 0.45); }
}

/* Fullscreen: let the stage fill the screen */
.arcade-stage:fullscreen { background: #000; width: 100vw; height: 100vh; }
.arcade-stage:-webkit-full-screen { background: #000; width: 100vw; height: 100vh; }

.arcade-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
