:root {
  --bg: #05060f;
  --text: #dff9ff;
  --cyan: #00f0ff;
  --magenta: #ff2bd6;
  --green: #7cff6b;
  --glass: rgba(15, 20, 40, 0.65);
  --border: rgba(0, 240, 255, 0.35);

  --glow-a: rgba(255, 43, 214, 0.12);
  --glow-b: rgba(0, 240, 255, 0.12);
  --grid-line: rgba(0, 240, 255, 0.07);
  --mini-bg: rgba(5, 6, 15, 0.85);
  --mini-grid: rgba(0, 240, 255, 0.08);
  --select-bg: rgba(0, 240, 255, 0.08);
  --option-bg: #0a0f24;

  /* Cuadrícula móvil (la actualiza app.js) */
  --grid: 40px;
  --gx: 0px;
  --gy: 0px;
}

/* Tema claro */
:root[data-theme="light"] {
  --bg: #eef3fb;
  --text: #10203a;
  --cyan: #0089b5;
  --magenta: #d6149f;
  --green: #2a9d1f;
  --glass: rgba(255, 255, 255, 0.78);
  --border: rgba(0, 120, 165, 0.35);

  --glow-a: rgba(214, 20, 159, 0.08);
  --glow-b: rgba(0, 137, 181, 0.10);
  --grid-line: rgba(0, 90, 140, 0.13);
  --mini-bg: rgba(255, 255, 255, 0.9);
  --mini-grid: rgba(0, 90, 140, 0.13);
  --select-bg: rgba(0, 137, 181, 0.08);
  --option-bg: #ffffff;
}

/* Cuadrícula oculta (el segundo selector es necesario para ganarle al tema claro) */
:root.no-grid,
:root.no-grid[data-theme="light"] {
  --grid-line: transparent;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
}

/* Fondo con cuadrícula infinita y resplandor */
body {
  background-image:
    radial-gradient(circle at 20% 10%, var(--glow-a), transparent 40%),
    radial-gradient(circle at 80% 90%, var(--glow-b), transparent 40%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: auto, auto, var(--grid) var(--grid), var(--grid) var(--grid);
  background-position: 0 0, 0 0, var(--gx) var(--gy), var(--gx) var(--gy);
}

/* ===== Escenario y lienzo ===== */

/* Escenario: recibe todos los eventos del puntero */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none; /* evita scroll/zoom del navegador al usar gestos */
}

/* Lienzo: del tamaño de la ventana; app.js dibuja solo la parte visible */
#board {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== Paneles de cristal ===== */
.panel {
  position: fixed;
  z-index: 10;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.15), inset 0 0 20px rgba(0, 240, 255, 0.05);
}

/* Barra superior */
.topbar {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 10px 20px;
}

.logo {
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
}
.logo span {
  color: var(--magenta);
  text-shadow: 0 0 10px var(--magenta);
}

.actions { display: flex; gap: 8px; }

/* Botones generales */
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.actions button,
.tool,
.zoombar button {
  width: 42px;
  height: 42px;
  font-size: 20px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all 0.2s ease;
}

.actions button:hover,
.tool:hover {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.5);
  transform: translateY(-2px);
}

/* Botones tipo interruptor (cuadrícula) */
.actions button.toggle.on {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}

/* Barra lateral de herramientas */
.toolbar {
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }

.tool.active {
  background: rgba(255, 43, 214, 0.2);
  border-color: var(--magenta);
  color: var(--text);
  box-shadow: 0 0 16px rgba(255, 43, 214, 0.7);
}

/* Barra inferior de opciones */
.options {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 32px);
}

.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

input[type="color"] {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

/* Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 130px;
  height: 4px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  border-radius: 4px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px var(--cyan);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px var(--cyan);
}

input[type="checkbox"] {
  accent-color: var(--magenta);
  width: 18px;
  height: 18px;
}

/* Colores rápidos */
.swatches { display: flex; gap: 8px; }
.swatches button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
  transition: transform 0.15s ease;
}
.swatches button:hover { transform: scale(1.25); }

/* ===== Herramienta de texto ===== */

/* Opciones visibles solo cuando la herramienta de texto está activa */
.text-opts {
  display: none;
  align-items: center;
  gap: 24px;
}
.text-opts.visible { display: flex; }

select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
  cursor: pointer;
}
select option {
  background: var(--option-bg);
  color: var(--text);
}

/* Cuadro de escritura flotante */
.text-input {
  position: fixed;
  z-index: 20;
  min-width: 40px;
  padding: 0;
  margin: 0;
  line-height: 1.2;
  white-space: pre;
  background: transparent;
  outline: 1px dashed var(--cyan);
  outline-offset: 4px;
  caret-color: var(--text);
}

/* ===== Zoom ===== */
.zoombar {
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.zoombar button:hover {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.5);
}

#zoomLabel {
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--cyan);
}

/* ===== Minimapa ===== */
.minimap {
  top: 16px;
  right: 16px;
  padding: 6px;
}
.minimap.hidden { display: none; }

.mini-view {
  position: relative;
  width: 200px;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 10px;
  background:
    linear-gradient(var(--mini-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--mini-grid) 1px, transparent 1px),
    var(--mini-bg);
  background-size: 20px 20px, 20px 20px, auto;
  cursor: pointer;
  touch-action: none;
}

#miniCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Zona visible actual */
.mini-rect {
  position: absolute;
  box-sizing: border-box;
  border: 1.5px solid var(--magenta);
  background: rgba(255, 43, 214, 0.12);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.7);
  pointer-events: none;
}

/* ===== Responsivo ===== */
@media (max-width: 700px) {
  .topbar { gap: 12px; padding: 8px 12px; }
  .logo { font-size: 13px; letter-spacing: 2px; }
  .actions { gap: 5px; }
  .actions button { width: 34px; height: 34px; font-size: 17px; }
  .toolbar { padding: 8px; gap: 8px; }
  .tool { width: 38px; height: 38px; }
  .zoombar { padding: 8px; gap: 8px; }
  .zoombar button { width: 38px; height: 38px; }
  .minimap { top: 72px; right: 8px; padding: 4px; }
  .mini-view { width: 110px; }
}

/* ===== Botón activo en la barra de zoom ===== */
.zoombar button.on {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}

/* ===== Calculadora científica ===== */
.calc {
  left: 100px;
  top: 90px;
  z-index: 15;
  width: min(320px, calc(100vw - 20px));
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 10px;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}
.calc.open { display: flex; }

.calc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px;
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
  cursor: grab;
  touch-action: none; /* permite arrastrar con el dedo */
}
.calc-head:active { cursor: grabbing; }

.calc-close {
  width: 28px;
  height: 28px;
  font-size: 14px;
  background: rgba(255, 43, 214, 0.1);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}
.calc-close:hover {
  background: rgba(255, 43, 214, 0.25);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.6);
}

/* Pantalla */
.calc-screen {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  min-height: 92px;
  padding: 10px 12px;
  text-align: right;
  background: var(--mini-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: copy;
  transition: box-shadow 0.2s ease;
}
.calc-screen.copied { box-shadow: 0 0 18px var(--cyan); }

.calc-hist {
  height: 16px;
  font-size: 12px;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calc-expr {
  font-size: 20px;
  line-height: 1.3;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.calc-expr::-webkit-scrollbar { display: none; }

.calc-result {
  height: 24px;
  font-size: 16px;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Después de "=": el resultado se muestra grande */
.calc-screen.done .calc-expr {
  font-size: 30px;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
}
.calc-screen.error .calc-expr {
  color: var(--magenta);
  text-shadow: 0 0 10px var(--magenta);
}

/* Teclas */
.calc-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.ck {
  height: 40px;
  font-size: 15px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.ck:hover {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.45);
}
.ck:active { transform: scale(0.94); }

.ck.fn { color: var(--cyan); font-size: 14px; }

.ck.op {
  color: var(--magenta);
  border-color: rgba(255, 43, 214, 0.45);
  background: rgba(255, 43, 214, 0.07);
}
.ck.op:hover {
  background: rgba(255, 43, 214, 0.2);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}

/* Tecla 2nd activa */
.ck.on {
  color: var(--text);
  background: rgba(255, 43, 214, 0.25);
  border-color: var(--magenta);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.6);
}

/* Igual: ocupa dos filas */
.ck.eq {
  grid-row: span 2;
  height: auto;
  font-size: 24px;
  color: #05060f;
  font-weight: 700;
  border: none;
  background: linear-gradient(160deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.5);
}
.ck.eq:hover { box-shadow: 0 0 22px rgba(255, 43, 214, 0.7); }

@media (max-width: 700px) {
  .calc { left: 10px; top: 130px; }
  .ck { height: 36px; }
}

/* ===== Barra de selección (copiar / cortar / pegar) ===== */
.selbar {
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: none;
  gap: 6px;
  padding: 6px 8px;
}
.selbar.visible { display: flex; }

.selbar button {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.selbar button:hover:not(:disabled) {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.45);
}
.selbar button.danger {
  color: var(--magenta);
  border-color: rgba(255, 43, 214, 0.45);
}
.selbar button.danger:hover:not(:disabled) {
  background: rgba(255, 43, 214, 0.2);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}
.selbar button:disabled {
  opacity: 0.35;
  cursor: default;
}

@media (max-width: 700px) {
  .selbar {
    top: 164px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100vw - 110px);
  }
  .selbar button { padding: 0 8px; font-size: 11px; }
}

/* ===== Medidas numéricas de la selección ===== */
.measure {
  top: 140px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
}
.measure.visible { display: flex; }

.measure label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--cyan);
}

.measure input {
  width: 72px;
  height: 30px;
  padding: 0 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.measure input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.35);
}

#mLock {
  width: 34px;
  height: 30px;
  font-size: 15px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#mLock.on {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.5);
}
#mLock:disabled { cursor: default; }

@media (max-width: 700px) {
  .measure {
    top: 256px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100vw - 110px);
    gap: 6px;
  }
  .measure input { width: 58px; }
}

/* ===== Calculadora: pestañas ===== */
.calc input { user-select: text; -webkit-user-select: text; }
.calc.wide { width: min(470px, calc(100vw - 20px)); }

.calc-tabs { display: flex; gap: 6px; }
.calc-tabs button {
  flex: 1;
  height: 30px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.calc-tabs button:hover { background: rgba(0, 240, 255, 0.15); }
.calc-tabs button.active {
  color: var(--text);
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.2);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.5);
}

.calc-view { display: flex; flex-direction: column; gap: 10px; }
.calc-view[hidden] { display: none; }

/* ===== Calculadora: historial ===== */
.hist-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 2px;
}
.hist-list:empty { display: none; }

.hist-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 10px;
  background: rgba(0, 240, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.hi-expr, .hi-res {
  max-width: 100%;
  padding: 0;
  background: transparent;
  border: none;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hi-expr { font-size: 13px; opacity: 0.75; }
.hi-res  { font-size: 18px; color: var(--cyan); }
.hi-expr:hover, .hi-res:hover { text-shadow: 0 0 8px var(--cyan); opacity: 1; }

.hi-badge {
  position: absolute;
  left: 8px;
  top: 6px;
  padding: 0 5px;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--magenta);
  border: 1px solid rgba(255, 43, 214, 0.4);
  border-radius: 6px;
}

.hist-empty {
  padding: 34px 0;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  opacity: 0.6;
}
.hist-empty[hidden] { display: none; }

.hist-clear {
  height: 32px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--magenta);
  background: rgba(255, 43, 214, 0.07);
  border: 1px solid rgba(255, 43, 214, 0.45);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.hist-clear:hover:not(:disabled) {
  background: rgba(255, 43, 214, 0.2);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}
.hist-clear:disabled { opacity: 0.35; cursor: default; }

/* ===== Calculadora: gráfica ===== */
.g-funcs { display: flex; flex-direction: column; gap: 6px; }
.g-row { display: flex; align-items: center; gap: 8px; }
.g-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
}
.g-lab { flex: none; width: 48px; font-size: 12px; opacity: 0.8; }
.g-in {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.g-in:focus { border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 240, 255, 0.35); }
.g-in.bad { border-color: var(--magenta); box-shadow: 0 0 10px rgba(255, 43, 214, 0.5); }

#gCanvas {
  display: block;
  width: 100%;
  height: 240px;
  background: var(--mini-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none; /* permite arrastrar con el dedo */
}

.g-info {
  min-height: 16px;
  font-size: 12px;
  text-align: center;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-tools { display: flex; gap: 6px; }
.g-tools button {
  flex: 1;
  height: 32px;
  font-size: 13px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.g-tools button:hover {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.45);
}
#gBoard { flex: 2; color: var(--cyan); }
#gBoard.flash {
  color: #05060f;
  background: linear-gradient(160deg, var(--cyan), var(--magenta));
}

/* ===== Figuras: menú desplegable ===== */
.tool svg {
  width: 26px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linejoin: round;
  pointer-events: none;
}

.shape-menu {
  left: 90px;
  top: 200px;
  z-index: 14;
  display: none;
  flex-direction: column;
  gap: 6px;
  width: min(392px, calc(100vw - 100px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 10px;
}
.shape-menu.visible { display: flex; }

.shape-menu h4 {
  margin: 4px 2px 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
}
.shape-menu h4:first-child { margin-top: 0; }

.sm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}

.shape-menu button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px 4px;
  font-size: 10px;
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s ease;
}
.shape-menu button:hover {
  background: rgba(0, 240, 255, 0.16);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.4);
}
.shape-menu button svg {
  width: 38px;
  height: 28px;
  fill: rgba(0, 240, 255, 0.12);
  stroke: var(--cyan);
  stroke-width: 2;
  stroke-linejoin: round;
}
.shape-menu button.active {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.5);
}
.shape-menu button.active svg {
  fill: rgba(255, 43, 214, 0.15);
  stroke: var(--magenta);
}
.sm-hint {
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.4;
  opacity: 0.65;
}

/* ===== Triángulos: panel de medidas ===== */
.tripanel {
  top: 194px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.tripanel.visible { display: flex; }

.tp-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.tripanel label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--cyan);
}
.tripanel input {
  width: 74px;
  height: 30px;
  padding: 0 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.tripanel input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.35);
}

#tLock {
  width: 34px;
  height: 30px;
  font-size: 15px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#tLock.on {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.5);
}

.tp-class {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--magenta);
  text-shadow: 0 0 8px rgba(255, 43, 214, 0.5);
}
.tp-warn {
  font-size: 12px;
  color: var(--magenta);
}
.tp-warn:empty { display: none; }

@media (max-width: 700px) {
  .shape-menu { left: 64px; }
  .tripanel {
    top: 360px;
    max-width: calc(100vw - 110px);
    gap: 6px;
  }
  .tripanel input { width: 60px; }
}

/* ===== Polígonos: panel de medidas ===== */
.polypanel { max-width: calc(100vw - 32px); }
#polyFields { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tripanel input.ro { opacity: 0.6; cursor: default; background: transparent; }

#polyLock {
  width: 34px;
  height: 30px;
  font-size: 15px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#polyLock.on, .pp-free.on {
  border-color: var(--magenta);
  background: rgba(255, 43, 214, 0.18);
  box-shadow: 0 0 10px rgba(255, 43, 214, 0.5);
}
.pp-free {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  letter-spacing: 0.5px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.pp-free:hover { background: rgba(0, 240, 255, 0.16); }

/* ===== Barra de selección con Agrupar / Desagrupar ===== */
.selbar {
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(760px, calc(100vw - 260px));
}
.selbar button { padding: 0 10px; }
