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

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 52px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d0b18;
  color: #ddd5c0;
  font-family: -apple-system, system-ui, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  height: calc(var(--header-h) + var(--safe-top));
  background: rgba(13, 11, 24, 0.95);
  border-bottom: 1px solid rgba(201, 169, 122, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 30;
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c9a97a;
  font-family: Georgia, 'Palatino Linotype', Palatino, serif;
}

.icon-btn {
  background: none;
  border: 1px solid rgba(201, 169, 122, 0.2);
  color: rgba(221, 213, 192, 0.5);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255,255,255,0.12); }

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.header-actions a.icon-btn {
  text-decoration: none;
}

/* === Map area === */
#constellation-map {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

#constellation-map svg {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* === Nodes === */
.node circle {
  cursor: pointer;
}

.node text {
  fill: #c0c0c0;
  font-size: 9px;
  pointer-events: none;
  text-anchor: middle;
}

/* === Links === */
.link {
  stroke-opacity: 0.2;
}
.link.highlighted {
  stroke-opacity: 0.7;
  stroke-width: 2px;
}

/* === Stats bar (top of map) === */
.stats-bar {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 0.65rem;
  opacity: 0.45;
  z-index: 5;
  pointer-events: none;
}
.stats-bar b { color: #7eb8da; }

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* === Filter drawer === */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: rgba(12, 12, 30, 0.97);
  border-left: 1px solid rgba(255,255,255,0.08);
  z-index: 40;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: calc(16px + var(--safe-top)) 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.drawer.open { transform: translateX(0); }

.drawer-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.15);
  margin: 0 auto 20px;
}

.filter-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.4;
  margin-bottom: 6px;
  margin-top: 16px;
}
.filter-label:first-child { margin-top: 0; }

.drawer select {
  width: 100%;
  background: rgba(255,255,255,0.06);
  color: #e0e0e0;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  appearance: none;
  -webkit-appearance: none;
}

.legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 20px;
}
.legend-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  opacity: 0.7;
  background: rgba(255,255,255,0.04);
  padding: 4px 8px;
  border-radius: 12px;
}
.legend-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* === Bottom sheet (archetype details) === */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  max-height: 70dvh;
  background: rgba(12, 12, 30, 0.97);
  border-top: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px 16px 0 0;
  z-index: 50;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.2);
  margin: 10px auto 0;
}

.sheet-content {
  padding: 16px 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  overflow-y: auto;
  max-height: calc(70vh - 20px);
  max-height: calc(70dvh - 20px);
  -webkit-overflow-scrolling: touch;
}

.sheet-content h2 {
  font-size: 1.15rem;
  margin-bottom: 2px;
  background: linear-gradient(135deg, #c9a0dc, #7eb8da);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sheet-content .system-tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.5;
  margin-bottom: 12px;
}

.sheet-content .description {
  font-size: 0.85rem;
  line-height: 1.6;
  opacity: 0.8;
  margin-bottom: 14px;
}

.sheet-content .detail-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.sheet-content .detail-item {
  font-size: 0.8rem;
  line-height: 1.4;
}
.sheet-content .detail-item strong {
  opacity: 0.5;
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 2px;
}

.sheet-content .section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.4;
  margin-bottom: 8px;
  margin-top: 4px;
}

.sheet-content .connection-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sheet-content .conn-chip {
  font-size: 0.72rem;
  background: rgba(255,255,255,0.05);
  padding: 5px 10px;
  border-radius: 14px;
  line-height: 1.3;
}
.sheet-content .conn-chip .conn-system {
  opacity: 0.4;
  font-size: 0.6rem;
  display: block;
}

.sheet-content .qualities-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}
.sheet-content .quality-tag {
  background: rgba(255,255,255,0.06);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
}

/* === Desktop overrides (> 768px) === */
@media (min-width: 769px) {
  header { padding: 12px 24px; }
  header h1 { font-size: 1.3rem; }

  .stats-bar { font-size: 0.75rem; gap: 20px; }

  .node text { font-size: 10px; }

  /* On desktop, bottom sheet becomes a side panel */
  .bottom-sheet {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    max-height: 100%;
    width: 380px;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid rgba(255,255,255,0.08);
    transform: translateX(100%);
  }
  .bottom-sheet.open { transform: translateX(0); }

  .sheet-content {
    max-height: 100%;
    padding-top: calc(20px + var(--safe-top));
  }

  .sheet-handle { display: none; }
}
