:root {
  --paper: #f7f5ef; --card: #fff; --ink: #16201b; --muted: #5b6660; --line: #d9d5c8;
  --green: #2f7a2a; --check: #6cbf2d; --red: #b8322a; --kraft: #c99a62;
  --grid: rgba(47, 122, 42, .07);
  font-family: 'Recursive', system-ui, sans-serif; font-variation-settings: 'CASL' 0, 'MONO' 0;
  color: var(--ink); background: var(--paper);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; background: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent;
}
code, pre, .mono, .last-code, .stats b, .kbd { font-variation-settings: 'MONO' 1, 'CASL' 0; font-family: 'Recursive', ui-monospace, monospace; }
h1 { font-size: 1.5rem; margin: .2rem 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 .4rem; }
.lead { margin: 0 0 1rem; color: var(--muted); }
.hint { margin: .2rem 0 .7rem; color: var(--muted); font-size: .9rem; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  border: 1.5px solid var(--ink); background: var(--card); border-radius: 8px; padding: .55rem .9rem;
  min-height: 44px; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: .4; cursor: default; }
button.primary, button.big { background: var(--ink); color: var(--paper); }
button[aria-pressed="true"] { background: #ffe9a8; }
:focus-visible { outline: 3px solid var(--check); outline-offset: 2px; }

/* Encabezado */
.top { position: sticky; top: 0; z-index: 5; background: var(--ink); color: var(--paper); padding: .6rem 16px 0; padding-top: max(.6rem, env(safe-area-inset-top)); }
.brand { display: flex; gap: .6rem; align-items: center; }
.brand svg { width: 32px; height: 32px; color: var(--paper); flex: none; }
.brand b { display: block; font-size: .95rem; }
.brand span { display: block; font-size: .78rem; opacity: .75; font-variation-settings: 'MONO' 1; }
.tabs { display: flex; gap: 2px; overflow-x: auto; margin: .5rem -16px 0; padding: 0 16px; scrollbar-width: none; }
.tabs button { border: 0; border-radius: 8px 8px 0 0; background: transparent; color: var(--paper); opacity: .7; padding: .55rem .62rem; white-space: nowrap; min-height: 42px; }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); opacity: 1; }

main { max-width: 760px; margin: 0 auto; padding: 1rem 16px 2rem; }
[hidden] { display: none !important; }

/* Visor de cámara */
.viewer { position: relative; aspect-ratio: 4 / 3; background: #0d1310; border-radius: 12px; overflow: hidden; }
.viewer video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame { position: absolute; left: 10%; right: 10%; top: 22.5%; bottom: 22.5%; pointer-events: none; opacity: 0; transition: opacity .2s; }
.viewer.on .frame { opacity: 1; }
.frame i { position: absolute; width: 26px; height: 26px; border: 4px solid #fff; }
.frame i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; }
.frame i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; }
.frame i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; }
.frame i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; }
.laser { position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; animation: laser 1.6s ease-in-out infinite alternate; }
@keyframes laser { from { transform: translateY(-40px); } to { transform: translateY(40px); } }
@media (prefers-reduced-motion: reduce) { .laser { animation: none; } }
.idle { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .6rem; padding: 1rem; text-align: center; color: #e9efe9; }
.idle[hidden] { display: none; }
.idle small { max-width: 30ch; opacity: .8; }
button.big { background: var(--check); color: var(--ink); border-color: var(--check); font-size: 1.1rem; padding: .8rem 1.4rem; }
.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.flash.ok { box-shadow: inset 0 0 0 6px var(--check); }
.flash.bad { box-shadow: inset 0 0 0 6px var(--red); }
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.camtools { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0; align-items: center; }
.sel { display: inline-flex; gap: .4rem; align-items: center; font-size: .9rem; color: var(--muted); }
.sel select, .sel input, .sel textarea { border: 1.5px solid var(--line); border-radius: 8px; background: var(--card); padding: .5rem; min-height: 44px; color: var(--ink); min-width: 0; }
.sel.full { display: grid; gap: .25rem; margin-bottom: .7rem; }
.sel.full input, .sel.full textarea { width: 100%; }
#camSel { max-width: 12rem; }
.zoom { display: flex; gap: .4rem; align-items: center; font-size: .9rem; flex: 1 1 100%; }
.zoom input { flex: 1; }
.mode { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin: .4rem 0 .8rem; }
.mode label { display: flex; gap: .35rem; align-items: center; min-height: 36px; }
.mode small { color: var(--muted); }

.last { background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: .8rem; }
.last-code { font-size: 1.5rem; font-weight: 700; overflow-wrap: anywhere; }
.last-meta { color: var(--muted); font-size: .88rem; }
.last-note span { display: block; font-size: .88rem; margin-top: .3rem; padding-left: .6rem; border-left: 3px solid var(--kraft); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: .7rem 0; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { font-size: .8rem; color: var(--muted); }

.count { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.count li { display: flex; justify-content: space-between; gap: .6rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; }
.count li.hi { border-color: var(--check); box-shadow: 0 0 0 2px var(--check); }
.count li div:first-child { min-width: 0; }
.count code { display: block; overflow-wrap: anywhere; font-weight: 600; }
.count small { color: var(--muted); font-size: .8rem; }
.count .empty, .devs .empty { display: block; color: var(--muted); background: none; border: 1px dashed var(--line); }
.qty { display: flex; align-items: center; gap: .4rem; flex: none; }
.qty button { width: 44px; padding: 0; font-size: 1.2rem; }
.qty b { min-width: 2ch; text-align: center; font-size: 1.15rem; font-variation-settings: 'MONO' 1; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0; align-items: center; }

.file { display: inline-flex; align-items: center; gap: .5rem; border: 1.5px dashed var(--ink); border-radius: 8px; padding: .6rem .9rem; min-height: 44px; cursor: pointer; font-weight: 600; background: var(--card); }
.file input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.photo-out { margin-top: .6rem; overflow-wrap: anywhere; }
.si { color: var(--green); } .no { color: var(--red); }

/* Hoja */
.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: .8rem; }
.sheet figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .8rem; display: grid; justify-items: center; gap: .4rem; }
.sheet svg { max-width: 100%; height: auto; }
.sheet svg text { font: 13px 'Recursive', monospace; font-variation-settings: 'MONO' 1; }
.sheet figcaption { font-size: .85rem; text-align: center; }
.sheet figcaption code { display: block; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
table.self { width: 100%; border-collapse: collapse; margin-top: .4rem; font-size: .85rem; background: var(--card); }
table.self th, table.self td { border-bottom: 1px solid var(--line); padding: .35rem .4rem; text-align: left; }
table.self td { white-space: nowrap; }

/* Equipo */
table.caps { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
table.caps td { width: 2.2rem; text-align: center; font-size: 1.2rem; font-weight: 700; border-bottom: 1px solid var(--line); }
table.caps th { text-align: left; font-weight: 600; padding: .5rem .5rem .5rem 0; border-bottom: 1px solid var(--line); }
table.caps small { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
#uaLine { font-size: .75rem; overflow-wrap: anywhere; font-variation-settings: 'MONO' 1; }

/* Lectoras */
.kbd { width: 100%; border: 2px solid var(--ink); border-radius: 10px; padding: .75rem; font-size: 1.1rem; min-height: 50px; background: var(--card); }
.kbd-log, .devs { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .35rem; }
.kbd-log li, .devs li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; }
.kbd-log code, .devs b { display: block; overflow-wrap: anywhere; }
.kbd-log small, .devs small { color: var(--muted); font-size: .82rem; }

.report { background: var(--ink); color: #dfe8df; border-radius: 10px; padding: .8rem; font-size: .75rem; overflow: auto; max-height: 60vh; white-space: pre-wrap; overflow-wrap: anywhere; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem 16px 2rem; }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .viewer { aspect-ratio: 16 / 9; }
}
@media print {
  .top, .foot, .row-btns, .lead, .hint, #selfOut { display: none !important; }
  body { background: #fff; }
  .panel { display: none !important; }
  #hoja { display: block !important; }
  .sheet figure { break-inside: avoid; border-color: #999; }
}
