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

:root {
  --bg: #08090d;
  --ink: #f2f3f5;
  --ink-dim: rgba(242, 243, 245, 0.55);
  --panel: rgba(15, 16, 22, 0.55);
  --panel-border: rgba(255, 255, 255, 0.1);
  --noun: #4fa8ff;
  --verb: #ff6b5e;
  --adjective: #4fd97a;
  --adverb: #ffc857;
  --pronoun: #c98bff;
  --preposition: #ff6ec7;
  --conjunction: #5ce1e6;
  --other: #9aa0ac;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  cursor: grab;
}

body.dragging {
  cursor: grabbing;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px;
  pointer-events: none;
  z-index: 10;
}

#progress {
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

#toggle-translation {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
  padding: 9px 16px 9px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#toggle-translation:hover {
  background: rgba(30, 32, 40, 0.7);
  border-color: rgba(255, 255, 255, 0.22);
}

#toggle-translation .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4fd97a;
  box-shadow: 0 0 8px #4fd97a;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

#toggle-translation[aria-pressed="false"] .dot {
  background: #5a5d68;
  box-shadow: none;
}

#legend {
  position: fixed;
  bottom: 22px;
  left: 24px;
  right: 200px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  pointer-events: none;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 16px;
  border-radius: 18px;
  width: fit-content;
  max-width: calc(100% - 240px);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}

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

.legend-item[data-pos="noun"] .swatch { background: var(--noun); box-shadow: 0 0 6px var(--noun); }
.legend-item[data-pos="verb"] .swatch { background: var(--verb); box-shadow: 0 0 6px var(--verb); }
.legend-item[data-pos="adjective"] .swatch { background: var(--adjective); box-shadow: 0 0 6px var(--adjective); }
.legend-item[data-pos="adverb"] .swatch { background: var(--adverb); box-shadow: 0 0 6px var(--adverb); }
.legend-item[data-pos="pronoun"] .swatch { background: var(--pronoun); box-shadow: 0 0 6px var(--pronoun); }
.legend-item[data-pos="preposition"] .swatch { background: var(--preposition); box-shadow: 0 0 6px var(--preposition); }
.legend-item[data-pos="conjunction"] .swatch { background: var(--conjunction); box-shadow: 0 0 6px var(--conjunction); }
.legend-item[data-pos="other"] .swatch { background: var(--other); box-shadow: 0 0 6px var(--other); }

#hint {
  position: fixed;
  bottom: 26px;
  right: 24px;
  z-index: 10;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  color: var(--ink-dim);
  pointer-events: none;
  opacity: 0.8;
  transition: opacity 1.2s ease;
}

#hint.hidden {
  opacity: 0;
}

@media (max-width: 640px) {
  #hud { padding: 16px; }
  #legend { left: 16px; bottom: 16px; gap: 10px; padding: 8px 12px; }
  .legend-item { font-size: 10.5px; }
  #hint { display: none; }
  #progress { font-size: 11.5px; padding: 7px 12px; }
  #toggle-translation { font-size: 12px; padding: 8px 14px 8px 10px; }
}
