:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255, 255, 255, 0.1);

  --type-toy: #3987e5;
  --type-game: #d95926;
  --type-tool: #199e70;
  --type-joke: #c98500;
  --type-explainer: #d55181;
  --type-art: #4dbf4d;
  --type-other: #6b6a63;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

#sky {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: grab;
}

#sky.dragging {
  cursor: grabbing;
}

.ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.ui > * {
  pointer-events: auto;
}

header.panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 0;
  max-width: 46ch;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#search {
  width: 220px;
  max-width: 46vw;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
}

#search::placeholder {
  color: var(--text-muted);
}

#count {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 60vw;
}

.legend button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: rgba(26, 26, 25, 0.85);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 5px 10px 5px 8px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.legend button[aria-pressed="false"] {
  opacity: 0.4;
}

.legend .swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

footer.panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}

footer.panel a {
  color: var(--text-secondary);
  text-decoration: none;
}

footer.panel a:hover {
  text-decoration: underline;
}

.footer-links {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

#card {
  position: fixed;
  pointer-events: none;
  max-width: 300px;
  background: rgba(20, 20, 19, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-secondary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 5;
}

#card.visible {
  display: block;
}

#card h3 {
  margin: 0 0 4px;
  font-size: 13.5px;
  color: var(--text-primary);
}

#card .meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

#card .type-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

#selected {
  position: fixed;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  width: min(420px, 90vw);
  background: rgba(20, 20, 19, 0.97);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: none;
  pointer-events: auto;
  z-index: 6;
}

#selected.visible {
  display: block;
}

#selected h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

#selected p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

#selected .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

#selected .row a,
#selected .row button {
  font-size: 12px;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

#selected .close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
}

@media (max-width: 640px) {
  .controls {
    align-items: flex-start;
  }
  #search {
    width: 100%;
    max-width: none;
  }
  .legend {
    justify-content: flex-start;
    max-width: 100%;
  }
}
