/* ==========================================================================
   Base & Dark Space Aesthetic
   ========================================================================== */

:root {
  --bg-space: #0b0f19;
  --bg-panel: rgba(15, 23, 42, 0.78);
  --bg-panel-border: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-blue: #3b82f6;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-space);
  background-image: 
    radial-gradient(circle at 50% 30%, rgba(30, 41, 59, 0.4) 0%, transparent 70%),
    radial-gradient(circle at 80% 80%, rgba(15, 23, 42, 0.8) 0%, transparent 60%);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Three.js CSS3D Scene Container
   ========================================================================== */

#container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
  z-index: 1;
}

#container > div {
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

/* ==========================================================================
   Top Navigation & Header Bar
   ========================================================================== */

.top-bar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 48px);
  max-width: 1400px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 20px;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-panel-border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Search Bar */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 440px;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 38px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #ffffff;
  font-size: 13px;
  outline: none;
  transition: all 0.2s ease;
}

#search-input:focus {
  border-color: var(--accent-cyan);
  background: rgba(30, 41, 59, 0.9);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35);
}

#search-input::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

.search-clear {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.15s ease;
}

.search-clear:hover {
  color: #ffffff;
}

/* Category Legend Component (Milestone M3) */
.category-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  max-width: 800px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.legend-item:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.legend-item:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 1px;
}

.legend-item.active,
.legend-item[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.legend-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.legend-item.active .legend-color-dot {
  transform: scale(1.25);
}

.legend-all-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan, #38bdf8);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.6);
  flex-shrink: 0;
}

.legend-label,
.legend-name {
  font-weight: 500;
  white-space: nowrap;
}

.legend-count-badge,
.legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
  transition: background 0.2s ease, color 0.2s ease;
}

.legend-item.active .legend-count-badge,
.legend-item.active .legend-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Accessibility: Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Bottom Controls HUD (Layout Switcher)
   ========================================================================== */

.bottom-controls {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
}

.layout-btn-group {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-panel-border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.layout-btn {
  padding: 10px 24px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.layout-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.layout-btn.active,
.layout-btn[aria-pressed="true"] {
  color: #ffffff;
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.35);
}
