:root {
  --bg: #0c0a09;
  --surface: #161210;
  --surface-2: #1f1916;
  --line: #2d2420;
  --text: #f4ece6;
  --muted: #9c8c84;
  --accent: #ff5a36;      /* luz de seguridad */
  --accent-ink: #1a0b06;
  --amber: #ffb547;
  --ok: #8fd18a;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --num: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

/* Modo luz roja: todo en rojo sobre negro para cuarto oscuro */
html.safelight {
  --bg: #000;
  --surface: #0d0000;
  --surface-2: #160101;
  --line: #2e0505;
  --text: #ff3b2a;
  --muted: #9a1f16;
  --accent: #ff2a1a;
  --accent-ink: #000;
  --amber: #ff2a1a;
  --ok: #ff2a1a;
}
html.safelight img, html.safelight svg { filter: none; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 16px); }

/* ---------- Header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.lamp { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px 3px color-mix(in srgb, var(--accent) 55%, transparent); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
}
.icon-btn.lg { width: 56px; height: 56px; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn:disabled { opacity: .35; }

.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600;
}
.link { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px; text-decoration: underline; text-underline-offset: 3px; }
.primary {
  border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 700; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
}
.primary:active, .ghost:active, .icon-btn:active { transform: scale(.97); }

/* ---------- Cards ---------- */
.stack { display: grid; gap: 12px; padding-bottom: 96px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; }
.lbl { display: block; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; }
.card > .lbl:first-child, .card-h .lbl { margin-top: 0; }
.card-h .lbl { margin-bottom: 0; }
.hint { text-transform: none; letter-spacing: 0; font-weight: 500; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
select, input {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; /* 16px evita zoom en iOS */
}
select { padding-right: 40px; }
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums;
}
.chip[aria-checked="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .push { font-size: 11px; font-weight: 700; margin-left: 5px; color: var(--amber); }
.chip[aria-checked="true"] .push { color: inherit; opacity: .7; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 0; border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--text); color: var(--bg); }

.stepper { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.stepper button { width: 40px; height: 38px; border: 0; background: none; font-size: 22px; font-weight: 500; border-radius: 9px; }
.stepper button:active { background: var(--line); }
.stepper output { flex: 1; text-align: center; font-weight: 700; font-family: var(--num); font-variant-numeric: tabular-nums; }

/* ---------- Resultado ---------- */
.result { text-align: center; padding: 20px 16px; }
.kicker { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.bigtime { font-family: var(--num); font-weight: 700; font-size: clamp(64px, 22vw, 96px); line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin: 8px 0 6px; }
.sub { color: var(--muted); font-size: 14px; min-height: 20px; }
.sub b { color: var(--amber); font-weight: 600; }
.actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.note.warn { color: var(--amber); }

/* ---------- Agitación ---------- */
.agit-list { display: grid; gap: 8px; }
.agit {
  display: grid; grid-template-columns: 20px 1fr; gap: 2px 12px; align-items: center; text-align: left;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 11px 14px;
}
.agit::before { content: ""; grid-row: span 2; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); }
.agit[aria-checked="true"] { border-color: var(--accent); }
.agit[aria-checked="true"]::before { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.agit b { font-size: 15px; }
.agit span { font-size: 13px; color: var(--muted); }

/* ---------- Pasos ---------- */
.steps { list-style: none; margin: 10px 0 0; padding: 0; }
.step { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.step.off .step-name, .step.off input { opacity: .4; }
.step-name { font-weight: 600; }
.step-name small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.step input.dur { width: 84px; text-align: center; padding: 8px; font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: 700; }
.step input.dur[readonly] { background: transparent; border-color: transparent; color: var(--accent); }
.toggle { position: relative; width: 44px; height: 26px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .15s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); }
.toggle input:disabled + span { opacity: .5; }
.total { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; color: var(--muted); }
.total strong { color: var(--text); font-family: var(--num); font-variant-numeric: tabular-nums; }

.cta {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(var(--safe-b) + 12px);
  background: linear-gradient(transparent, var(--bg) 35%);
  display: flex; justify-content: center;
}
.cta .primary { width: 100%; max-width: 528px; padding: 17px; font-size: 18px; }
.cta .primary:disabled { opacity: .4; }

/* ---------- Cronómetro ---------- */
#run { min-height: 100dvh; display: flex; flex-direction: column; gap: 14px; }
.run-top { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 10px; padding-top: 6px; }
.run-meta { text-align: center; min-width: 0; }
.run-step { font-weight: 700; font-size: 20px; }
.run-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-idx { text-align: center; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }

.dial { position: relative; width: min(84vw, 46dvh, 380px); aspect-ratio: 1; margin: 4px auto 0; }
.dial svg { width: 100%; height: 100%; display: block; }
.track { fill: none; stroke: var(--surface-2); stroke-width: 14; }
.prog { fill: none; stroke: var(--text); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.amark { fill: none; stroke: var(--accent); stroke-width: 14; opacity: .55; }
.amark.done { opacity: .18; }
.amark.now { opacity: 1; }
.dial-c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.runtime { font-family: var(--num); font-weight: 700; font-size: clamp(64px, 20vw, 104px); letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.runtotal { color: var(--muted); font-size: 14px; margin-top: 6px; font-variant-numeric: tabular-nums; }

.banner { border-radius: var(--radius); padding: 14px 16px; text-align: center; background: var(--surface); border: 1px solid var(--line); transition: background .2s, color .2s; }
.banner-t { font-weight: 800; font-size: 26px; letter-spacing: .02em; text-transform: uppercase; }
.banner-s { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; min-height: 21px; }
.banner.agitate { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); animation: pulse 1s ease-in-out infinite; }
.banner.agitate .banner-s { color: inherit; opacity: .8; }
.banner.drain { border-color: var(--amber); }
.banner.drain .banner-t { color: var(--amber); }
.banner.done { border-color: var(--ok); }
.banner.done .banner-t { color: var(--ok); }
@keyframes pulse { 50% { filter: brightness(1.15); transform: scale(1.01); } }

.run-note { margin: 0; text-align: center; font-size: 14px; color: var(--muted); min-height: 1em; }
.run-ctl { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: auto; }
.primary.big { min-width: 170px; max-width: 60vw; padding: 18px 24px; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mini { list-style: none; padding: 0; margin: 4px 0 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.mini li { flex: none; padding: 6px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini li b { display: block; color: var(--text); font-weight: 600; font-size: 13px; }
.mini li.cur { border-color: var(--accent); }
.mini li.past { opacity: .4; }

#flash { position: fixed; inset: 0; background: var(--accent); opacity: 0; pointer-events: none; z-index: 50; }
#flash.on { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }

/* ---------- Diálogos ---------- */
dialog {
  width: min(92vw, 480px); max-height: 85dvh; border: 1px solid var(--line); border-radius: 22px;
  background: var(--surface); color: var(--text); padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(3px); }
.dlg { padding: 20px; }
.dlg h2 { margin: 0 0 4px; font-size: 20px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.dlg-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }
.dlg-actions .primary { padding: 10px 18px; font-size: 15px; }
.file-btn { cursor: pointer; }
.mine { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.mine li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.mine li small { display: block; color: var(--muted); }
.mine .empty { display: block; color: var(--muted); text-align: center; }
.mine button { padding: 6px 10px; font-size: 13px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .banner.agitate { animation: none; }
  #flash.on { animation: none; }
}

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 12px; position: sticky; top: calc(var(--safe-t) + 4px); z-index: 5; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 0; border-radius: 10px; font-weight: 700; font-size: 15px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--amber); color: var(--bg); font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; }
#pChem, #pLog { padding-bottom: 32px; }
.intro { margin: 0 4px; }
.primary.block, .ghost.block { width: 100%; }
.actions.left { justify-content: flex-start; margin-top: 10px; }
.ghost.sm { padding: 6px 12px; font-size: 13px; }
.empty { list-style: none; color: var(--muted); text-align: center; padding: 24px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Químicos ---------- */
.chem-list, .log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.chem { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; --lvl: var(--ok); }
.chem.warn { --lvl: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); }
.chem.bad { --lvl: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.chem.archived { opacity: .55; --lvl: var(--muted); }
.chem-h, .log-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chem-h b, .log-h b { display: block; font-size: 16px; }
.chem-h small, .log-h small { color: var(--muted); font-size: 13px; }
.chem-left { text-align: right; line-height: 1.1; }
.chem-left strong { display: block; font-family: var(--num); font-size: 28px; color: var(--lvl); font-variant-numeric: tabular-nums; }
.chem-left small { color: var(--muted); font-size: 12px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); margin: 12px 0 8px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--lvl); border-radius: inherit; }
.chem-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.old summary { color: var(--muted); font-weight: 600; padding: 8px 4px; cursor: pointer; }
.old .chem-list { margin-top: 6px; }

/* ---------- Historial ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat strong { display: block; font-family: var(--num); font-size: 26px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12px; }
.log { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.rolls { font-family: var(--num); font-weight: 700; font-size: 18px; color: var(--accent); }
.log-note { margin-top: 6px; font-size: 14px; font-style: italic; }
.backup .lbl { margin-top: 0; }

/* ---------- Diálogo registrar ---------- */
.stepper.narrow { max-width: 180px; }
.check-list { display: grid; gap: 8px; }
.check { display: flex; gap: 12px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; padding: 0; appearance: auto; -webkit-appearance: checkbox; accent-color: var(--accent); }
.check b { display: block; font-size: 15px; }
.check small { color: var(--muted); font-size: 12px; }
.check:has(input:checked) { border-color: var(--accent); }
.chem-left strong.word { font-size: 20px; }
.chem-meta.spaced { margin-top: 10px; }
.note a { color: inherit; text-underline-offset: 3px; }
