:root {
  --bg: #000;
  --panel: rgba(18, 18, 26, 0.96);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f2f7;
  --muted: #9a9aab;
  --accent: #00e5ff;
  --accent2: #ff2d95;
  --danger: #ff5a5a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#stage { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; background: #000; }
#stage.framed { outline: 1px dashed rgba(255, 255, 255, 0.3); outline-offset: 2px; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { touch-action: none; }

/* barra inferior */
#bar {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b));
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 6px; z-index: 20; backdrop-filter: blur(12px);
}
#bar button {
  background: none; border: 0; border-radius: 12px; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
}
#bar button b { font-size: 20px; font-weight: 400; line-height: 1.1; }
#bar button span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#bar button.active { background: rgba(0, 229, 255, 0.14); }
#bar button.active span { color: var(--accent); }
#bar button.primary { background: linear-gradient(135deg, var(--accent2), #7a3cff); }
#bar button.primary span { color: #fff; }
@media (min-width: 700px) {
  #bar { left: 50%; right: auto; transform: translateX(-50%); width: 560px; }
}

/* panel deslizable */
#sheet {
  position: fixed; left: 8px; right: 8px; bottom: calc(80px + var(--safe-b));
  max-height: 58vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 6px 16px 16px; z-index: 19; backdrop-filter: blur(12px);
  transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
  user-select: text; -webkit-user-select: text;
}
#sheet.on { transform: none; opacity: 1; pointer-events: auto; }
@media (min-width: 700px) {
  #sheet { left: 50%; right: auto; width: 560px; margin-left: -280px; }
}
#sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 6px; cursor: pointer; }
#sheet h3 { margin: 6px 0 10px; font-size: 17px; }
#sheet h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#sheet p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tile {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 22px; text-align: center; cursor: pointer;
}
.tile span { font-size: 12px; color: var(--text); }
.tile.sel { border-color: var(--accent); background: rgba(0, 229, 255, 0.12); }
.tile.big { background: linear-gradient(135deg, rgba(255, 45, 149, .25), rgba(122, 60, 255, .25)); }

.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 6px; align-items: stretch; }
.row.sel .grow { border-color: var(--accent); }
.row .grow {
  flex: 1; min-width: 0; text-align: left; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
  display: flex; flex-direction: column; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .grow small { color: var(--muted); font-size: 12px; }
.row .icon {
  width: 42px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--muted); }
.field input:not([type=range]):not([type=color]), .field textarea, .joinrow input {
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; color: var(--text); font-size: 16px;
}
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field input[type=color] { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: none; padding: 2px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; margin: 10px 0; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions button, .actions .btn, .wide, .joinrow button {
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 12px; font-size: 14px; cursor: pointer;
}
.wide { width: 100%; margin: 8px 0; font-weight: 600; background: linear-gradient(135deg, rgba(0, 229, 255, .2), rgba(122, 60, 255, .25)); }
.danger { color: var(--danger); }
.opt { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 8px 0; }
.opt p { font-size: 13px; color: #cfcfdb; }
.joinrow { display: flex; gap: 8px; }
.joinrow input { flex: 1; min-width: 0; letter-spacing: .2em; text-align: center; font-size: 20px; }
.joinrow button { background: linear-gradient(135deg, var(--accent2), #7a3cff); border: 0; font-weight: 600; }
.tips { padding-left: 18px; margin: 0; font-size: 13px; color: #cfcfdb; }
.tips li { margin: 4px 0; }

/* ajuste fino */
#nudge {
  position: fixed; right: 10px; top: calc(10px + env(safe-area-inset-top, 0px));
  z-index: 15; display: none; flex-direction: column; gap: 4px; align-items: stretch;
  background: rgba(18, 18, 26, 0.75); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
  backdrop-filter: blur(8px);
}
#nudge.on { display: flex; }
#nudge .label { font-size: 11px; background: none; border: 0; color: var(--accent); padding: 2px; }
#nudge .pad { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; }
#nudge .pad button {
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; touch-action: none;
}
#nudge .pad button.active { background: var(--accent2); }

.chip {
  position: fixed; left: 10px; top: calc(12px + env(safe-area-inset-top, 0px)); z-index: 15;
  display: none; font-size: 12px; padding: 6px 10px; border-radius: 999px;
  background: rgba(18, 18, 26, 0.8); border: 1px solid var(--line);
}
.chip.on { display: block; }
.chip.ok { color: #6dffb0; }
.chip.warn { color: #ffd166; }

/* show / proyector: ocultar controles */
body.show #bar, body.show #sheet, body.show #nudge, body.show .chip,
body[data-role=output] #bar, body[data-role=output] #sheet, body[data-role=output] #nudge, body[data-role=output] .chip { display: none !important; }
body.show #stage, body[data-role=output] #stage { cursor: none; }

#exit {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  z-index: 30; display: none; background: rgba(18, 18, 26, 0.9); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 18px; font-size: 14px;
}
#exit.on { display: block; }

#outcard {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 25;
  display: none; text-align: center; background: rgba(12, 12, 18, 0.92); border: 1px solid var(--line);
  border-radius: 24px; padding: 28px 36px; max-width: 92vw;
}
#outcard.on { display: block; }
.oc-title { font-size: 22px; font-weight: 700; }
.oc-qr { width: 220px; height: 220px; margin: 16px auto; background: #fff; border-radius: 12px; overflow: hidden; }
.oc-qr svg { width: 100%; height: 100%; display: block; }
.oc-sub { color: var(--muted); }
.oc-code { font-size: 56px; font-weight: 800; letter-spacing: .12em; margin: 6px 0; color: var(--accent); font-variant-numeric: tabular-nums; }
.oc-status { margin-top: 6px; }
.oc-hint { margin-top: 14px; font-size: 12px; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translate(-50%, 20px);
  background: rgba(30, 30, 42, 0.95); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; z-index: 40; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* hoja "Agregar forma" */
#sheet h3.center { text-align: center; font-size: 20px; margin: 8px 0 14px; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.shape-ic { font-style: normal; font-size: 30px; line-height: 1.1; }
.feature {
  display: flex; gap: 12px; align-items: center; margin-top: 12px; cursor: pointer;
  border: 1.5px solid rgba(109, 255, 176, .55); border-radius: 16px; padding: 12px;
}
.feature > i {
  font-style: normal; font-size: 24px; width: 48px; height: 48px; flex: none;
  display: grid; place-items: center; border-radius: 12px; background: #3b2fa0;
}
.feature b { display: block; }
.feature small { color: var(--muted); font-size: 12px; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0 2px; }

/* herramienta de detección / fondo de mapeo */
#vision {
  position: fixed; inset: 0; z-index: 50; background: #07070b;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
#vision .v-head { padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 4px; }
#vision .v-head b { font-size: 17px; }
#vision .v-head small { color: #cfcfdb; font-size: 13px; }
#vision .v-stage { flex: 1; min-height: 0; position: relative; }
#vision canvas { position: absolute; inset: 0; touch-action: none; }
#vision .v-tools { padding: 6px 16px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#vision .v-tools[hidden] { display: none; }
#vision .v-tools input[type=range] { width: 100%; accent-color: var(--accent); }
#vision .v-foot { display: flex; gap: 10px; padding: 10px 16px 14px; }
#vision .v-foot button {
  flex: 1; padding: 12px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07); font-weight: 600;
}
#vision .v-foot button.primary { border: 0; background: linear-gradient(135deg, var(--accent2), #7a3cff); }
#vision .v-foot button:disabled { opacity: .4; }

/* borrar */
#nudge .nudge-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
#nudge .del {
  background: rgba(255, 90, 90, .15); border: 1px solid rgba(255, 90, 90, .45);
  border-radius: 9px; width: 34px; height: 30px; font-size: 14px;
}
.row .icon.danger { color: var(--danger); }
#toast.action { pointer-events: auto; display: flex; align-items: center; gap: 10px; }
#toast button {
  background: var(--accent); color: #000; border: 0; border-radius: 8px;
  padding: 6px 12px; font-weight: 700; font-size: 14px;
}
.ask { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .6); display: grid; place-items: center; padding: 16px; }
.ask-box { background: #16161f; border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: min(340px, 100%); }
.ask-box p { margin: 0 0 16px; font-size: 16px; }
.ask-btns { display: flex; gap: 10px; }
.ask-btns button { flex: 1; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .07); font-weight: 600; }
.ask-btns .danger-fill { background: var(--danger); border: 0; color: #fff; }
