:root {
  --gold: #f6ce73;
  --cyan: #79e8ff;
  --violet: #9b73ff;
  --ink: #09051a;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(circle at 50% 40%, #241b53 0, #0c0922 55%, #05040e 100%);
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
}

#game-shell {
  position: relative;
  width: min(96vw, calc(94vh * 16 / 9), 1280px);
  height: auto;
  aspect-ratio: 16 / 9;
  max-width: 1280px;
  max-height: 94vh;
  overflow: hidden;
  border: 1px solid rgba(152, 218, 255, .24);
  border-radius: 16px;
  background: #09051a;
  box-shadow: 0 30px 90px rgba(0,0,0,.75), 0 0 40px rgba(111,83,255,.12);
}

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.topbar {
  position: absolute;
  z-index: 5;
  left: 20px; right: 20px; top: 14px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s;
}
.topbar.visible { opacity: 1; }
.brand { font-size: clamp(11px, 1.35vw, 18px); letter-spacing: 3px; color: #d9ccff; text-shadow: 0 0 12px #805cff; }
.brand span { color: var(--gold); font-size: .75em; }
.hud { display: flex; gap: 8px; }
.hud-pill {
  min-width: 92px;
  text-align: center;
  padding: 6px 12px;
  border: 1px solid rgba(157, 218, 255, .22);
  border-radius: 8px;
  background: rgba(8, 6, 28, .78);
  backdrop-filter: blur(8px);
}
.hud-pill small { display: block; color: #9eaccd; font: 700 8px Arial, sans-serif; letter-spacing: 1.5px; }
.hud-pill strong { display: block; margin-top: 3px; color: #fff; font: 700 clamp(9px, 1vw, 13px) Arial, sans-serif; }
.actions { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 42px; height: 42px;
  border: 1px solid rgba(217, 200, 255, .28);
  border-radius: 50%;
  background: rgba(12, 9, 36, .82);
  color: #fff;
  cursor: pointer;
  font: 700 16px Arial, sans-serif;
}
.icon-btn:hover { border-color: var(--cyan); box-shadow: 0 0 18px rgba(121,232,255,.28); }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(rgba(5,3,18,.15), rgba(5,3,18,.5));
  transition: opacity .25s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.card {
  width: min(88%, 700px);
  max-height: calc(100% - 36px);
  overflow-y: auto;
  text-align: center;
  padding: clamp(20px, 4vh, 38px);
  border: 1px solid rgba(183, 164, 255, .24);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(24,17,58,.94), rgba(8,7,27,.96));
  box-shadow: 0 24px 70px rgba(0,0,0,.65), inset 0 0 40px rgba(123,94,205,.08);
}
.card h1 { margin: 0; color: #fff1bb; font-size: clamp(42px, 7vw, 78px); line-height: .9; letter-spacing: 5px; text-shadow: 0 3px 0 #8061ae, 0 0 28px #d9a7ff; }
.card h2 { margin: 6px 0 12px; color: var(--cyan); letter-spacing: 5px; font-size: clamp(18px, 2.5vw, 28px); }
.card h3 { margin: 0 0 12px; color: #fff0b0; font-size: clamp(24px, 4vw, 38px); }
.card p { margin: 12px auto; max-width: 520px; color: #bfc6df; font: 15px/1.55 Arial, sans-serif; }
.card .eyebrow { color: var(--gold); font: 700 11px Arial, sans-serif; letter-spacing: 4px; text-transform: uppercase; }

.primary, .secondary {
  margin: 10px 6px 0;
  border-radius: 8px;
  padding: 13px 22px;
  cursor: pointer;
  font: 700 12px Arial, sans-serif;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.primary { border: 1px solid #ffe6a5; color: #1a1328; background: linear-gradient(#ffe8a4, #d9ab55); box-shadow: 0 6px 24px rgba(246,206,115,.22); }
.secondary { border: 1px solid rgba(151,218,255,.38); color: #dff8ff; background: rgba(31,27,72,.85); }
.primary:hover, .secondary:hover { filter: brightness(1.12); transform: translateY(-1px); }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 18px auto; max-width: 540px; }
.level-btn { aspect-ratio: 1.35; border: 1px solid rgba(173,173,224,.24); border-radius: 8px; background: rgba(12,11,38,.9); color: #fff; cursor: pointer; }
.level-btn strong { display: block; font-size: 16px; }
.level-btn small { display: block; height: 24px; margin-top: 3px; color: #99a4c2; font: 8px/1.2 Arial, sans-serif; }
.level-btn.locked { opacity: .42; cursor: not-allowed; }
.level-btn.complete { border-color: rgba(246,206,115,.55); box-shadow: inset 0 0 14px rgba(246,206,115,.08); }
.level-btn.current { border-color: var(--cyan); box-shadow: 0 0 14px rgba(121,232,255,.16); }

.controls { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-top: 14px; color: #b9c0d6; font: 10px Arial, sans-serif; }
.controls b { color: #fff; border: 1px solid #77749a; border-radius: 4px; padding: 4px 7px; margin-right: 4px; }

.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin: 14px auto 6px; text-align: left; }
.help-item { min-height: 62px; padding: 10px 12px; border: 1px solid rgba(156,195,228,.16); border-radius: 9px; background: rgba(13,12,39,.72); }
.help-item strong { display: block; margin-bottom: 4px; color: #fff0b0; font: 700 11px Arial, sans-serif; letter-spacing: 1px; }
.help-item span { color: #bdc7dc; font: 12px/1.45 Arial, sans-serif; }
.help-item kbd { display: inline-block; margin-right: 3px; padding: 2px 5px; border: 1px solid #77749a; border-radius: 4px; background: #17152f; color: #fff; font: 700 10px Arial, sans-serif; }

@media (max-width: 760px), (max-height: 600px) {
  body { padding: 4px; }
  #game-shell { width: min(98vw, calc(92vh * 16 / 9), 1280px); }
  .topbar { left: 8px; right: 8px; top: 6px; height: 46px; }
  .brand { display: none; }
  .hud { gap: 4px; }
  .hud-pill { min-width: 70px; padding: 4px 6px; }
  .icon-btn { width: 34px; height: 34px; }
  .card { width: min(94%, 650px); padding: 14px; }
  .card h1 { font-size: clamp(34px, 9vw, 58px); }
  .card h2 { font-size: clamp(15px, 4vw, 22px); }
  .card h3 { font-size: clamp(20px, 5vw, 30px); }
  .card p { margin: 7px auto; font-size: 12px; }
  .primary, .secondary { padding: 9px 13px; font-size: 10px; }
  .level-grid { gap: 5px; margin: 8px auto; }
  .level-btn small { font-size: 7px; }
  .help-grid { gap: 5px; margin: 7px auto 3px; }
  .help-item { min-height: 48px; padding: 6px 8px; }
  .help-item strong { font-size: 9px; }
  .help-item span { font-size: 9px; }
}

@media (max-width: 520px) {
  .help-grid { grid-template-columns: 1fr 1fr; }
  .hud-pill { min-width: 58px; }
  .hud-pill small { font-size: 6px; }
  .hud-pill strong { font-size: 8px; }
}
