:root {
  --bg: #000000;
  --ink: #f5f5f5;
  --muted: rgba(245, 245, 245, 0.68);
  --accent: #ffffff;
  --line: rgba(255, 255, 255, 0.14);
  --app-height: 100dvh;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
}

#screen {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  height: var(--app-height);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  touch-action: none;
}

#game {
  width: 100%;
  height: 100%;
  background: var(--bg);
}

#splash,
#demo-lock {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

#splash {
  overflow: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

#splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-card,
.demo-card {
  width: min(100%, 420px);
  text-align: center;
}

.logo {
  display: block;
  width: min(300px, 82vw);
  height: 96px;
  margin: 0 auto 8px;
  object-fit: cover;
  object-position: center;
}

.splash-card h1,
.demo-card h1 {
  margin: 8px 0 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 600;
}

.splash-lead,
.demo-card p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.splash-status {
  margin: 22px 0 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.splash-status::after {
  content: "";
  display: block;
  width: 112px;
  height: 2px;
  margin: 14px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: printadaz-load 1.1s ease-in-out infinite;
}

.splash-shop,
.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  margin-top: 22px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #111111;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
}

.cta {
  width: 100%;
  padding: 14px 18px;
}

.splash-shop:focus-visible,
.cta:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.demo-timer {
  position: fixed;
  z-index: 30;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.demo-timer.is-warning {
  color: #ffb020;
  border-color: rgba(255, 176, 32, 0.45);
}

.demo-timer.is-danger {
  color: #ff5a5a;
  border-color: rgba(255, 90, 90, 0.5);
}

#demo-lock {
  z-index: 40;
}

#demo-lock[hidden],
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Capa do jogo no splash */
#splash.has-cover::before {
  content: "";
  position: absolute;
  inset: -40px;
  background: var(--cover-url) center / cover no-repeat;
  filter: blur(28px) brightness(0.45) saturate(1.2);
  transform: scale(1.1);
}

.splash-card {
  position: relative;
}

/* Card do jogo: capa, nome, texto e botão num painel fino e translúcido */
#splash.is-card .splash-card {
  width: min(86vw, 340px);
  padding: 12px 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  background: rgba(30, 30, 36, 0.5);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  animation: printadaz-cover-in 0.35s ease-out both;
}

.splash-cover {
  margin: 0;
}

.splash-cover img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 50vh;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

#splash.is-card .splash-card h1 {
  margin: 14px 4px 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

#splash.is-card .splash-lead {
  margin: 6px 6px 0;
  font-size: 13px;
  line-height: 1.4;
}

#splash.is-card .splash-status {
  margin-top: 16px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#splash.is-card .splash-status::after {
  margin-top: 10px;
}

.start-button {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.12);
  animation: printadaz-cover-in 0.25s ease-out both;
}

.start-button:active {
  transform: scale(0.98);
}

.start-button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

@keyframes printadaz-cover-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Aviso curto (falta 1 minuto, dica de save) */
.toast {
  position: fixed;
  z-index: 35;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

body[data-mode="demo"] .toast {
  top: calc(60px + env(safe-area-inset-top));
  bottom: auto;
  color: #ffb020;
  border-color: rgba(255, 176, 32, 0.45);
  font-weight: 600;
}

/* Tela de tempo esgotado */
.demo-card .demo-hint {
  margin-top: 18px;
  font-size: 14px;
}

#demo-lock .logo {
  -webkit-user-drag: none;
  touch-action: none;
}

.stand-form {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: left;
}

.stand-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stand-row {
  display: flex;
  gap: 8px;
}

.stand-row input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111;
  color: #fff;
  font-size: 18px;
  letter-spacing: 0.2em;
  -webkit-user-select: text;
  user-select: text;
}

.stand-row button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font-size: 15px;
  font-weight: 700;
}

.stand-message {
  min-height: 1.4em;
  margin: 8px 0 0 !important;
  font-size: 13px !important;
  color: #ff5a5a !important;
}

/*
 * Retrato no celular: a imagem do jogo fica no topo, na proporção do console,
 * e os controles virtuais do EmulatorJS ficam na área livre embaixo.
 * O RetroArch redesenha o quadro conforme o tamanho CSS do canvas.
 */
@media (orientation: portrait) and (pointer: coarse) {
  body.has-game #screen {
    padding-top: env(safe-area-inset-top);
  }

  body.has-game #game .ejs_canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: var(--game-aspect, 1.3333);
    max-height: 60%;
  }

  /* Timer logo abaixo da imagem, fora do jogo e longe do Start/Select. */
  body.has-game .demo-timer {
    top: calc(env(safe-area-inset-top) + 100vw / var(--game-aspect, 1.3333) + 10px);
    font-size: 14px;
    padding: 5px 12px;
  }

  body.has-game[data-mode="demo"] .toast {
    top: calc(env(safe-area-inset-top) + 100vw / var(--game-aspect, 1.3333) + 54px);
  }
}

/* Controles com skin (public/assets/skins.js) */
#skin {
  position: fixed;
  left: 0;
  z-index: 15;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#skin img {
  position: absolute;
  pointer-events: none;
  -webkit-user-drag: none;
}

#skin .skin-art {
  inset: 0;
  width: 100%;
  height: 100%;
}

body.skin-translucent #skin .skin-art {
  opacity: 0.75;
}

#skin .skin-knob {
  transition: transform 0.06s linear;
  will-change: transform;
}

#skin .skin-glow {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 255, 255, 0);
  transition: background 0.06s ease;
}

#skin .skin-glow.is-pressed {
  background: rgba(255, 255, 255, 0.28);
}

/* Com skin, o controle padrão do EmulatorJS some. */
body.has-skin #game .ejs_virtualGamepad_parent {
  display: none !important;
}

body.has-skin.skin-menu-open #skin {
  pointer-events: none;
  opacity: 0.2;
  transition: opacity 0.15s ease;
}

@media (orientation: portrait) and (pointer: coarse) {
  body.has-skin #game .ejs_canvas {
    max-height: 100%;
  }
}

/* Retrato com skin: parte de cima do console, desenhada pelo skins.js */
#skin-cap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 0;
  pointer-events: none;
}

body.has-skin:not(.skin-landscape) .demo-timer {
  top: calc(env(safe-area-inset-top) + 10px);
}

/* Com skin, os avisos ficam no alto, longe dos botões. */
body.has-skin .toast {
  top: calc(env(safe-area-inset-top) + 12px);
  bottom: auto;
}

body.has-skin[data-mode="demo"] .toast,
body.has-skin:not(.skin-landscape)[data-mode="demo"] .toast {
  top: calc(env(safe-area-inset-top) + 54px);
}

@keyframes printadaz-load {
  0% { transform: scaleX(0.35); opacity: 0.4; }
  50% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(0.35); opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  #splash,
  #splash.is-card .splash-card,
  .start-button,
  .splash-status::after {
    animation: none;
    transition: none;
  }
}
