/* The live map: a full-height night stage with a drawing's title block in the corner. */

.mapx {
  position: relative;
  height: max(660px, calc(100svh - 68px));
  overflow: hidden;
  background: radial-gradient(80% 70% at 60% 55%, color-mix(in oklab, var(--night) 80%, var(--clay)), var(--night) 75%);
}
.mapx-stage {
  position: absolute;
  inset: 0;
}
.mapx-top {
  position: absolute;
  z-index: 3;
  inset-block-start: 1rem;
  inset-inline: var(--gutter);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
}
.mapx-top > * {
  pointer-events: auto;
}

.lens-tabs,
.cam {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: color-mix(in oklab, var(--night) 82%, transparent);
  border: 1px solid var(--night-line);
  border-radius: 6px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.lens-tabs button,
.cam button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 40px;
  min-width: 40px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--on-night);
  background: none;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.cam button {
  padding: 0.4rem;
}
.cam .cam-text {
  padding-inline: 0.75rem;
}
.lens-tabs button:hover,
.cam button:hover {
  background: var(--night-2);
}
.lens-tabs button[aria-selected='true'],
.cam button[aria-pressed='true'] {
  background: var(--gold);
  color: var(--night);
}

.title-block {
  position: absolute;
  z-index: 3;
  inset-block-end: 1.25rem;
  inset-inline-start: var(--gutter);
  width: min(31rem, calc(100% - 2 * var(--gutter)));
  background: color-mix(in oklab, var(--night) 88%, transparent);
  border: 1px solid color-mix(in oklab, var(--plaster) 34%, transparent);
  border-radius: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.tb-head {
  padding: 1.1rem 1.25rem 1rem;
  display: grid;
  gap: 0.5rem;
}
.tb-head h1 {
  font-size: clamp(1.9rem, 3vw, 2.75rem);
}
.tb-head p {
  font-size: 0.95rem;
  max-width: 46ch;
}
.tb-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-block-start: 1px solid var(--night-line);
}
.tb-legend button {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--on-night);
  background: none;
  border: 0;
  border-block-end: 1px solid var(--night-line);
  text-align: start;
  cursor: pointer;
  transition: background-color 0.2s;
}
.tb-legend button:nth-child(odd) {
  border-inline-end: 1px solid var(--night-line);
}
.tb-legend button:hover {
  background: var(--night-2);
}
.tb-legend button[aria-pressed='true'] {
  background: var(--gold-soft);
}
.tb-legend b {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.sw {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--sw);
  border: 1px solid color-mix(in oklab, var(--plaster) 40%, transparent);
}
.sw[data-pulse='true'] {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--sw) 45%, transparent);
  animation: swpulse 1.9s ease-in-out infinite;
}
@keyframes swpulse {
  50% {
    box-shadow: 0 0 0 6px color-mix(in oklab, var(--sw) 0%, transparent);
  }
}
.tb-meta {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  margin: 0;
}
.tb-meta div {
  padding: 0.55rem 1.25rem 0.7rem;
}
.tb-meta div + div {
  border-inline-start: 1px solid var(--night-line);
}
.tb-meta dt {
  color: var(--on-night-soft);
  font-size: 0.72rem;
}
.tb-meta dd {
  margin: 0.15rem 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
}

/* Unit sheet. */
.sheet {
  position: absolute;
  z-index: 4;
  inset-block-start: 4.75rem;
  inset-inline-end: var(--gutter);
  width: min(23rem, calc(100% - 2 * var(--gutter)));
  max-height: calc(100% - 6.5rem);
  overflow: auto;
  background: var(--plaster);
  color: var(--ink);
  border-radius: 4px;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.92);
  animation: sheet-in 0.45s var(--ease-out);
}
@keyframes sheet-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-block-end: 1px solid var(--ink-hair);
}
.sheet-head h2 {
  font-size: 2rem;
}
.sheet-x {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  color: inherit;
  cursor: pointer;
}
.sheet-body {
  display: grid;
}
.sheet-body section {
  padding: 0.85rem 1.25rem;
  border-block-end: 1px solid var(--ink-hair);
  display: grid;
  gap: 0.3rem;
}
.sheet-body section:last-child {
  border: 0;
}
.sheet-body .label {
  color: color-mix(in oklab, var(--ink) 75%, var(--plaster));
}
.sheet-body .big {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
}
.state {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 650;
}
.state .sw {
  border-color: var(--ink-line);
}
.alias-note {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.9rem;
}

.sheet-figure {
  margin: 0;
  display: grid;
  justify-items: center;
}

/* Hover tip sits above the pointer; the arrow follows. */
.mapx .tip3d {
  left: 0;
  top: 0;
}

@media (max-width: 760px) {
  .mapx {
    height: auto;
    display: flex;
    flex-direction: column;
  }
  .mapx-stage {
    position: relative;
    height: 74svh;
    min-height: 420px;
  }
  .mapx-top {
    inset-block-start: 0.75rem;
  }
  .lens-tabs {
    width: 100%;
    justify-content: space-between;
  }
  .lens-tabs button span {
    font-size: 0.8rem;
  }
  .lens-tabs button {
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.35rem 0.3rem;
    flex: 1;
  }
  .cam {
    margin-inline-start: auto;
  }
  .title-block {
    position: relative;
    inset: auto;
    width: auto;
    margin: 0 var(--gutter) 1.25rem;
  }
  .sheet {
    position: fixed;
    inset-inline: 0;
    inset-block: auto 0;
    width: 100%;
    max-height: 70svh;
    border-radius: 14px 14px 0 0;
  }
}

/* ---------- Second option: the map as a live instrument ---------- */

.mapx {
  --lens-c: var(--cyan);
  background:
    radial-gradient(70% 60% at 62% 52%, rgba(139, 92, 255, 0.16), transparent 70%),
    radial-gradient(50% 40% at 30% 80%, rgba(34, 230, 255, 0.08), transparent 70%),
    #05060c;
}
/* Corner brackets and a slow scan line framing the stage. */
.hud {
  position: absolute;
  inset: 4.6rem var(--gutter) 1rem;
  z-index: 2;
  pointer-events: none;
}
.hud-c {
  position: absolute;
  inline-size: 34px;
  block-size: 34px;
  border: 0 solid var(--lens-c);
  filter: drop-shadow(0 0 6px var(--lens-c));
  transition: border-color 0.6s, filter 0.6s;
}
.hud-c.tl {
  inset-block-start: 0;
  inset-inline-start: 0;
  border-block-start-width: 2px;
  border-inline-start-width: 2px;
}
.hud-c.tr {
  inset-block-start: 0;
  inset-inline-end: 0;
  border-block-start-width: 2px;
  border-inline-end-width: 2px;
}
.hud-c.bl {
  inset-block-end: 0;
  inset-inline-start: 0;
  border-block-end-width: 2px;
  border-inline-start-width: 2px;
}
.hud-c.br {
  inset-block-end: 0;
  inset-inline-end: 0;
  border-block-end-width: 2px;
  border-inline-end-width: 2px;
}
.hud-scan {
  position: absolute;
  inset-inline: 0;
  block-size: 1px;
  background: linear-gradient(90deg, transparent, var(--lens-c), transparent);
  box-shadow: 0 0 14px var(--lens-c);
  opacity: 0.45;
  animation: hud-scan 7s linear infinite;
}
@keyframes hud-scan {
  from {
    inset-block-start: 0;
  }
  to {
    inset-block-start: 100%;
  }
}
.hud-strip {
  position: absolute;
  z-index: 3;
  inset-block-start: 5.4rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgba(8, 10, 22, 0.75);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}
[dir='rtl'] .hud-strip {
  transform: translateX(50%);
  letter-spacing: 0;
}
.hud-strip .num {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.hud-dot {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 10px var(--lime);
  animation: hud-blink 1.4s ease-in-out infinite;
}
@keyframes hud-blink {
  50% {
    opacity: 0.25;
  }
}
.hud-sep {
  inline-size: 1px;
  block-size: 12px;
  background: var(--line);
}
#hud-lens {
  color: var(--lens-c);
  transition: color 0.6s;
}

/* Lens chips: each glows in its own colour. */
.lens-tabs,
.cam {
  background: rgba(8, 10, 22, 0.75);
  border-color: var(--line);
  border-radius: 999px;
}
.lens-tabs button,
.cam button {
  border-radius: 999px;
  color: var(--ink-soft);
}
.lens-tabs button:hover,
.cam button:hover {
  background: rgba(160, 175, 255, 0.08);
  color: var(--ink);
}
.lens-tabs button[aria-selected='true'] {
  background: color-mix(in oklab, var(--c) 16%, transparent);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--c) 70%, transparent), 0 0 22px -6px var(--c);
}
.lens-tabs button[aria-selected='true'] .ic {
  color: var(--c);
}
.cam button[aria-pressed='true'] {
  background: var(--cyan);
  color: #04050a;
  box-shadow: 0 0 20px -4px var(--cyan);
}
.mapx kbd {
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  min-inline-size: 1.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(160, 175, 255, 0.08);
  color: var(--ink-soft);
  text-align: center;
}
.lens-tabs kbd {
  margin-inline-start: 0.15rem;
}

/* Title block as a glass instrument card. */
.title-block {
  background: rgba(8, 10, 22, 0.78);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.9), 0 0 50px -24px var(--lens-c);
  transition: box-shadow 0.6s;
}
.tb-legend {
  border-color: var(--line);
}
.tb-legend button {
  color: var(--ink);
  border-color: var(--line) !important;
}
.tb-legend button:hover {
  background: rgba(160, 175, 255, 0.06);
}
.tb-legend button[aria-pressed='true'] {
  background: color-mix(in oklab, var(--lens-c) 14%, transparent);
}
.sw {
  border-radius: 4px;
  border: 0;
  box-shadow: 0 0 10px var(--sw);
}
.sw[data-pulse='true'] {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--sw) 45%, transparent), 0 0 12px var(--sw);
}
.tb-meta div + div {
  border-color: var(--line);
}
.tb-meta dd {
  font-weight: 600;
}
#tb-heading {
  color: var(--cyan);
}

/* Live counters and compass, bottom end. */
.hud-panel {
  position: absolute;
  z-index: 3;
  inset-block-end: 1.25rem;
  inset-inline-end: var(--gutter);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem 1rem;
  align-items: center;
  padding: 1rem 1.1rem;
  inline-size: min(25rem, 40%);
  border-radius: 22px;
  background: rgba(8, 10, 22, 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.compass {
  position: relative;
  inline-size: 74px;
  block-size: 74px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    repeating-conic-gradient(from 0deg, rgba(160, 175, 255, 0.35) 0 1deg, transparent 1deg 30deg),
    radial-gradient(circle, rgba(34, 230, 255, 0.12), transparent 70%);
  box-shadow: inset 0 0 20px rgba(139, 92, 255, 0.3);
}
.compass-n {
  position: absolute;
  inset-block-start: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.needle {
  position: absolute;
  inset: 14px;
  transition: transform 0.2s linear;
}
.needle::before,
.needle::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  transform: translateX(-50%);
}
.needle::before {
  top: 0;
  border-bottom: 23px solid var(--magenta);
  filter: drop-shadow(0 0 6px var(--magenta));
}
.needle::after {
  bottom: 0;
  border-top: 23px solid rgba(160, 175, 255, 0.5);
}
.hud-counts {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 1rem;
}
.hud-counts dt {
  font-size: 0.72rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.hud-counts dt::before {
  content: '';
  inline-size: 7px;
  block-size: 7px;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
}
.hud-counts dd {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.keys {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.74rem;
  color: var(--ink-soft);
  padding-block-start: 0.6rem;
  border-block-start: 1px solid var(--line);
}
.keys span {
  margin-inline-end: 0.5rem;
}

/* Unit sheet: glass with a lens-coloured edge. */
.mapx .sheet {
  background: rgba(10, 13, 28, 0.94);
  color: var(--ink);
  border: 1px solid color-mix(in oklab, var(--lens-c) 50%, transparent);
  border-radius: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.95), 0 0 40px -14px var(--lens-c);
}
.sheet-head,
.sheet-body section {
  border-color: var(--line);
}
.sheet-head h2 {
  font-weight: 600;
}
.sheet-body .label {
  color: var(--ink-soft);
}
.sheet-x {
  border-color: var(--line);
  border-radius: 999px;
}

@media (max-width: 1100px) {
  .hud-panel {
    inline-size: min(22rem, 46%);
  }
  .keys {
    display: none;
  }
}
@media (max-width: 760px) {
  .hud,
  .hud-strip {
    display: none;
  }
  .hud-panel {
    position: relative;
    inset: auto;
    inline-size: auto;
    margin: 0 var(--gutter) 1.25rem;
  }
  .lens-tabs kbd {
    display: none;
  }
  .cam .cam-text span {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .hud-scan,
  .hud-dot {
    animation: none;
  }
}
/* The live strip sits between the lens chips and the camera controls. */
.mapx-top .hud-strip {
  position: static;
  transform: none;
  align-self: center;
}
@media (max-width: 1320px) {
  .mapx-top .hud-strip {
    display: none;
  }
}
@media (max-width: 760px) {
  .tb-meta {
    grid-template-columns: 1.4fr 1fr;
  }
  .tb-meta div:nth-child(3) {
    display: none;
  }
}
