:root {
  --ink: #060915;
  --panel: rgba(14, 21, 39, 0.9);
  --panel-soft: rgba(18, 28, 51, 0.72);
  --line: rgba(130, 214, 255, 0.18);
  --cyan: #36e5ff;
  --blue: #4c7dff;
  --lime: #b8ff57;
  --pink: #ff4f9a;
  --gold: #ffd54a;
  --text: #f4f8ff;
  --muted: #91a3bf;
  color-scheme: dark;
  font-family: Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: radial-gradient(circle at top, #101b37 0, var(--ink) 52%);
}

button, a { font: inherit; }
button { color: inherit; }

.escape-bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.escape-grid {
  position: absolute; inset: 0;
  opacity: .22;
  background-image: linear-gradient(rgba(54,229,255,.1) 1px, transparent 1px), linear-gradient(90deg, rgba(54,229,255,.1) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, #000, transparent 80%);
}
.escape-glow { position: absolute; width: 42vw; aspect-ratio: 1; border-radius: 50%; filter: blur(110px); opacity: .16; }
.glow-one { top: -15vw; left: -12vw; background: var(--cyan); }
.glow-two { right: -16vw; bottom: -20vw; background: var(--pink); }

.intro-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  overflow: hidden;
  background: #050912;
  transition: opacity .45s ease, visibility .45s ease;
}
.intro-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-overlay canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-skip { position: absolute; top: max(18px, env(safe-area-inset-top)); right: 20px; z-index: 2; padding: 10px 15px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: rgba(5,9,18,.72); cursor: pointer; font-weight: 800; }
.intro-title-card { position: relative; z-index: 2; display: grid; justify-items: center; opacity: 0; transform: translateY(18px); pointer-events: none; transition: .5s ease; }
.intro-title-card.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.intro-title-card h2 { margin: 10px 0 18px; font: 900 clamp(2.2rem,8vw,5.6rem) Orbitron,sans-serif; text-align: center; text-shadow: 0 0 32px rgba(54,229,255,.35); }

.game-header {
  width: min(1180px, calc(100% - 32px));
  min-height: 88px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.hub-link, .sound-button, .game-toolbar button, .secondary-action {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  transition: border-color .2s, background .2s, transform .2s;
}
.hub-link { justify-self: start; padding: 10px 14px; }
.sound-button { padding: 10px 14px; cursor: pointer; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.background-picker { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .68rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.background-picker select {
  min-height: 39px; padding: 7px 28px 7px 10px;
  border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); background: #11182a; cursor: pointer; font-weight: 800;
}
.hub-link:hover, .sound-button:hover, .game-toolbar button:hover, .secondary-action:hover { border-color: var(--cyan); background: rgba(54,229,255,.1); }

.game-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 14px;
  color: var(--ink); background: linear-gradient(135deg, var(--cyan), var(--lime));
  font: 900 1.3rem Orbitron, sans-serif;
  box-shadow: 0 0 28px rgba(54,229,255,.28);
}
.game-brand p { margin: 0 0 3px; color: var(--muted); font-size: .72rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.game-brand h1 { margin: 0; font: 900 clamp(1rem, 2vw, 1.3rem) Orbitron, sans-serif; letter-spacing: .02em; }

.game-page { width: min(1180px, calc(100% - 24px)); margin: 0 auto; }
.game-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(5, 10, 23, .88);
  box-shadow: 0 30px 100px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.04);
}

.game-toolbar {
  min-height: 70px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 25px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(54,229,255,.06), transparent 55%, rgba(255,79,154,.04));
}
.toolbar-stat { display: grid; gap: 3px; }
.toolbar-stat span { color: var(--muted); font-size: .68rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.toolbar-stat strong { font: 800 .95rem Orbitron, sans-serif; }
#lifeReadout { color: var(--pink); letter-spacing: .15em; }
.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.game-toolbar button { padding: 9px 12px; cursor: pointer; }
.game-toolbar button:disabled { opacity: .45; cursor: wait; }

.canvas-shell { position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 260px; background: #090e1d; }
canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }

.status-toast {
  position: absolute; top: 18px; left: 50%; z-index: 4;
  padding: 9px 15px;
  border: 1px solid rgba(184,255,87,.35);
  border-radius: 999px;
  background: rgba(6,9,21,.88);
  color: var(--lime);
  font-weight: 900;
  opacity: 0; transform: translate(-50%, -12px);
  transition: .25s;
  pointer-events: none;
}
.status-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.status-toast.achievement-toast { color: #101b05; border-color: var(--lime); background: var(--lime); animation: toastPop .42s ease; }
@keyframes toastPop { 0%{transform:translate(-50%,-16px) scale(.8)} 70%{transform:translate(-50%,2px) scale(1.05)} 100%{transform:translate(-50%,0) scale(1)} }

.yoyo-status {
  position: absolute; right: 14px; bottom: 14px; z-index: 4;
  display: grid; grid-template-columns: auto 72px auto; align-items: center; gap: 7px;
  padding: 7px 9px;
  border: 1px solid rgba(54,229,255,.28); border-radius: 12px;
  background: rgba(6,9,21,.82); color: var(--muted);
  font-size: .62rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase;
  pointer-events: none;
}
.yoyo-status.ready { color: var(--cyan); border-color: rgba(54,229,255,.55); }
.yoyo-meter { width: 72px; height: 5px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.1); }
.yoyo-meter i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--cyan),var(--lime)); transition: width .08s linear; }
.yoyo-status strong { min-width: 38px; color: inherit; font-size: .58rem; }

.game-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: none; place-items: center;
  padding: clamp(14px, 4vw, 34px);
  background: rgba(4,8,18,.78);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}
.game-overlay.visible { display: grid; }
.overlay-panel { width: min(600px, 100%); text-align: center; }
.compact-panel { width: min(430px, 100%); }
.overlay-kicker, .section-kicker { color: var(--cyan); font-size: .7rem; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.overlay-panel h2 { margin: 10px 0 12px; font: 900 clamp(1.65rem, 5vw, 3.2rem) Orbitron, sans-serif; }
.overlay-panel p { margin: 0 auto 18px; max-width: 560px; color: var(--muted); line-height: 1.65; }
.controls-copy { font-size: .78rem; }

.primary-action, .secondary-action {
  min-width: 180px;
  margin: 5px;
  padding: 13px 20px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 900;
}
.primary-action {
  border: 0;
  color: #031017;
  background: linear-gradient(135deg, var(--cyan), var(--lime));
  box-shadow: 0 10px 34px rgba(54,229,255,.22);
}
.primary-action:hover { transform: translateY(-2px); }

.achievement-panel { width: min(540px,100%); margin: 16px auto 0; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.035); }
.achievement-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.achievement-heading h3 { margin: 0; font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.achievement-heading strong { color: var(--lime); font-size: .75rem; }
.achievement-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.achievement-badge { padding: 6px 9px; border: 1px solid rgba(255,255,255,.08); border-radius: 999px; color: #65748e; background: rgba(255,255,255,.025); font-size: .66rem; font-weight: 800; }
.achievement-badge.unlocked { color: #142008; border-color: var(--lime); background: var(--lime); }

.level-choice { height: auto; min-height: 38px; padding: 5px 2px; }
.level-choice-number { display: block; }
.level-stars { display: block; margin-top: 2px; color: #61708b; font-size: .58rem; letter-spacing: -.08em; }
.level-stars.earned { color: var(--gold); }

.completion-panel { width: min(600px,100%); }
.game-overlay.visible .completion-panel { animation: completePanelIn .42s ease; }
@keyframes completePanelIn { from{opacity:0;transform:translateY(14px) scale(.97)} to{opacity:1;transform:translateY(0) scale(1)} }
.earned-stars { margin: 5px 0 13px; color: var(--gold); font-size: clamp(2rem,6vw,3.4rem); letter-spacing: .12em; animation: starEarn .65s ease; }
@keyframes starEarn { from{opacity:0;transform:scale(.55) rotate(-7deg)} to{opacity:1;transform:scale(1) rotate(0)} }
.completion-stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin: 14px 0 18px; }
.completion-stat { padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.04); }
.completion-stat span { display: block; color: var(--muted); font-size: .62rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.completion-stat strong { display: block; margin-top: 4px; font: 800 .88rem Orbitron,sans-serif; }
.celebration-overlay.visible { animation: celebrationIn .55s ease; }
@keyframes celebrationIn { from{opacity:0;transform:scale(1.04)} to{opacity:1;transform:scale(1)} }
.game-complete-panel { width: min(660px,100%); position: relative; }
.master-badge { display: inline-flex; padding: 8px 13px; border: 1px solid rgba(255,213,74,.6); border-radius: 999px; color: var(--gold); background: rgba(255,213,74,.09); font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.confetti-layer { position: absolute; inset: -50px; z-index: -1; overflow: hidden; pointer-events: none; }
.confetti { position: absolute; top: -20px; width: 8px; height: 14px; border-radius: 2px; animation: confettiFall 2.7s ease-in infinite; }
@keyframes confettiFall { to{transform:translateY(620px) rotate(720deg);opacity:.2} }

.level-picker { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; margin: 18px 0; }
.level-choice {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted); background: rgba(255,255,255,.04);
  font-weight: 900; cursor: pointer;
}
.level-choice.unlocked { color: var(--text); border-color: rgba(54,229,255,.35); }
.level-choice.selected { color: #07111b; border-color: transparent; background: var(--cyan); }
.level-choice:disabled { cursor: not-allowed; opacity: .35; }

.mobile-controls { display: none; }
.mobile-play-tools { display: none; }
.touch-button {
  min-width: 58px; height: 58px;
  border: 1px solid rgba(54,229,255,.3);
  border-radius: 17px;
  color: var(--text); background: rgba(7,14,29,.78);
  box-shadow: 0 6px 20px rgba(0,0,0,.28);
  font-size: .72rem; font-weight: 900;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-button.active { color: var(--ink); background: var(--cyan); box-shadow: 0 0 22px rgba(54,229,255,.48); transform: scale(.92); }
.move-button { width: 64px; }
.jump-button { width: 78px; height: 66px; border-color: rgba(184,255,87,.5); background: rgba(24,43,20,.82); font-size: .82rem; }
.jump-button.active { background: var(--lime); }
.yoyo-button { width: 54px; min-width: 54px; height: 42px; border-color: rgba(255,213,74,.45); background: rgba(42,34,8,.82); font-size: .62rem; }
.yoyo-button:active, .yoyo-button.active { color: #171103; background: var(--gold); transform: scale(.92); }
.yoyo-button:disabled { opacity: .32; cursor: not-allowed; }
.whistle-button { width: 54px; min-width: 54px; height: 42px; border-color: rgba(178,132,255,.45); background: rgba(27,17,46,.82); font-size: .58rem; }
.whistle-button:active, .whistle-button.active { color: #10091c; background: #b284ff; transform: scale(.92); }
.whistle-button:disabled { opacity: .4; cursor: wait; }
.mobile-tool-button {
  min-height: 30px; padding: 5px 9px;
  border: 1px solid rgba(255,255,255,.18); border-radius: 10px;
  color: var(--text); background: rgba(6,9,21,.72);
  font-size: .62rem; font-weight: 900;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}

.game-info {
  display: grid;
  grid-template-columns: .8fr 1.2fr;
  gap: 44px;
  align-items: start;
  padding: 46px clamp(10px, 4vw, 36px);
}
.game-info h2 { margin: 9px 0 0; font: 900 clamp(1.5rem, 3vw, 2.4rem) Orbitron, sans-serif; line-height: 1.15; }
.game-info p { margin: 0; color: var(--muted); line-height: 1.85; }

footer { display: flex; justify-content: center; gap: 10px; padding: 20px 20px 34px; color: var(--muted); font-size: .8rem; }
footer a { color: var(--cyan); text-decoration: none; }

@media (hover: none), (pointer: coarse) {
  html, body { overscroll-behavior: none; }
  body.mobile-playing { position: fixed; inset: 0; width: 100%; height: 100dvh; overflow: hidden; }
  body.mobile-playing .game-info, body.mobile-playing footer { display: none; }
  body.mobile-playing .game-page { height: calc(100dvh - 76px); padding-bottom: min(18dvh, 142px); }
  body.mobile-playing .game-card { display: flex; flex-direction: column; height: 100%; }
  body.mobile-playing .canvas-shell { flex: 1; min-height: 0; aspect-ratio: auto; }
  body.mobile-playing #gameCanvas { object-fit: contain; }
  .game-card, .canvas-shell, .mobile-controls, .touch-button { touch-action: none; }
  body.mobile-playing .mobile-controls {
    position: fixed; inset: auto 0 0; z-index: 40;
    display: block; height: min(18dvh, 142px); max-height: 32dvh;
    padding: 0 max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: linear-gradient(to top, rgba(5,9,20,.97) 0%, rgba(5,9,20,.88) 72%, transparent 100%);
    pointer-events: none; overscroll-behavior: none;
  }
  .mobile-controls button { pointer-events: auto; }
  .mobile-play-tools {
    position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 6px; white-space: nowrap;
    color: var(--muted); font-size: .56rem; font-weight: 800;
  }
  .mobile-pause-button { display: none; }
  .move-controls { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); display: flex; gap: 8px; }
  .action-controls {
    position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
    display: grid; grid-template-columns: 54px 54px 78px; align-items: end; gap: 7px;
  }
  .jump-button { grid-column: 3; grid-row: 1; }
}

@media (max-width: 720px) {
  .game-header { min-height: 76px; grid-template-columns: auto 1fr auto; width: calc(100% - 20px); }
  .game-brand { justify-self: center; }
  .game-brand p { display: none; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .hub-link, .sound-button { padding: 9px 10px; font-size: .78rem; }
  .header-actions { gap: 5px; }
  .background-picker span { display: none; }
  .background-picker select { min-height: 36px; max-width: 92px; padding: 6px 22px 6px 8px; font-size: .7rem; }
  .game-page { width: calc(100% - 12px); }
  .game-card { border-radius: 18px; }
  .game-toolbar { min-height: 62px; padding: 9px 11px; gap: 12px; }
  .toolbar-stat:nth-child(3), .toolbar-stat:nth-child(4) { display: none; }
  .toolbar-actions button { font-size: .72rem; padding: 8px; }
  #whistleToolbarButton { display: none; }
  .canvas-shell { min-height: 240px; }
  .overlay-panel p { font-size: .83rem; line-height: 1.45; margin-bottom: 12px; }
  .controls-copy { display: none; }
  .level-picker { margin: 12px 0; max-height: 150px; overflow-y: auto; }
  .level-choice { width: 36px; height: auto; min-height: 40px; }
  .achievement-panel { margin-top: 11px; padding: 9px; }
  .achievement-list { max-height: 66px; overflow-y: auto; }
  .completion-stats { gap: 6px; margin: 10px 0 12px; }
  .completion-stat { padding: 8px 6px; }
  .game-info { grid-template-columns: 1fr; gap: 18px; padding: 34px 14px; }
}

@media (max-width: 430px) {
  .game-brand h1 { font-size: .8rem; }
  .brand-mark { display: none; }
  .sound-button { font-size: 0; }
  .sound-button::after { content: attr(data-state); font-size: .82rem; }
  .toolbar-stat strong { font-size: .8rem; }
  .toolbar-stat span { font-size: .6rem; }
  body.mobile-playing .game-page { width: 100%; height: calc(100dvh - 70px); padding-bottom: min(17dvh, 132px); }
  body.mobile-playing .game-card { border-inline: 0; border-radius: 0; }
  body.mobile-playing .mobile-controls { height: min(17dvh, 132px); }
  .move-button { width: 60px; min-width: 60px; }
  .action-controls { grid-template-columns: 48px 48px 72px; gap: 6px; }
  .yoyo-button, .whistle-button { width: 48px; min-width: 48px; }
  .jump-button { width: 72px; min-width: 72px; }
  .yoyo-status { right: 8px; bottom: 8px; grid-template-columns: auto 52px auto; }
  .yoyo-meter { width: 52px; }
  .intro-title-card h2 { font-size: 2rem; }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  body.mobile-playing .escape-bg, body.mobile-playing .game-header, body.mobile-playing .game-info, body.mobile-playing footer { display: none; }
  body.mobile-playing .game-page { position: fixed; inset: 0; width: 100%; height: 100dvh; padding: 0; margin: 0; }
  body.mobile-playing .game-card { width: 100%; height: 100%; border: 0; border-radius: 0; }
  body.mobile-playing .game-toolbar {
    position: absolute; top: max(4px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); z-index: 25;
    min-height: 34px; padding: 4px 8px; gap: 12px; border: 0; border-radius: 10px; background: rgba(5,9,20,.58);
  }
  body.mobile-playing .toolbar-stat span { display: none; }
  body.mobile-playing .toolbar-stat strong { font-size: .68rem; }
  body.mobile-playing .toolbar-stat:nth-child(3), body.mobile-playing .toolbar-stat:nth-child(4), body.mobile-playing .toolbar-actions { display: none; }
  body.mobile-playing .canvas-shell { position: absolute; inset: 0; width: 100%; height: 100%; }
  body.mobile-playing .mobile-controls { inset: 0; width: 100%; height: 100dvh; max-height: none; padding: 0; background: transparent; }
  .mobile-play-tools { top: max(6px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); left: auto; transform: none; }
  .rotate-copy { display: none; }
  .mobile-pause-button { display: inline-block; }
  .move-controls { left: max(14px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); }
  .action-controls { right: max(14px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }
  .touch-button { background-color: rgba(6,12,25,.58); backdrop-filter: blur(5px); }
  .yoyo-status { right: 50%; bottom: max(7px, env(safe-area-inset-bottom)); transform: translateX(50%); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
