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

:root {
  --bg:          #09090f;
  --surface:     #12121e;
  --border:      #2a2a44;
  --text:        #e8e8f0;
  --text-dim:    #6b6b8a;
  --axis:        #ffffff;
  --era-1:       rgba(120, 80, 200, 0.08);
  --era-2:       rgba(60, 120, 200, 0.08);
  --era-3:       rgba(60, 180, 140, 0.08);
  --era-4:       rgba(220, 140, 40, 0.10);
  --era-5:       rgba(200, 60, 60, 0.10);
  --accent:      #4a90e2;
  --font-ui:     'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  touch-action: none;
}
#viewport:active { cursor: grabbing; }

#track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100vh;
  will-change: transform;
}

.era-band {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  padding-bottom: 12px;
  pointer-events: none;
  overflow: hidden;
}
.era-band span {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  padding-left: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform-origin: left center;
  display: inline-block;
  pointer-events: all;
  user-select: none;
}
.era-band span:hover {
  color: var(--text);
}
.era-1 { background: var(--era-1); border-right: 1px solid var(--border); }
.era-2 { background: var(--era-2); border-right: 1px solid var(--border); }
.era-3 { background: var(--era-3); border-right: 1px solid var(--border); }
.era-4 { background: var(--era-4); border-right: 1px solid var(--border); }
.era-5 { background: var(--era-5); }

.era-collapsed {
  border-right: 1px solid var(--border);
  opacity: 0.75;
  cursor: pointer;
}
.era-collapsed span {
  padding-left: 4px;
  font-size: 11px;
  letter-spacing: 0;
}

.axis-line {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--axis);
  box-shadow: 0 0 12px rgba(255,255,255,0.25);
  pointer-events: none;
}

#world-layer.dates-hidden .tick::before { display: none; }
.tick {
  position: absolute;
  top: 50%;
  width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.tick::before {
  content: '';
  width: 1px;
  height: 10px;
  background: rgba(255,255,255,0.35);
  margin-bottom: 4px;
}
.tick span {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  transform-origin: top center;
  display: inline-block;
}

.world-event {
  position: absolute;
  top: calc(50% - 160px);
  height: 160px;
  width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
  z-index: 10;
}

.world-event::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(1px * var(--inv-zoom, 1));
  background: linear-gradient(to bottom, transparent 35%, rgba(255,255,255,0.28) 100%);
  z-index: -1;
  pointer-events: none;
}

.event-dot {
  width: 10px;
  height: 10px;
  background: rgba(215, 215, 240, 0.95);
  box-shadow: 0 0 0 1.5px rgba(255,255,255,0.2), 0 0 12px rgba(215,215,240,0.5);
  flex-shrink: 0;
  margin-top: auto;
  transition: box-shadow 0.2s;
}
.world-event:hover .event-dot {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.4), 0 0 22px rgba(215,215,240,0.8);
}
.event-dot--no-url {
  background: rgba(120, 120, 140, 0.5);
  box-shadow: none;
}
.world-event:hover .event-dot--no-url {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.2), 0 0 12px rgba(180,180,200,0.4);
}

.world-event .event-label {
  font-size: 11px;
  color: var(--text);
  line-height: 1.55;
  background: rgba(14,14,26,0.93);
  border: 1px solid rgba(255,255,255,0.1);
  border-top: 2px solid rgba(255,255,255,0.28);
  padding: 6px 10px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  transform-origin: center top;
  display: inline-block;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.55);
  transition: border-top-color 0.2s, box-shadow 0.2s;
}
.world-event:hover .event-label {
  border-top-color: rgba(255,255,255,0.55);
  box-shadow: 0 0 18px rgba(255,255,255,0.08), 0 4px 16px rgba(0,0,0,0.6);
}

.event-label-text {
  pointer-events: auto;
}
.event-axis-year {
  position: absolute;
  top: calc(50% + 4px);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  transform-origin: top center;
  display: inline-block;
  pointer-events: none;
}
#world-layer.world-events-hidden .event-axis-year { display: none; }

.event-description {
  display: none;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255,255,255,0.1);
  white-space: normal;
  max-width: 200px;
  text-align: left;
  line-height: 1.45;
  pointer-events: auto;
}
.world-event:hover .event-description {
  display: block;
}
.event-description a,
.event-description p {
  display: block;
}
.event-description a + a,
.event-description a + p,
.event-description p + a,
.event-description p + p {
  border-top: 1px solid rgba(255,255,255,0.12);
  margin-top: 4px;
  padding-top: 4px;
}
.event-description a {
  color: var(--accent);
  text-decoration: none;
}
.event-description a:hover {
  text-decoration: underline;
}

.world-event.age::before {
  background: linear-gradient(to bottom, transparent 35%, rgba(246,224,94,0.38) 100%);
  bottom: 7px;
}
.world-event.age .event-dot {
  position: absolute;
  top: 153px;
  left: -7px;
  width: 14px;
  height: 14px;
  background: #f6e05e;
  box-shadow: 0 0 0 2px rgba(246,224,94,0.3), 0 0 18px rgba(246,224,94,0.65);
}
.world-event.age:hover .event-dot {
  box-shadow: 0 0 0 4px rgba(246,224,94,0.45), 0 0 30px rgba(246,224,94,0.9);
}
.world-event.age .event-label {
  font-weight: 700;
  color: #f6e05e;
  border-color: rgba(246,224,94,0.18);
  border-top-color: rgba(246,224,94,0.55);
  text-shadow: 0 0 16px rgba(246,224,94,0.3);
  box-shadow: 0 0 20px rgba(246,224,94,0.1), 0 4px 16px rgba(0,0,0,0.5);
}
.world-event.age:hover .event-label {
  border-top-color: rgba(246,224,94,0.85);
  box-shadow: 0 0 28px rgba(246,224,94,0.18), 0 4px 16px rgba(0,0,0,0.6);
}

.world-event:not(.world-event--below):not(.age):not(.convergence) .event-label { order: 1; }
.world-event:not(.world-event--below):not(.age):not(.convergence) .event-dot {
  order: 2;
  margin-top: 4px;
}
.world-event:not(.world-event--below):not(.age):not(.convergence)::before {
  top: 48px;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 0%, rgba(255,255,255,0.28) 65%);
}

.world-event .event-label {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.world-event:hover .event-label {
  opacity: 1;
  pointer-events: auto;
}
.world-event:hover {
  z-index: 200;
}
#world-layer.world-labels-always .world-event:not(.world-event--collapsed):not(.age) .event-label {
  opacity: 1;
  pointer-events: auto;
}

.world-event--collapsed .event-label { display: none; }
.world-event--collapsed .event-dot   { opacity: 0.45; }

.world-event[data-stack-idx="1"] { transform: translateY(-70px); }
.world-event[data-stack-idx="2"] { transform: translateY(-140px); }
.world-event[data-stack-idx="3"] { transform: translateY(-210px); }
.world-event[data-stack-idx="4"] { transform: translateY(-280px); }
.world-event[data-stack-idx="5"] { transform: translateY(-350px); }
.world-event[data-stack-idx="6"] { transform: translateY(-420px); }
#world-layer.world-events-hidden .world-event.age { transform: none; }
#world-layer.world-events-hidden .world-event.age::before { bottom: 7px; }

.world-event--below {
  top: 50%;
  justify-content: flex-end;
}
.world-event--below .event-dot {
  margin-top: 0;
  margin-bottom: 4px;
}
.world-event--below::before {
  top: 0;
  bottom: 48px;
  background: linear-gradient(to top, transparent 35%, rgba(255,255,255,0.28) 100%);
}
.world-event--below .event-label {
  transform-origin: center bottom;
}
.world-event--below[data-stack-idx="1"] { transform: translateY(70px); }
.world-event--below[data-stack-idx="2"] { transform: translateY(140px); }
.world-event--below[data-stack-idx="3"] { transform: translateY(210px); }
.world-event--below[data-stack-idx="4"] { transform: translateY(280px); }

#world-layer.world-events-hidden .world-event:not(.age) { display: none; }

#world-layer.age-bounds-hidden .world-event.age { display: none; }

.world-event.convergence .event-dot {
  position: absolute;
  top: 152px;
  left: -8px;
  width: 16px;
  height: 16px;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25), 0 0 22px rgba(255,255,255,0.6);
  animation: convergence-pulse 2.8s ease-in-out infinite;
}
.world-event.convergence::before {
  bottom: 8px;
  background: linear-gradient(to bottom, transparent 25%, rgba(255,255,255,0.38) 100%);
}
@keyframes convergence-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255,255,255,0.25), 0 0 22px rgba(255,255,255,0.6); }
  50%       { box-shadow: 0 0 0 7px rgba(255,255,255,0.10), 0 0 40px rgba(255,255,255,0.85); }
}

.convergence-pin {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(215,215,240,0.95);
  border: 2px solid rgba(9,9,15,0.9);
  cursor: pointer;
  z-index: 15;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.2), 0 0 14px rgba(215,215,240,0.5);
  animation: convergence-pulse 2.8s ease-in-out infinite;
}
.convergence-pin:hover {
  transform: translate(-50%, -50%) scaleX(var(--inv-zoom, 1)) scale(1.3) !important;
  z-index: 30;
}
#world-layer.heroes-hidden .convergence-pin,
#world-layer:not(.world-events-hidden) .convergence-pin { display: none; }


.world-event.birth .event-dot {
  background: #68d391;
  box-shadow: 0 0 0 1.5px rgba(104,211,145,0.3), 0 0 14px rgba(104,211,145,0.5);
}

#world-layer {
  position: relative;
  height: 100%;
  z-index: 1;
}

#set-layer {
  position: absolute;
  top: calc(50% + 12px);
  left: 0;
  width: 100%;
  transition: opacity 0.3s;
}

.set-column {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.set-img {
  position: absolute;
  width: 90px;
  height: auto;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer;
  transform-origin: left bottom;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  opacity: 0.72;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.set-img:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(74,144,226,0.35), 0 2px 10px rgba(0,0,0,0.5);
  opacity: 1;
}

.set-marker {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20,20,40,0.85);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  font-size: 11px;
  transform: scaleX(var(--inv-zoom, 1));
  transform-origin: left center;
}
.set-marker:hover {
  border-color: var(--accent);
  background: rgba(30,30,60,0.95);
}
.set-short {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  font-size: 12px;
}
.set-name { color: var(--text-dim); }

#hero-layer {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  overflow: visible;
  transition: opacity 0.35s;
  pointer-events: none;
}

#hero-svg {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

#hero-dots-layer {
  overflow: visible;
}

#hero-svg path {
  stroke-width: 1.5;
  fill: none;
}
#hero-svg path.hero-hit-path {
  pointer-events: all;
  cursor: pointer;
  stroke-width: 12;
  opacity: 0;
}

#hero-dots-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

#hero-layer.heroes-hidden .hero-dot { pointer-events: none; }

.hero-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(9,9,15,0.9);
  cursor: pointer;
  pointer-events: all;
  z-index: 15;
  transform: translate(-50%, -50%);
  transition: box-shadow 0.15s;
}
.hero-dot:hover {
  transform: translate(-50%, -50%) scale(1.3);
  z-index: 30;
}

.hero-dot--first,
.hero-dot--last {
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  width: 0;
  height: 0;
}

.hero-dot--first::before,
.hero-dot--last::before {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  color: currentColor;
  text-shadow: 0 0 8px currentColor;
  white-space: nowrap;
}
.hero-dot--first::before { content: '+'; }
.hero-dot--last::before  { content: '−'; }

.hero-dot--unknown {
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  width: 0;
  height: 0;
}
.hero-dot--unknown::before {
  content: '??';
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: currentColor;
  opacity: 0.55;
  text-shadow: 0 0 6px currentColor;
  white-space: nowrap;
}
.hero-dot--unknown::after {
  content: '';
  position: absolute;
  top: -14px;
  left: -14px;
  width: 28px;
  height: 28px;
}

.hero-dot--death {
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  width: 0;
  height: 0;
}
.hero-dot--death::before {
  content: '✕';
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  color: currentColor;
  text-shadow: 0 0 8px currentColor;
  white-space: nowrap;
}
.hero-dot--death::after {
  content: '';
  position: absolute;
  top: -14px;
  left: -14px;
  width: 28px;
  height: 28px;
}

.hero-dot--first::after,
.hero-dot--last::after {
  content: '';
  position: absolute;
  top: -14px;
  left: -14px;
  width: 28px;
  height: 28px;
}

.hero-event-label {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  white-space: nowrap;
  background: rgba(9,9,15,0.85);
  padding: 2px 6px;
  border-radius: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.hero-dot:hover .hero-event-label { opacity: 1; }

#hero-names-layer,
#hero-dots-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.35s;
}

.hero-start-label {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  padding: 2px 6px;
  background: rgba(9,9,15,0.88);
  border-radius: 4px;
  border-left: 3px solid currentColor;
  display: inline-block;
  pointer-events: auto;
  cursor: pointer;
  line-height: 1;
}

#ui {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 100;
}

.ui-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

button {
  background: rgba(20,20,40,0.92);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color 0.15s, background 0.15s;
  font-family: var(--font-ui);
}
button:hover {
  border-color: var(--accent);
  background: rgba(35,35,70,0.95);
}
button.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#zoom-display {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 50px;
  text-align: right;
}

button.active {
  border-color: var(--accent);
  background: rgba(74,144,226,0.18);
  color: var(--accent);
}
button.active:hover {
  background: rgba(74,144,226,0.28);
}

.legend-btn {
  width: 100%;
  font-size: 12px;
  padding: 5px 10px;
}

#mobile-layer-toggle {
  display: none;
}

#legend {
  position: fixed;
  bottom: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(9,9,15,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 100;
  max-height: 60vh;
  overflow-y: auto;
  min-width: 190px;
}
.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  cursor: grab;
}
#legend.minimized .legend-header {
  margin-bottom: 0;
}
#legend.minimized .legend-body {
  display: none;
}
#legend h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}
#legend-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  min-width: 0;
  cursor: pointer;
}
#legend-toggle:hover {
  color: var(--text);
  background: none;
  border-color: transparent;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-dot-age {
  background: #f6e05e;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(246,224,94,0.7);
}
.legend-dot-world {
  background: rgba(215,215,240,0.95);
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 6px rgba(215,215,240,0.5);
}
.legend-dot-story {
  background: #a0a0c0;
  border: 2px solid rgba(9,9,15,0.9);
}
.legend-hero-marker {
  width: 10px;
  text-align: center;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  color: #a0a0c0;
  text-shadow: 0 0 6px #a0a0c0;
}
.legend-hero-marker--unknown {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.55;
  letter-spacing: 0.05em;
}
.legend-caption {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.legend-section-label {
  margin-top: 6px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.legend-note {
  color: #9090b0;
  font-size: 11px;
}
.legend-note-strong {
  color: var(--text);
}
.legend-note-dim {
  color: var(--text-dim);
}
.legend-hint {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 11px;
}
.legend-btn-group {
  margin-top: 8px;
  flex-direction: column;
  gap: 5px;
  align-items: stretch;
}
.legend-btn-group--divider {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

#hamburger-btn {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

#menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#menu-overlay.open {
  opacity: 1;
  pointer-events: all;
}

#menu-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
#menu-overlay.open #menu-panel {
  transform: translateX(0);
}

#menu-panel h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
#menu-panel p {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.menu-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.menu-actions button {
  flex: 1;
  font-size: 12px;
  padding: 5px 8px;
}

#hero-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  font-size: 13px;
}
.menu-item:hover { background: rgba(255,255,255,0.05); }

.menu-item input[type=checkbox] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.menu-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.menu-item span:not(.menu-dot):not(.menu-class) {
  flex: 1;
  font-weight: 500;
}

.menu-hero-name {
  cursor: pointer;
}
.menu-hero-name:hover {
  text-decoration: underline;
  opacity: 0.85;
}

.menu-class {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

#year-hover {
  position: fixed;
  display: none;
  background: rgba(10, 10, 22, 0.82);
  border: 1px solid rgba(160, 160, 200, 0.25);
  color: #a0a0c8;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  padding: 2px 7px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 900;
  white-space: nowrap;
  transform: translate(14px, -50%);
}

#tooltip {
  position: fixed;
  display: none;
  background: rgba(12,12,24,0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 300px;
  z-index: 300;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.tt-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
}
.tt-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.tt-extra:not(:empty) { margin-top: 8px; }
.tt-story-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}
.tt-story-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
a.tt-story-label {
  pointer-events: auto;
}
a.tt-story-label:hover {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.tt-hero-names {
  font-size: 10px;
  color: var(--text-dim);
  line-height: 1.5;
}
.tt-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0 6px;
}
.tt-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}
.tt-section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }



@media (max-width: 900px) {
  #legend {
    min-width: 170px;
    max-height: 50vh;
    font-size: 12px;
    padding: 8px 12px;
  }
  .legend-btn {
    padding: 6px 10px;
  }
}

@media (max-width: 600px) {
  #menu-panel { width: 85vw; }
  #legend { display: none; }
  #non-canon-panel { display: none; }

  #ui {
    top: 8px;
    right: 8px;
    gap: 5px;
  }
  .ui-row { gap: 5px; }

  button {
    font-size: 12px;
    padding: 5px 10px;
  }
  button.icon-btn {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
  #btn-reset, #btn-jump-modern {
    padding: 5px 8px;
  }

  #tooltip {
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    pointer-events: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  #mobile-layer-toggle {
    display: flex;
    position: fixed;
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    gap: 3px;
    z-index: 100;
    background: rgba(9,9,15,0.88);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  }
  .mobile-toggle-btn {
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    min-height: 40px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    background: transparent;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-toggle-btn:hover {
    border-color: transparent;
    background: transparent;
  }
  .mobile-toggle-btn.active {
    background: rgba(74,144,226,0.32);
    color: var(--text);
  }
}

@media (max-height: 500px) {
  .world-event {
    top: calc(50% - 80px);
    height: 80px;
  }
  #legend {
    max-height: 45vh;
    bottom: 8px;
    left: 8px;
    padding: 6px 10px;
  }
  #ui {
    top: 6px;
    right: 6px;
  }
  button.icon-btn {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }
  button {
    padding: 4px 8px;
    font-size: 12px;
  }
}

@media (max-height: 350px) {
  .world-event {
    top: calc(50% - 50px);
    height: 50px;
  }
}

#non-canon-panel {
  position: fixed;
  bottom: 14px;
  right: 14px;
  background: rgba(9, 9, 15, 0.85);
  border: 1px dashed rgba(180, 130, 60, 0.45);
  border-radius: 8px;
  padding: 10px 14px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 100;
  max-width: 230px;
  box-shadow: 0 0 18px rgba(180, 100, 40, 0.08), 0 4px 20px rgba(0,0,0,0.5);
}
.non-canon-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  cursor: grab;
}
#non-canon-panel.minimized .non-canon-header {
  margin-bottom: 0;
}
#non-canon-panel.minimized .non-canon-body {
  display: none;
}
.non-canon-header h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(200, 150, 80, 0.85);
}
#non-canon-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  min-width: 0;
  cursor: pointer;
}
#non-canon-toggle:hover {
  color: var(--text);
  background: none;
  border-color: transparent;
}
.non-canon-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.non-canon-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(200, 150, 80, 0.7);
  border: 1px dashed rgba(200, 150, 80, 0.35);
  border-radius: 3px;
  padding: 2px 7px;
  align-self: flex-start;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.non-canon-tag:hover {
  color: rgba(220, 170, 100, 1);
  border-color: rgba(220, 170, 100, 0.7);
  box-shadow: 0 0 8px rgba(200, 140, 60, 0.3);
}
.non-canon-tag.active {
  color: rgba(230, 180, 90, 1);
  border-color: rgba(230, 180, 90, 0.85);
  border-style: solid;
  background: rgba(200, 140, 50, 0.15);
  box-shadow: 0 0 12px rgba(200, 140, 50, 0.35);
}
.non-canon-body p {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}
.non-canon-body p strong {
  color: rgba(220, 170, 90, 0.9);
  font-weight: 600;
}

#hero-svg [data-hero]                { transition: opacity 0.15s; }
#hero-names-layer .hero-start-label  { transition: opacity 0.15s; }
#hero-dots-screen .hero-dot          { transition: box-shadow 0.15s, opacity 0.15s; }

#hero-svg.has-highlight path:not(.hero-hit-path):not(.highlighted),
#hero-svg.has-highlight line:not(.highlighted) { opacity: 0.07; }
#hero-svg.has-highlight path:not(.hero-hit-path).highlighted,
#hero-svg.has-highlight line.highlighted       { opacity: 1; stroke-width: 2.5; }

#hero-dots-screen.has-highlight .hero-dot:not(.highlighted) { opacity: 0.08; }
#hero-names-layer.has-highlight .hero-start-label:not(.highlighted) { opacity: 0.12; }

.world-event.hero-event-highlighted              { z-index: 50; }
.world-event.hero-event-highlighted .event-label { opacity: 1 !important; }
.world-event.hero-event-highlighted .event-dot   { filter: brightness(2.2); }
.convergence-pin.hero-event-highlighted          { filter: brightness(1.6); z-index: 25; }
