/* ========== herramientas del lector: resaltador, lápiz, goma, regla y PDF ========== */
/* Compartido por los artículos de mercados; los textos y la lógica están en /reader-tools.js. */
:root{
  --hl-yellow: #f3ecb4;
  --hl-green:  #d6e6c3;
  --hl-blue:   #cfdcec;
  --bar-bg:    var(--ink);
  --bar-fg:    #faf9f5;
  --bar-mute:  var(--muted-2);
}

/* ---- resaltador y barra ---- */
body{ padding-bottom: 80px; }
mark.hl{ color: inherit; border-radius: 2px; padding: 0 1px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
mark.hl[data-c="y"]{ background: var(--hl-yellow); }
mark.hl[data-c="g"]{ background: var(--hl-green); }
mark.hl[data-c="b"]{ background: var(--hl-blue); }
body.erasing mark.hl{ outline: 1px dashed var(--muted); }
.hl-bar{
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  display: flex; align-items: center; gap: 4px; padding: 6px;
  background: var(--bar-bg); color: var(--bar-fg); border-radius: 999px;
  box-shadow: 0 6px 24px rgba(20,20,15,.22); max-width: calc(100vw - 24px); overflow-x: auto;
  font: 500 12px/1 var(--font-mono); letter-spacing: .04em;
}
.hl-bar button{
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 38px; padding: 0 12px; border: 0; border-radius: 999px;
  background: transparent; color: var(--bar-fg); font: inherit; cursor: pointer;
}
.hl-bar button:hover{ background: rgba(255,255,255,.1); }
.hl-bar button[aria-pressed="true"]{ background: rgba(255,255,255,.18); }
.hl-bar button:focus-visible{ outline: 2px solid var(--bar-fg); outline-offset: 1px; }
.hl-bar svg{ width: 18px; height: 18px; flex: none; }
.hl-bar .sep{ width: 1px; height: 22px; background: rgba(255,255,255,.2); flex: none; margin: 0 2px; }
.hl-bar .swatch{ width: 38px; padding: 0; justify-content: center; }
.hl-bar .swatch i{ width: 18px; height: 18px; border-radius: 50%; display: block; border: 2px solid transparent; }
.hl-bar .swatch[aria-pressed="true"] i{ border-color: var(--bar-fg); }
.hl-bar .count{ color: var(--bar-mute); font-variant-numeric: tabular-nums; padding: 0 6px 0 2px; }
@media (max-width: 560px){ .hl-bar .lbl{ display: none; } .hl-bar button{ padding: 0 10px; } }
.hl-pop{
  position: fixed; z-index: 60; padding: 0 14px; min-height: 36px; border: 0; border-radius: 999px;
  background: var(--bar-bg); color: var(--bar-fg); font: 500 12px/36px var(--font-mono); letter-spacing: .04em;
  box-shadow: 0 4px 16px rgba(20,20,15,.22); cursor: pointer;
}
.hl-toast{
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  background: var(--bar-bg); color: var(--bar-fg); padding: 10px 16px; border-radius: 4px;
  font: 400 12.5px/1.5 var(--font-mono); max-width: min(92vw, 420px); text-align: center;
  box-shadow: 0 4px 16px rgba(20,20,15,.22);
}
/* fórmulas resaltadas: un rectángulo dentro del dibujo de MathJax (se imprime aunque no se impriman fondos) */
rect.hl-rect[data-c="y"]{ fill: var(--hl-yellow); }
rect.hl-rect[data-c="g"]{ fill: var(--hl-green); }
rect.hl-rect[data-c="b"]{ fill: var(--hl-blue); }

/* lápiz: una capa SVG del tamaño de la página */
.ink-layer{ position: absolute; left: 0; top: 0; z-index: 45; pointer-events: none; overflow: visible; }
.ink-layer path{ fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ink-layer path.snapped{ transition: d .12s ease-out; }
.ink-layer path.marker{ stroke-width: 18; stroke-opacity: .42; mix-blend-mode: multiply; }
.ink-anchor{ position: relative; }
svg.ink-piece{ position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
svg.ink-piece path{ fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
svg.ink-piece path.marker{ stroke-width: 18; stroke-opacity: .42; mix-blend-mode: multiply; }
body.drawing .ink-layer{ pointer-events: auto; cursor: crosshair; touch-action: none; }
body.drawing article{ user-select: none; -webkit-user-select: none; }
body.erasing .ink-layer{ cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Ccircle cx='13' cy='13' r='11.5' fill='rgba(255,255,255,.55)' stroke='%2314140f' stroke-width='1.2'/%3E%3C/svg%3E") 13 13, cell; }

/* regla estilo Windows Ink: se arrastra, se gira y guía al lápiz */
.ruler{
  position: fixed; left: 0; top: 0; z-index: 48;
  transform-origin: 50% 50%;
  background: rgba(255,255,255,.84);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  border: 1px solid #cfcab8;
  border-radius: 6px;
  box-shadow: 0 8px 28px rgba(20,20,15,.18), inset 0 1px 0 rgba(255,255,255,.9);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.ruler.dragging{ cursor: grabbing; box-shadow: 0 12px 36px rgba(20,20,15,.24); }
.ruler:focus-visible{ outline: 2px solid var(--accent); outline-offset: 3px; }
.ruler svg{ display: block; position: absolute; inset: 0; }
.ruler svg line{ stroke: var(--ink); stroke-width: 1; shape-rendering: crispEdges; }
.ruler svg text{ font: 500 10px/1 var(--font-mono); fill: var(--ink-2); text-anchor: middle; }
.ruler-deg{
  position: absolute; left: 50%; top: 50%;
  font: 500 13px/1 var(--font-mono); color: var(--accent);
  background: var(--paper); border: 1px solid var(--rule); border-radius: 999px;
  padding: 5px 10px; pointer-events: none;
}


@media print{
  .hl-bar, .hl-pop, .hl-toast, .ruler, .width-fly, .toc, .related{ display: none !important; }
  body{ padding-bottom: 0; }
  /* Safari no imprime fondos: el resaltado de texto pasa a ser un subrayado grueso detrás de las letras */
  mark.hl{ background: none !important; text-decoration-line: underline; text-decoration-thickness: 1.12em; text-underline-offset: -0.86em; text-decoration-skip-ink: none; -webkit-text-decoration-skip: none; }
  mark.hl[data-c="y"]{ text-decoration-color: #f3ecb4; }
  mark.hl[data-c="g"]{ text-decoration-color: #d6e6c3; }
  mark.hl[data-c="b"]{ text-decoration-color: #cfdcec; }
  mark.hl a{ text-decoration: none; }
  .ink-layer{ display: none !important; }
  html, body, main, article{ height: auto !important; min-height: 0 !important; }
}
@media (prefers-reduced-motion: reduce){ *{ transition: none !important; } }

/* panel de grosor del lápiz y el resaltador */
.width-fly{
  position: fixed; z-index: 62;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; max-width: calc(100vw - 16px);
  background: var(--bar-bg); color: var(--bar-fg); border-radius: 14px;
  box-shadow: 0 8px 28px rgba(20,20,15,.28);
  font: 500 12px/1 var(--font-mono); letter-spacing: .04em;
}
.width-fly[hidden]{ display: none; }
.width-fly .wf-lbl{ color: var(--bar-mute); text-transform: uppercase; letter-spacing: .16em; font-size: 10.5px; }
.width-fly .wf-dots{ display: flex; gap: 4px; }
.width-fly .wf-dots button{
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 999px; background: transparent; cursor: pointer;
}
.width-fly .wf-dots button:hover{ background: rgba(255,255,255,.1); }
.width-fly .wf-dots button[aria-pressed="true"]{ background: rgba(255,255,255,.2); }
.width-fly .wf-dots i{ display: block; border-radius: 50%; background: var(--bar-fg); }
.width-fly .wf-dots i.m{ border-radius: 3px; background: #f0d34a; opacity: .85; }
.width-fly input[type="range"]{ width: 130px; accent-color: var(--accent); }
.width-fly .wf-val{ min-width: 52px; color: var(--bar-mute); font-variant-numeric: tabular-nums; }
