:root, [data-theme="dark"] {
  --bg: #050505;
  --bg-subtle: #111;
  --text: #ccc;
  --text-bright: #fff;
  --text-secondary: #888;
  --text-dim: #555;
  --text-muted: #444;
  --tooltip-bg: rgba(10, 10, 10, 0.92);
  --tooltip-border: #333;
  --overlay-bg: rgba(5, 5, 5, 0.85);
}

[data-theme="light"] {
  --bg: #f5f5f0;
  --bg-subtle: #eee;
  --text: #333;
  --text-bright: #111;
  --text-secondary: #555;
  --text-dim: #888;
  --text-muted: #999;
  --tooltip-bg: rgba(245, 245, 240, 0.92);
  --tooltip-border: #ccc;
  --overlay-bg: rgba(245, 245, 240, 0.85);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: monospace;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

canvas:active {
  cursor: grabbing;
}

/* header overlay */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.header h1 {
  font-size: 12px;
  font-weight: normal;
}

.header h1 a {
  color: var(--text-secondary);
  text-decoration: none;
}

.header h1 a:hover {
  color: var(--text-bright);
}

.header .dim {
  color: var(--text-dim);
}

.header .nav {
  font-size: 11px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.header .nav a {
  color: var(--text-dim);
  text-decoration: none;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.header .nav a:hover {
  color: var(--text-secondary);
}

.theme-toggle {
  cursor: pointer;
  color: var(--text-dim);
  user-select: none;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  color: var(--text-secondary);
}

/* tooltip */
.tooltip {
  display: none;
  position: fixed;
  z-index: 20;
  background: var(--tooltip-bg);
  border: 1px solid var(--tooltip-border);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 320px;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.tooltip .title {
  color: var(--text-bright);
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tooltip .meta {
  color: var(--text-secondary);
  font-size: 11px;
}

.tooltip .platform-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 2px;
  margin-top: 2px;
}

/* loading overlay */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: opacity 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay .spinner {
  color: var(--text-dim);
  font-size: 13px;
}

/* bottom bar: legend + stats stacked */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px 10px;
}

.legend {
  pointer-events: auto;
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  padding: 6px 8px;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.legend-item:hover {
  background: rgba(128, 128, 128, 0.15);
}

.legend-item.dimmed {
  opacity: 0.3;
}

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

.stats {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

/* search */
.search-form {
  display: flex;
  align-items: center;
}

#search-input {
  background: var(--bg-subtle);
  border: 1px solid var(--tooltip-border);
  color: var(--text);
  font-family: monospace;
  font-size: 11px;
  padding: 3px 8px;
  width: 140px;
  outline: none;
  transition: width 0.2s, border-color 0.2s;
}

#search-input:focus {
  width: 200px;
  border-color: var(--text-dim);
}

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

.search-status {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 6px;
  white-space: nowrap;
}

/* mobile */
@media (max-width: 600px) {
  .header { padding: 8px 10px; }
  .header h1 { font-size: 11px; }
  .header .nav { gap: 4px; font-size: 10px; }
  #search-input { width: 80px; font-size: 10px; padding: 4px 6px; }
  #search-input:focus { width: 120px; }
  .bottom-bar { padding: 4px 8px 6px; gap: 2px; }
  .legend { gap: 0; }
  .legend-item { padding: 5px 6px; font-size: 9px; }
  .legend-dot { width: 6px; height: 6px; }
  .stats { font-size: 9px; }
  .tooltip { max-width: 260px; font-size: 11px; }
  .tooltip .meta { font-size: 10px; }
  .tooltip .platform-badge { font-size: 9px; }
}
