:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: #050505;
  color: #f5f5f5;
  --red: #ff3154;
  --yellow: #ffd447;
  --green: #80ff72;
  --line: #333;
  --panel: #0d0d0d;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #050505; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 49, 84, 0.09), transparent 34rem),
    linear-gradient(#070707 1px, transparent 1px),
    #050505;
  background-size: auto, 100% 32px, auto;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

a { color: #fff; text-underline-offset: 0.22em; }
a:hover { color: var(--yellow); }

.app-shell { width: min(1120px, 100%); margin: 0 auto; min-height: 100dvh; padding: 0 28px 40px; }

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  gap: 24px;
}

.brand { font-weight: 900; letter-spacing: 0.14em; text-decoration: none; color: var(--yellow); }
.runtime-state { color: #aaa; font-size: 0.78rem; display: flex; align-items: center; gap: 9px; text-align: right; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #777; box-shadow: 0 0 0 4px #222; }
.state-dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgba(128, 255, 114, 0.12); }
.state-dot.bad { background: var(--red); box-shadow: 0 0 0 4px rgba(255, 49, 84, 0.12); }

.launcher { padding-top: clamp(56px, 10vw, 112px); }
.hero-copy { max-width: 850px; margin-bottom: 42px; }
.eyebrow, .step { color: var(--red); font-size: 0.72rem; letter-spacing: 0.18em; font-weight: 800; margin: 0 0 12px; }
h1 { font-size: clamp(3.4rem, 13vw, 8.5rem); letter-spacing: -0.08em; line-height: 0.8; margin: 0; font-weight: 950; }
.subtitle { font-size: clamp(1rem, 2.4vw, 1.45rem); color: #bbb; margin: 28px 0 0; }

.legal-note {
  border: 1px solid #5b4c1b;
  border-left: 5px solid var(--yellow);
  padding: 18px 20px;
  background: #171408;
  color: #d8d2b6;
  line-height: 1.65;
}
.legal-note strong { display: block; color: var(--yellow); margin-bottom: 4px; }

.status-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); margin: 22px 0 42px; }
.support-item { background: #090909; padding: 14px 16px; display: flex; justify-content: space-between; gap: 16px; font-size: 0.78rem; }
.support-item span { color: #888; }
.support-item b { color: #bbb; }
.support-item.ok b { color: var(--green); }
.support-item.bad b { color: var(--red); }

.import-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px 44px;
  padding: clamp(24px, 5vw, 46px);
  background: var(--panel);
  border: 1px solid #3a3a3a;
  box-shadow: 12px 12px 0 #121212;
}
h2 { font-size: clamp(1.25rem, 3vw, 2rem); margin: 0 0 12px; }
.muted, .details p { color: #aaa; line-height: 1.65; margin: 0; max-width: 700px; }
code { color: var(--yellow); font-size: 0.92em; }

.actions { min-width: 240px; display: flex; flex-direction: column; align-items: stretch; gap: 10px; justify-content: center; }
button { cursor: pointer; border-radius: 0; }
button:disabled { cursor: not-allowed; opacity: 0.42; }
.primary, .secondary, .quiet {
  min-height: 50px;
  padding: 0 18px;
  border: 1px solid #666;
  font-weight: 800;
}
.primary { color: #050505; background: #fff; border-color: #fff; }
.primary:hover:not(:disabled) { background: var(--yellow); border-color: var(--yellow); }
.secondary { color: #050505; background: var(--green); border-color: var(--green); }
.quiet { color: #aaa; background: transparent; }
.quiet:hover:not(:disabled) { color: #fff; border-color: #aaa; }
.danger:hover:not(:disabled) { color: var(--red); border-color: var(--red); }

.progress-wrap, .message { grid-column: 1 / -1; }
.progress-copy { display: flex; justify-content: space-between; color: #bbb; font-size: 0.78rem; margin-bottom: 8px; }
progress { appearance: none; width: 100%; height: 10px; border: 0; background: #222; }
progress::-webkit-progress-bar { background: #222; }
progress::-webkit-progress-value { background: var(--yellow); }
progress::-moz-progress-bar { background: var(--yellow); }
.message { min-height: 1.4em; margin: 0; color: #bbb; line-height: 1.5; }
.message.error { color: var(--red); }
.message.success { color: var(--green); }

.details { display: flex; justify-content: space-between; gap: 40px; align-items: center; padding: 62px 0; border-bottom: 1px solid var(--line); }
.privacy-badge { flex: 0 0 auto; border: 1px solid #285b24; color: var(--green); padding: 16px 18px; display: flex; gap: 12px; align-items: center; }
.privacy-badge div { display: flex; flex-direction: column; }
.privacy-badge small { color: #789174; margin-top: 4px; }
footer { padding: 28px 0; color: #777; font-size: 0.75rem; line-height: 1.7; }
footer p { margin: 4px 0; }

.game-view { min-height: calc(100dvh - 78px); padding: 16px 0 max(16px, env(safe-area-inset-bottom)); }
.game-toolbar { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #aaa; font-size: 0.78rem; }
.toolbar-button { min-height: 36px; padding: 0 14px; color: #eee; background: #111; border: 1px solid #444; }
.toolbar-button:hover { border-color: #fff; }
.canvas-stage {
  position: relative;
  min-height: min(72dvh, 760px);
  display: grid;
  place-items: center;
  background: #000;
  border: 1px solid #333;
  overflow: hidden;
  touch-action: none;
}
#canvas {
  display: block;
  max-width: 100%;
  max-height: min(72dvh, 760px);
  width: auto;
  height: auto;
  outline: none;
  image-rendering: pixelated;
  background: #000;
}
.audio-gate { position: absolute; inset: auto 50% 18px auto; translate: 50% 0; padding: 12px 16px; color: #050505; background: var(--yellow); border: 0; font-weight: 800; }

.touch-controls { display: none; justify-content: space-between; align-items: end; gap: 28px; padding: 20px 10px 0; user-select: none; touch-action: none; }
.dpad { display: grid; grid-template: repeat(3, 54px) / repeat(3, 54px); }
.dpad button, .action-pad button { color: #fff; background: #151515; border: 1px solid #555; font-weight: 900; touch-action: none; }
.dpad button[data-key="38"] { grid-area: 1 / 2; }
.dpad button[data-key="37"] { grid-area: 2 / 1; }
.dpad button[data-key="40"] { grid-area: 2 / 2; }
.dpad button[data-key="39"] { grid-area: 2 / 3; }
.action-pad { display: flex; align-items: end; gap: 8px; }
.action-pad button { width: 58px; height: 58px; border-radius: 50%; }
.action-pad .key-z { width: 70px; height: 70px; border-color: #ddd; }
.action-pad .key-x { margin-bottom: 36px; }
.action-pad .key-c { margin-bottom: 70px; }
.touch-controls button.active { background: #fff; color: #000; translate: 0 2px; }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls { display: flex; }
  .canvas-stage { min-height: 52dvh; }
  #canvas { max-height: 52dvh; }
}

@media (max-width: 720px) {
  .app-shell { padding-inline: 16px; }
  .topbar { min-height: 64px; }
  .runtime-state { max-width: 62%; }
  .launcher { padding-top: 54px; }
  .status-grid { grid-template-columns: 1fr; }
  .import-card { grid-template-columns: 1fr; padding: 24px 20px; }
  .actions { min-width: 0; }
  .details { align-items: stretch; flex-direction: column; }
  .privacy-badge { width: 100%; }
  .game-view { min-height: calc(100dvh - 64px); }
}

@media (max-width: 430px) {
  .dpad { grid-template: repeat(3, 47px) / repeat(3, 47px); }
  .action-pad button { width: 48px; height: 48px; }
  .action-pad .key-z { width: 58px; height: 58px; }
  .action-pad .key-x { margin-bottom: 28px; }
  .action-pad .key-c { margin-bottom: 52px; }
}

:fullscreen .game-toolbar { padding-inline: max(12px, env(safe-area-inset-left)); }
:fullscreen .canvas-stage { min-height: calc(100dvh - 72px); border: 0; }
:fullscreen #canvas { max-height: calc(100dvh - 72px); }
:fullscreen .touch-controls { position: fixed; inset: auto 0 max(12px, env(safe-area-inset-bottom)); padding-inline: 22px; pointer-events: none; }
:fullscreen .touch-controls button { pointer-events: auto; opacity: 0.72; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
