:root {
  --navy: #0A1628;
  --navy-mid: #12233D;
  --navy-light: #1A3254;
  --blue: #4A90D9;
  --blue-dark: #2B6CB0;
  --blue-light: #6BB0F0;
  --gold: #C8A84E;
  --gray-300: #C8CDD3;
  --gray-500: #5C6270;
  --white: #FFFFFF;
}

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

body {
  background: var(--navy);
  color: var(--white);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Header */
header {
  background: var(--navy);
  border-bottom: 1px solid rgba(74, 144, 217, 0.15);
  padding: 0.75rem 2rem;
  flex-shrink: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-logo {
  flex-shrink: 0;
}

.header-brand {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--gray-300);
  text-transform: uppercase;
}

.header-program {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--gold);
  text-transform: uppercase;
}

/* Main / Game */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 70% 20%, rgba(74, 144, 217, 0.06) 0%, transparent 60%),
    linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 50%, var(--navy-light) 100%);
}

/* Game Boy Color frame */
#gbc {
  position: relative;
  width: 420px;
  flex-shrink: 0;
}

.gbc-frame {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

#game {
  position: absolute;
  top: 15%;
  left: 12.5%;
  width: 75%;
  height: 52%;
}

#game canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Controls hint */
#controls-hint {
  padding: 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--gray-500);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#controls-hint .key {
  color: var(--gray-300);
  font-weight: 600;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.65rem;
  background: rgba(74, 144, 217, 0.1);
  border: 1px solid rgba(74, 144, 217, 0.2);
  border-radius: 3px;
  padding: 0.15em 0.4em;
}

#controls-hint .separator {
  color: var(--gray-500);
  opacity: 0.4;
  margin: 0 0.25rem;
}

/* Footer */
footer {
  background: var(--navy);
  border-top: 1px solid rgba(74, 144, 217, 0.15);
  padding: 1.25rem 2rem;
  text-align: center;
  flex-shrink: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.footer-bottom {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.footer-text {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--gray-500);
  letter-spacing: 0.05em;
  opacity: 0.3;
}

.footer-link {
  position: absolute;
  right: 0;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--gray-500);
  text-decoration: none;
  opacity: 0.3;
  letter-spacing: 0.05em;
}

.footer-link:hover {
  color: var(--blue);
  opacity: 0.6;
}

/* Mobile controller (touch devices) */
#controller {
  display: none;
  position: fixed;
  bottom: 0;
  height: 210px;
  width: 100%;
  touch-action: none;
  opacity: 0.8;
}

#controller_dpad {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 184px;
  height: 184px;
}

#controller_dpad::before {
  content: "";
  display: block;
  width: 48px;
  height: 48px;
  background: var(--navy-light);
  position: absolute;
  left: 68px;
  top: 68px;
}

#controller_left {
  position: absolute;
  left: 20px;
  top: 68px;
  width: 48px;
  height: 48px;
  background: var(--navy-mid);
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

#controller_right {
  position: absolute;
  left: 116px;
  top: 68px;
  width: 48px;
  height: 48px;
  background: var(--navy-mid);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

#controller_up {
  position: absolute;
  left: 68px;
  top: 20px;
  width: 48px;
  height: 48px;
  background: var(--navy-mid);
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

#controller_down {
  position: absolute;
  left: 68px;
  top: 116px;
  width: 48px;
  height: 48px;
  background: var(--navy-mid);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
}

#controller_a {
  position: absolute;
  bottom: 110px;
  right: 20px;
}

#controller_b {
  position: absolute;
  bottom: 80px;
  right: 100px;
}

.roundBtn {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--white);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--blue-dark);
  box-shadow: 0 4px 5px rgba(0, 0, 0, 0.3);
}

.capsuleBtn {
  font-weight: 600;
  font-size: 0.625rem;
  color: var(--gray-300);
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  width: 64px;
  height: 32px;
  border-radius: 40px;
  background: var(--navy-mid);
  border: 1px solid rgba(74, 144, 217, 0.2);
  box-shadow: 0 4px 5px rgba(0, 0, 0, 0.3);
}

#controller_start {
  position: absolute;
  bottom: 20px;
  right: 15px;
}

#controller_select {
  position: absolute;
  bottom: 20px;
  right: 100px;
}

.btnPressed {
  opacity: 0.5;
}

/* Loading spinner */
.spinner {
  height: 50px;
  width: 50px;
  margin: 0 auto;
  animation: rotation 0.8s linear infinite;
  border: 10px solid var(--navy-light);
  border-top-color: var(--blue);
  border-radius: 50%;
  background: var(--navy);
}

@keyframes rotation {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.gbc-pwr-led {
  animation: pulse-led 3s ease-in-out infinite;
}

/* Mobile portrait */
@media only screen and (max-width: 640px) {
  header {
    padding: 0.5rem 1rem;
  }

  .header-brand {
    font-size: 0.65rem;
  }

  .header-program {
    font-size: 0.65rem;
  }

  #controls-hint {
    display: none;
  }

  footer {
    padding: 0.4rem 1rem;
  }
}

@media only screen and (max-device-width: 812px) and (orientation: portrait) {
  #game canvas {
    width: 100%;
    max-width: 512px;
  }

  #controller {
    display: block;
  }

  main {
    padding-bottom: 210px;
  }
}

@media only screen and (max-device-width: 320px) and (orientation: portrait) {
  #controller_dpad {
    left: -5px;
    bottom: -5px;
  }

  #controller_a {
    right: 5px;
    bottom: 95px;
  }

  #controller_b {
    right: 80px;
  }

  #controller_start {
    right: 5px;
  }

  #controller_select {
    right: 80px;
  }
}

/* Landscape with touch controller */
@media only screen and (min-width: 300px) and (orientation: landscape) {
  #controller {
    bottom: 50%;
    transform: translateY(50%);
    opacity: 0.5;
  }
}

/* Too small for landscape */
@media only screen and (max-device-width: 300px) and (orientation: landscape) {
  #game::after {
    content: "PLEASE ROTATE";
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: var(--gray-300);
  }

  #game canvas {
    display: none;
  }

  #controller {
    display: none;
  }
}
