:root {
  --fondo: #0b0f14;
  --panel: rgba(16, 21, 28, 0.82);
  --panel-solido: #121820;
  --borde: rgba(255, 255, 255, 0.08);
  --borde-fuerte: rgba(255, 255, 255, 0.16);
  --texto: #e8edf3;
  --texto-2: #9aa7b5;
  --texto-3: #6b7785;
  --acento: #4fd1c5;
  --acento-2: #2bb3a8;
  --acento-suave: rgba(79, 209, 197, 0.14);
  --rojo: #ff6b6b;
  --verde: #5ad18a;
  --ambar: #ffc857;
  --radio: 14px;
  --sombra: 0 20px 50px rgba(0, 0, 0, 0.45);
  --letra: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: linear-gradient(180deg, #1a2633 0%, #0f161e 55%, #080b0f 100%) fixed var(--fondo); color: var(--texto); font: 14px/1.45 var(--letra); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--acento); }

#lienzo { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#lienzo.cursor-elegir { cursor: pointer; }
#lienzo.cursor-ocultar { cursor: crosshair; }

/* ---------- barra superior ---------- */
#barra {
  position: fixed; top: 12px; left: 12px; right: 12px; height: 52px; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 10px 0 14px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra);
}
.marca { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.marca svg { width: 22px; height: 22px; fill: var(--acento); }
.marca b, .carga-titulo b { font-weight: 700; color: var(--acento); margin-left: 3px; }
#modos { display: flex; gap: 2px; background: rgba(255,255,255,0.04); padding: 3px; border-radius: 10px; }
#modos button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; color: var(--texto-2); font-weight: 500; }
#modos button:hover { color: var(--texto); }
#modos button.activo { background: var(--acento-suave); color: var(--acento); }
.buscador { position: relative; margin-left: auto; width: min(380px, 34vw); }
.buscador > svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--texto-3); stroke-width: 2; stroke-linecap: round; }
#buscar { width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 10px; border: 1px solid var(--borde); background: rgba(255,255,255,0.05); outline: none; }
#buscar:focus { border-color: var(--acento); background: rgba(255,255,255,0.08); }
#resultados {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 60vh; overflow: auto; z-index: 30;
  background: var(--panel-solido); border: 1px solid var(--borde-fuerte); border-radius: 12px; box-shadow: var(--sombra); padding: 4px;
}
#resultados button { display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; }
#resultados button:hover, #resultados button.sel { background: rgba(255,255,255,0.06); }
#resultados .r-nombre { flex: 1; min-width: 0; }
#resultados .r-nombre small { display: block; color: var(--texto-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#resultados .vacio { padding: 12px; color: var(--texto-3); }
.punto { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,0.08); }

/* ---------- paneles ---------- */
.panel {
  position: fixed; top: 76px; bottom: 34px; z-index: 15; width: 300px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px 14px 18px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#izq { left: 12px; }
#der { right: 12px; width: 360px; padding-top: 16px; }
.panel h2 { margin: 4px 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--texto-3); }
.panel h2:not(:first-child) { margin-top: 22px; }
.panel h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--texto-2); }

#capas { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#capas li { display: grid; grid-template-columns: 26px 1fr 74px 24px; align-items: center; gap: 6px; padding: 4px 4px; border-radius: 9px; }
#capas li:hover { background: rgba(255,255,255,0.04); }
#capas li.apagada .c-nombre { color: var(--texto-3); }
#capas li.cargando .c-nombre::after { content: " · cargando"; color: var(--texto-3); font-size: 11px; }
.ojo { width: 26px; height: 26px; border-radius: 7px; border: 0; background: none; display: grid; place-items: center; padding: 0; }
.ojo i { width: 12px; height: 12px; border-radius: 4px; transition: opacity .15s, transform .15s; }
#capas li.apagada .ojo i { opacity: 0.2; transform: scale(0.8); }
.c-nombre { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.c-nombre small { color: var(--texto-3); font-weight: 400; margin-left: 4px; }
.solo { border: 0; background: none; color: var(--texto-3); font-size: 11px; padding: 2px; border-radius: 6px; }
.solo:hover { color: var(--acento); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px; background: rgba(255,255,255,0.12); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--texto); border: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--texto); border: 0; }

.preajustes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--borde); background: rgba(255,255,255,0.04); color: var(--texto-2); padding: 5px 10px; border-radius: 999px; font-size: 12.5px; }
.chip:hover { color: var(--texto); border-color: var(--borde-fuerte); }
.chip.activo { background: var(--acento-suave); border-color: transparent; color: var(--acento); }

.segmentado { display: flex; background: rgba(255,255,255,0.05); border-radius: 10px; padding: 3px; gap: 2px; }
.segmentado button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 7px; font-size: 12.5px; color: var(--texto-2); white-space: nowrap; }
.segmentado button.activo { background: rgba(255,255,255,0.12); color: var(--texto); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.fila { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.botones button, .vistas button, .boton {
  flex: 1; border: 1px solid var(--borde); background: rgba(255,255,255,0.05); padding: 7px 8px; border-radius: 9px; font-size: 12.5px; white-space: nowrap;
}
.botones button:hover:not(:disabled), .vistas button:hover, .boton:hover { background: rgba(255,255,255,0.09); }
button:disabled { opacity: 0.4; cursor: default; }
.boton.primario { background: var(--acento); color: #04201d; border-color: transparent; font-weight: 600; }
.boton.primario:hover { background: #6fe0d6; }
.icono { flex: none; width: 34px; border: 1px solid var(--borde); background: rgba(255,255,255,0.05); border-radius: 9px; padding: 5px; }
.vistas { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.deslizador { display: grid; gap: 8px; color: var(--texto-2); font-size: 12.5px; margin-bottom: 12px; }
.interruptor { display: flex; align-items: center; gap: 10px; margin: 8px 0; color: var(--texto-2); font-size: 13px; cursor: pointer; user-select: none; }
.interruptor input { display: none; }
.interruptor span { width: 34px; height: 20px; border-radius: 20px; background: rgba(255,255,255,0.14); position: relative; transition: background .2s; flex: none; }
.interruptor span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.interruptor input:checked + span { background: var(--acento-2); }
.interruptor input:checked + span::after { transform: translateX(14px); }

/* ---------- ficha ---------- */
.cerrar { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.07); font-size: 18px; line-height: 1; color: var(--texto-2); }
.cerrar:hover { background: rgba(255,255,255,0.14); color: var(--texto); }
.f-capa { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--texto-2); padding: 3px 9px 3px 7px; border-radius: 999px; background: rgba(255,255,255,0.05); }
.f-nombre { font-size: 21px; font-weight: 650; letter-spacing: -0.015em; line-height: 1.2; margin: 10px 30px 4px 0; }
.f-latin { font-style: italic; color: var(--texto-2); }
.f-ingles { color: var(--texto-3); font-size: 12.5px; margin-top: 2px; }
.f-acciones { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0 6px; }
.f-acciones button { border: 1px solid var(--borde); background: rgba(255,255,255,0.05); border-radius: 10px; padding: 8px 2px 6px; font-size: 11.5px; color: var(--texto-2); display: grid; justify-items: center; gap: 3px; }
.f-acciones button:hover { color: var(--texto); background: rgba(255,255,255,0.09); }
.f-acciones svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.f-seccion { margin-top: 16px; }
.f-seccion h4 { margin: 0 0 6px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--texto-3); }
.f-seccion p { margin: 0; color: #d3dae2; }
.f-enf { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.f-enf li { position: relative; padding: 9px 11px 9px 32px; background: var(--acento-suave); border-radius: 10px; color: #dff7f4; }
.f-enf li::before { content: "+"; position: absolute; left: 11px; top: 7px; font-weight: 700; color: var(--acento); font-size: 15px; }
.f-recuerda { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--ambar); background: rgba(255,200,87,0.08); border-radius: 0 10px 10px 0; color: #f6e7c4; }
.f-recuerda b { color: var(--ambar); }
.f-sin { color: var(--texto-3); margin-top: 16px; font-size: 13px; }
.f-rel { display: flex; flex-wrap: wrap; gap: 6px; }
.f-medidas { color: var(--texto-3); font-size: 12px; margin-top: 14px; }

/* ---------- etiqueta flotante y marcas ---------- */
#etiqueta {
  position: fixed; z-index: 25; pointer-events: none; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 500;
  background: rgba(10, 14, 20, 0.88); border: 1px solid var(--borde-fuerte); white-space: nowrap; transform: translate(14px, 12px);
}
#etiqueta small { color: var(--texto-3); font-weight: 400; margin-left: 6px; }
#marcas { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
.marca3d { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.marca3d .bola { width: 22px; height: 22px; border-radius: 50%; background: var(--c, var(--acento)); color: #061b19; display: grid; place-items: center; font-size: 11px; font-weight: 700; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c, var(--acento)) 30%, transparent), 0 0 18px var(--c, var(--acento)); }
.marca3d .texto { background: rgba(10,14,20,0.85); border: 1px solid var(--borde-fuerte); padding: 3px 8px; border-radius: 7px; font-size: 12px; white-space: nowrap; }
.marca3d.oculta { opacity: 0.3; }
.marca3d.oculta .texto { display: none; }

/* ---------- modos ---------- */
.lista-modo { display: grid; gap: 8px; }
.tarjeta { text-align: left; border: 1px solid var(--borde); background: rgba(255,255,255,0.04); border-radius: 12px; padding: 11px 12px; display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; }
.tarjeta:hover { background: rgba(255,255,255,0.08); border-color: var(--borde-fuerte); }
.tarjeta.activo { border-color: var(--acento); background: var(--acento-suave); }
.tarjeta .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; background: rgba(255,255,255,0.06); }
.tarjeta b { display: block; font-weight: 600; }
.tarjeta small { color: var(--texto-3); font-size: 12px; }
.volver { border: 0; background: none; color: var(--acento); padding: 0; margin-bottom: 10px; font-weight: 500; }
.texto-modo p { margin: 0 0 10px; color: #d3dae2; }
.texto-modo ol, .texto-modo ul { margin: 0 0 10px; padding-left: 18px; color: #d3dae2; }
.texto-modo li { margin-bottom: 6px; }
.aviso { padding: 9px 11px; border-radius: 10px; background: rgba(255,107,107,0.1); border-left: 3px solid var(--rojo); color: #ffd9d9; margin: 10px 0; font-size: 13px; }
.leyenda-marcas { display: grid; gap: 6px; margin: 10px 0; }
.leyenda-marcas button { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; text-align: left; border: 0; background: rgba(255,255,255,0.04); border-radius: 10px; padding: 8px; }
.leyenda-marcas button:hover { background: rgba(255,255,255,0.08); }
.leyenda-marcas .n { width: 22px; height: 22px; border-radius: 50%; background: var(--c, var(--acento)); color: #061b19; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.leyenda-marcas small { display: block; color: var(--texto-2); font-size: 12.5px; margin-top: 2px; }

#paso {
  position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%); z-index: 18; width: min(640px, calc(100vw - 680px));
  min-width: 360px; background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--borde-fuerte); border-radius: 16px; box-shadow: var(--sombra); padding: 16px 18px;
}
#paso .p-cab { display: flex; align-items: center; gap: 10px; color: var(--texto-3); font-size: 12px; margin-bottom: 4px; }
#paso .p-puntos { display: flex; gap: 4px; margin-left: auto; }
#paso .p-puntos i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.18); }
#paso .p-puntos i.si { background: var(--acento); }
#paso h3 { margin: 0 0 6px; font-size: 17px; }
#paso p { margin: 0; color: #d3dae2; }
#paso .p-nav { display: flex; gap: 8px; margin-top: 12px; }
#paso .p-nav .boton { flex: none; padding: 7px 16px; }
#paso .p-nav .boton:last-child { margin-left: auto; }

/* examen */
.marcador { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.marcador div { background: rgba(255,255,255,0.05); border-radius: 10px; padding: 8px; text-align: center; }
.marcador b { display: block; font-size: 20px; }
.marcador small { color: var(--texto-3); font-size: 11.5px; }
.pregunta { font-size: 17px; font-weight: 600; margin: 6px 0 12px; line-height: 1.3; }
.opciones { display: grid; gap: 8px; }
.opciones button { text-align: left; border: 1px solid var(--borde); background: rgba(255,255,255,0.05); border-radius: 11px; padding: 11px 12px; }
.opciones button:hover:not(:disabled) { border-color: var(--borde-fuerte); background: rgba(255,255,255,0.09); }
.opciones button.bien { border-color: var(--verde); background: rgba(90,209,138,0.15); }
.opciones button.mal { border-color: var(--rojo); background: rgba(255,107,107,0.13); }
.resultado { padding: 10px 12px; border-radius: 10px; margin-top: 10px; }
.resultado.bien { background: rgba(90,209,138,0.13); color: #c9f5da; }
.resultado.mal { background: rgba(255,107,107,0.12); color: #ffd6d6; }
.barra-progreso { height: 4px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; margin-bottom: 12px; }
.barra-progreso i { display: block; height: 100%; background: var(--acento); transition: width .3s; }
.repaso { margin-top: 12px; display: grid; gap: 6px; }
.repaso button { text-align: left; border: 0; background: rgba(255,107,107,0.08); border-radius: 9px; padding: 7px 10px; font-size: 13px; }
.chips-capas { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.nota-grande { font-size: 44px; font-weight: 700; text-align: center; letter-spacing: -0.03em; margin: 8px 0 0; }
.nota-grande + p { text-align: center; color: var(--texto-2); margin-top: 0; }

/* ---------- carga ---------- */
#carga { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at center, #13202a 0%, var(--fondo) 70%); transition: opacity .6s; }
#carga.fuera { opacity: 0; pointer-events: none; }
.carga-caja { width: min(340px, 80vw); text-align: center; }
.carga-titulo { font-size: 28px; letter-spacing: -0.02em; margin-bottom: 18px; }
.carga-barra { height: 4px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.carga-barra i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--acento-2), var(--acento)); transition: width .25s; }
#carga-texto { margin-top: 12px; color: var(--texto-3); font-size: 13px; }

#creditos { position: fixed; left: 12px; right: 12px; bottom: 8px; z-index: 10; font-size: 11px; color: var(--texto-3); text-align: center; pointer-events: none; }
#creditos a { pointer-events: auto; color: var(--texto-2); }
.flotante { display: none; }

/* ---------- móvil ---------- */
@media (max-width: 900px) {
  #barra { top: 8px; left: 8px; right: 8px; height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .marca span { display: none; }
  #modos { order: 3; width: 100%; justify-content: space-between; }
  #modos button { flex: 1; padding: 7px 4px; }
  .buscador { width: auto; flex: 1; }
  .panel { top: auto; bottom: 0; left: 0 !important; right: 0 !important; width: auto !important; max-height: 52vh; border-radius: 18px 18px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  #izq { transform: translateY(105%); transition: transform .3s; }
  body.panel-abierto #izq { transform: none; }
  #der { z-index: 16; }
  .flotante { display: grid; place-items: center; position: fixed; right: 14px; bottom: calc(30px + env(safe-area-inset-bottom)); z-index: 17; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--borde-fuerte); background: var(--panel); backdrop-filter: blur(14px); font-size: 20px; box-shadow: var(--sombra); }
  body.panel-abierto .flotante { bottom: calc(52vh + 12px); }
  #paso { width: calc(100vw - 16px); min-width: 0; bottom: 90px; }
  #creditos { display: none; }
}
@media (max-width: 900px) { body:has(#der:not([hidden])) .flotante { display: none; } }
