@font-face {
  font-family: 'PressStart2P';
  src: url('../assets/fonts/PressStart2P.woff2') format('woff2');
  font-display: block;
}

@font-face {
  font-family: 'VT323';
  src: url('../assets/fonts/VT323.woff2') format('woff2');
  font-display: block;
}

:root {
  --bg: #06090c;
  --panel: rgba(8, 13, 18, 0.88);
  --line: rgba(255, 211, 74, 0.35);
  --amber: #ffd34a;
  --amber-d: #b8860b;
  --text: #e8f0ff;
  --dim: #7a8a99;
  --red: #ff5544;
  --cyan: #5df2ff;
  --green: #5dff7a;
  --u: clamp(10px, 1.05vw, 16px);
  --p: 16px;
  --ps: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', monospace;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
}

body.playing {
  cursor: none;
}

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
}

#hud {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

#ui {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: radial-gradient(ellipse at center, rgba(6, 9, 12, 0.35) 0%, rgba(6, 9, 12, 0.82) 75%);
}

#ui.show {
  display: flex;
}

#ui::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.12) 0px, rgba(0, 0, 0, 0.12) 1px, transparent 1px, transparent 3px);
}

.screen {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: screenIn 0.35s ease-out both;
  max-height: 96vh;
}

@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.logo {
  text-align: center;
  font-family: 'PressStart2P', monospace;
  line-height: 1;
  margin-bottom: calc(var(--u) * 2.4);
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.6));
}

.logo-top {
  font-size: calc(var(--p) * 2);
  letter-spacing: 0.32em;
  color: #e8f0ff;
  text-shadow: 3px 3px 0 #1c2a36, -1px -1px 0 #000;
  margin-bottom: calc(var(--u) * 0.8);
  padding-left: 0.32em;
}

.logo-main {
  font-size: calc(var(--p) * 4);
  color: var(--amber);
  letter-spacing: 0.06em;
  text-shadow: 0 4px 0 #c46a00, 0 8px 0 #7a2c00, 5px 12px 0 rgba(0, 0, 0, 0.55), -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000;
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.15);
  }
}

.logo-sub {
  margin-top: calc(var(--u) * 1.6);
  font-size: var(--p);
  letter-spacing: 0.5em;
  color: var(--red);
  padding-left: 0.5em;
  text-shadow: 2px 2px 0 #000;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.45);
  align-items: stretch;
  min-width: calc(var(--u) * 24);
}

.menu.row {
  flex-direction: row;
  justify-content: center;
  gap: calc(var(--u) * 1);
  margin-top: calc(var(--u) * 1.4);
  min-width: 0;
}

.menu.small {
  margin-top: calc(var(--u) * 1.4);
  flex-direction: row;
  justify-content: center;
  gap: calc(var(--u) * 1);
  min-width: 0;
}

.btn {
  font-family: 'PressStart2P', monospace;
  font-size: var(--p);
  color: var(--text);
  background: rgba(10, 16, 22, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.5), 0 3px 0 rgba(0, 0, 0, 0.6);
  padding: calc(var(--u) * 0.85) calc(var(--u) * 1.6);
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.06em;
  position: relative;
  transition: transform 0.06s, background 0.08s, color 0.08s;
  outline: none;
}

.btn.focus {
  background: var(--amber);
  color: #1a1000;
  border-color: #fff3b0;
  transform: translateX(4px);
  box-shadow: inset 0 -3px 0 #c48a00, 0 3px 0 rgba(0, 0, 0, 0.6), 0 0 18px rgba(255, 211, 74, 0.35);
}

.btn.focus::before {
  content: '\25B6';
  position: absolute;
  left: calc(var(--u) * -1.6);
  top: 50%;
  transform: translateY(-50%);
  color: var(--amber);
  font-size: var(--ps);
  animation: nudge 0.6s ease-in-out infinite;
}

.menu.row .btn.focus,
.menu.small .btn.focus {
  transform: translateY(-2px);
}

.menu.row .btn.focus::before,
.menu.small .btn.focus::before {
  display: none;
}

.btn.primary {
  border-color: rgba(255, 211, 74, 0.6);
}

.btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

@keyframes nudge {
  0%,
  100% {
    margin-left: 0;
  }
  50% {
    margin-left: -4px;
  }
}

.footer {
  margin-top: calc(var(--u) * 2.6);
  display: flex;
  gap: calc(var(--u) * 3);
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--dim);
}

.blink {
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.panel-screen {
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.6), 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: calc(var(--u) * 2) calc(var(--u) * 2.6);
  min-width: min(92vw, calc(var(--u) * 40));
  max-width: 94vw;
  overflow-y: auto;
}

.panel-screen.wide {
  min-width: min(94vw, calc(var(--u) * 56));
}

h1,
h2,
h3,
h4 {
  font-family: 'PressStart2P', monospace;
  font-weight: normal;
  margin: 0;
}

h2 {
  font-size: calc(var(--p) * 2);
  color: var(--amber);
  margin-bottom: calc(var(--u) * 1.6);
  letter-spacing: 0.08em;
  text-shadow: 3px 3px 0 #000;
}

h3 {
  font-size: var(--ps);
  color: var(--amber);
  margin: calc(var(--u) * 1.2) 0 calc(var(--u) * 0.6);
  letter-spacing: 0.08em;
}

.diff-notes {
  margin-top: calc(var(--u) * 1.4);
  font-size: calc(var(--u) * 1.35);
  color: var(--dim);
  max-width: calc(var(--u) * 36);
}

.diff-notes p {
  margin: 0.25em 0;
}

.diff-notes b {
  color: var(--text);
  font-weight: normal;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.6);
  width: 100%;
}

.btn.card {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 1.4);
  text-align: left;
  padding: calc(var(--u) * 0.9) calc(var(--u) * 1.2);
  font-family: 'VT323', monospace;
}

.btn.card.focus {
  transform: translateX(6px);
}

.card-num {
  font-family: 'PressStart2P', monospace;
  font-size: calc(var(--p) * 2);
  color: var(--amber);
  text-shadow: 2px 2px 0 #000;
  min-width: 2.2em;
}

.btn.card.focus .card-num {
  color: #1a1000;
  text-shadow: none;
}

.card-body {
  flex: 1;
}

.card-title {
  font-family: 'PressStart2P', monospace;
  font-size: var(--p);
  margin-bottom: 0.4em;
}

.card-sub {
  font-size: calc(var(--u) * 1.3);
  opacity: 0.85;
}

.card-best {
  font-size: calc(var(--u) * 1.15);
  margin-top: 0.2em;
  opacity: 0.8;
}

.card-rank {
  font-family: 'PressStart2P', monospace;
  font-size: calc(var(--p) * 2);
}

.rank-S {
  color: #ff6bd5;
}

.rank-A {
  color: #ffd34a;
}

.rank-B {
  color: #5dff7a;
}

.rank-C {
  color: #5df2ff;
}

.rank-D {
  color: #aab;
}

.btn.focus .card-rank {
  color: #1a1000;
}

.opts {
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.35);
  width: 100%;
}

.opt {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 1);
  padding: calc(var(--u) * 0.55) calc(var(--u) * 0.9);
  font-family: 'PressStart2P', monospace;
  font-size: var(--p);
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid transparent;
  cursor: pointer;
}

.opt.focus {
  border-color: var(--amber);
  background: rgba(255, 211, 74, 0.1);
}

.opt .lbl {
  flex: 1;
  text-align: left;
}

.opt .val {
  min-width: 9em;
  text-align: right;
  color: var(--amber);
}

.opt .bar {
  width: calc(var(--u) * 12);
  height: calc(var(--u) * 0.7);
  background: #111;
  border: 2px solid #333;
  position: relative;
}

.opt .bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(#ffe48a, #ffb000);
}

.btn.opt.bind {
  display: flex;
  justify-content: space-between;
  text-align: left;
  font-size: var(--p);
  padding: calc(var(--u) * 0.55) calc(var(--u) * 0.9);
}

.btn.opt.bind.focus {
  color: var(--text);
  background: rgba(255, 211, 74, 0.1);
  transform: none;
}

.btn.opt.bind.focus::before {
  display: none;
}

.btn.opt.bind.capturing .val {
  color: var(--red);
}

.ctrl {
  border-collapse: collapse;
  font-size: calc(var(--u) * 1.45);
  min-width: calc(var(--u) * 34);
}

.ctrl td {
  padding: 0.18em 0.6em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ctrl td.k {
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--amber);
  white-space: nowrap;
}

.tips {
  margin-top: calc(var(--u) * 1);
  max-width: calc(var(--u) * 38);
  font-size: calc(var(--u) * 1.3);
  color: var(--dim);
}

.tips p {
  margin: 0.3em 0;
}

.briefing {
  width: min(96vw, calc(var(--u) * 72));
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.6), 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: calc(var(--u) * 1.6) calc(var(--u) * 2);
  align-items: stretch;
}

.brief-head {
  border-bottom: 2px solid var(--line);
  padding-bottom: calc(var(--u) * 0.8);
  margin-bottom: calc(var(--u) * 1);
}

.brief-op {
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--red);
  letter-spacing: 0.2em;
  margin-bottom: 0.8em;
}

.brief-head h1 {
  font-size: calc(var(--p) * 2);
  color: var(--amber);
  text-shadow: 3px 3px 0 #000;
}

.brief-sub {
  font-size: calc(var(--u) * 1.5);
  color: var(--dim);
  margin-top: 0.3em;
}

.brief-body {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: calc(var(--u) * 1.6);
  min-height: 0;
}

.brief-map {
  position: relative;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: #000;
  align-self: start;
  overflow: hidden;
}

.brief-map::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 0%, rgba(93, 242, 255, 0.12) 50%, transparent 100%);
  background-size: 100% 30%;
  animation: scan 3s linear infinite;
  pointer-events: none;
}

@keyframes scan {
  from {
    background-position: 0 -100%;
  }
  to {
    background-position: 0 300%;
  }
}

.map-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.brief-right {
  overflow-y: auto;
  max-height: 58vh;
  padding-right: 0.5em;
}

.brief-right h3:first-child {
  margin-top: 0;
}

.brief-text {
  font-size: calc(var(--u) * 1.45);
  line-height: 1.15;
  white-space: pre-wrap;
  min-height: 6em;
  color: #d8e4f0;
}

.ghost {
  visibility: hidden;
}

.brief-text.center {
  text-align: center;
  max-width: calc(var(--u) * 42);
  margin-bottom: calc(var(--u) * 1.4);
}

.brief-objs {
  margin: 0;
  padding-left: 1.6em;
  font-size: calc(var(--u) * 1.4);
}

.brief-objs li {
  margin: 0.15em 0;
  animation: screenIn 0.4s both;
}

.brief-objs li::marker {
  color: var(--amber);
  font-family: 'PressStart2P', monospace;
  font-size: 0.6em;
}

.brief-bonus h4 {
  font-size: var(--ps);
  color: #9ad0ff;
  margin: calc(var(--u) * 1) 0 0.4em;
}

.brief-bonus ul {
  margin: 0;
  padding-left: 1.6em;
  font-size: calc(var(--u) * 1.3);
  color: #cfe6ff;
}

.pause h2 {
  font-size: calc(var(--p) * 3);
}

.pause-obj {
  font-size: calc(var(--u) * 1.4);
  color: var(--dim);
  margin: calc(var(--u) * -0.8) 0 calc(var(--u) * 1.6);
}

.debrief {
  width: min(94vw, calc(var(--u) * 60));
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.6), 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: calc(var(--u) * 1.8) calc(var(--u) * 2.2);
  align-items: stretch;
}

.deb-head {
  text-align: center;
  margin-bottom: calc(var(--u) * 1.4);
}

.deb-title {
  font-family: 'PressStart2P', monospace;
  font-size: calc(var(--p) * 2);
  color: var(--amber);
  text-shadow: 3px 3px 0 #000;
  animation: screenIn 0.5s both;
}

.debrief.fail .deb-title {
  color: var(--red);
}

.deb-sub {
  font-size: calc(var(--u) * 1.5);
  color: var(--dim);
  margin-top: 0.5em;
}

.deb-body {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: calc(var(--u) * 2);
  align-items: center;
}

.deb-line {
  display: flex;
  justify-content: space-between;
  font-size: calc(var(--u) * 1.5);
  padding: 0.12em 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  animation: screenIn 0.3s both;
}

.deb-line .v {
  color: var(--amber);
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  align-self: center;
}

.deb-right {
  text-align: center;
}

.deb-label {
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--dim);
  margin-top: calc(var(--u) * 0.8);
}

.deb-score {
  font-family: 'PressStart2P', monospace;
  font-size: calc(var(--p) * 2);
  color: #fff;
  text-shadow: 3px 3px 0 #000;
  margin: 0.4em 0;
}

.deb-rank {
  font-family: 'PressStart2P', monospace;
  font-size: calc(var(--p) * 5);
  opacity: 0;
  text-shadow: 4px 4px 0 #000;
}

.deb-rank.stamp {
  animation: stamp 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

@keyframes stamp {
  from {
    opacity: 0;
    transform: scale(3) rotate(-14deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(-6deg);
  }
}

.deb-best {
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--green);
  margin-top: 0.8em;
}

.credits .credit-list {
  text-align: center;
  font-size: calc(var(--u) * 1.5);
}

.credits .logo {
  transform: scale(0.7);
  margin-bottom: 0;
}

.credit-list p {
  margin: 0.15em 0;
}

.dim {
  color: var(--dim);
}

.ending {
  max-width: min(92vw, calc(var(--u) * 50));
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.8s;
}

#loading.done {
  opacity: 0;
  pointer-events: none;
}

.load-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.load-bar {
  width: calc(var(--u) * 26);
  height: calc(var(--u) * 1);
  border: 2px solid #333;
  background: #0b0f13;
  padding: 2px;
}

#load-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--amber) 0 8px, #e0a800 8px 10px);
  transition: width 0.2s;
}

#load-label {
  margin-top: calc(var(--u) * 1);
  font-family: 'PressStart2P', monospace;
  font-size: var(--ps);
  color: var(--dim);
  letter-spacing: 0.2em;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: #333;
}

@media (max-width: 760px) {
  .brief-body,
  .deb-body {
    grid-template-columns: 1fr;
  }
}

#touch {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

body.touch.playing #touch {
  display: block;
}

body.touch.playing {
  cursor: default;
}

.t-stick {
  position: absolute;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  background: rgba(10, 16, 22, 0.28);
  pointer-events: none;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.t-stick.on {
  opacity: 1;
}

.t-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 211, 74, 0.55);
  border: 3px solid rgba(255, 243, 176, 0.85);
  transform: translate(-50%, -50%);
}

.t-right {
  border-color: rgba(255, 140, 110, 0.35);
}

.t-right .t-knob {
  background: rgba(255, 90, 60, 0.55);
  border-color: rgba(255, 200, 180, 0.85);
}

.t-btn {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'PressStart2P', monospace;
  font-size: 8px;
  color: #fff;
  background: rgba(10, 16, 22, 0.55);
  border: 3px solid rgba(255, 211, 74, 0.65);
  text-shadow: 1px 1px 0 #000;
  user-select: none;
  -webkit-user-select: none;
}

.t-btn span {
  pointer-events: none;
}

.t-btn.on {
  background: rgba(255, 211, 74, 0.65);
  color: #1a1000;
  text-shadow: none;
}

.t-rocket {
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(28px + env(safe-area-inset-bottom));
  border-color: rgba(255, 110, 80, 0.8);
}

.t-dodge {
  width: 60px;
  height: 60px;
  right: calc(104px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
}

.t-small {
  width: 50px;
  height: 50px;
  font-size: 8px;
  top: calc(var(--hs, 1) * 100px + 8px);
}

.t-pause {
  right: calc(14px + env(safe-area-inset-right));
}

.t-map {
  right: calc(74px + env(safe-area-inset-right));
}

#rotate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg);
  font-family: 'PressStart2P', monospace;
  font-size: 12px;
  color: var(--amber);
  text-align: center;
}

.rotate-icon {
  width: 44px;
  height: 72px;
  border: 4px solid var(--amber);
  border-radius: 8px;
  animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
  0%,
  30% {
    transform: rotate(0deg);
  }
  60%,
  100% {
    transform: rotate(-90deg);
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate {
    display: flex;
  }
}

@media (pointer: coarse) {
  .btn {
    min-height: 44px;
    font-size: max(var(--p), 12px);
  }

  .opt {
    min-height: 40px;
  }

  .btn.focus {
    transform: none;
  }
}

@media (max-height: 520px) {
  .title-screen .menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .logo {
    margin-bottom: 12px;
  }

  .footer {
    margin-top: 12px;
  }

  .briefing,
  .debrief,
  .panel-screen {
    max-height: 98vh;
    overflow-y: auto;
  }

  .brief-right {
    max-height: none;
  }
}
