.level-map {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.level-map [hidden] { display: none !important; }

.level-map__intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.25rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(90deg, transparent 0 29px, rgba(255, 255, 255, 0.035) 29px 30px),
    repeating-linear-gradient(0deg, transparent 0 29px, rgba(255, 255, 255, 0.035) 29px 30px),
    var(--bg);
}

.level-map__note { margin: 0; max-width: 38rem; color: var(--muted); }

.level-map__body { display: flex; flex-direction: column; gap: 0.75rem; }

.level-map__toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.level-map__controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.level-map__controls .button { min-width: 2.6rem; }
.level-map__controls .button.is-playing { background: var(--stars); color: #2a1c00; }

.level-map__toggles { display: flex; gap: 1rem; flex-wrap: wrap; }

.level-map__toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.level-map__toggle:hover { color: var(--text); }
.level-map__toggle input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--brand); cursor: pointer; }
.level-map__toggle input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.level-map__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  margin: 0 0 0 auto;
}
.level-map__stats div { display: flex; flex-direction: column; line-height: 1.15; }
.level-map__stats dt {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.level-map__stats dd {
  margin: 0;
  font-family: var(--display);
  font-size: 0.95rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.level-map__stats .level-map__clock { color: var(--stars); min-width: 3ch; }

.level-map__viewport {
  position: relative;
  height: clamp(260px, 52vh, 540px);
  border: 2px solid #000;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.level-map__canvas,
.level-map__minimap {
  display: block;
  width: 100%;
  touch-action: pan-y;
}

.level-map__canvas { height: 100%; cursor: grab; }
.level-map__canvas.is-dragging { cursor: grabbing; }

.level-map__minimap {
  height: 64px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #000;
  cursor: pointer;
}

.level-map__canvas:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.level-map__minimap:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.level-map__hint {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  margin: 0;
  padding: 0.3rem 0.75rem;
  transform: translateX(-50%);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(10, 13, 22, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.level-map__hint.is-visible { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .level-map__hint { transition: none; }
}

.level-map__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
}

.level-map__legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }

.level-map__swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  background: var(--swatch);
  border: 1px solid rgba(0, 0, 0, 0.6);
  border-radius: 2px;
}
.level-map__swatch--block { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.level-map__swatch--hazard { border: 0; border-radius: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.level-map__swatch--orb { border-radius: 50%; box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--swatch); transform: scale(0.8); }
.level-map__swatch--pad { height: 0.4rem; border-radius: 0.4rem 0.4rem 0 0; }
.level-map__swatch--portal { width: 0.45rem; height: 1rem; border-radius: 0.3rem; background: transparent; border: 2px solid var(--swatch); }
.level-map__swatch--speed { border: 0; border-radius: 0; clip-path: polygon(0 0, 45% 0, 100% 50%, 45% 100%, 0 100%, 55% 50%); }
.level-map__swatch--coin { border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35); }
.level-map__swatch--start { background: transparent; border: 2px dashed var(--swatch); }
.level-map__swatch--trigger { width: 0.3rem; border: 0; border-radius: 0; }

.level-map__status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.level-map__status:empty { display: none; }

@media (max-width: 640px) {
  .level-map { padding: 0.75rem; }
  .level-map__stats { margin-left: 0; }
}
