:root {
  --bg: #04010c;
  --fg: #c9f7ff;
  --accent: #00f0ff;
  --accent-2: #ff2fd0;
  --panel: rgba(6, 2, 22, 0.72);
  --edge: rgba(0, 240, 255, 0.35);
  --glow: 0 0 12px rgba(0, 240, 255, 0.55);
  --font: ui-monospace, monospace;
  --radius: 0px;
  --scrim: rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  transition: background 0.4s ease, color 0.4s ease;
}

#viewport {
  position: fixed;
  inset: 0;
}
#viewport.placing {
  cursor: crosshair;
}
#viewport canvas {
  display: block;
}

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Zero-size anchor pinned to the marker — CSS2DRenderer owns its transform. */
.city-label {
  width: 0;
  height: 0;
  transition: opacity 0.25s ease;
  user-select: none;
  pointer-events: none; /* the marker under the label owns the click */
}

/* The child carries the offset, so the text clears the pin instead of sitting
   on it, with a leader rule bridging the gap. */
.city-label > span {
  position: absolute;
  left: 16px;
  top: -6px;
  font: 500 11px/1 var(--font);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg);
  white-space: nowrap;
  text-shadow: var(--glow);
  transition: color 0.2s ease;
}
.city-label > span::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 10px;
  margin-right: 5px;
  border-top: 1px solid currentColor;
  opacity: 0.7;
}
.city-label.primary > span {
  color: var(--accent-2);
  font-weight: 700;
}
.city-label.selected > span {
  color: var(--accent-2);
  font-weight: 700;
}

/* Cyberpunk-only atmospherics ------------------------------------------ */

#grid-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
  background:
    radial-gradient(circle at 50% 50%, transparent 45%, rgba(4, 1, 12, 0.85) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 240, 255, 0.05) 0 1px, transparent 1px 3px);
}
body.scanlines #grid-overlay {
  opacity: 1;
}
body.scanlines::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255, 47, 208, 0.06), transparent 30%, rgba(0, 240, 255, 0.06));
  mix-blend-mode: screen;
}

/* HUD ------------------------------------------------------------------ */

#hud-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--scrim), transparent);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  text-shadow: var(--glow);
}
.brand .mark {
  color: var(--accent-2);
  font-size: 16px;
}
.brand em {
  color: var(--accent-2);
  font-style: normal;
  margin: 0 2px;
}
.readout {
  display: flex;
  gap: 22px;
}
.readout span {
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.readout i {
  font-style: normal;
  opacity: 0.55;
  font-size: 10px;
}
.readout b {
  color: var(--accent);
  text-shadow: var(--glow);
}

/* #hud-top is pointer-events:none so it never blocks the globe — the one
   interactive thing in it has to opt back in. */
.page-link {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  color: var(--fg);
  text-decoration: none;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  transition: all 0.18s ease;
}
.page-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--glow);
}
.page-link em {
  font-style: normal;
  color: var(--accent-2);
}

/* Map switcher — lives in the pointer-events:none HUD, so it opts back in. */
#map-switch {
  display: flex;
  gap: 6px;
  margin-left: 14px;
  pointer-events: auto;
}
.map-tab {
  padding: 4px 9px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--fg);
  text-decoration: none;
  opacity: 0.55;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: all 0.18s ease;
}
.map-tab:hover {
  opacity: 1;
  border-color: var(--edge);
}
.map-tab.on {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
}
#map-name {
  font-weight: 700;
}

/* Panel ---------------------------------------------------------------- */

#panel-toggle {
  border-radius: var(--radius);
  position: fixed;
  top: 46px;
  right: 16px;
  z-index: 3;
  width: 34px;
  height: 34px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--fg);
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

#panel {
  position: fixed;
  top: 88px;
  right: 16px;
  bottom: 16px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--edge);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  overflow: hidden;
}
body[data-theme='cyberpunk'] #panel {
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
}
body.panel-hidden #panel {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  visibility: hidden; /* keeps off-screen controls out of click and tab order */
  pointer-events: none;
}

/* Tabs: editing on one page, configuration on the other. A hidden page keeps
   its controls in the DOM, so keyboard shortcuts still drive them. */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--edge);
}
.tabs .tab {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  padding: 8px 6px 9px;
  font-size: 10px;
  letter-spacing: 0.26em;
  opacity: 0.55;
}
.tabs .tab:hover:not(:disabled) {
  box-shadow: none;
  opacity: 0.9;
}
.tabs .tab.on {
  opacity: 1;
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-page {
  display: none;
}
.tab-page.on {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto; /* settings may outgrow a short window; the page scrolls, not the panel */
  scrollbar-width: thin;
}

#panel section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 0 0 auto; /* only .grow may take slack; the rest keep their height */
}
#panel section.grow {
  flex: 1 1 auto;
  min-height: 96px;
}
/* Routes may shrink to nothing before the locations list does. */
#panel section.shrink {
  flex: 0 1 auto;
}

h2 {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  opacity: 0.6;
  border-bottom: 1px solid var(--edge);
  padding-bottom: 6px;
}

button {
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--edge);
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.18s ease;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow);
}
button:disabled {
  opacity: 0.35;
  cursor: default;
}
button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
button.ghost {
  opacity: 0.6;
}
button.danger:hover {
  color: var(--accent-2);
  border-color: var(--accent-2);
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
/* A row ending in a colour swatch gives it just its own width. */
.btn-row:has(.swatch) {
  grid-template-columns: 1fr auto;
}
.btn-row.single {
  grid-template-columns: 1fr;
}
.btn-row button {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-inline: 6px;
  font-size: 10px;
}

.slider {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.18em;
  opacity: 0.8;
}
/* A slider row that also carries a colour swatch gets a fourth column. */
.slider:has(.swatch) {
  grid-template-columns: auto 1fr auto auto;
}
.slider b {
  color: var(--accent);
  min-width: 32px;
  text-align: right;
}
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--edge);
  outline: none;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  box-shadow: var(--glow);
  cursor: pointer;
  border-radius: 0;
}
input[type='range']::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 0;
  background: var(--accent);
  cursor: pointer;
}

.hint {
  margin: 0;
  font-size: 10px;
  line-height: 1.7;
  opacity: 0.45;
}
kbd {
  border: 1px solid var(--edge);
  padding: 0 4px;
  font-size: 9px;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
}
#link-list {
  flex: 0 1 auto;
  max-height: 26vh;
}

li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px;
  border-left: 2px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
li:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
li.sel {
  border-left-color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
}

button.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  border: 0;
  padding: 7px 8px;
  text-transform: none;
}
button.row:hover {
  box-shadow: none;
}
.name {
  font-size: 12px;
  letter-spacing: 0.06em;
}
.coord {
  font-size: 9px;
  opacity: 0.45;
  white-space: nowrap;
}

button.icon {
  border: 0;
  padding: 6px 7px;
  opacity: 0.4;
  font-size: 11px;
}
button.icon:hover {
  opacity: 1;
  box-shadow: none;
}

#link-list li {
  grid-template-columns: 1fr auto;
  padding-left: 8px;
  font-size: 11px;
}
.route {
  padding: 6px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.route em {
  color: var(--accent);
  font-style: normal;
  margin: 0 4px;
}

.connect {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  opacity: 0.85;
}

/* Boot splash ---------------------------------------------------------- */

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 10;
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--accent);
  transition: opacity 0.6s ease, visibility 0.6s;
}
#boot span {
  animation: flicker 1.4s infinite;
}
#boot.done {
  opacity: 0;
  visibility: hidden;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  45% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

@media (max-width: 720px) {
  #panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 58vh;
  }
  .readout span:nth-child(3) {
    display: none;
  }
}

/* Logo / monogram chip beside the pin. The chip background matters: a mark
   with a transparent background disappears on whichever skin shares its ink
   (the CIH artwork is white-on-transparent, invisible on cream). */
.city-logo {
  display: inline-block;
  height: calc(15px * var(--logo-scale, 1));
  width: auto;
  max-width: calc(46px * var(--logo-scale, 1));
  object-fit: contain;
  vertical-align: calc(-3px * var(--logo-scale, 1));
  margin-right: 5px;
  padding: calc(2px * var(--logo-scale, 1)) calc(3px * var(--logo-scale, 1));
  background: var(--logo-chip);
  border-radius: 3px;
}
.city-logo.mono {
  font-size: calc(9px * var(--logo-scale, 1));
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: calc(11px * var(--logo-scale, 1));
  color: var(--logo-ink);
  padding: calc(2px * var(--logo-scale, 1)) calc(4px * var(--logo-scale, 1));
}

/* Drawn in 3D instead (ground mode, or a chip fixed to the globe): the chip
   goes and a site whose monogram was standing in for its name gets the name
   back. A text-only monogram has nothing to draw in 3D and stays. */
.city-label .alt {
  display: none;
}
.logos-3d .city-logo:not(.mono) {
  display: none;
}
.logos-3d .city-label .alt {
  display: inline;
  font-style: normal;
}
/* No backing: the artwork sits straight on the page. */
.logos-bare .city-logo {
  background: transparent;
}

/* Labels fixed to the globe are painted onto signs in the scene instead; the
   CSS ones go. (They are still positioned every frame — cheap, and it keeps
   the far-side logic in one place.) */
.labels-3d .city-label {
  display: none;
}

/* City and country under the name, for sites named after a brand. */
.city-label .place {
  display: none;
  margin-top: 3px;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.1em;
  opacity: 0.7;
}
.labels-place .city-label .place:not(:empty) {
  display: block;
}

/* An SVG mark is painted with the chip's ink through a mask, so one flat icon
   works on every skin instead of being baked to a single colour. The mask goes
   on a pseudo-element: masking the chip itself would cut away its background
   too, leaving the mark the same colour as the page.  */
.city-logo.mark {
  position: relative;
  width: calc(20px * var(--logo-scale, 1));
  height: calc(15px * var(--logo-scale, 1));
  padding: 0;
}
.city-logo.mark::before {
  content: '';
  position: absolute;
  inset: calc(2.5px * var(--logo-scale, 1));
  background-color: var(--logo-ink);
  -webkit-mask: var(--mark) center / contain no-repeat;
  mask: var(--mark) center / contain no-repeat;
}

/* Checkbox row, styled like the rest of the panel. */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.8;
  cursor: pointer;
}
.check input {
  appearance: none;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.check input:checked {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: var(--glow);
}
.check input:checked::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent);
}

/* Colour swatch button — the native input is hidden behind a themed square. */
.swatch {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 18px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
}
.swatch input[type='color'] {
  width: 150%;
  height: 150%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
