:root {
  --bg: #0f1410;
  --panel: #18211b;
  --panel2: #1f2b23;
  --line: #2c3a30;
  --text: #e6efe8;
  --muted: #93a89a;
  --accent: #2ee27a;
  --accent-d: #1f7a4d;
  --warn: #ffd23f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}

.appbar {
  display: flex; align-items: center; gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.appbar strong { display: block; font-size: 15px; }
.appbar span { display: block; font-size: 11px; color: var(--muted); }

main { flex: 1; overflow: hidden; position: relative; }
.screen { position: absolute; inset: 0; overflow-y: auto; display: none; }
.screen.active { display: block; }
.pad { padding: 12px; padding-bottom: 24px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.fit { width: 100%; height: auto; border-radius: 10px; display: block; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); border-radius: 10px; padding: 11px 14px; font-size: 14px;
  font-weight: 600; cursor: pointer; flex: 1;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent-d); border-color: var(--accent-d); color: #f1fff6; }
.btn.primary:disabled { opacity: .4; }
.btn.block { display: block; width: 100%; text-align: center; }
.row { display: flex; gap: 8px; margin-top: 10px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.grid2 label, .slider { display: flex; flex-direction: column; font-size: 12.5px; color: var(--muted); gap: 4px; }
.grid2 input { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px; font-size: 16px; }
.slider { margin-top: 12px; }
.slider input { accent-color: var(--accent); }

.canvas-box { background: #0a0d0b; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 8px; }
.canvas-box canvas { width: 100%; height: auto; display: block; }

.banner {
  margin: 12px 0 0; padding: 9px 11px; font-size: 12px;
  background: rgba(255,210,63,.1); border: 1px solid rgba(255,210,63,.35);
  border-radius: 9px; color: #f3e2a8;
}

/* Visor */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chip { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; }
.chip.on { background: var(--accent-d); color: #f1fff6; border-color: var(--accent-d); }
.readout { margin-left: auto; font-size: 12.5px; color: var(--accent); font-weight: 600; }
.canvas-stage { position: absolute; inset: 49px 0 0 0; touch-action: none; background: #0a0d0b; }
#screen-view .canvas-stage canvas { width: 100%; height: 100%; display: block; }
.empty { padding: 30px 20px; text-align: center; color: var(--muted); }

/* Clasificar */
.results { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.piece-row { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.pnum { width: 26px; height: 26px; flex: none; display: grid; place-items: center; background: var(--panel2); border-radius: 7px; font-weight: 700; font-size: 13px; }
.swatch { width: 26px; height: 26px; flex: none; border-radius: 6px; border: 1px solid rgba(255,255,255,.2); }
.pzone { font-size: 18px; font-weight: 800; color: var(--accent); min-width: 44px; }
.pmeta { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }

/* Progreso */
.zone-grid { display: grid; gap: 3px; padding: 4px; }
.zone-cell { aspect-ratio: 1; border: 1px solid rgba(0,0,0,.3); border-radius: 4px; padding: 0; position: relative; cursor: pointer; }
.zone-cell.done::after { content: '✓'; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); color: var(--accent); font-weight: 800; border-radius: 4px; }

/* Escáner (cámara en vivo) */
.scan-stage { position: relative; width: 100%; height: 56vh; background: #0a0d0b; overflow: hidden; }
.scan-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.scan-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.scan-hint { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.legend .lg { display: flex; align-items: center; gap: 5px; font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; }
.seg { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.seg-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.room-input { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 10px; font-size: 15px; width: 110px; letter-spacing: 1px; }
.net { font-size: 12px; color: var(--muted); margin-left: auto; }

/* Tabbar */
.tabbar { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px 2px 10px; font-size: 10px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabbar button span { font-size: 18px; }
.tabbar button.active { color: var(--accent); }

/* Overlay de procesamiento */
.busy { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(8,12,9,.72); backdrop-filter: blur(2px); color: var(--text); }
.busy[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
