:root {
  --bg-deep: #050b1a;
  --bg-panel: #0b1428;
  --bg-card: rgba(12, 22, 44, 0.88);
  --border-subtle: rgba(56, 189, 248, 0.22);
  --border-bright: rgba(56, 189, 248, 0.55);
  --cyan: #0ea5e9;
  --cyan-light: #38bdf8;
  --gold: #f59e0b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --shadow-glow: 0 20px 60px rgba(2, 6, 23, 0.85), 0 0 42px rgba(14, 165, 233, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #0d1f44 0%, var(--bg-deep) 65%);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  padding: 10px 16px;
  gap: 10px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(9, 17, 36, 0.82);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--cyan) 0 46%, #182236 46% 54%, #f8fafc 54% 100%);
  border: 2px solid #e2e8f0;
  flex-shrink: 0;
  position: relative;
}

.brand-mark::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: #f8fafc;
  border: 2px solid #182236;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-title {
  font-family: 'Exo 2', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.build-badge {
  font-family: 'Exo 2', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--cyan-light);
  background: rgba(14, 165, 233, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.14s ease, background-color 0.14s ease, border-color 0.14s ease;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
  border-color: rgba(148, 163, 184, 0.22);
}

.btn-ghost:hover {
  color: var(--text-main);
  border-color: var(--border-bright);
}

.btn-secondary {
  color: #e0f2fe;
  background: rgba(14, 165, 233, 0.18);
  border-color: rgba(56, 189, 248, 0.42);
}

.btn-secondary:hover {
  background: rgba(14, 165, 233, 0.28);
}

.btn-outline {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.38);
}

.btn-outline:hover {
  background: rgba(245, 158, 11, 0.22);
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gba-stage {
  position: relative;
  width: min(100%, calc((100dvh - 130px) * 1.5));
  max-width: 1120px;
  max-height: calc(100dvh - 130px);
  aspect-ratio: 3 / 2;
  background: #020612;
  border: 1px solid var(--border-bright);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-glow);
}

.emu-mount {
  width: 100%;
  height: 100%;
}

.launch-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 25%, rgba(14, 165, 233, 0.22), transparent 58%),
    radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.14), transparent 45%),
    linear-gradient(160deg, #07122b 0%, #050b1a 60%, #030712 100%);
}

.launch-bg-glow {
  position: absolute;
  inset: 14px;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.16);
  pointer-events: none;
}

.launch-content {
  position: relative;
  z-index: 1;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.eyebrow {
  margin: 0;
  font-family: 'Exo 2', sans-serif;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--cyan-light);
}

.hero-title {
  margin: 0;
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: clamp(1.7rem, 4.2vw, 3rem);
  line-height: 1.08;
  background: linear-gradient(180deg, #ffffff 0%, #bae6fd 70%, #7dd3fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 8px 30px rgba(14, 165, 233, 0.25);
}

.hero-tagline {
  margin: 0;
  font-size: clamp(0.88rem, 1.8vw, 1.05rem);
  font-weight: 600;
  color: #cbd5e1;
}

.feature-pills {
  list-style: none;
  margin: 4px 0 6px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.feature-pills li {
  font-size: 0.76rem;
  font-weight: 700;
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.32);
  padding: 5px 11px;
  border-radius: 999px;
}

.launch-cta-row {
  margin-top: 6px;
}

.btn-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 34px;
  border: 1px solid rgba(125, 211, 252, 0.75);
  border-radius: 999px;
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 55%, #38bdf8 100%);
  color: #031126;
  font-family: 'Exo 2', sans-serif;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(14, 165, 233, 0.42);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.btn-play:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 36px rgba(56, 189, 248, 0.56);
  filter: brightness(1.05);
}

.btn-play:active {
  transform: translateY(0) scale(0.99);
}

.play-triangle {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 12px solid #031126;
}

.rom-meta {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.rom-meta code {
  color: var(--gold);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.emu-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(5, 11, 26, 0.94);
  color: #fca5a5;
}

.bottom-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.controls-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(9, 17, 36, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.controls-strip kbd,
.key-grid kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: #e2e8f0;
  background: #13213e;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 5px;
}

.controls-note {
  color: #7dd3fc;
}

.modal-backdrop[hidden],
.launch-overlay[hidden],
.emu-mount[hidden],
.emu-error[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(560px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: #0a142a;
  border: 1px solid var(--border-bright);
  border-radius: 16px;
  box-shadow: var(--shadow-glow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 16px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #cbd5e1;
}

.help-section h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--cyan-light);
}

.key-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  align-items: center;
  background: rgba(15, 23, 42, 0.7);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.help-tip {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.help-section ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@media (max-width: 768px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .top-bar {
    padding: 8px 10px;
    flex-wrap: wrap;
  }

  .brand-title {
    font-size: 0.9rem;
  }

  .btn {
    padding: 6px 9px;
    font-size: 0.75rem;
  }

  .gba-stage {
    width: 100%;
    max-height: calc(100dvh - 140px);
    aspect-ratio: 3 / 2;
  }

  .launch-overlay {
    padding: 14px;
  }

  .feature-pills {
    gap: 5px;
  }

  .feature-pills li {
    font-size: 0.68rem;
    padding: 3px 8px;
  }

  .btn-play {
    padding: 11px 24px;
    font-size: 0.96rem;
  }

  .controls-strip {
    font-size: 0.68rem;
    padding: 6px 10px;
  }

  body.is-playing .app-shell {
    padding: 0;
    gap: 0;
  }

  body.is-playing .top-bar,
  body.is-playing .bottom-bar {
    display: none;
  }

  body.is-playing .gba-stage {
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
  }
}
