html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: 'Inter', system-ui, sans-serif;
  margin: 0;
  background: linear-gradient(135deg, #0d1333 60%, #1a2c47 100%);
  color: #e3e8ff;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

main {
  flex: 1 0 auto;
  max-width: 1200px;
  width: 100vw;
  margin: 2.2rem auto 0 auto;
  background: rgba(23, 28, 57, 0.75);
  padding: 2.2rem 1.2rem 2rem;
  border-radius: 28px;
  box-shadow: 0 6px 32px 0 rgba(42,54,96,0.09), 0 1.5px 8px 0 rgba(0,0,0,0.10), 0 0 0 3px rgba(25, 178, 255, 0.12);
  backdrop-filter: blur(9px) saturate(1.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 70vh;
  position: relative;
  overflow-y: visible;
  border: 1.5px solid rgba(25,145,255,0.13);
}

footer {
  background: rgba(17, 22, 43, 0.97);
  color: #a3bafc;
  text-align: center;
  padding: 1.25rem 0;
  margin-top: 2.4rem;
  border-radius: 0 0 18px 18px;
  font-size: 1rem;
  box-shadow: 0 -2px 16px 0 rgba(40,40,40,0.10);
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

/* HUD Bar */
.hud-bar {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 1.1rem auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2vw;
  padding: 0.9rem 1.2rem;
  background: rgba(20,32,58,0.52);
  border-radius: 15px;
  box-shadow: 0 1.5px 16px 0 rgba(25,178,255,0.14);
  backdrop-filter: blur(6px) brightness(1.1);
  border: 1.5px solid rgba(25,178,255,0.16);
  font-family: 'Orbitron', 'Inter', monospace, sans-serif;
  font-size: 1.11rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #8be9fd;
  text-shadow: 0 0 8px #22e0ff, 0 0 2px #fff;
  box-sizing: border-box;
}

.hud-item {
  flex: 1 1 0;
  text-align: center;
  filter: drop-shadow(0 0 6px #74f9ffcc);
  padding: 0 0.7em;
}

/* Controls Bar */
.controls-bar {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 1.1rem auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.6rem;
  padding: 0.7rem 1.1rem;
  background: rgba(16, 27, 44, 0.47);
  border-radius: 15px;
  box-shadow: 0 1.5px 8px 0 rgba(36,139,255,0.09);
  backdrop-filter: blur(5px) brightness(1.05);
  border: 1.2px solid rgba(25,178,255,0.10);
  min-height: 54px;
}

.btn {
  appearance: none;
  outline: none;
  border: none;
  font-family: 'Orbitron', 'Inter', Arial, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 11px;
  padding: 0.75em 2.1em;
  margin: 0;
  cursor: pointer;
  background: linear-gradient(100deg, #21295c 70%, #293991 100%);
  color: #d3f8ff;
  box-shadow: 0 1.5px 10px 0 rgba(36,139,255,0.13);
  transition: background 0.13s, color 0.12s, box-shadow 0.13s, opacity 0.13s, filter 0.13s;
  text-shadow: 0 0 6px #8be9fd55, 0 0 2px #fff4;
  border: 2px solid transparent;
}

.btn--primary {
  background: linear-gradient(100deg, #17e8ff 45%, #08b5fa 100%);
  color: #05203c;
  box-shadow: 0 0 16px 0 #29fffaaa, 0 2px 8px 0 #01bada33;
}
.btn--primary:focus, .btn--primary:hover {
  background: linear-gradient(90deg, #5fffd7 60%, #38c3ff 100%);
  color: #012030;
  box-shadow: 0 0 18px 0 #5fffd7cc, 0 2px 12px 0 #01bada44;
  border: 2px solid #38c3ff;
}

.btn--secondary {
  background: linear-gradient(100deg, #3546a6 60%, #27396c 100%);
  color: #b6c7ff;
  box-shadow: 0 0 13px 0 #3e4fff77, 0 2px 8px 0 #2433ff11;
}
.btn--secondary:focus, .btn--secondary:hover {
  background: linear-gradient(90deg, #6c7fff 60%, #38c3ff 100%);
  color: #001a38;
  box-shadow: 0 0 14px 0 #6c7fffcc, 0 2px 10px 0 #3e4fff44;
  border: 2px solid #38c3ff;
}

.btn:active {
  filter: brightness(0.95) contrast(1.01);
}
.btn:disabled {
  opacity: 0.57;
  filter: grayscale(0.22) brightness(0.92);
  cursor: not-allowed;
  box-shadow: none;
  border: 2px solid transparent;
}

@media (max-width: 850px) {
  .controls-bar {
    font-size: 0.97rem;
    padding: 0.5rem 0.3rem;
    border-radius: 8px;
    gap: 0.7rem;
    min-height: 36px;
  }
  .btn {
    font-size: 0.98rem;
    padding: 0.5em 1.1em;
    border-radius: 7px;
  }
}

/* Game Layout: Canvas + Controls Sidebar */
.game-layout {
  display: flex;
  gap: 1.2rem;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  margin: 0 auto 1.1rem;
}
.canvas-container { 
  flex: 1 1 auto; 
  min-width: 0; 
  aspect-ratio: 4/3;
  /* leave ~250px vertical space for HUD + controls bar + margins */
  max-height: min(675px, calc(100vh - 250px));
  /* leave ~340px horizontal space for sidebar + gaps */
  max-width: min(860px, calc(100vw - 340px));
}

/* Controls Card (Sidebar) */
.controls-card {
  flex: 0 0 240px;
  max-width: 260px;
  background: rgba(16,27,44,0.55);
  border: 1.2px solid rgba(25,178,255,0.15);
  border-radius: 16px;
  box-shadow: 0 0 18px 0 rgba(36,139,255,0.10);
  backdrop-filter: blur(6px) brightness(1.05);
  color: #cfe9ff;
  padding: 1rem 1rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0;
}
.controls-title {
  font-family: 'Orbitron', 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 1.05rem;
  color: #74f9ff;
  margin: 0 0 0.6rem;
  text-shadow: 0 0 12px #08f7fe;
}
.controls-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}
.controls-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.key-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  background: linear-gradient(100deg, #1f2a56 60%, #1a3768 100%);
  color: #d3f8ff;
  font-family: 'Orbitron','Inter',sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
  border: 1px solid rgba(56,195,255,0.22);
  box-shadow: 0 0 10px #29fff922;
  text-align: center;
}
.key-desc {
  color: #b9dafe;
  font-size: 0.98rem;
}
.key-tip {
  margin-top: 0.4rem;
  color: #a3cafc;
  opacity: 0.88;
  font-size: 0.92rem;
}

/* Canvas Styling */
.canvas-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 380px;
  margin: 0 auto 1.5rem auto;
  flex: 1 0 auto;
  position: relative;
  aspect-ratio: 4/3;
  max-width: 640px;
  max-height: 480px;
}

#game {
  display: block;
  margin: 0 auto;
  background: transparent;
  outline: none;
  border-radius: 18px;
  box-shadow: 0 0 0 3px #2ddcff44, 0 0 28px 4px #0088ff33;
  border: 1.5px solid #2ddcff44;
  transition: box-shadow 0.2s;
  width: 100%;
  height: auto;
  max-width: min(860px, calc(100vw - 340px));
  max-height: min(675px, calc(100vh - 250px));
}

/* Keep aspect ratio and responsive scaling */
.canvas-container {
  aspect-ratio: 4/3;
  max-width: 800px;
  max-height: 600px;
  width: 100%;
  background: none;
  /* fallback for browsers with no aspect-ratio support: */
  position: relative;
}
.canvas-container:before {
  content: '';
  display: block;
  padding-top: 75%; /* 4:3 aspect ratio fallback for old browsers */
}
#game {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  max-width: min(860px, calc(100vw - 340px));
  max-height: min(675px, calc(100vh - 250px));
}

/* Headings, Typography */
h1, .hud-bar {
  font-family: 'Orbitron', 'Inter', Arial, sans-serif;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

h1 {
  color: #74f9ff;
  text-shadow: 0 0 16px #08f7fe, 0 0 2px #fff;
  font-size: 2.15rem;
  text-align: center;
  margin-bottom: 0.4em;
}

@media (max-width: 950px) {
  main {
    max-width: 99vw;
    padding: 0.9rem 0.2rem 0.7rem;
  }
  .hud-bar {
    font-size: 0.98rem;
    padding: 0.5rem 0.6rem;
  }
  .canvas-container {
    min-height: 220px;
  }
  .game-layout {
    max-width: 99vw;
    gap: 0.8rem;
  }
}

@media (max-width: 850px) {
  .game-layout {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-card {
    flex: 0 0 auto;
    max-width: 100%;
    margin-top: 0.8rem;
  }
  .canvas-container {
    max-width: min(860px, 100%);
    max-height: min(675px, calc(100vh - 250px));
  }
  #game {
    max-width: min(860px, 100%);
    max-height: min(675px, calc(100vh - 250px));
  }
}

@media (max-width: 700px) {
  main {
    padding: 0.3rem 0.1rem 0.4rem;
    border-radius: 8px;
  }
  .hud-bar {
    border-radius: 8px;
    font-size: 0.91rem;
  }
  .canvas-container {
    min-height: 120px;
  }
  .instructions {
    font-size: 0.97rem;
    border-radius: 7px;
    max-width: 99vw;
    padding: 0.25rem 0.3rem;
  }
}

::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-thumb {
  background: #163f67;
  border-radius: 7px;
}
::-webkit-scrollbar-track {
  background: #101828;
}
