:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #5f6875;
  --page: #eef3ff;
  --panel: #ffffff;
  --blue: #173a8f;
  --blue-dark: #102b72;
  --yellow: #fff58b;
  --border: #cbd5e1;
  --danger: #b42318;
  --success: #18864b;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 245, 139, 0.72), transparent 34rem),
    var(--page);
  font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
  font: inherit;
}

button:focus-visible,
summary:focus-visible,
canvas:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}

.page-shell {
  width: min(100% - 24px, 920px);
  margin: 0 auto;
  padding: 28px 0 40px;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 7vw, 3.7rem);
  font-weight: 500;
  line-height: 0.98;
}

.game-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(23, 58, 143, 0.12);
}

.screen-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #0000ee;
}

.screen-container canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  background: #000;
}

.welcome-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0000ee;
  transition: opacity 240ms ease;
}

.welcome-overlay.is-hidden {
  pointer-events: none;
  opacity: 0;
}

.welcome-overlay img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
}

.welcome-panel {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 9px;
  width: min(86%, 340px);
  margin-top: 48%;
  padding: 14px 18px;
  border: 2px solid rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
}

.welcome-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 9px 22px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  min-width: 160px;
  border: 2px solid var(--blue-dark);
  color: #fff;
  background: var(--blue);
  box-shadow: 0 5px 0 var(--blue-dark);
}

.primary-button:hover:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 4px 0 var(--blue-dark);
}

.primary-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--blue-dark);
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--ink);
  background: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status-area {
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 24px;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
}

.status-dot.is-busy {
  background: #f59e0b;
  animation: pulse 1s infinite alternate;
}

.status-dot.is-error {
  background: var(--danger);
}

@keyframes pulse {
  to { opacity: 0.35; }
}

progress {
  display: block;
  width: 100%;
  height: 11px;
  margin-top: 10px;
  accent-color: var(--blue);
}

.download-status {
  min-height: 1.2em;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.tips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.tips p {
  margin: 0;
  padding: 13px 15px;
  border: 1px solid rgba(23, 58, 143, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
  line-height: 1.45;
}

details {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.72);
}

summary {
  cursor: pointer;
  font-weight: 700;
}

#diagnosticMessage {
  margin: 12px 0 8px;
}

#logOutput {
  max-height: 220px;
  overflow: auto;
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 8px;
  color: #d7f7d7;
  background: #111827;
  font: 0.75rem/1.45 Consolas, Monaco, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#fallbackUploader p {
  margin: 0 0 10px;
}

footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  text-align: center;
}

.engine-controls {
  display: none !important;
}

.screen-container:fullscreen {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  background: #000;
}

.screen-container:fullscreen canvas,
.screen-container:fullscreen .welcome-overlay {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 16px, 920px);
    padding-top: 18px;
  }

  .site-header {
    align-items: start;
  }

  .tips {
    grid-template-columns: 1fr;
  }

  .welcome-panel {
    margin-top: 42%;
    padding: 10px 12px;
  }

  .welcome-panel p {
    display: none;
  }

  .secondary-button {
    padding-inline: 14px;
  }
}
