/* The landing palette, type, wordmark and controls are packaged verbatim at build time. */
@import url("/pilot/brand/landing.css");
@import url("/pilot/brand/social-links.css");

/* Shared shell and typography */
:root {
  color-scheme: dark;
}

[hidden] {
  display: none !important;
}

header {
  max-width: 1500px;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.release-label {
  flex: 1;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

main {
  max-width: 1500px;
  margin: auto;
  padding: 32px;
  gap: 32px;
}

main > section {
  padding: 0;
  margin: 0;
  max-width: none;
  min-width: 0;
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 272px;
}

article,
aside,
dialog {
  background: var(--v1);
  border: 1px solid var(--line);
  padding: 24px;
}

aside {
  align-self: start;
}

article {
  margin: 24px 0;
}

h1 {
  font-size: clamp(26px, 3vw, 40px);
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
}

p,
small,
time {
  color: var(--v7);
}

#world-list small {
  display: block;
  margin-bottom: 16px;
}

/* Health labels remain readable without relying on colour alone. */
.server-health {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.server-health::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

[data-health="online"] .server-health::before {
  background: #72c990;
}

[data-health="updating"] .server-health::before {
  background: #e8ae52;
}

[data-health="offline"] .server-health::before {
  background: #e47777;
}

#world-list [data-health="coming-soon"] {
  filter: grayscale(1);
}

#world-list [data-health="coming-soon"] h2 {
  color: var(--muted);
}

/* Shared controls */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: var(--signal);
  color: var(--v0);
  padding: 12px 16px;
  font:
    700 12px/1.2 ui-monospace,
    monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  box-shadow: 4px 4px 0 var(--v3);
  margin: 4px 8px 8px 0;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--signal-hi);
}

button:active,
.button:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

button:disabled {
  background: var(--v4);
  color: var(--v6);
  box-shadow: none;
  cursor: default;
}

button[aria-pressed="true"] {
  background: var(--v8);
  outline: 2px solid var(--signal);
}

/* Lobby sponsorship */
.sponsor-banner {
  display: block;
  margin: -24px -24px 24px;
  border-bottom: 1px solid var(--line);
}

.sponsor-banner img {
  display: block;
  width: 100%;
  height: clamp(152px, 22vw, 220px);
  object-fit: cover;
}

.sponsor-banner-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(152px, 22vw, 220px);
  background: var(--v2);
  color: var(--v8);
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 700;
  text-transform: uppercase;
}

/* Dialogs and forms */
dialog {
  max-width: min(90vw, 500px);
  color: var(--v8);
  box-shadow: 8px 8px 0 var(--v3);
}

dialog::backdrop {
  background: #07090acc;
}

label {
  margin: 16px 0;
}

input {
  width: 100%;
  font: inherit;
}

footer {
  justify-content: flex-start;
  gap: 32px;
  padding-top: 24px;
  padding-bottom: 24px;
}

/* Play arena and telemetry */
.arena {
  position: relative;
  min-height: 650px;
  overflow: hidden;
  border: 1px solid var(--line);
}

#viewport {
  position: absolute;
  inset: 0;
}

#viewport canvas {
  display: block;
  touch-action: none;
}

.world-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  pointer-events: none;
  background: #07090acc;
  padding: 8px 16px;
}

.world-overlay h1 {
  margin: 4px 0;
  font-size: 22px;
}

.world-overlay p {
  margin: 6px 0;
  font-size: 12px;
}

#asset-progress {
  display: block;
  width: 100%;
  height: 12px;
  accent-color: var(--signal);
}

#asset-retry {
  pointer-events: auto;
}

.timing {
  position: absolute;
  right: 16px;
  top: 16px;
  max-width: 230px;
  background: #07090ee6;
  padding: 12px;
  font-size: 12px;
}

.timing dl {
  width: 264px;
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
}

.timing dl > div {
  display: grid;
  grid-template-columns: 1fr 8ch;
  gap: 8px;
  line-height: 1.8;
  white-space: nowrap;
}

.timing dd {
  margin: 0;
  text-align: right;
}

.direction-pad {
  position: fixed;
  z-index: 4;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
}

.direction-pad button {
  width: 56px;
  height: 56px;
  padding: 0;
  margin: 0;
  font-size: 24px;
  border: 2px solid #eaf2f7;
  background: #15263366;
  color: #fff;
  text-shadow: 0 1px 3px #000;
  box-shadow: 0 2px 6px #0004;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.direction-pad button:disabled {
  background: #15263333;
  color: #d4dfe6;
  border-color: #d4dfe6aa;
}

.direction-pad button:active {
  transform: none;
  background: #d7953499;
}

/* Controlled robot indicator */
.controlled-robot-marker {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -100%);
  padding: 4px 8px;
  background: var(--signal-hi);
  color: var(--v0);
  font-weight: bold;
  font-size: 12px;
  margin-top: -10px;
}

.controlled-robot-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 9px solid var(--signal-hi);
}

/* Responsive layout */
@media (max-width: 850px) {
  main {
    padding: 16px;
    gap: 24px;
  }

  .lobby-layout,
  .play-layout {
    grid-template-columns: 1fr;
  }

  .arena {
    min-height: 65vh;
  }

  header {
    padding: 16px;
    gap: 16px;
  }

  header .wordmark {
    font-size: 19px;
    white-space: nowrap;
  }

  .release-label {
    font-size: 10px;
  }

  .timing {
    top: auto;
    bottom: 64px;
  }
}

/* Pilot play fills the viewport; only the HUD panels intercept camera input. */
.world-play {
  height: 100dvh;
  overflow: hidden;
}

.world-play .play-layout,
.world-play .arena {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100dvh;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.world-play header {
  position: fixed;
  z-index: 2;
  inset: 0 0 auto;
  height: 56px;
  max-width: none;
  padding: 12px 16px;
  background: transparent;
  border: 0;
  text-shadow: 0 1px 3px #000;
}

.world-play header .quiet-link {
  display: inline-flex;
}

.world-play .world-overlay {
  top: 72px;
  max-width: calc(100% - 320px);
  padding: 8px 12px;
  overflow-wrap: anywhere;
  opacity: 1;
  transition: opacity 200ms;
}

.world-play .world-overlay-settled {
  opacity: 0;
  transition: opacity 800ms 1800ms;
}

.world-play:has(.play-controls[open]) .world-overlay-settled {
  transition: none;
}

.world-play .timing {
  top: auto;
  bottom: 16px;
  left: 16px;
  right: auto;
  max-width: min(300px, calc(100% - 32px));
}

.play-controls {
  position: fixed;
  z-index: 1;
  top: 72px;
  right: 16px;
  width: 264px;
  max-width: calc(100% - 32px);
  color: var(--v8);
  background: #07090a99;
  border: 1px solid var(--line);
}

.play-controls > summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 700;
}

.play-controls:not([open]) {
  width: auto;
  min-width: 128px;
}

.play-controls-content {
  max-height: calc(100dvh - 252px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.play-controls-content h2 {
  font-size: 16px;
  margin: 12px 0;
}

@media (max-width: 600px) {
  .world-play .world-overlay {
    top: 112px;
    max-width: calc(100% - 32px);
  }

  .world-play .world-overlay h1 {
    font-size: 16px;
  }

  .play-controls {
    top: 64px;
  }

  .play-controls-content {
    max-height: calc(100dvh - 284px);
  }
}

/* Directions remain independent of the disclosure and reachable at all four edges. */
@media (max-width: 600px), (hover: none) and (pointer: coarse) {
  .direction-pad {
    inset: 0;
    transform: none;
    display: block;
    pointer-events: none;
  }

  .direction-pad button {
    position: absolute;
    pointer-events: auto;
    width: 52px;
    height: 52px;
  }

  [data-direction="forward"] {
    top: calc(60px + env(safe-area-inset-top, 0px));
    left: calc(50% - 26px);
  }

  [data-direction="backward"] {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: calc(50% - 26px);
  }

  [data-direction="left"] {
    left: calc(12px + env(safe-area-inset-left, 0px));
    top: calc(50% - 26px);
  }

  [data-direction="right"] {
    right: calc(12px + env(safe-area-inset-right, 0px));
    top: calc(50% - 26px);
  }

  .world-play .timing {
    left: calc(76px + env(safe-area-inset-left, 0px));
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100% - 92px);
  }

  .timing dl {
    width: min(264px, calc(100vw - 116px));
    font-size: 11px;
  }

  .world-play .world-overlay {
    top: 124px;
    left: calc(76px + env(safe-area-inset-left, 0px));
    max-width: min(300px, calc(100% - 152px));
  }

  .play-controls {
    top: 64px;
    max-width: calc(50% - 48px);
  }

  .play-controls[open] {
    top: 124px;
    right: 76px;
    max-width: calc(100% - 152px);
  }

  .play-controls:not([open]) {
    min-width: 0;
  }

  .play-controls > summary {
    padding: 12px 8px;
  }

  .play-controls-content {
    padding: 10px;
    max-height: calc(100dvh - 220px);
  }
}

@media (max-height: 500px) and (min-width: 650px) and (pointer: coarse) {
  .world-play .world-overlay {
    top: 64px;
  }

  .world-play .world-overlay p {
    margin: 4px 0;
    font-size: 11px;
    line-height: 1.4;
  }

  .world-play .timing {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* Portrait panels share one narrow column: actionable status takes the top slot. */
@media (max-width: 600px) {
  .play-controls[open] {
    --controls-top: 124px;
    top: var(--controls-top);
  }

  .world-play:has(.world-overlay:not(.world-overlay-settled)) .play-controls[open] {
    --controls-top: var(--world-status-bottom, 360px);
  }

  .play-controls-content {
    max-height: max(40px, calc(100dvh - var(--controls-top) - 260px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .world-play .world-overlay {
    transition: none;
  }
}
