*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #07070c; color: #f4f4f7;
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
}
body {
  display: flex; flex-direction: column;
}

/* Always-visible Console Controls Bar on top while playing (flex sibling above #game, zero overlap!) */
.retro-topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 12px; min-height: 36px;
  background: linear-gradient(90deg, #0d1020 0%, #141933 100%);
  border-bottom: 1px solid rgba(255,255,255,0.14);
  color: #e2e8f0; font-size: 12px; line-height: 1.25;
  user-select: none; z-index: 9998;
}
.retro-topbar.collapsed { display: none; }

.retro-topbar-left {
  display: flex; align-items: center; gap: 8px 12px;
  flex-wrap: wrap; min-width: 0;
}
.retro-sys-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-weight: 800; font-size: 10.5px; letter-spacing: 0.6px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; color: #fff; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.retro-keys-bar {
  display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap;
}
.retro-key-chip {
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap; font-size: 11.5px; color: #cbd5e1;
}
.retro-key-chip kbd {
  display: inline-block;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.24);
  border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px;
  font: 700 10.5px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #fff;
}
.retro-topbar-right {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.retro-top-btn {
  background: rgba(255,255,255,0.09); color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.18); border-radius: 7px;
  padding: 4px 9px; font: 600 11px/1.1 inherit; cursor: pointer;
  transition: background 0.14s, color 0.14s; white-space: nowrap;
}
.retro-top-btn:hover { background: rgba(99, 102, 241, 0.85); color: #fff; border-color: transparent; }

/* Small floating restore pill shown only when the player hides the top bar */
.retro-restore-btn {
  position: fixed; top: 8px; right: 10px; z-index: 9998;
  display: none;
  background: rgba(15, 16, 28, 0.88); color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 999px;
  padding: 5px 11px; font: 600 11.5px/1 inherit; cursor: pointer;
  backdrop-filter: blur(8px); box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}
.retro-restore-btn.visible { display: inline-flex; align-items: center; gap: 5px; }
.retro-restore-btn:hover { background: rgba(99, 102, 241, 0.92); color: #fff; }

/* Emulator canvas fills exact remaining height cleanly */
#game { flex: 1 1 auto; min-height: 0; width: 100%; }

/* Info & License popover */
.retro-help-card {
  position: fixed; top: 44px; right: 10px; z-index: 9999;
  width: min(370px, calc(100vw - 20px));
  background: rgba(14, 14, 22, 0.97); color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.18); border-radius: 14px;
  padding: 15px 17px; backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0,0,0,0.7);
  display: none; font-size: 12.5px; line-height: 1.5;
}
.retro-help-card.open { display: block; }
.retro-help-card h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px; color: #fff; }
.retro-help-card .meta { font-size: 11.5px; color: #94a3b8; margin-bottom: 10px; }
.retro-help-card .keys {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 12px;
  background: rgba(255,255,255,0.05); padding: 9px 11px; border-radius: 9px;
  margin-bottom: 10px; font-size: 12px;
}
.retro-help-card .keys b { color: #a5b4fc; font-weight: 600; }
.retro-help-card .links { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.retro-help-card a { color: #818cf8; text-decoration: none; font-weight: 600; font-size: 12px; }
.retro-help-card a:hover { text-decoration: underline; }
.retro-help-card .close-btn {
  background: rgba(255,255,255,0.1); border: none; color: #fff;
  padding: 4px 10px; border-radius: 7px; cursor: pointer; font: 600 11.5px inherit;
}

.retro-notice {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(circle at 50% 30%, #171832 0%, #090910 75%);
}
.retro-notice-box {
  max-width: 520px; width: 100%; background: rgba(20,21,36,0.96);
  border: 1px solid rgba(129,140,248,0.35); border-radius: 18px;
  padding: 26px 28px; box-shadow: 0 24px 60px rgba(0,0,0,0.65);
  text-align: center;
}
.retro-notice-box h2 { font-size: 20px; margin-bottom: 10px; color: #fff; }
.retro-notice-box p { font-size: 13.5px; color: #cbd5e1; line-height: 1.6; margin-bottom: 14px; }
.retro-notice-box .launch-tab-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
  border: none; border-radius: 12px; padding: 12px 22px; margin: 6px 0 14px;
  font: 700 14px/1 'Space Grotesk', system-ui, sans-serif; cursor: pointer;
  box-shadow: 0 8px 24px rgba(99,102,241,0.45); transition: transform 0.12s;
}
.retro-notice-box .launch-tab-btn:hover { transform: translateY(-2px); }
.retro-notice-box code {
  display: inline-block; background: rgba(255,255,255,0.08);
  padding: 2px 7px; border-radius: 6px; font-size: 12px; color: #a5b4fc;
}

@media (max-width: 720px) {
  .retro-topbar { padding: 5px 8px; font-size: 11px; }
  .retro-key-chip { font-size: 10.5px; }
  .retro-key-chip kbd { font-size: 10px; padding: 1px 4px; }
}
