/* =============================================================
   MideTuRed — test de velocidad
   1. Tokens · 2. Reset · 3. Utilidades · 4. Tipografía
   5. Cabecera · 6. Herramienta · 7. Resultados · 8. Historial
   9. Secciones de contenido · 10. Anuncios · 11. Pie
   12. Responsive · 13. Reduced motion
   ============================================================= */

/* ============ 1. Tokens ============ */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --ink: #12141d;
  --ink-soft: #555c73;
  --line: #e2e5ef;
  --accent: #4f7cff;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --ok: #12a06a;
  --warn: #d68309;
  --bad: #d93a3a;
  --shadow: 0 1px 2px rgba(18, 20, 29, .05), 0 10px 30px rgba(18, 20, 29, .07);
  --radius: 16px;
  --wrap: 1080px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f18;
    --surface: #161a27;
    --surface-2: #1d2231;
    --ink: #eef1f8;
    --ink-soft: #a3abc2;
    --line: #2a3040;
    --accent: #6f95ff;
    --accent-ink: #0d0f18;
    --accent-soft: #1e2740;
    --ok: #2fcf90;
    --warn: #f0a83a;
    --bad: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 34px rgba(0, 0, 0, .35);
  }
}

/* ============ 2. Reset ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3 { text-wrap: balance; line-height: 1.15; letter-spacing: -.02em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* ============ 3. Utilidades ============ */
.wrap { width: min(100% - 2rem, var(--wrap)); margin-inline: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 999;
  padding: .6rem 1rem; background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .8rem 1.35rem; border-radius: 12px; font-weight: 600;
  border: 1px solid transparent; transition: transform .18s var(--ease-out), background .18s, border-color .18s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-bad { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--ink-soft); font-size: .9rem; margin-top: .9rem; }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }

/* ============ 4. Tipografía ============ */
h1 { font-size: clamp(1.85rem, 5.2vw, 2.7rem); }
h2 { font-size: clamp(1.4rem, 3.6vw, 1.95rem); }
h3 { font-size: 1.12rem; }
.section-lead { color: var(--ink-soft); max-width: 62ch; margin-top: .5rem; }
.section-h3 { margin: 2rem 0 .8rem; }

/* ============ 5. Cabecera ============ */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 62px; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.02em; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
}
.brand-name { font-size: 1.05rem; }
.header-nav { display: none; gap: 1.4rem; color: var(--ink-soft); font-size: .95rem; }
.header-nav a:hover { color: var(--accent); }

/* ============ 6. Herramienta ============ */
.hero { padding: 1.6rem 0 2.2rem; }
.hero h1 { margin-bottom: .5rem; }
.hero-sub { color: var(--ink-soft); max-width: 62ch; margin-bottom: 1.3rem; }

.tool-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); padding: 1.2rem 1rem 1.4rem; text-align: center;
}
.mode-row {
  display: inline-flex; gap: .25rem; padding: .25rem; margin-bottom: .4rem;
  background: var(--surface-2); border-radius: 999px; border: 1px solid var(--line);
}
.mode-btn {
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  padding: .45rem 1rem; border-radius: 999px; color: var(--ink-soft);
  transition: background .2s var(--ease-out), color .2s;
}
.mode-btn .mode-name { font-weight: 600; font-size: .95rem; }
.mode-btn .mode-hint { font-size: .72rem; opacity: .8; }
.mode-btn.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tool-card[data-state="running"] .mode-btn { opacity: .45; pointer-events: none; }

.gauge-wrap { width: min(100%, 400px); margin: .6rem auto 0; }
.gauge { width: 100%; height: auto; overflow: visible; }
.gauge-track { stroke: var(--surface-2); stroke-width: 16; }
.gauge-fill { stroke-width: 16; stroke-dasharray: 1 1; transition: none; }
.gauge-tick { stroke: var(--line); stroke-width: 2; }
.gauge-tick-label { fill: var(--ink-soft); font-size: 11px; font-family: var(--sans); text-anchor: middle; }
.needle { stroke: var(--ink); stroke-width: 3.4; stroke-linecap: round; }
.needle-hub { fill: var(--ink); }
/* El centro de giro va en el propio atributo transform del SVG: definir aquí
   transform-origin lo aplicaria dos veces y sacaria la aguja del medidor. */

.gauge-readout { text-align: center; margin-top: -.2rem; pointer-events: none; }
.gauge-value { font-size: clamp(2.1rem, 8vw, 2.9rem); font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.gauge-unit { font-size: 1rem; color: var(--ink-soft); margin-left: .25rem; }
.gauge-phase { display: block; font-size: .92rem; color: var(--ink-soft); margin-top: .1rem; min-height: 1.4em; }

.start-btn {
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: .4rem; padding: 1rem 3rem; min-width: 230px;
  font-size: 1.12rem; font-weight: 700; letter-spacing: .01em;
  color: var(--accent-ink); background: var(--accent); border-radius: 999px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .18s var(--ease-out), filter .18s;
}
.start-btn:hover { filter: brightness(1.06); }
.start-btn:active { transform: translateY(1px); }
.tool-card[data-state="running"] .start-btn { background: var(--surface-2); color: var(--ink-soft); box-shadow: none; }

.tool-note { margin-top: .9rem; font-size: .9rem; color: var(--ink-soft); }
.live-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line);
}
.live-item { display: flex; flex-direction: column; gap: .1rem; }
.live-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.live-value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.02rem; white-space: nowrap; }
.live-unit { font-weight: 500; font-size: .78rem; color: var(--ink-soft); }
.tool-error {
  display: none; margin-top: 1rem; padding: .8rem 1rem; border-radius: 12px;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad); font-size: .95rem; text-align: left;
}
.tool-card[data-state="error"] .tool-error, .tool-error[data-forced] { display: block; }

.privacy-badge {
  margin: 1rem auto 0; max-width: 62ch; text-align: center;
  font-size: .92rem; color: var(--ink-soft);
}

/* ============ 7. Resultados ============ */
.results { margin-top: 2rem; scroll-margin-top: 76px; }
.results-title { margin-bottom: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.stat-label { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.stat-value { font-size: clamp(1.6rem, 6vw, 2.2rem); font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-unit { color: var(--ink-soft); margin-left: .3rem; font-size: .95rem; }
.stat-main { background: linear-gradient(180deg, var(--accent-soft), var(--surface)); }

.contract-box {
  margin-top: 1.4rem; padding: 1.2rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
}
.contract-help { color: var(--ink-soft); font-size: .95rem; margin: .3rem 0 .9rem; }
.contract-form { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: .3rem; flex: 1 1 200px; text-align: left; }
.field-label { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.field-input { display: flex; align-items: center; gap: .4rem; }
.field input {
  width: 100%; padding: .75rem .9rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-suffix { color: var(--ink-soft); font-weight: 600; }
.contract-result { margin-top: 1.1rem; }
.contract-bar {
  height: 14px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; border: 1px solid var(--line);
}
.contract-bar > span {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: var(--ok); transition: width .9s var(--ease-out);
}
.contract-bar[data-level="warn"] > span { background: var(--warn); }
.contract-bar[data-level="bad"] > span { background: var(--bad); }
.contract-headline { font-size: 1.2rem; font-weight: 700; margin-top: .7rem; }
.contract-detail { color: var(--ink-soft); font-size: .95rem; }

.verdicts { list-style: none; padding: 0; display: grid; gap: .6rem; grid-template-columns: 1fr; }
.verdict {
  display: flex; align-items: flex-start; gap: .8rem; padding: .85rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 12px;
}
.verdict[data-level="ok"] { border-left-color: var(--ok); }
.verdict[data-level="warn"] { border-left-color: var(--warn); }
.verdict[data-level="bad"] { border-left-color: var(--bad); }
.verdict-icon { flex: 0 0 auto; width: 26px; height: 26px; margin-top: .1rem; }
.verdict[data-level="ok"] .verdict-icon { color: var(--ok); }
.verdict[data-level="warn"] .verdict-icon { color: var(--warn); }
.verdict[data-level="bad"] .verdict-icon { color: var(--bad); }
.verdict-body { text-align: left; min-width: 0; }
.verdict-name { display: block; font-weight: 650; }
.verdict-msg { display: block; font-size: .92rem; color: var(--ink-soft); }

.conn-grid { display: grid; gap: .6rem; grid-template-columns: 1fr; margin-top: .3rem; }
.conn-item {
  display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.conn-item dt { color: var(--ink-soft); font-size: .9rem; }
.conn-item dd { font-weight: 600; text-align: right; word-break: break-word; }

.save-row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; margin-top: 1.4rem; }
.field-inline { flex: 1 1 260px; }
.actions-row { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: .9rem; }
.save-feedback { margin-top: .7rem; color: var(--ok); font-weight: 600; font-size: .95rem; }
.results-disclaimer { margin-top: 1rem; font-size: .85rem; color: var(--ink-soft); }

/* ============ 8. Historial ============ */
.history-empty {
  padding: 1.2rem; border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-soft); background: var(--surface); margin-top: 1rem;
}
.history-body { margin-top: 1rem; }
.chart-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.chart-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: baseline; justify-content: space-between; }
.chart-legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--ink-soft); margin: 0; }
canvas[data-chart] { width: 100%; height: 260px; margin-top: .6rem; }

.table-scroll { overflow-x: auto; margin-top: 1rem; -webkit-overflow-scrolling: touch; }
.history-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 620px; }
.history-table th, .history-table td { padding: .65rem .7rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history-table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.history-table td:first-child { color: var(--ink-soft); }
.row-del { color: var(--ink-soft); font-size: 1.1rem; line-height: 1; padding: .2rem .4rem; border-radius: 8px; }
.row-del:hover { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.history-actions { margin-top: 1rem; }

/* ============ 9. Secciones de contenido ============ */
.section { padding: 2.6rem 0; scroll-margin-top: 62px; }
.section-alt { background: var(--surface); border-block: 1px solid var(--line); }
.steps { list-style: none; padding: 0; display: grid; gap: 1rem; margin-top: 1.4rem; }
.step {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem;
}
.section-alt .step { background: var(--surface-2); }
.step-icon {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); margin-bottom: .7rem;
}
.step h3 { margin-bottom: .3rem; }
.step p { color: var(--ink-soft); font-size: .95rem; }

.ideas { display: grid; gap: 1rem; margin-top: 1.4rem; }
.idea { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.idea h3 { margin-bottom: .35rem; }
.idea p { color: var(--ink-soft); font-size: .95rem; }

.prose { max-width: 72ch; }
.prose h3 { margin: 1.6rem 0 .4rem; }
.prose p { margin-bottom: .9rem; color: var(--ink-soft); }
.prose strong { color: var(--ink); }

.faq { margin-top: 1.2rem; display: grid; gap: .6rem; }
.faq-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .3rem .2rem;
}
.faq-item summary {
  cursor: pointer; list-style: none; padding: .8rem 2.2rem .8rem 1rem;
  font-weight: 620; position: relative;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+"; position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
  font-size: 1.3rem; color: var(--accent); line-height: 1;
}
.faq-item[open] summary::after { content: "−"; }
.faq-answer { padding: 0 1rem .9rem; color: var(--ink-soft); font-size: .95rem; }

/* ============ 10. Anuncios (huecos, sin código de terceros) ============ */
.ad-slot {
  position: relative; display: grid; place-items: center;
  border: 1px dashed color-mix(in srgb, var(--ink-soft) 45%, transparent);
  border-radius: 12px; background: var(--surface-2);
  color: var(--ink-soft); overflow: hidden;
}
.ad-tag { font-size: .72rem; letter-spacing: .18em; font-weight: 700; opacity: .65; }
.ad-leaderboard { min-height: 100px; margin: 1.6rem 0; }
.ad-incontent { min-height: 250px; margin: 1.6rem 0; }

.ad-modal {
  border: 1px solid var(--line); border-radius: 18px; padding: 1.6rem 1.2rem 1.1rem;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  width: min(92vw, 360px); position: relative; margin: auto;
}
.ad-modal::backdrop { background: rgba(8, 10, 18, .55); backdrop-filter: blur(2px); }
.ad-modal-close {
  position: absolute; top: .4rem; right: .5rem; width: 34px; height: 34px;
  font-size: 1.5rem; line-height: 1; border-radius: 50%; color: var(--ink-soft);
}
.ad-modal-close:hover { background: var(--surface-2); color: var(--ink); }
.ad-modal-slot { min-height: 250px; width: 100%; }
.ad-modal-continue { width: 100%; margin-top: .9rem; }

.ad-toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  width: min(88vw, 300px); padding: 1.4rem .7rem .7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  animation: toastIn .4s var(--ease-out) both;
}
.ad-toast-close {
  position: absolute; top: .2rem; right: .3rem; width: 28px; height: 28px;
  font-size: 1.25rem; line-height: 1; border-radius: 50%; color: var(--ink-soft);
}
.ad-toast-close:hover { background: var(--surface-2); color: var(--ink); }
.ad-toast-slot { min-height: 100px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ============ 11. Pie ============ */
.site-footer { border-top: 1px solid var(--line); padding: 1.6rem 0 3rem; background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; justify-content: space-between; align-items: center; }
.footer-brand { font-size: .92rem; color: var(--ink-soft); }
.footer-nav { display: flex; gap: 1.1rem; font-size: .92rem; color: var(--ink-soft); }
.footer-nav a:hover { color: var(--accent); }

/* ============ 12. Responsive ============ */
@media (min-width: 540px) {
  .verdicts { grid-template-columns: repeat(2, 1fr); }
  .conn-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 720px) {
  .header-nav { display: flex; }
  .hero { padding: 2.6rem 0 3rem; }
  .tool-card { padding: 1.6rem 2rem 2rem; max-width: 760px; margin-inline: auto; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .steps, .ideas { grid-template-columns: repeat(3, 1fr); }
  .ideas { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .ideas { grid-template-columns: repeat(3, 1fr); }
  .section { padding: 3.4rem 0; }
}

/* ============ 13. Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ad-toast { animation: none; }
  .contract-bar > span { transition: none; }
}
