:root {
    --sky: #87CEEB;
    --ground: #5C8A3C;
    --ground-dark: #3A5A28;
    --platform: #C4843A;
    --platform-dark: #8B5E2A;
    --accent: #FFD700;
    --pixel: #1a1a2e;
    --white: #fff;
    --cloud: rgba(255,255,255,0.9);
    --char-w: 40px;
    --char-h: 56px;
    --ground-h: 80px;
    --level-h: 100vh;
    --world-w: 5000px;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    background: var(--pixel);
    font-family: 'DM Sans', sans-serif;
    overflow: hidden;
    height: 100vh;
    cursor: none;
  }

  /* ── LOADING SCREEN ── */
  #loading {
    position: fixed; inset: 0; z-index: 100;
    background: var(--pixel);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 24px;
    transition: opacity 0.6s ease;
  }
  #loading h1 {
    font-family: 'Press Start 2P', monospace;
    color: var(--accent);
    font-size: clamp(14px, 3vw, 24px);
    text-align: center;
    line-height: 1.8;
    animation: blink 1s step-end infinite;
  }
  #loading .bar-outer {
    width: 240px; height: 16px;
    border: 3px solid var(--accent);
    position: relative;
  }
  #loading .bar-inner {
    height: 100%; width: 0;
    background: var(--accent);
    animation: loadbar 2s ease forwards;
  }
  @keyframes loadbar { to { width: 100%; } }
  @keyframes blink { 50% { opacity: 0; } }

  /* ── HUD ── */
  #hud {
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px;
    background: rgba(0,0,0,0.5);
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--accent);
    pointer-events: none;
  }
  #hud .lives { display: flex; gap: 6px; }
  #hud .life { width: 14px; height: 14px; background: #ff4c4c; clip-path: polygon(50% 0%,61% 35%,98% 35%,68% 57%,79% 91%,50% 70%,21% 91%,32% 57%,2% 35%,39% 35%); }
  #hud .score span { font-size: 12px; color: #fff; }

  /* ── SCROLL HINT ── */
  #hint {
    position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
    font-family: 'Press Start 2P', monospace; font-size: 9px;
    color: rgba(255,255,255,0.6);
    z-index: 50;
    animation: float 2s ease-in-out infinite;
    pointer-events: none;
  }
  @keyframes float { 0%,100%{transform:translateX(-50%) translateY(0)} 50%{transform:translateX(-50%) translateY(-6px)} }

  /* ── VIEWPORT ── */
  #viewport {
    width: 100vw; height: 100vh;
    overflow: hidden;
    position: relative;
  }

  /* ── WORLD ── */
  #world {
    position: absolute;
    width: var(--world-w);
    height: 100vh;
    will-change: transform;
    transition: transform 0.12s linear;
  }

  /* ── SKY ── */
  .sky {
    position: absolute; inset: 0 0 var(--ground-h) 0;
    background: linear-gradient(180deg, #1a1a5e 0%, #3a7bd5 50%, #87CEEB 100%);
    filter: blur(1.5px);
  }

  /* ── STARS (animated) ── */
  .stars {
    position: absolute; top: 0; left: 0; right: 0; height: 40%;
    pointer-events: none;
    filter: blur(0.5px);
  }
  .star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    animation: twinkle var(--d, 2s) ease-in-out infinite;
  }
  @keyframes twinkle { 0%,100%{opacity:1} 50%{opacity:0.2} }

  /* ── CLOUDS ── */
  .cloud {
    position: absolute;
    background: var(--cloud);
    border-radius: 50px;
    filter: blur(2px);
    animation: driftCloud linear infinite;
    opacity: 0.85;
  }
  .cloud::before, .cloud::after {
    content: ''; position: absolute;
    background: var(--cloud);
    border-radius: 50%;
  }
  @keyframes driftCloud {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-200px); }
  }

  /* ── GROUND ── */
  .ground {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: var(--ground-h);
    background: linear-gradient(180deg, var(--ground) 0 16px, var(--ground-dark) 16px 100%);
    image-rendering: pixelated;
  }
  /* grass pixels */
  .ground::before {
    content: '';
    position: absolute; top: -8px; left: 0; right: 0; height: 8px;
    background: repeating-linear-gradient(
      90deg,
      var(--ground) 0 16px,
      #76aa4a 16px 32px
    );
  }

  /* ── PLATFORMS ── */
  .platform {
    position: absolute;
    height: 24px;
    background: linear-gradient(180deg, var(--platform) 0 8px, var(--platform-dark) 8px 100%);
    border-top: 4px solid #e8a040;
    border-radius: 4px 4px 0 0;
    image-rendering: pixelated;
  }

  /* ── SECTION BLOCKS ── */
  .section-block {
    position: absolute;
    background: rgba(0,0,0,0.7);
    border: 3px solid var(--accent);
    border-radius: 8px;
    padding: 20px 24px;
    width: 340px;
    backdrop-filter: blur(8px);
    box-shadow: 0 0 20px rgba(255,215,0,0.15), inset 0 0 20px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.5s ease;
    transform: translateY(10px);
    pointer-events: none;
  }
  .section-block.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
  }
  .section-block h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: var(--accent);
    margin-bottom: 4px;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .section-block .date {
    font-size: 10px;
    color: rgba(255,255,255,0.5);
    margin-bottom: 10px;
    font-style: italic;
  }
  .section-block p {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    line-height: 1.6;
  }

  /* ── SKILL BARS ── */
  .skill-row {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 8px;
  }
  .skill-row label {
    font-size: 10px; color: rgba(255,255,255,0.7);
    width: 90px; flex-shrink: 0;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
  }
  .skill-bar {
    flex: 1; height: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    overflow: hidden;
  }
  .skill-fill {
    height: 100%; width: 0;
    background: linear-gradient(90deg, var(--accent), #ff9900);
    border-radius: 2px;
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1) 0.3s;
  }
  .section-block.visible .skill-fill {
    width: var(--pct);
  }

  /* ── COLLECTIBLE COINS ── */
  .coin {
    position: absolute;
    width: 24px; height: 24px;
    background: var(--accent);
    border-radius: 50%;
    border: 3px solid #b8860b;
    box-shadow: 0 0 8px rgba(255,215,0,0.5);
    animation: coinBob 1.2s ease-in-out infinite;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
  }
  .coin:hover { transform: scale(1.2) translateY(-4px); }
  .coin.collected {
    transform: translateY(-40px) scale(0.5);
    opacity: 0;
    pointer-events: none;
  }
  @keyframes coinBob {
    0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)}
  }

  /* ── QUESTION BLOCK ── */
  .qblock {
    position: absolute;
    width: 40px; height: 40px;
    background: linear-gradient(180deg, #e8a040 0 4px, var(--platform) 4px 100%);
    border: 3px solid #b8860b;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Press Start 2P', monospace;
    color: var(--pixel);
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.1s;
  }
  .qblock:active { transform: translateY(-4px); }

  /* ── CHARACTER (Kaz Robot) ── */
  #character {
    position: fixed;
    bottom: var(--ground-h);
    width: 60px;
    height: 78px;
    z-index: 20;
    left: 120px;
    will-change: transform, bottom;
  }
  .char-body {
    position: absolute;
    width: 100%; height: 100%;
    transform-origin: bottom center;
  }
  #character.facing-left .char-body {
    transform: scaleX(-1);
  }
  .char-body.idle {
    animation: kazIdle 2s ease-in-out infinite;
  }
  @keyframes kazIdle {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
  }
  #character.facing-left .char-body.idle {
    animation: kazIdleFlip 2s ease-in-out infinite;
  }
  @keyframes kazIdleFlip {
    0%,100% { transform: scaleX(-1) translateY(0); }
    50%      { transform: scaleX(-1) translateY(-4px); }
  }
  .char-body.walking {
    animation: kazWalk 0.28s steps(2) infinite;
  }
  @keyframes kazWalk {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
  }
  #character.facing-left .char-body.walking {
    animation: kazWalkFlip 0.28s steps(2) infinite;
  }
  @keyframes kazWalkFlip {
    0%,100% { transform: scaleX(-1) translateY(0); }
    50%      { transform: scaleX(-1) translateY(-3px); }
  }
  .char-body.walking #kaz-leg-l {
    animation: legLSwing 0.28s steps(2) infinite;
    transform-origin: 81px 196px;
  }
  .char-body.walking #kaz-leg-r {
    animation: legRSwing 0.28s steps(2) infinite;
    transform-origin: 119px 196px;
  }
  @keyframes legLSwing {
    0%,100% { transform: rotate(16deg); }
    50%      { transform: rotate(-16deg); }
  }
  @keyframes legRSwing {
    0%,100% { transform: rotate(-16deg); }
    50%      { transform: rotate(16deg); }
  }
  .char-body.idle #kaz-eye-l,
  .char-body.idle #kaz-eye-r {
    animation: eyePulse 2s ease-in-out infinite;
  }
  @keyframes eyePulse {
    0%,100% { opacity: 0.9; }
    50%      { opacity: 0.4; }
  }
  .dust {
    position: fixed;
    width: 30px; height: 12px;
    border-radius: 50%;
    background: rgba(255,140,6,0.35);
    pointer-events: none;
    animation: dustPuff 0.4s ease-out forwards;
    z-index: 19;
  }
  @keyframes dustPuff {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(2.5); opacity: 0; }
  }
 50%{transform:translateY(-2px)} }

  /* ── LEVEL SIGNS ── */
  .level-sign {
    position: absolute;
    width: 60px;
    background: var(--accent);
    border: 3px solid #b8860b;
    border-radius: 6px;
    text-align: center;
    padding: 6px 4px;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: var(--pixel);
    line-height: 1.6;
  }
  .level-sign .post {
    position: absolute;
    bottom: -30px; left: 50%; transform: translateX(-50%);
    width: 6px; height: 30px;
    background: #b8860b;
  }

  /* ── TREES / DECORATIONS ── */
  .tree {
    position: absolute;
    bottom: var(--ground-h);
  }
  .tree-trunk {
    width: 16px; height: 32px;
    background: #7a5230;
    border: 2px solid #5c3d1e;
    margin: 0 auto;
  }
  .tree-top {
    width: 48px; height: 48px;
    background: #3a7a2a;
    border: 2px solid #2a5a1a;
    border-radius: 50% 50% 40% 40%;
    margin: 0 auto;
    position: relative;
    top: 8px;
  }

  /* ── PIPE ── */
  .pipe {
    position: absolute;
    bottom: var(--ground-h);
  }
  .pipe-top {
    width: 56px; height: 16px;
    background: #2ea833;
    border: 3px solid #1a7022;
    border-radius: 4px;
    position: relative; left: -4px;
  }
  .pipe-body {
    width: 48px; height: 56px;
    background: #2ea833;
    border: 3px solid #1a7022;
    border-top: none;
  }

  /* ── PROGRESS INDICATOR ── */
  #progress-bar {
    position: fixed; top: 44px; left: 0; right: 0; height: 3px;
    background: rgba(255,255,255,0.1);
    z-index: 50;
  }
  #progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff6600);
    width: 0%;
    transition: width 0.2s ease;
    box-shadow: 0 0 8px rgba(255,215,0,0.5);
  }

  /* ── CRT SCANLINES ── */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.03) 0px,
      rgba(0,0,0,0.03) 1px,
      transparent 1px,
      transparent 3px
    );
    pointer-events: none;
    z-index: 99;
  }

  /* ── FILM GRAIN OVERLAY ── */
  body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    opacity: 0.04;
    pointer-events: none;
    z-index: 100;
    mix-blend-mode: overlay;
  }

  /* ── CHROMATIC ABERRATION FLASH ── */
  #ca-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 98;
    opacity: 0;
    background: transparent;
    mix-blend-mode: screen;
  }

  /* ── EFFECTS CANVAS (ripples + lens flares) ── */
  #fx-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 97;
    width: 100%;
    height: 100%;
  }

  /* ── CUSTOM CURSOR ── */
  #cursor {
    position: fixed; pointer-events: none; z-index: 999;
    width: 20px; height: 20px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.1s ease;
    mix-blend-mode: difference;
  }
  #cursor.big { transform: translate(-50%,-50%) scale(1.8); }
