* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #c8a76a;            /* ambre apagat del HUD */
  --ink-dim: #6b5a3a;
  --ink-bright: #f0dcae;
  --hud-font: "SF Mono", "Menlo", "Consolas", "Roboto Mono", monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #020409;
  font-family: var(--hud-font);
  -webkit-user-select: none;
  user-select: none;
}

canvas#stage { position: fixed; inset: 0; display: block; }

/* ---------- HUD ---------- */
.hud { position: fixed; z-index: 10; color: var(--ink); }

#hud-top {
  top: 0; left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 16px 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
#hud-top > * { pointer-events: auto; }

body.ui-hidden #hud-top,
body.ui-hidden #zoom,
body.ui-hidden #status { opacity: 0; pointer-events: none !important; }
body.ui-hidden #hud-top > * { pointer-events: none !important; }

#brand { text-align: center; letter-spacing: .5em; line-height: 1.7; }
#brand .t1 { display: block; font-size: 11px; color: var(--ink-bright); }
#brand .t2 { display: block; font-size: 8px; color: var(--ink-dim); }

/* ciutats */
#cities { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; position: relative; }
.chip {
  font-family: inherit;
  font-size: 9px;
  letter-spacing: .25em;
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(200,167,106,.35);
  padding: 4px 10px 3px;
  cursor: pointer;
  text-transform: uppercase;
}
.chip .x { margin-left: 7px; color: var(--ink-dim); }
.chip:hover { border-color: rgba(200,167,106,.8); }
.chip.toggle.on { color: #061018; background: var(--ink); border-color: var(--ink); }

#city-search {
  font-family: inherit;
  font-size: 9px;
  letter-spacing: .25em;
  color: var(--ink-bright);
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(200,167,106,.35);
  padding: 4px 2px 3px;
  width: 110px;
  outline: none;
  text-transform: uppercase;
}
#city-search::placeholder { color: var(--ink-dim); }

#city-results {
  position: absolute;
  top: 26px; left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  background: rgba(2,6,12,.92);
  border: 1px solid rgba(200,167,106,.25);
  z-index: 20;
  min-width: 220px;
}
#city-results .res {
  font-size: 9px; letter-spacing: .18em;
  padding: 6px 10px;
  color: var(--ink);
  cursor: pointer;
  text-transform: uppercase;
}
#city-results .res:hover { background: rgba(200,167,106,.15); color: var(--ink-bright); }

/* timeline */
#timeline { display: flex; align-items: center; gap: 14px; width: min(560px, 86vw); }
.date { font-size: 8px; letter-spacing: .2em; color: var(--ink); white-space: nowrap; }
#tl-track {
  position: relative;
  flex: 1;
  height: 18px;
  cursor: pointer;
}
#tl-track::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 8.5px;
  height: 1px;
  background: rgba(200,167,106,.3);
}
#tl-range {
  position: absolute; top: 8px; height: 2px;
  background: var(--ink);
  opacity: .8;
}
.tl-handle {
  position: absolute; top: 4px;
  width: 9px; height: 9px;
  border: 1px solid var(--ink);
  background: #020409;
  transform: translateX(-50%) rotate(45deg);
  cursor: ew-resize;
}
.tl-handle:hover, .tl-handle.drag { background: var(--ink); }

#ranges { display: flex; gap: 18px; }
.rng {
  font-family: inherit; font-size: 8px; letter-spacing: .3em;
  color: var(--ink-dim);
  background: none; border: none; cursor: pointer;
  padding: 2px 2px;
}
.rng:hover { color: var(--ink); }
.rng.sel { color: var(--ink-bright); border-bottom: 1px solid rgba(240,220,174,.5); }

/* zoom vertical center-right */
#zoom {
  right: -44px; top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transition: opacity 1.2s ease;
}
#zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
#zoom-slider::-webkit-slider-runnable-track {
  height: 1px;
  background: rgba(200, 167, 106, .35);
}
#zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px; height: 9px;
  margin-top: -4px;
  border: 1px solid var(--ink);
  background: #020409;
  transform: rotate(45deg);
}
#zoom-slider::-webkit-slider-thumb:hover { background: var(--ink); }
#zoom-slider::-moz-range-track { height: 1px; background: rgba(200, 167, 106, .35); }
#zoom-slider::-moz-range-thumb {
  width: 9px; height: 9px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: #020409;
  transform: rotate(45deg);
}

#units { display: flex; gap: 12px; }

#tl-label {
  position: absolute;
  left: 50%; top: 17px;
  transform: translateX(-50%);
  font-size: 8px;
  letter-spacing: .3em;
  color: var(--ink-bright);
  white-space: nowrap;
}

/* estat / loading */
#status {
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  font-size: 8px; letter-spacing: .4em;
  color: var(--ink-dim);
  transition: opacity .6s ease;
  opacity: 0;
}
#status.on { opacity: 1; }

/* ---------- specimen labels ---------- */
#labels { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.spec-label {
  position: absolute;
  color: var(--ink);
  letter-spacing: .22em;
  line-height: 1.75;
  font-size: 8px;
  white-space: nowrap;
  text-transform: uppercase;
  transition: opacity .8s ease;
}
.spec-label .name { font-size: 10px; color: var(--ink-bright); letter-spacing: .3em; }
.spec-label .dim { color: var(--ink-dim); }
.spec-label .delta {
  font-size: 11px;
  letter-spacing: .25em;
  text-shadow: 0 0 8px rgba(2, 4, 9, 1);
}

/* anotació de costella (hover) */
#rib-note { position: fixed; z-index: 8; pointer-events: none; }
#rib-line {
  position: absolute;
  width: 1px; height: 34px;
  background: linear-gradient(to bottom, rgba(240,220,174,.9), rgba(240,220,174,0));
  transform-origin: top left;
}
#rib-text {
  position: absolute; top: -44px; left: 8px;
  font-size: 8px; letter-spacing: .25em;
  color: var(--ink-bright);
  line-height: 1.7;
  text-transform: uppercase;
  text-shadow: 0 0 6px rgba(2, 4, 9, 1);
}
#rib-text span { display: block; }
#rib-text #rib-temp { color: #ff8a70; font-size: 16px; letter-spacing: .12em; }

#ranges .sep { width: 1px; height: 10px; background: rgba(200,167,106,.3); align-self: center; }

#years { display: flex; gap: 14px; align-items: center; }
.yrs-label, .rib-label { font-size: 7px; letter-spacing: .35em; color: var(--ink-dim); align-self: center; }

/* marcadors d'any (mode patró): anell al punt de l'espina */
.yr-marker {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .8s ease;
}
.markers-on .yr-marker { opacity: .9; }
.markers-dim .yr-marker { opacity: .3; }
.yr-marker .ring {
  position: absolute;
  width: var(--ring-size, 15px); height: var(--ring-size, 15px);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(240, 220, 174, .9);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(2, 4, 9, .9);
}
.yr-marker .txt {
  position: absolute;
  left: 11px; top: -17px;
  font-size: 9px;
  letter-spacing: .18em;
  color: var(--ink-bright);
  white-space: nowrap;
  background: rgba(2, 4, 9, .55);
  padding: 2px 5px;
  text-shadow: 0 0 6px rgba(2, 4, 9, 1);
}

@media (max-width: 640px) {
  #brand { letter-spacing: .35em; }
  #timeline { width: 92vw; }
}


/* fletxa de vora: espècimen fora de pantalla */
.edge-arrow {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
}
.edge-arrow svg {
  position: absolute;
  left: -9px; top: -9px;
  fill: rgba(200, 167, 106, .12);
  stroke: var(--ink);
  stroke-width: 1;
}

.edge-arrow { cursor: pointer; pointer-events: auto; }
.edge-arrow .ea-txt {
  position: absolute;
  font-size: 7px;
  letter-spacing: .2em;
  color: var(--ink);
  white-space: nowrap;
  text-shadow: 0 0 5px rgba(2, 4, 9, 1);
}

/* panell de tuning (tecla D) */
#debug-panel {
  position: fixed;
  left: 16px; top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  background: rgba(2, 5, 11, .88);
  border: 1px solid rgba(200, 167, 106, .3);
  padding: 10px 12px;
  font-size: 8px;
  color: var(--ink);
  letter-spacing: .12em;
}
#debug-panel.off { display: none; }
#debug-panel .dbg-title { color: var(--ink-bright); letter-spacing: .3em; margin-bottom: 8px; font-size: 8px; }
#debug-panel .dbg-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
#debug-panel .dbg-name { width: 110px; color: var(--ink-dim); }
#debug-panel .dbg-val { width: 34px; text-align: right; color: var(--ink-bright); }
#debug-panel input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 12px; background: transparent; cursor: pointer;
}
#debug-panel input[type=range]::-webkit-slider-runnable-track { height: 1px; background: rgba(200,167,106,.35); }
#debug-panel input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 7px; height: 7px; margin-top: -3px;
  background: var(--ink); transform: rotate(45deg);
}
#debug-panel input[type=range]::-moz-range-track { height: 1px; background: rgba(200,167,106,.35); }
#debug-panel input[type=range]::-moz-range-thumb { width: 7px; height: 7px; border: none; border-radius: 0; background: var(--ink); }
#debug-panel input[type=color] {
  width: 42px; height: 16px;
  border: 1px solid rgba(200,167,106,.4);
  background: transparent;
  padding: 0;
  cursor: pointer;
}
#debug-panel .dbg-btn {
  font-family: inherit; font-size: 7px; letter-spacing: .2em;
  color: var(--ink-dim);
  background: none;
  border: 1px solid rgba(200,167,106,.3);
  padding: 2px 8px;
  cursor: pointer;
}
#debug-panel .dbg-btn.sel { color: #061018; background: var(--ink); }
#debug-panel .dbg-export { display: block; margin-top: 8px; width: 100%; color: var(--ink-bright); }
