:root {
  --sky-top: #1a1e24;
  --sky-bottom: #0b0d10;
  --ground: #4a3b2b;
  --ground-edge: #6d543e;
  --platform: #5c422b;
  --platform-edge: #856140;
  --player: #ff4040;
  --accent: #d6dbe2;
  --hud-bg: rgba(15, 18, 24, 0.85);
  --hud-border: rgba(255, 255, 255, 0.1);
  --font-primary: 'Trebuchet MS', 'Lucida Sans', Arial, sans-serif;
  --primary-btn: #ffd500;
  --primary-btn-text: #1e2a38;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  font-family: var(--font-primary);
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  color: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 100svh;
  aspect-ratio: auto;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  background: #0f1216;
  border: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #000; 
}

/* HUD System */
.hud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 8px 24px;
  font-size: 14px;
  font-weight: 600;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  width: auto;
  max-width: 90%;
  z-index: 10;
}

.pill {
  background: transparent;
  padding: 0;
  border: none;
  color: #f2f4f7;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill span {
    opacity: 0.7;
    font-weight: 400;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hud-toggle {
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #f2f4f7;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
}

.hud-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Controls */
.controls {
  position: absolute;
  inset: auto 24px 24px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  opacity: 0.8;
  user-select: none;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.3s;
}

.controls:hover, .controls:active {
    opacity: 1;
}

.joystick-right .controls {
  flex-direction: row-reverse;
}

.fullscreen-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--hud-bg);
  color: #f2f4f7;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 10;
  backdrop-filter: blur(4px);
  transition: all 0.2s;
}

.fullscreen-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.controls button {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,0.1);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  transition: transform 0.1s, background 0.2s;
  display: grid;
  place-items: center;
}

.controls button:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.25);
}

.joystick {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.1);
    position: relative;
    pointer-events: auto;
    touch-action: none;
    backdrop-filter: blur(2px);
}

.joystick-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(0,0,0,0.1);
}

.jump-button {
    font-size: 14px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 12, 0.6);
  backdrop-filter: blur(8px);
  color: #fff;
  text-align: center;
  padding: 24px;
  z-index: 100;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: rgba(20, 24, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 32px 40px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.overlay-card h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, #fff, #aab);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.overlay-card p {
  margin: 0;
  font-size: 15px;
  color: #9aa5b1;
  line-height: 1.5;
}

.overlay-card button {
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  font-weight: 700;
  font-size: 16px;
  background: var(--primary-btn);
  color: var(--primary-btn-text);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 213, 0, 0.2);
  transition: all 0.2s;
  width: 100%;
  margin-top: 8px;
}

.overlay-card button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 213, 0, 0.3);
}

.overlay-card button:active {
    transform: translateY(0);
}

.leaderboard {
  width: 100%;
  text-align: left;
  font-size: 13px;
  color: #cbd2d9;
  background: rgba(0,0,0,0.2);
  padding: 16px;
  border-radius: 12px;
}

.leaderboard h2 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #7b8794;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 8px;
}

.leaderboard ol {
  margin: 0;
  padding-left: 20px;
}

.leaderboard li {
  margin-bottom: 6px;
  font-family: monospace;
  font-size: 14px;
}

.initials-form {
  display: none;
  width: 100%;
  gap: 12px;
  flex-direction: column;
}

.initials-form input {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 12px;
  color: #fff;
  font-size: 24px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
  font-family: monospace;
}

.initials-form input:focus {
    outline: none;
    border-color: var(--primary-btn);
}

@media (max-width: 720px) {
  body {
    padding: 0;
  }
  
  .hud {
     top: 10px;
     width: 95%;
     padding: 6px 12px;
     gap: 12px;
  }
  
  .fullscreen-toggle {
    top: auto;
    bottom: 16px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.5;
  }

  .controls {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .joystick {
    width: 120px;
    height: 120px;
  }
  .joystick-knob {
    width: 40px;
    height: 40px;
  }
  .jump-button {
    width: 72px;
    height: 72px;
  }
}
