* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; background: #0E2430; overflow: hidden; touch-action: none;
  font-family: "IBM Plex Mono", "Courier New", monospace; }

/* Portal-style shell: capped game in the center, ad rails around it */
:root {
  --map-ink: #07151C;
  --map-deep: #0E2430;
  --map-teal: #1B4D4A;
  --map-foam: #D7F2E3;
  --map-acid: #E7F06A;
  --map-coral: #FF6B4A;
  --map-node: #F3EFE2;
  --map-locked: #143038;
  /* Embed size — matches canvas 16:9 */
  --game-max-w: 960px;
  --game-max-h: 540px;
  --ad-side-w: 160px;
  --ad-top-h: 90px;
}

#shell {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 16px 20px;
  box-sizing: border-box;
  background: #0E2430;
  overflow: auto;
  touch-action: pan-y;
}
.shell-mid {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  flex: 0 0 auto;
  max-width: 100%;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0A1C24;
  flex-shrink: 0;
  z-index: 1;
  border: 1px solid #143038;
  border-radius: 4px;
}
.ad-slot > * {
  max-width: 100%;
  max-height: 100%;
}
.ad-slot img,
.ad-slot iframe,
.ad-slot video {
  display: block;
  border: 0;
  max-width: 100%;
  max-height: 100%;
}

/* Top banner sits above the game row (game width + side ads) */
.ad-top {
  width: min(100%, calc(var(--game-max-w) + var(--ad-side-w) * 2 + 24px));
  height: var(--ad-top-h);
  min-height: var(--ad-top-h);
  max-height: var(--ad-top-h);
}
.ad-bottom {
  width: min(100%, calc(var(--game-max-w) + var(--ad-side-w) * 2 + 24px));
  min-height: 0;
  max-height: 0;
  background: transparent;
  border: none;
}
.ad-bottom.has-ad {
  min-height: var(--ad-top-h);
  max-height: var(--ad-top-h);
  background: #0A1C24;
  border: 1px solid #143038;
}

.ad-left, .ad-right {
  width: var(--ad-side-w);
  min-width: var(--ad-side-w);
  max-width: var(--ad-side-w);
  /* Match game frame height */
  height: var(--game-max-h);
  align-self: center;
}

.ad-placeholder {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
  color: #5A7A82; padding: 8px 12px;
  border: 1px dashed #2A4A52; border-radius: 4px;
  text-transform: uppercase; white-space: nowrap;
  background: rgba(14, 36, 48, 0.6);
}
.ad-left .ad-placeholder, .ad-right .ad-placeholder {
  writing-mode: vertical-rl; text-orientation: mixed;
}

/* Game frame — fixed portal size, not full screen */
#wrap {
  position: relative;
  width: var(--game-max-w);
  height: var(--game-max-h);
  max-width: min(var(--game-max-w), calc(100vw - var(--ad-side-w) * 2 - 64px));
  max-height: var(--game-max-h);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  background: #07151C;
  border-radius: 6px;
}
canvas {
  image-rendering: pixelated;
  background: #163A42;
  max-width: 100%;
  max-height: 100%;
  border: 4px solid #07151C;
  border-radius: 4px;
}
#wrap.on-map canvas,
#wrap.on-map #hud,
#wrap.on-map #controls { visibility: hidden; pointer-events: none; }

/* ── World map ───────────────────────────────── */
#map-screen {
  position: absolute; inset: 0; z-index: 5;
  display: flex;
  flex-direction: column;
  color: var(--map-foam);
  overflow: hidden;
  border: 4px solid var(--map-ink);
  border-radius: 4px;
  margin: auto;
}
#map-screen[hidden] { display: none !important; }

.map-sky {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, #2A6B66 0%, transparent 55%),
    linear-gradient(180deg, #163A42 0%, #0E2430 42%, #1B4D4A 100%);
  animation: map-sky-shift 14s ease-in-out infinite alternate;
}
.map-grid {
  position: absolute; inset: 0; opacity: 0.14; pointer-events: none;
  background-image:
    linear-gradient(rgba(231, 240, 106, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(231, 240, 106, 0.35) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, transparent, #000 18%, #000 78%, transparent);
  animation: map-grid-drift 20s linear infinite;
}
@keyframes map-sky-shift {
  from { filter: hue-rotate(0deg) brightness(1); }
  to { filter: hue-rotate(12deg) brightness(1.06); }
}
@keyframes map-grid-drift {
  from { background-position: 0 0; }
  to { background-position: 48px 24px; }
}

.map-mast {
  position: relative; z-index: 2;
  text-align: center;
  padding: 18px 16px 8px;
  clip-path: polygon(0 0, 100% 0, 100% 78%, 96% 100%, 88% 86%, 78% 100%, 68% 88%, 58% 100%, 48% 86%, 38% 100%, 28% 88%, 18% 100%, 8% 86%, 0 100%);
  background: linear-gradient(180deg, #0A1C24 0%, #123038 100%);
  border-bottom: 3px solid var(--map-acid);
}
.map-eyebrow {
  font-size: 11px; letter-spacing: 0.28em; color: var(--map-acid);
  margin-bottom: 6px; font-weight: 700;
}
.map-title {
  font-family: "Bungee", "Impact", sans-serif;
  font-size: clamp(28px, 6vw, 52px);
  line-height: 0.95;
  color: var(--map-acid);
  text-shadow: 4px 4px 0 var(--map-ink), -1px 0 0 var(--map-coral);
  letter-spacing: 0.02em;
  animation: map-title-bob 3.2s ease-in-out infinite;
}
@keyframes map-title-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.map-board {
  position: relative; z-index: 2;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-width: 960px;
  margin: 0 auto;
}
.map-path-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  overflow: visible;
}
.map-path-glow {
  stroke: rgba(231, 240, 106, 0.22);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.map-path-line {
  stroke: var(--map-acid);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 10 8;
  animation: map-dash 1.2s linear infinite;
}
@keyframes map-dash {
  to { stroke-dashoffset: -36; }
}

.map-nodes { position: absolute; inset: 0; }
.map-node {
  position: absolute;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%);
  border: none; background: transparent; padding: 0;
  cursor: pointer;
}
.map-node-face {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  font-family: "Bungee", sans-serif;
  font-size: 13px;
  border: 3px solid var(--map-ink);
  background: var(--map-locked);
  color: #4A6A70;
  clip-path: polygon(12% 0, 88% 0, 100% 18%, 100% 100%, 0 100%, 0 18%);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  transition: transform 0.15s ease, background 0.15s ease;
}
.map-node.is-open .map-node-face {
  background: var(--map-node);
  color: var(--map-ink);
}
.map-node.is-cleared .map-node-face {
  background: var(--map-acid);
  color: var(--map-ink);
}
.map-node.is-selected .map-node-face,
.map-node.is-open:hover .map-node-face {
  transform: scale(1.08);
  background: #FFF8C8;
  box-shadow: 0 0 0 3px var(--map-coral), 3px 3px 0 rgba(0,0,0,0.35);
}
.map-node.is-boss .map-node-face {
  width: 54px; height: 54px; margin: -5px;
  font-size: 22px;
  background: var(--map-coral);
  color: #fff;
  clip-path: polygon(50% 0, 100% 28%, 100% 100%, 0 100%, 0 28%);
}
.map-node.is-boss.is-locked .map-node-face {
  background: #5A2A22;
  color: #9A6A62;
}
.map-boss-mark { display: block; line-height: 1; }

.map-cursor {
  position: absolute;
  transform: translate(-50%, -100%);
  color: var(--map-acid);
  font-size: 18px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 var(--map-ink));
  animation: map-arrow 0.7s ease-in-out infinite;
}
@keyframes map-arrow {
  0%, 100% { transform: translate(-50%, -100%); }
  50% { transform: translate(-50%, calc(-100% - 6px)); }
}
.map-hint {
  position: absolute;
  transform: translate(-50%, 0);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--map-ink);
  background: var(--map-acid);
  padding: 3px 8px;
  border: 2px solid var(--map-ink);
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
  animation: map-hint-pulse 1.4s ease-in-out infinite;
}
@keyframes map-hint-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

.map-dock {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px 14px;
  background: linear-gradient(180deg, transparent, rgba(7, 21, 28, 0.85));
}
.map-dock-panel {
  display: flex; align-items: center; gap: 12px;
  background: var(--map-ink);
  border: 2px solid var(--map-teal);
  padding: 8px 12px;
  min-width: 0;
}
.map-icon-btn {
  width: 32px; height: 32px; border: 2px solid var(--map-acid);
  background: transparent; color: var(--map-acid); cursor: pointer;
  font-size: 16px;
}
.map-icon-btn.is-off { opacity: 0.35; text-decoration: line-through; }
.map-best, .map-level-name {
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  white-space: nowrap;
}
.map-level-name { color: var(--map-acid); overflow: hidden; text-overflow: ellipsis; }
.map-play {
  font-family: "Bungee", sans-serif;
  font-size: 16px;
  padding: 12px 22px;
  border: 3px solid var(--map-ink);
  background: var(--map-coral);
  color: #fff;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--map-ink);
  transition: transform 0.12s ease;
}
.map-play:hover, .map-play:focus-visible { transform: translate(-2px, -2px); }
.map-play:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--map-ink); }

.map-back-btn {
  margin-left: 10px; vertical-align: middle;
  border: 2px solid #E7F06A; background: rgba(231, 240, 106, 0.15);
  color: #E7F06A; font-family: inherit; font-weight: bold;
  font-size: 11px; padding: 2px 8px; border-radius: 6px; cursor: pointer;
}

#hud { position: absolute; top: 10px; left: 14px; color: #E7F06A; font-weight: bold;
  font-size: 15px; letter-spacing: 1px; user-select: none; z-index: 2;
  text-shadow: 0 1px 2px #07151C; }
#lvlsel { display: none !important; }
.lbtn { display: none; }
#msg { position: absolute; top: 42%; width: 100%; text-align: center; color: #E7F06A;
  font-size: clamp(18px, 5vw, 38px); font-weight: bold; letter-spacing: 2px;
  text-transform: uppercase; pointer-events: none; opacity: 0; transition: opacity .4s; z-index: 2;
  text-shadow: 0 2px 0 #07151C; }
#controls { position: absolute; bottom: 12px; width: 100%; display: flex;
  justify-content: space-between; padding: 0 16px; pointer-events: none; z-index: 2; }
.pad { display: flex; gap: 10px; pointer-events: auto; }
.btn { width: 62px; height: 62px; border: 2px solid #E7F06A; background: rgba(27, 77, 74, 0.85);
  color: #E7F06A; font-size: 24px; font-weight: bold; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; user-select: none;
  -webkit-user-select: none; }
.btn:active { background: #E7F06A; color: #07151C; }
@media (hover:hover) and (pointer:fine) { #controls { display: none; } }

@media (max-width: 1280px) {
  :root { --ad-side-w: 120px; --game-max-w: 860px; --game-max-h: 484px; }
}
@media (max-width: 1100px) {
  :root { --ad-side-w: 100px; --game-max-w: 760px; --game-max-h: 428px; }
}
@media (max-width: 900px) {
  .ad-left, .ad-right { display: none !important; }
  :root { --ad-top-h: 50px; --game-max-w: 100%; --game-max-h: min(540px, 56vw); }
  #wrap {
    width: min(960px, 100%);
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: none;
  }
  .map-node { width: 36px; height: 36px; }
  .map-node-face { font-size: 10px; }
  .map-title { font-size: clamp(22px, 7vw, 36px); }
}
@media (max-height: 720px) {
  :root { --ad-top-h: 50px; --game-max-h: 420px; --game-max-w: 748px; }
}
