/**
 * Atlas UltraDissection v2 — Hoja de estilos (/recursos/atlas-anatomico-real/)
 * Basado en prototipo-atlas/index.html con mejoras de accesibilidad AA,
 * safe-areas móviles (360-430 px), enlaces SEO por región y compuerta ATLAS_PUBLIC.
 */
:root {
  --bg: #05090b;
  --navy: #0d1f26;
  --cy: #00bcd4;
  --gold: #f4bd18;
  --tx: #eaf4f6;
  --mut: #9db4ba;
  --mut-aa: #8ca6ad;
  --line: #1d3a44;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html,
body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  font-family: 'Montserrat', 'Roboto', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input[type="range"]:focus-visible,
#rail:focus-visible {
  outline: 2px solid var(--cy);
  outline-offset: 2px;
}

.app {
  display: grid;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: calc(54px + var(--safe-t)) 1fr auto;
  grid-template-columns: 230px minmax(0, 1fr) 360px;
  grid-template-areas:
    "top top top"
    "rail stage panel"
    "foot foot foot";
}

.app > * {
  min-width: 0;
}

/* Cabecera superior */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: var(--safe-t) calc(18px + var(--safe-r)) 0 calc(18px + var(--safe-l));
  border-bottom: 1px solid #10242b;
  background: rgba(5, 9, 11, 0.94);
  z-index: 5;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--cy);
  white-space: nowrap;
  text-decoration: none;
}

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 auto;
  background: #0a1519;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px;
}

.tabs button {
  border: 0;
  background: none;
  min-height: 34px;
  padding: 6px 18px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mut);
  transition: background-color 0.18s ease, color 0.18s ease;
}

.tabs button[aria-selected="true"] {
  background: var(--cy);
  color: #041014;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  background: var(--gold);
  color: #111;
  font-weight: 800;
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 99px;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.chip:hover {
  filter: brightness(1.06);
}

/* Regla con silueta del cuerpo */
#rail {
  grid-area: rail;
  position: relative;
  border-right: 1px solid #10242b;
  touch-action: none;
  cursor: ns-resize;
  background: linear-gradient(90deg, #071014, #05090b);
  user-select: none;
  -webkit-user-select: none;
}

#rail canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Escenario principal */
.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: #000;
  touch-action: none;
  cursor: grab;
  min-height: 0;
}

.stage:active {
  cursor: grabbing;
}

/* Imagen estática prerenderizada para SEO y respaldo sin JS */
.seo-slice-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.2s ease;
}

.stage.canvas-ready .seo-slice-img {
  opacity: 0;
}

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

.hud {
  position: absolute;
  left: 14px;
  top: 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--mut);
  text-shadow: 0 1px 6px #000, 0 0 10px #000;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 3;
}

.hud b {
  color: var(--gold);
  font-size: 15px;
  letter-spacing: 0.04em;
}

.tools {
  position: absolute;
  right: 12px;
  top: 10px;
  display: flex;
  gap: 6px;
  z-index: 3;
}

.tools button {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(5, 9, 11, 0.78);
  color: var(--tx);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tools button:hover {
  border-color: var(--cy);
  background: rgba(13, 31, 38, 0.92);
}

.sub {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  z-index: 3;
  flex-wrap: wrap;
  max-width: calc(100% - 28px);
}

.sub button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: rgba(5, 9, 11, 0.82);
  padding: 6px 13px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--mut);
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sub button[aria-pressed="true"] {
  border-color: var(--cy);
  color: var(--tx);
  box-shadow: 0 0 10px rgba(0, 188, 212, 0.35);
}

.load {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--mut);
  background: rgba(5, 9, 11, 0.75);
  padding: 6px 12px;
  border-radius: 99px;
  pointer-events: none;
  z-index: 2;
}

.load:empty {
  display: none;
}

/* Panel derecho de información y navegación */
.panel {
  grid-area: panel;
  border-left: 1px solid #10242b;
  padding: 20px 22px;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(7, 16, 20, 0.95);
}

.kick {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--cy);
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(22px, 2.1vw, 30px);
  line-height: 1.1;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--tx);
}

.meta {
  font-size: 12px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.lead {
  color: var(--mut);
  font-size: 13.5px;
  line-height: 1.55;
  margin-bottom: 14px;
}

h3 {
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--mut-aa);
  text-transform: uppercase;
  margin: 14px 0 8px;
  font-weight: 700;
}

ul.t {
  list-style: none;
}

ul.t li {
  font-size: 13.5px;
  padding: 6px 0 6px 22px;
  position: relative;
  border-bottom: 1px solid #16272d;
  color: var(--tx);
}

ul.t li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cy);
  box-shadow: 0 0 10px var(--cy);
}

.niv {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.niv button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #0a1519;
  border-radius: 99px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tx);
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.niv button:hover {
  border-color: var(--cy);
}

.niv button.on {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(244, 189, 24, 0.1);
}

.cta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  text-align: center;
  background: var(--gold);
  color: #111;
  font-weight: 800;
  padding: 11px 18px;
  border-radius: 99px;
  text-decoration: none;
  font-size: 13.5px;
  border: 1.5px solid transparent;
  transition: filter 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
  color: var(--cy);
  border-color: var(--cy);
}

.btn.ghost:hover {
  background: rgba(0, 188, 212, 0.1);
}

/* Enlaces internos SEO por región */
.reg-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.reg-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid #162c35;
  background: #081216;
  color: var(--mut);
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.reg-nav a:hover,
.reg-nav a[aria-current="page"] {
  border-color: var(--cy);
  color: var(--tx);
  background: rgba(0, 188, 212, 0.12);
}

.note {
  font-size: 11px;
  color: var(--mut-aa);
  line-height: 1.5;
  margin-top: 14px;
}

/* Pie del visor con slider y atribución NLM */
.foot {
  grid-area: foot;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px calc(16px + var(--safe-r)) calc(8px + var(--safe-b)) calc(16px + var(--safe-l));
  border-top: 1px solid #10242b;
  background: #05090b;
}

.foot input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--cy);
  height: 34px;
  cursor: pointer;
}

.foot .val {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  min-width: 92px;
  text-align: right;
  white-space: nowrap;
}

.foot small {
  font-size: 10.5px;
  color: var(--mut-aa);
  line-height: 1.35;
  max-width: 54ch;
}

/* Compuerta cuando ATLAS_PUBLIC = false */
.atlas-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(circle at 50% 25%, #0d1f26 0%, #05090b 75%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.atlas-gate[hidden] {
  display: none !important;
}

.atlas-gate-card {
  max-width: 540px;
  width: 100%;
  background: rgba(7, 16, 20, 0.94);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.atlas-gate-card h2 {
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--tx);
}

.atlas-gate-card p {
  color: var(--mut);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* Respaldo sin JS */
noscript {
  position: fixed;
  inset: 54px 0 0;
  background: #05090b;
  padding: 24px;
  z-index: 20;
  overflow-y: auto;
}

.noscript-box {
  max-width: 720px;
  margin: 0 auto;
  background: #071014;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.noscript-box img {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: 14px auto;
  border-radius: 8px;
  background: #000;
}

/* Responsivo Móvil y Tablet Vertical (< 900px) */
@media (max-width: 899px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: calc(48px + var(--safe-t)) 78px minmax(180px, 1fr) auto auto;
    grid-template-areas:
      "top"
      "rail"
      "stage"
      "foot"
      "panel";
    overflow: hidden;
  }

  .top {
    gap: 6px;
    padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l));
  }

  .brand {
    font-size: 9.5px;
    letter-spacing: 0.08em;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tabs {
    padding: 2px;
    gap: 2px;
  }

  .tabs button {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 10.5px;
    letter-spacing: 0.03em;
  }

  .chip {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 10px;
  }

  #rail {
    border-right: 0;
    border-bottom: 1px solid #10242b;
    cursor: ew-resize;
  }

  .hud {
    left: 10px;
    top: 8px;
    max-width: calc(100% - 124px);
    font-size: 9.5px;
    letter-spacing: 0.06em;
    line-height: 1.4;
  }

  .hud b {
    font-size: 12.5px;
  }

  .tools {
    top: 8px;
    right: 8px;
    gap: 4px;
  }

  /* Botones de zoom táctiles (40 px) */
  .tools button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 15px;
  }

  .sub {
    left: 10px;
    bottom: 8px;
    gap: 4px;
    max-width: calc(100% - 20px);
  }

  .sub button {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 10px;
  }

  .foot {
    flex-wrap: wrap;
    row-gap: 2px;
    column-gap: 10px;
    padding: 4px calc(12px + var(--safe-r)) calc(4px + var(--safe-b)) calc(12px + var(--safe-l));
  }

  .foot input[type="range"] {
    height: 30px;
  }

  .foot .val {
    min-width: 0;
    font-size: 11.5px;
  }

  .foot small {
    flex-basis: 100%;
    max-width: none;
    font-size: 9px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .panel {
    max-height: 29vh;
    border-left: 0;
    border-top: 1px solid #10242b;
    padding: 10px 14px calc(12px + var(--safe-b));
  }

  h1 {
    font-size: 19px;
    margin-bottom: 4px;
  }

  .meta {
    margin-bottom: 6px;
    font-size: 11.5px;
  }

  .lead {
    font-size: 12.5px;
    line-height: 1.45;
    margin-bottom: 8px;
  }

  h3 {
    margin: 10px 0 6px;
  }

  ul.t li {
    font-size: 12.5px;
    padding: 5px 0 5px 18px;
  }

  ul.t li::before {
    top: 10px;
    width: 7px;
    height: 7px;
  }
}

/* Reducción de movimiento */
/* Teléfonos: la marca se muestra como icono (el texto no cabe junto a tabs + CTA) */
@media (max-width: 520px) {
  .brand {
    font-size: 0;
    letter-spacing: 0;
    width: 28px;
    height: 28px;
    min-width: 28px;
    flex: 0 0 28px;
    border-radius: 6px;
    background: url("favicon-32.jpg") center / contain no-repeat;
  }
}

/* Teléfonos muy angostos (≤360 px): sin marca, caben tabs + CTA */
@media (max-width: 360px) {
  .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* v2: texto solo para lectores de pantalla (estado del visor) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
