:root {
  --ink: #0A0D18;
  --slate: #1C2438;
  --bone: #E9E4D6;
  --amber: #F2A03D;
  --red: #E0433A;
  --green: #6FA96B;
  --hudH: clamp(84px, 24vh, 210px);
  --line: rgba(233, 228, 214, 0.5);
  --type: 'Barlow Semi Condensed', 'Arial Narrow', sans-serif;
  --display: 'Chakra Petch', 'Arial Narrow', sans-serif;
  --mono: 'Azeret Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--type);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.mono { font-family: var(--mono); font-weight: 400; }

#field {
  position: fixed;
  top: var(--hudH);
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ink);
  overflow: hidden;
  transform: translateX(0);
  will-change: transform;
}

#field canvas {
  display: block;
  position: relative;
  z-index: 1;
}

body.deck-away #field {
  transform: translateX(106%);
  transition: transform 0.72s cubic-bezier(0.55, 0, 0.25, 1);
}

body.deck-return #field {
  transform: translateX(-106%);
  transition: none;
}

body.deck-back #field {
  transform: translateX(0);
  transition: transform 0.6s cubic-bezier(0.3, 0, 0.25, 1);
}

body.drained #field canvas {
  filter: grayscale(1) brightness(0.52) contrast(1.02);
}

body.drained .minigem { background: var(--bone); }
body.drained #hudLoot.flash { color: var(--bone); }

#swarmEdges {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#swarmEdges .edge {
  position: absolute;
  background: var(--red);
  opacity: 0;
}

#swarmEdges .top { top: 0; left: 0; right: 0; height: 4px; }
#swarmEdges .bottom { bottom: 0; left: 0; right: 0; height: 4px; }
#swarmEdges .left { top: 0; bottom: 0; left: 0; width: 4px; }
#swarmEdges .right { top: 0; bottom: 0; right: 0; width: 4px; }

body.swarm #swarmEdges .edge {
  animation: edgePulse 2.2s steps(2, end) infinite;
}

@keyframes edgePulse {
  0% { opacity: 0.28; }
  50% { opacity: 0.62; }
  100% { opacity: 0.28; }
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hudH);
  z-index: 90;
  background: var(--ink);
  border-bottom: 2px solid var(--bone);
  overflow: hidden;
}

#hud::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--bone);
  opacity: 0.55;
  z-index: 4;
}

.hud-sky {
  position: absolute;
  inset: 0;
  background-image: url(assets/deep_space_backdrop.webp);
  background-size: cover;
  background-position: center 38%;
  z-index: 0;
}

.hud-planet {
  position: absolute;
  right: -10%;
  bottom: -40%;
  height: 140%;
  width: auto;
  z-index: 1;
  pointer-events: none;
}

.hud-row {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: flex-start;
  gap: clamp(10px, 2vw, 26px);
  padding: clamp(8px, 1.4vh, 16px) clamp(14px, 2vw, 30px) 0;
}

.brand {
  flex: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(12px, 1.3vw, 22px);
  letter-spacing: 0.18em;
  line-height: 1;
  white-space: nowrap;
  color: var(--bone);
}

.icons {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(7px, 1.2vw, 18px);
  min-width: 0;
  padding-bottom: 2px;
}

.bar {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--bone);
  opacity: 0.34;
  flex: none;
}

.ico {
  display: inline-block;
  width: clamp(20px, 2vw, 30px);
  height: clamp(19px, 1.9vw, 28px);
  background-image: url(assets/hud_icon_set.webp);
  background-size: 400% 200%;
  background-repeat: no-repeat;
  opacity: 0.9;
  flex: none;
}

.ico.gem { background-position: 0% 0%; }
.ico.clock { background-position: 33.333% 0%; }
.ico.eye { background-position: 66.666% 0%; }
.ico.runner { background-position: 100% 0%; }
.ico.wifi { background-position: 0% 100%; }

.ico.eye.suspect {
  filter: drop-shadow(0 0 0 var(--red));
  opacity: 1;
  background-color: transparent;
}

.readout {
  flex: none;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1vw, 14px);
  font-family: var(--mono);
  font-size: clamp(12px, 1.15vw, 20px);
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  padding-bottom: 2px;
}

.hudset {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hudset[hidden] { display: none !important; }

.minigem {
  display: inline-block;
  width: 9px;
  height: 9px;
  background: var(--amber);
  transform: rotate(45deg);
  flex: none;
}

.pip {
  display: inline-block;
  width: 9px;
  height: 9px;
  background: var(--bone);
  transform: rotate(45deg);
  flex: none;
}

.pip.off {
  background: transparent;
  border: 1px solid rgba(233, 228, 214, 0.45);
}

#hudLoot.flash { color: var(--amber); }

.hud-status {
  position: absolute;
  top: clamp(4px, 0.7vh, 9px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-family: var(--type);
  font-weight: 600;
  font-size: clamp(8px, 0.82vw, 12px);
  letter-spacing: 0.24em;
  color: rgba(233, 228, 214, 0.72);
  white-space: nowrap;
  pointer-events: none;
  text-align: center;
}

.hud-status.alert { color: var(--red); }
.hud-status.amber { color: var(--amber); }

body.hasstatus .icons { opacity: 0.12; }
body.hasstatus .brand { opacity: 0.3; }

@media (max-width: 620px) {
  body.hasstatus .brand { opacity: 0.12; }
  .hud-status { max-width: 76vw; overflow: hidden; text-overflow: ellipsis; }
}

body.suspect #hud { border-bottom-color: var(--red); }
body.suspect .hud-status { color: var(--red); }

body.alarm #hud,
body.alarm #hud::before,
body.alarm .hud-status,
body.alarm .brand,
body.alarm .readout,
body.alarm .hud-status {
  color: var(--red) !important;
  border-color: var(--red) !important;
}

body.alarm #hud::before { background: var(--red) !important; }
body.alarm .bar { background: var(--red) !important; }

#cheat {
  position: fixed;
  left: clamp(12px, 1.5vw, 22px);
  bottom: clamp(10px, 1.5vh, 18px);
  z-index: 70;
  color: rgba(233, 228, 214, 0.5);
  font-family: var(--type);
  font-weight: 500;
  font-size: clamp(9px, 0.78vw, 12px);
  letter-spacing: 0.16em;
  line-height: 1.56;
  pointer-events: none;
  display: none;
}

body.playing #cheat { display: block; }

.cheat-kb, .cheat-touch {
  display: grid;
  grid-template-columns: auto;
}

.cheat-touch { display: none; }

body.touch .cheat-kb { display: none; }
body.touch .cheat-touch { display: grid; }

#cheat b {
  font-weight: 600;
  color: rgba(233, 228, 214, 0.76);
}

.crow {
  display: grid;
  grid-template-columns: 4.6em 5.2em;
  column-gap: 1.2em;
}

#cheat .near,
#cheat .near b {
  color: var(--amber);
}

#touch {
  position: fixed;
  right: clamp(12px, 1.5vw, 20px);
  bottom: clamp(12px, 1.5vh, 18px);
  z-index: 74;
  display: none;
  gap: 9px;
  align-items: flex-end;
}

body.touch.playing #touch { display: flex; }

.tbtn {
  width: clamp(58px, 7.4vw, 74px);
  height: clamp(58px, 7.4vw, 74px);
  border: 1px solid rgba(233, 228, 214, 0.68);
  background: rgba(10, 13, 24, 0.52);
  color: var(--bone);
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(9px, 1.1vw, 12px);
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.tbtn:active { background: var(--bone); color: var(--ink); }
.tbtn.near { border-color: var(--amber); color: var(--amber); }
.tbtn.on { background: var(--bone); color: var(--ink); border-color: var(--bone); }

#pauseBtn {
  position: fixed;
  right: clamp(12px, 1.5vw, 20px);
  bottom: calc(clamp(58px, 7.4vw, 74px) + 26px);
  z-index: 74;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(233, 228, 214, 0.42);
  color: rgba(233, 228, 214, 0.75);
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 0.02em;
  background: rgba(10, 13, 24, 0.42);
  display: none;
}

body.touch.playing #pauseBtn { display: block; }

#overlay {
  position: fixed;
  top: var(--hudH);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  background: rgba(10, 13, 24, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#overlay.caught { background: rgba(10, 13, 24, 0.66); }

.ov-copy {
  width: min(620px, 92vw);
  text-align: center;
}

.ov-kicker {
  margin: 0 0 14px;
  font-family: var(--type);
  font-weight: 600;
  font-size: clamp(9px, 0.9vw, 12px);
  letter-spacing: 0.3em;
  color: rgba(233, 228, 214, 0.55);
}

.ov-copy h2 {
  margin: 0 auto;
  max-width: 13ch;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(27px, 5.2vw, 62px);
  line-height: 1.02;
  letter-spacing: 0.1em;
  color: var(--bone);
  animation: dropIn 0.32s steps(4, end) both;
}

@keyframes dropIn {
  from { transform: translateY(-28px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.ov-sub {
  margin: 16px 0 0;
  font-family: var(--type);
  font-weight: 500;
  font-size: clamp(12px, 1.2vw, 16px);
  letter-spacing: 0.18em;
  color: rgba(233, 228, 214, 0.62);
}

.ov-stats {
  margin: 18px 0 26px;
  font-size: clamp(11px, 1.1vw, 15px);
  letter-spacing: 0.1em;
  color: var(--amber);
  min-height: 1.2em;
}

.play {
  display: inline-block;
  min-width: 200px;
  padding: 18px 44px;
  background: var(--amber);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(15px, 1.5vw, 21px);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  line-height: 1;
  border: 1px solid var(--amber);
}

.play:hover { background: var(--bone); border-color: var(--bone); }
.play:active { transform: translateY(1px); }
.play.small { min-width: 170px; padding: 14px 32px; font-size: clamp(13px, 1.2vw, 17px); }

.ghost {
  display: inline-block;
  margin-top: 12px;
  padding: 11px 24px;
  border: 1px solid rgba(233, 228, 214, 0.4);
  color: rgba(233, 228, 214, 0.85);
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(10px, 0.95vw, 13px);
  letter-spacing: 0.2em;
  line-height: 1;
}

.ghost:hover { border-color: var(--bone); color: var(--bone); }

#ovAlt, #ovSound { display: block; margin-left: auto; margin-right: auto; }
#ovBtn { display: block; margin: 0 auto; }

#endcard {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--ink);
  overflow: hidden;
}

.end-sky {
  position: absolute;
  inset: 0;
  background-image: url(assets/deep_space_backdrop.webp);
  background-size: cover;
  background-position: center 42%;
}

.end-planet {
  position: absolute;
  right: -70%;
  bottom: 0;
  width: auto;
  height: 100%;
  pointer-events: none;
}

.end-copy {
  position: absolute;
  left: clamp(24px, 7vw, 110px);
  top: 50%;
  transform: translateY(-50%);
  width: min(720px, 86vw);
}

.end-kicker {
  margin: 0 0 16px;
  font-family: var(--type);
  font-weight: 600;
  font-size: clamp(9px, 0.9vw, 12px);
  letter-spacing: 0.32em;
  color: rgba(233, 228, 214, 0.6);
}

.end-copy h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(32px, 6.4vw, 84px);
  line-height: 0.98;
  letter-spacing: 0.08em;
  color: var(--bone);
}

.end-loot {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin: 18px 0 6px;
  color: var(--amber);
}

.end-loot .mono {
  font-size: clamp(58px, 11vw, 132px);
  line-height: 0.86;
  letter-spacing: -0.04em;
}

.end-loot em {
  font-family: var(--type);
  font-style: normal;
  font-weight: 600;
  font-size: clamp(10px, 1.1vw, 14px);
  letter-spacing: 0.3em;
  color: rgba(242, 160, 61, 0.8);
}

.end-stats {
  margin: 16px 0 0;
  font-size: clamp(11px, 1.05vw, 15px);
  letter-spacing: 0.1em;
  color: rgba(233, 228, 214, 0.7);
  line-height: 1.7;
}

.end-board {
  margin: 18px 0 26px;
  font-family: var(--mono);
  font-size: clamp(10px, 0.95vw, 13px);
  letter-spacing: 0.04em;
  color: rgba(233, 228, 214, 0.62);
  line-height: 1.9;
  min-height: 0;
}

.end-board .row {
  display: flex;
  gap: 14px;
  align-items: baseline;
  max-width: 420px;
  border-bottom: 1px solid rgba(233, 228, 214, 0.12);
  padding-bottom: 2px;
}

.end-board .rank { color: rgba(233, 228, 214, 0.35); width: 2.2em; flex: none; }
.end-board .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.end-board a { color: var(--bone); text-decoration: none; }
.end-board a:hover { text-decoration: underline; }
.end-board .val { color: var(--amber); flex: none; }

#endBtn, #endAlt { margin-top: 0; }
#endBtn { margin-right: 14px; }

#landing {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: var(--ink);
  overflow: hidden;
}

.land-sky {
  position: absolute;
  inset: 0;
  background-image: url(assets/deep_space_backdrop.webp);
  background-size: cover;
  background-position: center 42%;
}

.land-planet {
  position: absolute;
  right: -62%;
  bottom: 0;
  width: auto;
  height: 100%;
  pointer-events: none;
}

.land-inner {
  position: absolute;
  left: clamp(22px, 6vw, 96px);
  top: clamp(16vh, 18vh, 24vh);
  width: min(760px, 86vw);
}

.kicker {
  margin: 0 0 clamp(10px, 1.4vh, 18px);
  font-family: var(--type);
  font-weight: 600;
  font-size: clamp(9px, 0.9vw, 13px);
  letter-spacing: 0.36em;
  color: rgba(233, 228, 214, 0.62);
}

#landing h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(42px, 8.2vw, 116px);
  line-height: 0.9;
  letter-spacing: 0.1em;
  color: var(--bone);
}

#playBtn {
  display: block;
  margin-top: clamp(22px, 3.6vh, 44px);
}

.bestline {
  margin: clamp(14px, 2vh, 22px) 0 0;
  font-size: clamp(9px, 0.85vw, 12px);
  letter-spacing: 0.08em;
  color: rgba(233, 228, 214, 0.46);
}

.coop { margin-left: 14px; }

.land-controls {
  display: none;
  position: absolute;
  left: clamp(22px, 6vw, 96px);
  bottom: clamp(18px, 3vh, 30px);
  z-index: 2;
  font-family: var(--type);
  font-weight: 500;
  font-size: clamp(9px, 0.8vw, 12px);
  letter-spacing: 0.18em;
  color: rgba(233, 228, 214, 0.5);
}

.tonly { display: none; }
body.touch .kbonly { display: none; }
body.touch .tonly { display: inline; }
body.touch .land-controls { display: none; }

.land-load {
  position: absolute;
  right: clamp(18px, 3vw, 34px);
  bottom: clamp(18px, 3vh, 30px);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  color: rgba(233, 228, 214, 0.4);
}

.land-load.error { color: var(--red); }

#landing.launch { background: transparent; }
#landing.launch .land-sky { opacity: 0; transition: opacity 0.55s steps(4, end); }
#landing.launch .land-planet { transform: translateX(118%); transition: transform 0.78s cubic-bezier(0.5, 0, 0.2, 1); }
#landing.launch .land-inner { opacity: 0; transform: translateX(-34px); transition: opacity 0.3s steps(3, end), transform 0.3s steps(3, end); }
#landing.launch .land-controls, #landing.launch .land-load { opacity: 0; transition: opacity 0.25s steps(2, end); }
#landing.gone { display: none; }

@media (max-width: 900px) {
  .icons { display: none; }
  .hud-row { justify-content: space-between; }
}

@media (max-width: 620px) {
  .brand { font-size: 11px; letter-spacing: 0.14em; }
  .readout { font-size: 11px; gap: 7px; }
  .hud-row { padding-left: 13px; padding-right: 13px; gap: 8px; }
  #landing h1 { letter-spacing: 0.07em; }
  .land-planet { height: 72vh; right: -60%; bottom: 0; }
  .land-inner { top: 15vh; }
  .land-controls { max-width: 78vw; line-height: 1.7; }
  .end-planet { height: 72vh; right: -60%; bottom: 0; }
  .end-copy { left: 22px; width: calc(100vw - 44px); }
  .end-board .row { max-width: 100%; }
  #endBtn { display: block; margin: 0 0 12px; }
  #endAlt { display: block; margin: 0; }
}

@media (max-width: 420px) {
  .brand { font-size: 10px; }
  .readout { font-size: 10px; }
  .pip, .minigem { width: 7px; height: 7px; }
  .crow { grid-template-columns: 4.2em 4.6em; column-gap: 0.9em; }
}

@media (max-height: 440px) and (orientation: landscape) {
  :root { --hudH: 78px; }
  #landing h1 { font-size: clamp(34px, 6vw, 64px); }
  .land-inner { top: 14vh; }
  .land-planet { height: 100%; right: -55%; bottom: 0; }
  .end-copy { top: 54%; }
  .end-loot .mono { font-size: clamp(44px, 8vh, 78px); }
  .end-board { display: none; }
}


#stick {
  position: fixed;
  width: 110px;
  height: 110px;
  border: 1px solid rgba(233, 228, 214, 0.42);
  border-radius: 50%;
  z-index: 73;
  display: none;
  pointer-events: none;
}

#stick i {
  position: absolute;
  left: 0;
  top: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(233, 228, 214, 0.3);
  border: 1px solid rgba(233, 228, 214, 0.6);
}


@media (orientation: portrait) {
  .land-planet { height: 45vh; right: -75%; bottom: 0; }
  .end-planet { height: 38vh; right: -78%; bottom: 0; }
}


@media (max-width: 700px) {
  .hud-planet { right: -45%; }
}
