:root {
  color-scheme: dark light;
  --bg: #0d0d10;
  --fg: #e8e8ea;
  --muted: #8a8a92;
  --accent: #4ea1ff;
  --danger: #ff6464;
  --ok: #6cd070;
  --bar: #1c1c22;
  --panel: #16161b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); height: 100%; overflow: hidden; }

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bar);
  border-bottom: 1px solid #2a2a30;
  font-size: 13px;
}
.bar__title { font-weight: 600; }
.bar__state {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #333;
  background: #202028;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#app[data-state="preload"] .bar__state  { color: var(--accent); border-color: var(--accent); }
#app[data-state="running"] .bar__state  { color: var(--ok);     border-color: var(--ok); }
#app[data-state="error"]   .bar__state  { color: var(--danger); border-color: var(--danger); }

.canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

#gameCanvas {
  background: #000;
  max-width: 100%;
  max-height: calc(100vh - 130px);
  height: auto;
  aspect-ratio: 16 / 9;
  border: 1px solid #2a2a30;
  outline: none;
  image-rendering: auto;
  touch-action: none;
}

.canvas-wrap__overlay {
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* The runtime hides this layer after AppDelegate has started the Lua client. */
#app[data-state="running"] .canvas-wrap__overlay {
  display: none;
}
.overlay__panel {
  pointer-events: auto;
  max-width: 720px;
  width: calc(100% - 24px);
  background: rgba(20, 20, 24, 0.96);
  border: 1px solid #393943;
  border-radius: 12px;
  padding: 22px 24px 20px;
  text-align: left;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
}
.loader__mascot {
  height: 58px;
  margin: -2px 0 8px;
  overflow: hidden;
  position: relative;
}
.loader__mascot::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5px;
  height: 2px;
  background: #2a2a30;
}
.loader__mascot img {
  position: absolute;
  bottom: 7px;
  left: 0;
  width: 52px;
  height: 52px;
  object-fit: contain;
  animation: loader-pokemon-run 2.4s linear infinite;
}
@keyframes loader-pokemon-run {
  from { transform: translateX(-12px) scaleX(1); }
  48% { transform: translateX(calc(100% - 40px)) scaleX(1); }
  52% { transform: translateX(calc(100% - 40px)) scaleX(-1); }
  to { transform: translateX(-12px) scaleX(-1); }
}
.overlay__title { margin: 0 0 8px 0; font-size: 19px; }
.overlay__body  { margin: 0 0 12px 0; color: #cfcfd4; line-height: 1.45; }
.overlay__detail {
  margin: 0;
  padding: 10px;
  background: #0e0e12;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  font-size: 12px;
  color: #c8c8d0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#app[data-state="running"] .overlay__panel { opacity: 0.4; pointer-events: none; }

.overlay__progress {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.overlay__progress-bar {
  flex: 1;
  height: 8px;
  background: #2a2a30;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.overlay__progress-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--progress, 0%);
  background: var(--accent);
  transition: width 0.2s ease-out;
}
.overlay__progress-text {
  min-width: 4ch;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
}
.overlay__meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.overlay__meta span:last-child { text-align: right; white-space: nowrap; }

.overlay__button {
  margin-top: 12px;
  padding: 6px 12px;
  background: var(--accent);
  color: #001120;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.overlay__button:hover { filter: brightness(1.1); }

.footer {
  padding: 8px 14px;
  background: var(--bar);
  border-top: 1px solid #2a2a30;
  font-size: 12px;
  color: var(--muted);
}
.footer summary { cursor: pointer; user-select: none; }
.footer ul { padding-left: 18px; margin: 6px 0 0 0; }
.footer code { background: #202028; padding: 0 4px; border-radius: 3px; }

@media (max-width: 900px), (pointer: coarse) {
  html,
  body,
  #app {
    width: 100%;
    height: 100%;
    min-height: 100%;
  }

  #app {
    display: block;
  }

  .bar,
  .footer {
    display: none;
  }

  .canvas-wrap {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
      env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  #gameCanvas {
    max-width: 100%;
    max-height: 100%;
    border: 0;
  }

  .canvas-wrap__overlay {
    inset: env(safe-area-inset-top) env(safe-area-inset-right)
      env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .overlay__panel {
    width: min(500px, calc(100% - 24px));
    padding: 18px 16px 16px;
  }
  .overlay__title { font-size: 17px; }
  .overlay__body { font-size: 13px; }
  .overlay__meta { font-size: 11px; }
}
