/* =========================================================================
   SECTOR — single-pager stylesheet

   Tokens follow the FDT design system contract: --fdt-* for FDT extensions.
   No bare tokens, no --color-* generics. Canonical values live at
   design.frontierdefensetech.com.
   ========================================================================= */

/* Self-hosted Latin subsets — defense endpoints can't assume external
   resolution. Inter v20, Barlow Condensed v13, JetBrains Mono v24, all OFL. */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/inter-v20-latin-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/inter-v20-latin-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/inter-v20-latin-700.woff2') format('woff2');
}

@font-face {
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/barlow-condensed-v13-latin-700.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-v24-latin-regular.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-v24-latin-500.woff2') format('woff2');
}

:root,
.wa-dark {
  /* Navy surfaces */
  --fdt-navy-900: #0A1220;
  --fdt-navy-800: #0F1A2E;
  --fdt-navy-700: #16243D;
  --fdt-navy-600: #1E3050;

  /* Fog (text + light UI) */
  --fdt-fog-100: #E8EEF7;
  --fdt-fog-200: #C5D1E2;

  /* Steel (metadata + muted UI) */
  --fdt-steel-300: #8A9BB4;
  --fdt-steel-400: #5A6D8A;

  /* Electric (single accent) */
  --fdt-electric-300: #7BA9FF;
  --fdt-electric-400: #4A8DFF;
  --fdt-electric-500: #1D6EF5;
  --fdt-electric-600: #1456C7;

  /* Semantic */
  --fdt-hostile:  #E0322C;
  --fdt-neutral:  #2FA85A;
  --fdt-caution:  #F2B535;

  /* Divider / border */
  --fdt-divider: #1F3352;

  /* Glow scale */
  --fdt-glow-xs: 0 0   8px 2px rgba(29, 110, 245, 0.20);
  --fdt-glow-sm: 0 0  16px 2px rgba(29, 110, 245, 0.30);
  --fdt-glow-md: 0 0  32px 4px rgba(29, 110, 245, 0.35);

  /* Typography */
  --fdt-font-body:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --fdt-font-wordmark: 'Barlow Condensed', 'Oswald', 'Arial Narrow', sans-serif;
  --fdt-font-mono:     'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Spacing (4px base) */
  --fdt-space-1: 4px;
  --fdt-space-2: 8px;
  --fdt-space-3: 12px;
  --fdt-space-4: 16px;
  --fdt-space-5: 24px;
  --fdt-space-6: 32px;
  --fdt-space-7: 48px;

  /* Radii */
  --fdt-radius-sm: 2px;
  --fdt-radius-md: 4px;
  --fdt-radius-lg: 8px;

  /* Motion */
  --fdt-motion-fast: 150ms;
  --fdt-motion-base: 200ms;
  --fdt-ease-ui:     cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

body {
  background: var(--fdt-navy-900);
  color: var(--fdt-fog-100);
  font-family: var(--fdt-font-body);
  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(--fdt-navy-900);
  border-bottom: 1px solid rgba(29, 110, 245, 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-family: var(--fdt-font-wordmark);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fdt-fog-100);
  text-transform: uppercase;
}

.header-program {
  font-family: var(--fdt-font-wordmark);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fdt-electric-300);
  text-transform: uppercase;
  padding-left: var(--fdt-space-3);
  border-left: 1px solid var(--fdt-divider);
}

/* 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(29, 110, 245, 0.06) 0%, transparent 60%),
    linear-gradient(135deg, var(--fdt-navy-900) 0%, var(--fdt-navy-800) 50%, var(--fdt-navy-700) 100%);
}

/* Game Boy Color frame.
   isolation: isolate creates a clean stacking context so the cartridge can
   sit *behind* the SVG frame (its bottom hidden in the slot) while #game
   sits *on top* of the SVG screen rect. */
#gbc {
  position: relative;
  isolation: isolate;
  width: 420px;
  flex-shrink: 0;
}

.gbc-frame {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  position: relative;
  z-index: 2;
}

/* Cartridge plugged into the top of the GBC. Container is full cartridge
   size; clip-path crops to the visible 30px peek slice — this masks the
   bottom of the image AND constrains the button's hit area, so clicks on
   the GBC frame area below the peek don't accidentally trigger the modal.
   z-index ordering keeps the cartridge layered correctly relative to
   the SVG and #game (canvas). */
.cartridge-eject {
  position: absolute;
  left: 50%;
  top: -30px;
  width: 220px;
  height: 202px;
  z-index: 1;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translateX(-50%);
  clip-path: inset(0 0 calc(100% - 30px) 0);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
  transition:
    transform var(--fdt-motion-base) var(--fdt-ease-ui),
    filter var(--fdt-motion-base) var(--fdt-ease-ui);
}

.cartridge-eject:hover {
  /* Affordance via shadow + electric glow only — translating the cartridge
     causes the GBC to appear to jitter, since the cartridge is layered
     on top via stacking context. */
  filter:
    drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6))
    drop-shadow(0 0 12px rgba(29, 110, 245, 0.45));
}

.cartridge-eject:focus-visible {
  outline: 2px solid var(--fdt-electric-500);
  outline-offset: 4px;
  border-radius: var(--fdt-radius-sm);
}

.cartridge-img {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Cartridge modal ──────────────────────────────────────────────────── */

.cart-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: cart-modal-fade-in 200ms var(--fdt-ease-ui);
}

@keyframes cart-modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cart-modal[hidden] {
  display: none;
}

.cart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 32, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 0;
  padding: 0;
  cursor: pointer;
}

.cart-modal-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--fdt-space-5);
  padding: var(--fdt-space-7) var(--fdt-space-6);
  animation: cart-modal-pop-in 280ms var(--fdt-ease-ui);
  max-width: min(440px, 90vw);
}

@keyframes cart-modal-pop-in {
  from { transform: translateY(12px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.cart-modal-img {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.6));
  border-radius: var(--fdt-radius-md);
}

.cart-modal-download {
  position: relative;
  font-family: var(--fdt-font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fdt-electric-300);
  text-decoration: underline;
  text-underline-offset: 6px;
  padding: var(--fdt-space-2) var(--fdt-space-4);
  border-radius: var(--fdt-radius-sm);
  transition:
    color var(--fdt-motion-fast) var(--fdt-ease-ui),
    filter var(--fdt-motion-base) var(--fdt-ease-ui);
}

.cart-modal-download:hover {
  color: var(--fdt-fog-100);
  /* Layered drop-shadow: each layer is fully blurred (no hard edge), and
     stacking three at decreasing alpha gives a feathered radial bleed
     instead of a rectangular halo. drop-shadow respects the rendered
     glyph + underline shape, not the link's bounding box. */
  filter:
    drop-shadow(0 0 8px rgba(29, 110, 245, 0.55))
    drop-shadow(0 0 20px rgba(29, 110, 245, 0.35))
    drop-shadow(0 0 36px rgba(123, 169, 255, 0.20));
}

.cart-modal-download:focus-visible {
  outline: 2px solid var(--fdt-electric-500);
  outline-offset: 4px;
}

.cart-modal-close {
  position: absolute;
  /* Sit outside the modal-content box (above + right of the cartridge image)
     so the X doesn't visually crowd the cover art. */
  top: -16px;
  right: -16px;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--fdt-navy-800);
  border: 1px solid var(--fdt-divider);
  color: var(--fdt-steel-300);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  transition:
    color var(--fdt-motion-fast) var(--fdt-ease-ui),
    border-color var(--fdt-motion-fast) var(--fdt-ease-ui),
    transform var(--fdt-motion-fast) var(--fdt-ease-ui);
}

.cart-modal-close:hover {
  color: var(--fdt-fog-100);
  border-color: var(--fdt-electric-500);
  transform: scale(1.05);
}

@media (prefers-reduced-motion: reduce) {
  .cart-modal,
  .cart-modal-content {
    animation: none;
  }
}

/* Position to match the SVG screen rect at viewBox 62,76 width=316 height=276
   in the 440x520 viewBox (62/440=14.09%, 316/440=71.82%, 76/520=14.62%,
   276/520=53.08%). Screen aspect 316:276 ≈ 256:224 (GB native 8:7). */
#game {
  position: absolute;
  top: 14.6%;
  left: 14.1%;
  width: 71.8%;
  height: 53.1%;
  z-index: 3;
}

#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(--fdt-steel-300);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#controls-hint .key {
  color: var(--fdt-fog-200);
  font-weight: 600;
  font-family: var(--fdt-font-mono);
  font-size: 0.65rem;
  background: rgba(29, 110, 245, 0.1);
  border: 1px solid rgba(29, 110, 245, 0.2);
  border-radius: 3px;
  padding: 0.15em 0.4em;
}

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

/* Footer */
footer {
  background: var(--fdt-navy-900);
  border-top: 1px solid rgba(29, 110, 245, 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(--fdt-steel-300);
  letter-spacing: 0.05em;
}

.footer-link {
  position: absolute;
  right: 0;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--fdt-steel-300);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  letter-spacing: 0.05em;
}

.footer-link:hover {
  color: var(--fdt-electric-400);
}

/* 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(--fdt-navy-700);
  position: absolute;
  left: 68px;
  top: 68px;
}

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

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

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

#controller_down {
  position: absolute;
  left: 68px;
  top: 116px;
  width: 48px;
  height: 48px;
  background: var(--fdt-navy-800);
  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(--fdt-fog-100);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--fdt-electric-500);
  box-shadow: 0 4px 5px rgba(0, 0, 0, 0.3);
}

.capsuleBtn {
  font-weight: 600;
  font-size: 0.625rem;
  color: var(--fdt-fog-200);
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  width: 64px;
  height: 32px;
  border-radius: 40px;
  background: var(--fdt-navy-800);
  border: 1px solid rgba(29, 110, 245, 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(--fdt-navy-700);
  border-top-color: var(--fdt-electric-400);
  border-radius: 50%;
  background: var(--fdt-navy-900);
}

@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(--fdt-fog-200);
  }

  #game canvas {
    display: none;
  }

  #controller {
    display: none;
  }
}

/* ── Visually-hidden but available to AT ──────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Skip link & focus ────────────────────────────────────────────────── */

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--fdt-space-4);
  z-index: 300;
  padding: var(--fdt-space-3) var(--fdt-space-5);
  background: var(--fdt-navy-800);
  color: var(--fdt-fog-100);
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 0 0 var(--fdt-radius-md) var(--fdt-radius-md);
  text-decoration: underline;
}

.skip-link:focus {
  top: 0;
}

:focus-visible {
  outline: 2px solid var(--fdt-electric-500);
  outline-offset: 2px;
  border-radius: var(--fdt-radius-sm);
}

/* ── Reduced motion (design system § Motion / § Accessibility) ────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
