/* ------------------------------------------------------------------ Tokens */
:root {
  --vt-void: #05040f;
  --vt-plate: rgba(8, 11, 30, 0.84);
  --vt-plate-strong: rgba(7, 9, 26, 0.95);
  --vt-line: rgba(120, 220, 255, 0.24);
  --vt-line-strong: rgba(125, 232, 255, 0.6);
  --vt-cyan: #5ff6ff;
  --vt-teal: #3dffc5;
  --vt-violet: #9b8bff;
  --vt-ember: #ff8a3a;
  --vt-text: #e6f2ff;
  --vt-muted: #8f9ec2;
  --vt-dim: #5e6b90;
  --vt-ok: #3dffc5;
  --vt-warn: #ffb03a;
  --vt-danger: #ff4a5a;
  --vt-metal: #c3cbe0;
  --vt-biomass: #4fe3b5;
  --vt-water: #5cb8ff;
  --vt-font-body: "Exo 2", "Segoe UI", system-ui, sans-serif;
  --vt-font-display: "Chakra Petch", "Exo 2", "Segoe UI", sans-serif;
  --vt-plate-fill:
    linear-gradient(180deg, rgba(95, 246, 255, 0.07), transparent 42%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px),
    var(--vt-plate);
  /* Room for notches, the Dynamic Island and the home indicator (index.html sets viewport-fit=cover); 0 elsewhere. */
  --vt-safe-t: env(safe-area-inset-top, 0px);
  --vt-safe-r: env(safe-area-inset-right, 0px);
  --vt-safe-b: env(safe-area-inset-bottom, 0px);
  --vt-safe-l: env(safe-area-inset-left, 0px);
  /* 1vw / 1vh of the safe area, for panels centred on screen. */
  --vt-safe-vw: calc((100vw - var(--vt-safe-l) - var(--vt-safe-r)) / 100);
  --vt-safe-vh: calc((100vh - var(--vt-safe-t) - var(--vt-safe-b)) / 100);
  /* One tile of the stabilizer's hex lattice; size it 13.86px × 24px. */
  --vt-hex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13.86' height='24'%3E%3Cpath d='M6.93 0L13.86 4V12L6.93 16L0 12V4ZM6.93 16V24' fill='none' stroke='%237de8ff' stroke-opacity='0.075'/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------------ Layout */
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  touch-action: none;
  /* Nothing in the game is text to copy or a link to drag: presses never select, call out or lift
     anything, and the pointer stays an arrow over words. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}

a,
img,
svg {
  -webkit-user-drag: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  cursor: auto;
}

/* iOS otherwise enlarges long paragraphs (the field manual) in landscape. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--vt-font-body);
  color: var(--vt-text);
  background-color: var(--vt-void);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.vt-hidden {
  display: none !important;
}

/* ---------------------------------------------------------- Chamfer plates
   Chamfered elements cut the top-left and bottom-right corners. `--shape` clips the element and
   `--ring` (an even-odd frame) draws its 1px outline on ::before, so fills can stay translucent. */
.vt-plate,
.vt-btn,
.vt-close,
.vt-square-btn,
.vt-seg,
.vt-seg button,
.vt-panel,
.action-btn,
.toast,
.build-card,
.upgrade-card,
.piece-card,
.mission-card,
.hangar-tab,
.chron-chip,
.home-dossier,
.instructions-content,
.core-grid-wrap,
.loading-card {
  --cut: 10px;
  --plate-line: var(--vt-line);
  --shape: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  --ring: polygon(evenodd,
    var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut), var(--cut) 0,
    calc(var(--cut) + 0.41px) 1px, 1px calc(var(--cut) + 0.41px), 1px calc(100% - 1px),
    calc(100% - var(--cut) - 0.41px) calc(100% - 1px), calc(100% - 1px) calc(100% - var(--cut) - 0.41px),
    calc(100% - 1px) 1px, calc(var(--cut) + 0.41px) 1px);
  position: relative;
  border: 0;
  clip-path: var(--shape);
}

.vt-plate::before,
.vt-btn::before,
.vt-close::before,
.vt-square-btn::before,
.vt-seg::before,
.vt-panel::before,
.action-btn::before,
.toast::before,
.build-card::before,
.upgrade-card::before,
.piece-card::before,
.mission-card::before,
.hangar-tab::before,
.chron-chip::before,
.home-dossier::before,
.instructions-content::before,
.core-grid-wrap::before,
.loading-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--plate-line);
  clip-path: var(--ring);
  transition: background 0.15s ease;
}

.vt-plate {
  background: var(--vt-plate-fill);
  backdrop-filter: blur(9px) saturate(130%);
  -webkit-backdrop-filter: blur(9px) saturate(130%);
}

/* Corner brackets on the two square corners. */
.vt-brackets::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  --b: var(--bracket-color, var(--vt-cyan));
  background:
    linear-gradient(var(--b), var(--b)) right top / 12px 2px no-repeat,
    linear-gradient(var(--b), var(--b)) right top / 2px 12px no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / 12px 2px no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / 2px 12px no-repeat;
  opacity: var(--bracket-opacity, 0.85);
}

/* ------------------------------------------------------------------ Icons */
.vt-icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -0.22em;
  overflow: visible;
}

/* ------------------------------------------------------------------- Tags */
.vt-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--vt-font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  line-height: 1.2;
  text-transform: uppercase;
  color: var(--vt-muted);
}

.vt-tag.rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--vt-line), transparent);
}

/* ---------------------------------------------------------------- Buttons */
.vt-btn {
  --cut: 8px;
  --plate-line: rgba(125, 232, 255, 0.5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 20px;
  background: linear-gradient(180deg, rgba(95, 246, 255, 0.16), rgba(95, 246, 255, 0.04));
  color: var(--vt-text);
  font-family: var(--vt-font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}

.vt-btn .vt-icon {
  width: 17px;
  height: 17px;
}

.vt-btn:hover:not(:disabled) {
  --plate-line: var(--vt-cyan);
  background: linear-gradient(180deg, rgba(95, 246, 255, 0.3), rgba(95, 246, 255, 0.1));
}

.vt-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.vt-btn:disabled {
  opacity: 0.38;
  cursor: default;
  filter: saturate(0.5);
}

.vt-btn.primary {
  --plate-line: rgba(255, 255, 255, 0.7);
  background: linear-gradient(180deg, #8afbff 0%, #39d3ea 55%, #22b3d6 100%);
  color: #03141c;
}

.vt-btn.primary:hover:not(:disabled) {
  --plate-line: #ffffff;
  background: linear-gradient(180deg, #b4fdff 0%, #5fe6f6 55%, #2cc3e3 100%);
}

/* Unlocking the full version, in the gold the game uses for stars and best times. */
.vt-btn.gold {
  --plate-line: rgba(255, 244, 214, 0.75);
  background: linear-gradient(180deg, #ffe9a6 0%, #ffcb55 55%, #e9a637 100%);
  color: #241503;
}

.vt-btn.gold:hover:not(:disabled) {
  --plate-line: #ffffff;
  background: linear-gradient(180deg, #fff3c9 0%, #ffd874 55%, #f2b447 100%);
}

.vt-btn.danger {
  --plate-line: rgba(255, 90, 105, 0.7);
  background: linear-gradient(180deg, rgba(255, 74, 90, 0.2), rgba(255, 74, 90, 0.06));
  color: #ffd6da;
}

.vt-btn.danger:hover:not(:disabled) {
  --plate-line: #ff6b78;
  background: linear-gradient(180deg, rgba(255, 74, 90, 0.36), rgba(255, 74, 90, 0.12));
}

.vt-btn.ghost {
  --plate-line: transparent;
  background: transparent;
  color: var(--vt-muted);
}

.vt-btn.ghost:hover:not(:disabled) {
  --plate-line: var(--vt-line);
  background: rgba(95, 246, 255, 0.07);
  color: var(--vt-text);
}

.vt-btn.small {
  --cut: 6px;
  min-height: 32px;
  padding: 6px 13px;
  gap: 7px;
  font-size: 11px;
  letter-spacing: 0.12em;
}

.vt-btn.small .vt-icon {
  width: 15px;
  height: 15px;
}

.vt-btn kbd {
  margin-left: 2px;
  background: rgba(0, 0, 0, 0.2);
}

.vt-btn.primary kbd {
  color: #03141c;
  border-color: rgba(3, 20, 28, 0.35);
}

/* Square icon buttons (close, HUD menu, sound). */
.vt-close,
.vt-square-btn {
  --cut: 7px;
  --plate-line: var(--vt-line-strong);
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: linear-gradient(180deg, rgba(20, 32, 66, 0.92), rgba(8, 11, 30, 0.92));
  color: var(--vt-cyan);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.vt-close .vt-icon,
.vt-square-btn .vt-icon {
  width: 18px;
  height: 18px;
}

.vt-square-btn:hover {
  --plate-line: var(--vt-cyan);
  background: linear-gradient(180deg, rgba(40, 70, 120, 0.95), rgba(12, 20, 46, 0.95));
}

.vt-square-btn:active,
.vt-close:active {
  transform: translateY(1px);
}

.vt-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 34px;
  height: 34px;
  color: var(--vt-muted);
}

.vt-close:hover {
  --plate-line: var(--vt-danger);
  background: rgba(255, 74, 90, 0.2);
  color: #ffd6da;
}

/* Segmented control (difficulty / graphics). */
.vt-seg {
  --cut: 8px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(4, 7, 22, 0.7);
}

.vt-seg button {
  --cut: 6px;
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  background: transparent;
  color: var(--vt-muted);
  font-family: var(--vt-font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.vt-seg button:hover {
  color: var(--vt-text);
  background: rgba(95, 246, 255, 0.08);
}

.vt-seg button.selected {
  background: linear-gradient(180deg, rgba(95, 246, 255, 0.34), rgba(95, 246, 255, 0.14));
  color: #fff;
}

/* ------------------------------------------------------------------- Keys */
kbd,
.key {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--vt-text);
  font-family: var(--vt-font-display);
  font-size: 10.5px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: 0.04em;
  line-height: 1;
  vertical-align: 0.05em;
}

.key + .key {
  margin-left: 3px;
}

/* -------------------------------------------------------------- Scrollbars */
.vt-panel,
.instructions-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 246, 255, 0.35) transparent;
}

.vt-panel::-webkit-scrollbar,
.instructions-content::-webkit-scrollbar {
  width: 6px;
}

.vt-panel::-webkit-scrollbar-thumb,
.instructions-content::-webkit-scrollbar-thumb {
  background: rgba(95, 246, 255, 0.35);
}

/* Rings only while travelling by Tab (main.js sets .keyboard-nav): browsers otherwise outline the
   last-pressed button as soon as a game key is pressed. */
:focus-visible {
  outline: none;
}

.keyboard-nav :focus-visible {
  outline: 2px solid var(--vt-cyan);
  outline-offset: 3px;
}

/* ------------------------------------------------------------ Sound toggle */
.sound-toggle {
  position: fixed;
  top: calc(14px + var(--vt-safe-t));
  right: calc(14px + var(--vt-safe-r));
  z-index: 2600;
}

/* In a mission it sits under the HUD (z-index 100), so side panels such as Rover Assembly cover it rather
   than it covering their close buttons. The HUD lets clicks through everywhere else. */
body.in-game .sound-toggle {
  z-index: 99;
}

/* ----------------------------------------------------------------- Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 60%, rgba(70, 40, 140, 0.25), transparent 60%),
    var(--vt-void);
  color: var(--vt-text);
  transition: opacity 0.8s ease;
}

.loading-overlay.fade {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  --cut: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 260px;
  max-width: min(420px, 86vw);
  padding: 28px 34px 26px;
  background: var(--vt-plate-fill);
  text-align: center;
}

.loading-lattice {
  display: grid;
  grid-template-columns: repeat(4, 11px);
  gap: 4px;
}

.loading-lattice i {
  width: 11px;
  height: 11px;
  background: rgba(95, 246, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(95, 246, 255, 0.28);
  animation: vt-lattice-fill 1.6s ease-in-out infinite;
}

.loading-lattice i:nth-child(1), .loading-lattice i:nth-child(4), .loading-lattice i:nth-child(13), .loading-lattice i:nth-child(16) {
  visibility: hidden;
}

@keyframes vt-lattice-fill {
  0%, 100% { background: rgba(95, 246, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(95, 246, 255, 0.28); }
  35%, 60% { background: var(--vt-cyan); box-shadow: 0 0 10px rgba(95, 246, 255, 0.8); }
}

.loading-text {
  font-family: var(--vt-font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.3em;
  color: var(--vt-cyan);
}

.loading-sub {
  font-size: 13px;
  color: var(--vt-muted);
  line-height: 1.5;
}

.loading-sub small {
  display: block;
  margin-top: 6px;
  word-break: break-word;
}

/* ---------------------------------------------------- Orientation warning */
#orientation-warning {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px;
  box-sizing: border-box;
  text-align: center;
  color: var(--vt-text);
  background:
    radial-gradient(ellipse at 50% 35%, rgba(80, 50, 160, 0.35), transparent 65%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 3px),
    #06051a;
}

#orientation-warning .orientation-icon {
  width: 84px;
  height: 84px;
  margin-bottom: 8px;
  color: var(--vt-cyan);
  filter: drop-shadow(0 0 14px rgba(95, 246, 255, 0.5));
  animation: vt-rotate-device 2.4s ease-in-out infinite;
}

#orientation-warning .orientation-icon .vt-icon {
  width: 100%;
  height: 100%;
}

#orientation-warning h2 {
  margin: 0;
  font-family: var(--vt-font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

#orientation-warning p {
  margin: 0 0 18px;
  max-width: 300px;
  color: var(--vt-muted);
  line-height: 1.5;
}

@keyframes vt-rotate-device {
  0%, 25% { transform: rotate(0deg); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

@media (orientation: portrait) and (max-width: 768px) {
  #orientation-warning {
    display: flex;
  }
}

body.allow-portrait #orientation-warning {
  display: none;
}

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