:root {
  --bg: #eef1f3;
  --surface: #fff;
  --surface-2: #e5eaed;
  --ink: #10202b;
  --ink-2: #41515c;
  --ink-3: #5c6b75;
  --line: #d9dfe3;
  --accent: #0b5c7a;
  --accent-soft: #dfedf3;
  --on-accent: #fff;
  --note: #f6efdf;
  --note-ink: #5f4500;
  --danger: #a8201a;
  --danger-soft: #f9e6e4;
  --ok: #1a6a4a;
  --ok-soft: #dff0e8;
  --plate-empty: #33424d;
  --plate-moderado: #856000;
  --plate-alto: #b0500f;
  --plate-muyAlto: #a8201a;
  --plate-extremo: #5e1224;
  --radius: 12px;
  --tab-h: 62px;
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1519;
    --surface: #172127;
    --surface-2: #212d34;
    --ink: #e8eef1;
    --ink-2: #b1bdc4;
    --ink-3: #94a2aa;
    --line: #2b383f;
    --accent: #6cc1dd;
    --accent-soft: #17323d;
    --on-accent: #06222d;
    --note: #322a14;
    --note-ink: #eed08a;
    --danger: #f0a39d;
    --danger-soft: #3b1b1a;
    --ok: #86d3b0;
    --ok-soft: #16322a;
    --plate-empty: #2a3841;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
::selection { background: var(--accent-soft); }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
main:focus { outline: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.top-actions { display: flex; gap: 2px; margin-right: -10px; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: none; border: 0; color: var(--ink-2); border-radius: 10px; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--surface-2); }

main {
  max-width: 560px; margin: 0 auto;
  padding: 0 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 32px);
}

h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.02em; margin: 8px 0 16px; text-wrap: balance; }
h2 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 28px 4px 8px; }
h3 { font-size: 16px; margin: 18px 0 4px; }
p { margin: 8px 0; }
.lead { color: var(--ink-2); margin: -8px 4px 16px; }

/* La placa: el cartel que da la respuesta */
.plate {
  position: sticky; top: calc(env(safe-area-inset-top) + 6px); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 88px; padding: 12px 18px; border-radius: var(--radius);
  background: var(--plate-empty); color: #fff;
  box-shadow: 0 6px 16px -10px rgba(10, 25, 35, .55);
  transition: background-color .22s ease-out;
}
.plate[data-risk="moderado"] { background: var(--plate-moderado); }
.plate[data-risk="alto"] { background: var(--plate-alto); }
.plate[data-risk="muyAlto"] { background: var(--plate-muyAlto); }
.plate[data-risk="extremo"] { background: var(--plate-extremo); }
.plate[data-risk="ok"] { background: #17634a; }
.plate-num { font-size: 46px; font-weight: 700; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plate-num small { font-size: 14px; font-weight: 500; letter-spacing: 0; opacity: .92; margin-left: 3px; }
.plate-num.prompt { font-size: 19px; font-weight: 600; letter-spacing: -.01em; white-space: normal; line-height: 1.2; }
.plate-side { text-align: right; font-size: 14px; line-height: 1.25; }
.plate-side b { display: block; font-size: 15px; font-weight: 600; }

/* Grupos de campos */
.group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 50px; padding: 11px 14px;
  border-top: 1px solid var(--line);
}
.group > :first-child, .group > [hidden] + .row { border-top: 0; }
.row-text { flex: 1; min-width: 0; }
.row-text small { display: block; color: var(--ink-3); font-size: 13px; line-height: 1.3; margin-top: 1px; }
label.row { cursor: pointer; }
label.row:active { background: var(--surface-2); }

.row input[type="checkbox"], .row input[type="radio"] {
  appearance: none; flex: none; width: 24px; height: 24px; margin: 0;
  border: 1.5px solid var(--ink-3); border-radius: 7px; background: transparent;
  display: grid; place-items: center; cursor: pointer;
  transition: background-color .15s ease-out, border-color .15s ease-out;
}
.row input[type="radio"] { border-radius: 50%; }
.row input:checked { background: var(--accent); border-color: var(--accent); }
.row input[type="checkbox"]:checked::after {
  content: ""; width: 11px; height: 6px; margin-top: -2px;
  border-left: 2px solid var(--on-accent); border-bottom: 2px solid var(--on-accent);
  transform: rotate(-45deg);
}
.row input[type="radio"]:checked::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--on-accent); }

.num {
  width: 92px; height: 42px; padding: 0 10px; text-align: right;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
  font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num:focus { border-color: var(--accent); outline: 1px solid var(--accent); }
.num::placeholder { color: var(--ink-3); font-weight: 400; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  padding: 2px; background: var(--surface-2); border-radius: 11px; margin: 0;
}
.seg label { position: relative; min-width: 0; cursor: pointer; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span {
  display: grid; place-items: center; min-height: 44px; padding: 4px 6px;
  border-radius: 9px; font-size: 14px; font-weight: 500; text-align: center; line-height: 1.15;
  color: var(--ink-2); transition: background-color .15s ease-out;
}
.seg input:checked + span { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(10, 25, 35, .18); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-pad { padding: 11px 14px; border-top: 1px solid var(--line); }
.group > .field-pad:first-child { border-top: 0; }
.field-label { font-size: 14px; color: var(--ink-2); margin: 0 0 7px; }

/* Resultado */
.result { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-top: 10px; overflow-wrap: anywhere; }
.result > :first-child { margin-top: 0; }
.result > :last-child { margin-bottom: 0; }
.answer { font-size: 18px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
.src { display: block; font-size: 13px; color: var(--ink-3); margin-top: 3px; font-weight: 400; letter-spacing: 0; }
.opt { padding: 11px 0; border-top: 1px solid var(--line); }
.opt:first-of-type { border-top: 0; padding-top: 2px; }
.opt:last-child { padding-bottom: 0; }
.opt b { display: block; font-weight: 600; }
.opt span { font-size: 14px; color: var(--ink-2); }
.band-title { font-size: 14px; font-weight: 600; color: var(--accent); margin: 16px 0 2px; }
.band-title:first-child { margin-top: 0; }
.stat { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 15px; border-top: 1px solid var(--line); }
.stat:first-child { border-top: 0; padding-top: 0; }
.stat:last-child { padding-bottom: 0; }
.stat b { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

.note, .alert, .good { display: flex; gap: 10px; padding: 11px 13px; border-radius: 10px; font-size: 14.5px; line-height: 1.4; margin-top: 8px; }
.note { background: var(--note); color: var(--note-ink); }
.alert { background: var(--danger-soft); color: var(--danger); }
.good { background: var(--ok-soft); color: var(--ok); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 50px; margin-top: 12px; padding: 10px 16px;
  border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  font-size: 16px; font-weight: 600; text-decoration: none;
}
.btn:active { filter: brightness(.92); }
.link-btn { background: none; border: 0; padding: 8px 4px; color: var(--accent); font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.empty { background: var(--surface); border-radius: var(--radius); padding: 18px 14px; color: var(--ink-2); }

/* Línea de seguimiento: paradas de una misma línea */
.line { list-style: none; margin: 0; padding: 4px 0; background: var(--surface); border-radius: var(--radius); }
.line li { position: relative; padding: 10px 14px 10px 44px; }
.line li::before { content: ""; position: absolute; left: 21px; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.line li:first-child::before { top: 18px; }
.line li:last-child::before { bottom: calc(100% - 18px); }
.line li::after {
  content: ""; position: absolute; left: 15px; top: 13px; width: 15px; height: 15px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--accent);
}
.line li.here::after { background: var(--accent); }
.line b { display: block; }
.line span { color: var(--ink-2); font-size: 14.5px; }
.line .when { font-variant-numeric: tabular-nums; }

/* Desplegables */
details.acc { background: var(--surface); border-top: 1px solid var(--line); }
details.acc:first-of-type { border-top: 0; }
.accs { border-radius: var(--radius); overflow: hidden; }
details.acc > summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 52px; padding: 11px 14px; font-weight: 600; cursor: pointer;
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary svg { width: 18px; height: 18px; flex: none; color: var(--ink-3); transition: transform .18s ease-out; }
details.acc[open] > summary svg { transform: rotate(90deg); }
.acc-body { padding: 0 14px 14px; color: var(--ink); font-size: 15px; }
.acc-body ul, .acc-body ol { margin: 6px 0; padding-left: 20px; }
.acc-body li { margin: 4px 0; }
.acc-body > :first-child { margin-top: 0; }
.acc-body .src { margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px 7px 0; border-top: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); }
tr:first-child th, tr:first-child td { border-top: 0; }
.scroll-x { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
.scroll-x table { min-width: 460px; }

.flow { list-style: none; padding: 0; margin: 8px 0; counter-reset: s; }
.flow li { counter-increment: s; position: relative; padding: 0 0 12px 32px; }
.flow li::before {
  content: counter(s); position: absolute; left: 0; top: 0; width: 22px; height: 22px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700;
}

.foot { color: var(--ink-3); font-size: 13px; margin: 18px 4px 0; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: var(--tab-h); color: var(--ink-3); text-decoration: none;
  font-size: 11px; font-weight: 500; max-width: 140px; width: 100%; margin: 0 auto;
}
.tabs svg { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabs a[aria-current="page"]::before {
  content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--accent);
}

@media (max-width: 359px) {
  .plate { padding: 12px 14px; gap: 10px; }
  .plate-num { font-size: 38px; }
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
