/* Hitbox Viewer component: drop into any wiki page via .hitbox-viewer[data-enemy] */

/* Vars need to apply to both the viewer AND the fullscreen overlay
   (overlay is attached to <body>, outside the viewer's scope) */
.hitbox-viewer,
.hbv-overlay {
  --hbv-bg: #16181c;
  --hbv-border: #2a2d33;
  --hbv-accent: #c9302c;
  --hbv-accent-glow: rgba(201, 48, 44, 0.4);
  --hbv-gold: #c8a84b;
  --hbv-gold-glow: rgba(200, 168, 75, 0.4);
  --hbv-text: #fff;
  /* Hitbox legend colors, sampled from the actual hitbox-only images */
  --hbv-body: #b81616;
  --hbv-head: #258821;
  --hbv-special: #c0bc45;  /* Biovore-sampled yellow */
  --hbv-reduced: #4c6c84;  /* Trygon-sampled blue */
  --hbv-anchored: #6898b8; /* Biovore-sampled blue (anchored body) */
}

.hitbox-viewer {
  position: relative;
  background: var(--hbv-bg);
  border: 1px solid var(--hbv-border);
  border-radius: 8px;
  padding: 20px;
  margin: 24px 0;
  color: var(--hbv-text);
}

/* Control bar = legend (left), slider (centered), dropdown (right).
   3-column grid keeps the slider perfectly centered regardless of side content. */
.hbv-control-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.hbv-control-bar > .hbv-legend {
  grid-column: 1;
  justify-self: end;
}
.hbv-control-bar .hbv-slider-row {
  grid-column: 2;
  margin: 0;
}
.hbv-control-bar .hbv-controls {
  grid-column: 3;
  justify-self: start;
}
/* Added by the viewer only when the one-row bar overflows (tablet widths,
   wider fonts): the stance/variant toggle drops to a second row, centered
   under the slider. */
@media (min-width: 901px) {
  .hbv-control-bar.hbv-wrap .hbv-controls {
    grid-column: 2;
    grid-row: 2;
    justify-self: center;
  }
}

/* Legend */
.hbv-legend {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  background: rgba(0,0,0,0.45);
  border: 1px solid var(--hbv-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.hbv-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hbv-legend-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
  display: inline-block;
}
.hbv-legend-swatch.body    { background: var(--hbv-body); }
.hbv-legend-swatch.head    { background: var(--hbv-head); }
.hbv-legend-swatch.special { background: var(--hbv-special); }
.hbv-legend-swatch.reduced { background: var(--hbv-reduced); }
.hbv-legend-swatch.anchored { background: var(--hbv-anchored); }
.hbv-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.hbv-controls label {
  font-size: 1rem;
  font-weight: 600;
  margin-right: 4px;
  color: #fff;
}
/* Stance/variant picker: segmented toggle (buttons), easier to use than a
   native <select> on touch. */
.hbv-seg {
  display: inline-flex;
  border: 1px solid var(--hbv-border);
  border-radius: 6px;
  overflow: hidden;
}
.hbv-seg-btn {
  background: #0d0e10;
  color: #fff;
  border: none;
  border-right: 1px solid var(--hbv-border);
  padding: 8px 16px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms, color 120ms;
}
.hbv-seg-btn:last-child { border-right: none; }
.hbv-seg-btn:hover { background: #1a1c20; }
.hbv-seg-btn.active { background: var(--hbv-gold); color: #1a1a1a; }
.hbv-seg-btn:focus-visible { outline: 2px solid var(--hbv-accent); outline-offset: -2px; }

/* Background scroll lock while the fullscreen overlay is open. */
body.hbv-fs-open { overflow: hidden; }

.hbv-slider-row {
  display: flex;
  align-items: center;
  gap: 18px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 18px;
  padding: 14px 22px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--hbv-border);
  border-radius: 6px;
}
.hbv-slider-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 396px;
}
.hbv-slider-row .hbv-legend {
  background: transparent;
  border: none;
  padding: 0;
}
/* 3-col grid keeps the middle button (BOTH) centered on the middle tick
   regardless of MESH/HITBOX width differences. justify-self at the edges
   keeps MESH flush left and HITBOX flush right. */
.hbv-slider-labels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.hbv-slider-labels button:nth-child(1) { justify-self: start; }
.hbv-slider-labels button:nth-child(2) { justify-self: center; }
.hbv-slider-labels button:nth-child(3) { justify-self: end; }
.hbv-slider-labels button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.6);
  color: var(--hbv-text);
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  padding: 3px 10px;
  border-radius: 4px;
  transition: background 120ms, border-color 120ms;
}
.hbv-slider-labels button:hover { background: rgba(255,255,255,0.08); }
.hbv-slider-labels button.active {
  background: #4a4d54;
  border-color: #fff;
}

.hbv-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #6a6a6a;
  border-radius: 3px;
  outline: none;
  margin: 0;
  /* Let the slider own touch drags so the browser doesn't treat them as a
     scroll/pan gesture; this is what made the fullscreen slider unresponsive
     on mobile. */
  touch-action: none;
}
/* Keyboard focus only (Tab); the arrows then move the slider. */
.hbv-slider:focus-visible { outline: 2px solid var(--hbv-gold); outline-offset: 6px; }
.hbv-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: #fff;
  border: 2px solid rgba(0,0,0,0.35);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.4), 0 2px 6px rgba(0,0,0,0.5);
  transition: transform 80ms;
}
.hbv-slider::-webkit-slider-thumb:hover { transform: scale(1.12); }
.hbv-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  background: #fff;
  border: 2px solid rgba(0,0,0,0.35);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.4), 0 2px 6px rgba(0,0,0,0.5);
}
.hbv-ticks {
  position: relative;
  height: 8px;
  margin-top: -3px;
}
.hbv-ticks::before,
.hbv-ticks::after,
.hbv-ticks > span {
  content: "";
  position: absolute;
  top: 0;
  width: 2px;
  height: 8px;
  background: rgba(255,255,255,0.3);
}
.hbv-ticks::before { left: 9px; }
.hbv-ticks::after  { right: 9px; }
.hbv-ticks > span  { left: 50%; transform: translateX(-50%); }

.hbv-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.hbv-panels.three { grid-template-columns: 1fr 1fr; }
.hbv-panels.three .hbv-panel:last-child {
  grid-column: 1 / span 2;
  width: calc(50% - 7px);
  justify-self: center;
}

.hbv-panel {
  position: relative;
  aspect-ratio: 2557 / 1597;
  background: #0d0e10;
  border: 1px solid var(--hbv-border);
  border-radius: 6px;
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color 120ms, box-shadow 120ms;
}
.hbv-panel:hover {
  border-color: var(--hbv-gold);
  box-shadow: 0 0 0 1px var(--hbv-gold-glow);
}
/* Panels are keyboard buttons (Tab, then Enter or Space opens fullscreen).
   The ring shows for keyboard focus only, never after a mouse click. */
.hbv-panel:focus { outline: none; }
.hbv-panel:focus-visible {
  border-color: var(--hbv-gold);
  outline: 2px solid var(--hbv-gold);
  outline-offset: 2px;
}
.hbv-layer {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
  transition: opacity 80ms linear;
  will-change: opacity;
}
.hbv-panel-label {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0,0,0,0.6);
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 10;
  color: #fff;
}
.hbv-fs-icon {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 26px;
  height: 26px;
  padding: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 4px;
  z-index: 10;
  pointer-events: none;
  transition: background 120ms, transform 120ms;
}
.hbv-panel:hover .hbv-fs-icon,
.hbv-panel:focus-visible .hbv-fs-icon {
  background: var(--hbv-gold);
  color: #1a1a1a;
  transform: scale(1.08);
}

/* Fullscreen overlay, attached to <body> when active */
.hbv-overlay {
  position: fixed;
  inset: 0;
  background: #0d0e10;
  z-index: 9999;
  display: none;
}
.hbv-overlay.open { display: block; }
/* The dialog itself takes focus on open (so arrow keys and Tab start inside
   it); it needs no ring, its controls have their own. */
.hbv-overlay:focus { outline: none; }

.hbv-overlay .hbv-fs-panel {
  position: absolute;
  inset: 0;
  background: #0d0e10;
}
.hbv-overlay .hbv-layer {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  transition: opacity 80ms linear;
}
/* Top-left stack: view label, then the host page's extras slot
   (HitboxViewer mount opts.overlayExtras). The max-width keeps both clear
   of the close button; the view arrows sit at mid-height below them. */
.hbv-overlay .hbv-fs-top {
  position: fixed;
  top: 16px;
  left: 18px;
  max-width: calc(100vw - 96px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  z-index: 10010;
  pointer-events: none;
}
.hbv-overlay .hbv-fs-top > * { pointer-events: auto; }
.hbv-overlay .hbv-fs-label {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0,0,0,0.65);
  padding: 6px 14px;
  border-radius: 4px;
  color: #fff;
}
.hbv-overlay .hbv-fs-extras {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  color: #fff;
  font-size: 1rem;
}
.hbv-overlay .hbv-fs-extras:empty { display: none; }
/* Optional ready-made look for host controls placed in .hbv-fs-extras
   (buttons or links), matching the overlay chrome. */
.hbv-overlay .hbv-fs-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  box-sizing: border-box;
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.hbv-overlay a.hbv-fs-chip:hover,
.hbv-overlay button.hbv-fs-chip:hover { border-color: var(--hbv-gold); background: rgba(0,0,0,0.8); }
.hbv-overlay .hbv-fs-chip:focus-visible { outline: 2px solid var(--hbv-gold); outline-offset: 2px; }
.hbv-overlay .hbv-close-btn,
.hbv-overlay .hbv-nav-btn {
  position: fixed;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  line-height: 1;
  cursor: pointer;
  z-index: 10010;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, transform 120ms;
}
.hbv-overlay .hbv-close-btn {
  top: 16px; right: 16px;
  width: 44px; height: 44px;
  font-size: 1.4rem;
}
.hbv-overlay .hbv-nav-btn {
  top: 50%;
  transform: translateY(-50%);
  width: 56px; height: 56px;
  font-size: 1.8rem;
}
.hbv-overlay .hbv-nav-btn.prev { left: 16px; }
.hbv-overlay .hbv-nav-btn.next { right: 16px; }
.hbv-overlay .hbv-close-btn:hover { background: var(--hbv-accent, #c9302c); transform: scale(1.06); }
.hbv-overlay .hbv-nav-btn:hover { background: var(--hbv-accent, #c9302c); transform: translateY(-50%) scale(1.06); }

.hbv-overlay .hbv-slider-row {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  background: rgba(22, 24, 28, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10010;
  width: fit-content;
}

/* ── Mobile ──────────────────────────────────────────────────────────────────
   The desktop layout uses a rigid 3-column control bar and a fixed 396px slider
   stack, both of which overflow a phone. Stack everything vertically, make the
   slider + fullscreen slider fluid, and give the toggle a full-width tap area. */
@media (max-width: 900px) {
  .hitbox-viewer { padding: 14px; }

  /* Control bar: one column (legend, slider, then the stance/variant toggle). */
  .hbv-control-bar {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 14px;
  }
  .hbv-control-bar > .hbv-legend { grid-column: 1; justify-self: center; }
  .hbv-control-bar .hbv-slider-row { grid-column: 1; }
  .hbv-control-bar .hbv-controls { grid-column: 1; }

  /* Fluid slider row + stack (kills the fixed 396px width that overflowed). */
  .hbv-slider-row {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    gap: 12px;
  }
  .hbv-slider-stack { width: 100%; }
  .hbv-legend { flex-wrap: wrap; justify-content: center; }

  /* Bigger touch target for the slider thumb. */
  .hbv-slider { height: 8px; }
  .hbv-slider::-webkit-slider-thumb { width: 28px; height: 28px; }
  .hbv-slider::-moz-range-thumb { width: 28px; height: 28px; }

  /* Stance/variant toggle: full-width, tall, easy to tap. */
  .hbv-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .hbv-controls label { text-align: center; margin-right: 0; }
  .hbv-seg { width: 100%; }
  .hbv-seg-btn { flex: 1; min-height: 46px; padding: 8px 10px; }

  /* Fullscreen slider row: span the screen with margins instead of a centered
     fit-content block that ran off both edges (thumb was unreachable). */
  .hbv-overlay .hbv-slider-row {
    left: 12px;
    right: 12px;
    bottom: 16px;
    width: auto;
    max-width: none;
    transform: none;
    box-sizing: border-box;
    flex-wrap: wrap;
    justify-content: center;
    padding: 12px 14px;
  }
  .hbv-overlay .hbv-slider-row .hbv-slider-stack { width: 100%; }

  /* Fullscreen chrome: trim so it doesn't crowd the image. */
  .hbv-overlay .hbv-close-btn { width: 42px; height: 42px; }
  .hbv-overlay .hbv-nav-btn { width: 46px; height: 46px; font-size: 1.5rem; }
  .hbv-overlay .hbv-fs-label { font-size: 1rem; max-width: 60vw; }
  .hbv-overlay .hbv-fs-top { max-width: calc(100vw - 88px); }
}

/* Phones: one panel per row so the hitbox images are actually legible. */
@media (max-width: 600px) {
  .hbv-panels,
  .hbv-panels.three { grid-template-columns: 1fr; }
  .hbv-panels.three .hbv-panel:last-child {
    grid-column: auto;
    width: auto;
    justify-self: stretch;
  }
}
