/* Estilos de superposicion y contenedor responsivo.
   Objetivo: que el canvas ocupe todo el area util del iPad sin que Safari
   intercepte gestos ni introduzca scroll elastico sobre la superficie de video. */

:root {
  --bg: #08090c;
  --surface: #12141a;
  --surface-2: #1b1e26;
  --border: #262a35;
  --text: #e7e9ee;
  --muted: #939aab;
  --accent: #4c8dff;
  --ok: #3ddc84;
  --error: #ff5f57;
  --bar-height: 3.25rem;
  --radius: 0.625rem;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;   /* corta el rebote elastico de iPadOS */
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Respeta la isla y las esquinas redondeadas cuando se usa viewport-fit=cover. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}

/* --- barras superior e inferior ----------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--bar-height);
  padding: 0.5rem 0.875rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.bar h1 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.address {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}

#url {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;             /* 16px: por debajo, iOS hace zoom al enfocar */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  appearance: none;
}

#url:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.status-bar {
  border-bottom: 0;
  border-top: 1px solid var(--border);
}

#status {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status[data-kind="ok"]    { color: var(--ok); }
#status[data-kind="error"] { color: var(--error); }
#status[data-kind="busy"]  { color: var(--accent); }

/* --- botones ------------------------------------------------------------- */

button {
  min-height: 2.75rem;         /* objetivo tactil comodo */
  padding: 0 0.875rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;  /* elimina el retardo de 300 ms */
}

button:active { background: #2a2f3b; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  color: #06131f;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

button.primary:active { background: #3f7ae6; }

/* --- area de video ------------------------------------------------------- */

.viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;               /* deja que el flex encoja de verdad */
  background: #000;
  overflow: hidden;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

/* Capa de gestos: sin touch-action, Safari se queda el arrastre para hacer
   scroll y los eventos nunca llegan al InputBridge. */
.overlay {
  position: absolute;
  inset: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Cualquier <video> que el interceptor haya capturado. */
video[data-hcs-hidden="1"] {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* --- controles ----------------------------------------------------------- */

.controls {
  position: absolute;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: calc(100% - 1.5rem);
  padding: 0.5rem;
  background: rgba(18, 20, 26, 0.82);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  flex-wrap: wrap;
  justify-content: center;
}

.controls.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(0.5rem);
  pointer-events: none;
}

.volume {
  display: flex;
  align-items: center;
  padding: 0 0.25rem;
}

#volume {
  width: 6rem;
  accent-color: var(--accent);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.375rem;
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.toggle input { accent-color: var(--accent); }

/* --- HUD de diagnostico -------------------------------------------------- */

.hud {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  margin: 0;
  padding: 0.625rem 0.75rem;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ok);
  background: rgba(8, 9, 12, 0.78);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  pointer-events: none;
  white-space: pre;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hidden { display: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- adaptaciones -------------------------------------------------------- */

/* iPhone y iPad en vertical estrecho: la barra de direcciones pasa a dos filas. */
@media (max-width: 620px) {
  .bar { flex-wrap: wrap; }
  .bar h1 { flex: 1 0 100%; font-size: 0.8125rem; color: var(--muted); }
  #volume { width: 4rem; }
}

/* En horizontal el alto es escaso: encogemos las barras para dar sitio al video. */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --bar-height: 2.75rem; }
  .bar h1 { display: none; }
  button { min-height: 2.25rem; }
}

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

/* --- barra de navegacion ------------------------------------------------- */

.navbar { gap: 0.5rem; }

.nav-btns {
  display: flex;
  gap: 0.25rem;
  flex: 0 0 auto;
}

button.icon {
  min-height: 2.25rem;
  width: 2.25rem;
  padding: 0;
  font-size: 1.125rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

/* Campo invisible que hace aparecer el teclado del iPad. No se puede usar
   display:none ni visibility:hidden: iOS no enfoca un campo oculto, y sin foco
   no sale el teclado. Va fuera de la pantalla pero sigue siendo enfocable. */
.kbd-sink {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 1rem;      /* 16px: evita que iOS haga zoom al enfocarlo */
}

/* --- pantalla de inicio -------------------------------------------------- */

.launcher {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(76, 141, 255, 0.16), transparent 70%),
    radial-gradient(700px 400px at 90% 110%, rgba(139, 92, 246, 0.12), transparent 70%),
    var(--bg);
}

.launcher.hidden { display: none; }

.launcher-inner {
  max-width: 56rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3rem) 1.25rem 3rem;
}

/* --- cabecera --- */

.hero { text-align: center; margin-bottom: 2.5rem; }

.hero-mark {
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1rem;
}

.hero-mark svg { width: 100%; height: 100%; }

.hero h2 {
  margin: 0 0 0.625rem;
  font-size: clamp(1.375rem, 4vw, 1.875rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.hero-sub {
  margin: 0 auto;
  max-width: 34rem;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--muted);
}

.hero code, .notice code {
  padding: 0.1em 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.3rem;
}

.section-title {
  margin: 0 0 0.875rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- tarjetas de fuente --- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 2.25rem;
}

.card {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  min-height: 0;                /* anula el min-height global de button */
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.card:active { transform: scale(0.985); }

@media (hover: hover) {
  .card:hover { border-color: #39404f; background: var(--surface-2); }
}

.card-icon {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  background: var(--surface-2);
}

.card-icon svg { width: 1.25rem; height: 1.25rem; }

.card-text { min-width: 0; }

.card-title {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.1875rem;
}

.card-meta {
  display: block;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fuente conocida como no disponible: se muestra, pero sin fingir que va. */
.card.unavailable { opacity: 0.55; }
.card.unavailable .card-title::after {
  content: "bloqueado";
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--error);
  background: rgba(255, 95, 87, 0.12);
  border: 1px solid rgba(255, 95, 87, 0.3);
  border-radius: 0.25rem;
  vertical-align: middle;
}

/* --- pegar URL --- */

.paste-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2.25rem;
}

#url2 {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.75rem 0.875rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  appearance: none;
}

#url2:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* --- aviso desplegable --- */

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  overflow: hidden;
}

.notice summary {
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}

.notice summary::-webkit-details-marker { display: none; }

.notice summary::before {
  content: "›";
  display: inline-block;
  margin-right: 0.5rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.notice[open] summary::before { transform: rotate(90deg); }

.notice-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}

.notice-body p {
  margin: 0.875rem 0 0;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--muted);
}

.notice-body strong { color: var(--text); font-weight: 600; }
.notice-body .muted { font-size: 0.8125rem; opacity: 0.8; }

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .paste-row { flex-wrap: wrap; }
  #url2 { flex: 1 0 100%; }
}
