/* ---------- Tokens ---------- */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-translucent: rgba(255, 255, 255, 0.72);
  --border: #e3e3e6;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --accent: #0a66ff;
  --accent-contrast: #ffffff;
  --ok-bg: #e7f6ec;
  --ok-text: #1d7a3c;
  --fail-bg: #fdecec;
  --fail-text: #c62f2f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-translucent: rgba(28, 28, 30, 0.72);
    --border: #2c2c2e;
    --text: #f5f5f7;
    --text-muted: #98989d;
    --accent: #3b82ff;
    --ok-bg: #0f2a18;
    --ok-text: #4ade80;
    --fail-bg: #2d1414;
    --fail-text: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-translucent: rgba(28, 28, 30, 0.72);
  --border: #2c2c2e;
  --text: #f5f5f7;
  --text-muted: #98989d;
  --accent: #3b82ff;
  --ok-bg: #0f2a18;
  --ok-text: #4ade80;
  --fail-bg: #2d1414;
  --fail-text: #f87171;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header ---------- */
header.site {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: var(--surface-translucent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid transparent;
  box-shadow: 0 1px 0 transparent;
  transition: border-color 220ms var(--spring), box-shadow 220ms var(--spring);
}
/* Scroll-edge effect: the hairline only appears once content is actually
   under the translucent header, instead of a hard divider that's always there. */
header.site.is-scrolled {
  border-bottom-color: var(--border);
  box-shadow: 0 1px 0 var(--border), 0 8px 16px -12px rgba(0, 0, 0, 0.25);
}

header.site .brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

header.site .brand .mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), #6aa9ff);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

/* .brand-name en páginas que ya tienen su propio <h1>: el nombre del sitio en
   el header no debe competir con él por el único H1 de la página. */
header.site h1,
header.site .brand-name {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header.site nav {
  display: flex;
  gap: 4px;
  font-size: 14px;
}

header.site nav a {
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 550;
  transition: background 120ms var(--spring), color 120ms var(--spring);
}
header.site nav a:hover, header.site nav a.active {
  background: rgba(10, 102, 255, 0.1);
  color: var(--accent);
}

/* ---------- Layout ---------- */
main.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) 60px;
}

@media (max-width: 860px) {
  main.layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Form sidebar ---------- */
aside.form-panel {
  align-self: start;
  position: sticky;
  top: 72px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 860px) {
  aside.form-panel { position: static; }
}

.form-panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0;
  font-weight: 650;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field label {
  font-size: 14px;
  color: var(--text);
}

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 92px;
  text-align: right;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transition: border-color 120ms var(--spring), box-shadow 120ms var(--spring);
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 102, 255, 0.15);
}

.order-toggle {
  position: relative;
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
  background: var(--bg);
}
/* A single sliding pill carries the "active" state between the two buttons,
   instead of each button flashing its own background on/off. */
.order-toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  background: var(--accent);
  border-radius: 999px;
  transition: transform 260ms var(--spring);
  z-index: 0;
}
.order-toggle:has(button[data-orden="descendente"].active)::before {
  transform: translateX(100%);
}
.order-toggle button {
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 150ms var(--spring), transform 80ms var(--spring);
}
.order-toggle button.active { color: white; }
.order-toggle button:active { transform: scale(0.96); }

/* Browsers without :has() still work: fall back to a flat background per button. */
@supports not selector(:has(a)) {
  .order-toggle::before { display: none; }
  .order-toggle button.active { background: var(--accent); }
}

button.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 100ms var(--spring), filter 120ms var(--spring), background 120ms var(--spring);
}
button.btn:active { transform: scale(0.97); }
button.btn.primary { background: var(--accent); color: white; }
button.btn.primary:hover { filter: brightness(1.08); }
button.btn.secondary { background: var(--ok-bg); color: var(--ok-text); }
button.btn.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.btn-row { display: flex; flex-direction: column; gap: 8px; }

.panel-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- Single score calculator ---------- */
.quick-calc {
  padding: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.quick-calc .title {
  font-weight: 650;
  font-size: 15px;
  flex: 1 1 200px;
}
.quick-calc .input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.quick-calc input[type="text"] {
  width: 110px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}
.result-badge {
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: background 150ms var(--spring), color 150ms var(--spring), transform 150ms var(--spring);
}
.result-badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.result-badge.fail { background: var(--fail-bg); color: var(--fail-text); }
.result-badge.pop { animation: pop 320ms var(--spring); }
@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }

.page-lede {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 62ch;
}

/* ---------- Table ---------- */
.table-wrap {
  padding: 18px;
}
.tablas-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: flex-start;
  opacity: 1;
  transition: opacity 180ms var(--spring);
}
.tablas-grid.is-refreshing { opacity: 0; }
table.escala {
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  align-self: flex-start;
}
table.escala thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: right;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}
table.escala thead th:first-child, table.escala td:first-child { text-align: left; padding-left: 14px; }
table.escala td { text-align: right; padding: 5px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.escala tbody tr:last-child td { border-bottom: 0; }
table.escala tbody tr:nth-child(even) { background: rgba(0,0,0,0.015); }
@media (prefers-color-scheme: dark) {
  table.escala tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
}
table.escala td a { text-decoration: none; color: inherit; display: block; }
table.escala td.nota a { font-weight: 650; }
table.escala tr.reprobado td.nota a { color: var(--fail-text); }
table.escala tr.aprobado td.nota a { color: var(--ok-text); }
table.escala tbody tr { transition: background 100ms var(--spring); }
table.escala tbody tr:hover { background: rgba(10, 102, 255, 0.08); }

/* ---------- Ad slots ---------- */
.ad-slot {
  margin: 24px 0;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}
.ad-slot .ad-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ---------- FAQ ---------- */
section.faq { margin-top: 28px; }
section.faq h2 { font-size: 20px; letter-spacing: -0.01em; margin-bottom: 14px; }
.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--surface);
}
.faq-item summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: background 100ms var(--spring);
}
.faq-item summary:active { background: rgba(10, 102, 255, 0.07); }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  font-size: 20px;
  color: var(--text-muted);
  transition: transform 180ms var(--spring);
  flex-shrink: 0;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item .faq-body {
  padding: 0 16px 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}
.faq-item .faq-body p { margin: 0 0 10px; }
.faq-item .faq-body p:last-child { margin-bottom: 0; }

/* ---------- Explicación page ---------- */
.explain-card { padding: 24px; max-width: 760px; margin: 0 auto; }
.formula {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
}
.param-list { display: grid; gap: 8px; margin: 16px 0; }
.param-list .row { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding-bottom: 6px; font-size: 14px; }
.param-list .row b { font-variant-numeric: tabular-nums; }

/* ---------- Generic page content (privacidad / contacto) ---------- */
.content-page { max-width: 760px; margin: 0 auto; padding: 32px 16px 60px; line-height: 1.7; }
.content-page h1 { font-size: 28px; letter-spacing: -0.01em; }
.content-page h2 { font-size: 18px; margin-top: 28px; }

/* ---------- Footer ---------- */
footer.site {
  border-top: 1px solid var(--border);
  padding: 24px max(16px, env(safe-area-inset-left)) 40px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
footer.site a { color: var(--text-muted); text-decoration: underline; }
footer.site .links { display: flex; justify-content: center; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Print ---------- */
@media print {
  header.site, aside.form-panel, .quick-calc, .ad-slot, section.faq, footer.site { display: none !important; }
  main.layout { display: block; padding: 0; }
}
