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

:root {
  --bg: #0b0d12;
  --bg-soft: #12151d;
  --panel: #161a24;
  --border: #262c3a;
  --text: #e8eaf1;
  --muted: #98a0b3;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #d97706;
  --radius: 12px;
}

html { scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59, 130, 246, 0.14), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(37, 99, 235, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 13, 18, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(38, 44, 58, 0.6);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-icon { width: 26px; height: 26px; }

.site-header nav { display: flex; gap: 1.4rem; }

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.site-header nav a:hover { color: var(--text); }

/* ---------- Hero ---------- */

.hero {
  text-align: center;
  padding: clamp(1.2rem, 3vw, 2.2rem) 1rem 0.8rem;
  max-width: 860px;
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(1.5rem, 3.2vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.15;
  text-wrap: balance;
}

.accent {
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: clamp(0.88rem, 1.5vw, 1rem);
  max-width: 640px;
  margin-inline: auto;
  text-wrap: balance;
}

/* ---------- Layout app ---------- */

main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.2rem;
  padding: 1.2rem clamp(1rem, 4vw, 3rem) 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
  #viewer-wrap { min-height: 55vh; }
}

#panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  align-self: start;
}

/* ---------- Toggle de modo ---------- */

#cad-toggle {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.cad {
  grid-column: span 2;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.45rem 0.3rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

/* fila inferior equilibrada: 2 botones de 3 columnas */
.cad:nth-child(4), .cad:nth-child(5) { grid-column: span 3; }

.cad.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}

.beta {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: super;
  margin-left: 0.25rem;
  color: var(--warn);
}

.cad.active .beta { color: #ffe6bf; }

#engine-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.engine {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.engine.active {
  background: #2a3348;
  color: var(--text);
}

/* ---------- Inputs y botones ---------- */

textarea {
  width: 100%;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: inherit;
  font: inherit;
  resize: vertical;
  transition: border-color 0.15s;
}

textarea:focus { outline: none; border-color: var(--accent); }
textarea::placeholder { color: #5a6274; }

.btn-primary, #export, #refine {
  padding: 0.7rem 1rem;
  border-radius: 10px;
  border: none;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: filter 0.15s, transform 0.05s;
}

.btn-primary:hover, #export:hover, #refine:hover { filter: brightness(1.1); }
.btn-primary:active { transform: translateY(1px); }

.btn-primary:disabled, #refine:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: wait;
}

#export { background: linear-gradient(180deg, #34d399, #16a34a); display: block; }
#refine { background: linear-gradient(180deg, #f59e0b, var(--warn)); }

.kbd-hint {
  color: #5a6274;
  font-size: 0.75rem;
  text-align: center;
  margin-top: -0.35rem;
}

/* ---------- Chips de ejemplo ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chip {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.chip:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Estado ---------- */

#status {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#status.working::before {
  content: "";
  width: 14px; height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#status.error { border-color: #7f1d1d; color: #fca5a5; background: rgba(127, 29, 29, 0.12); }
#spec { color: var(--muted); font-size: 0.85rem; }

/* ---------- Pairing ---------- */

#pairing {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
}

#pairing-status { display: flex; align-items: center; gap: 0.55rem; }

#pairing-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #6b7280;
  flex: none;
}

#pairing-dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(34, 197, 94, 0.7); }
#pairing-dot.off { background: var(--bad); }

#pairing-help { margin-top: 0.6rem; color: var(--muted); }
#pairing-help ol { margin: 0.4rem 0 0.4rem 1.2rem; display: grid; gap: 0.3rem; }
#pairing-help code {
  background: var(--bg);
  padding: 0.12rem 0.45rem;
  border-radius: 5px;
  color: var(--text);
}
#pair-code { font-weight: 700; letter-spacing: 0.15em; color: var(--accent-2) !important; }
#pairing-help a { color: var(--accent-2); }
.small { font-size: 0.75rem; }

.cmd-row {
  display: flex;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.cmd-row code {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--text);
}

#copy-cmd, #copy-cmd-fusion {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0 0.7rem;
  cursor: pointer;
}

#copy-cmd:hover, #copy-cmd-fusion:hover { filter: brightness(1.1); }

/* ---------- Código y refine ---------- */

#code-box {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
}

#code-box summary { cursor: pointer; color: var(--muted); }

#code {
  margin-top: 0.5rem;
  max-height: 300px;
  overflow: auto;
  font-size: 0.75rem;
  color: #c9d1e0;
  white-space: pre-wrap;
}

#refine-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

#refine-hint { color: var(--muted); font-size: 0.85rem; }

/* ---------- Visor ---------- */

#viewer-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  min-height: 480px;
}

#viewer { position: absolute; inset: 0; }

#view-toolbar {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 5;
  display: flex;
  gap: 3px;
  background: rgba(15, 17, 21, 0.75);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}

.view {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
}

.view.active { background: var(--accent); color: white; }

#view-dims {
  position: absolute;
  bottom: 0.7rem;
  right: 0.9rem;
  z-index: 5;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.8rem;
  color: #2c3646;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid #cdd5e0;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
}

#export-box { display: flex; flex-direction: column; gap: 0.45rem; }

#export { display: block; }

#export-formats {
  display: flex;
  gap: 0.35rem;
}

.fmt {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.fmt:hover { border-color: #16a34a; color: var(--text); }
.fmt:disabled { opacity: 0.5; cursor: wait; }

/* ---------- Secciones informativas ---------- */

.info {
  max-width: 1000px;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1rem, 4vw, 3rem);
}

.info h2 {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  margin-bottom: 1.4rem;
  letter-spacing: -0.01em;
}

.info-lead {
  color: var(--muted);
  margin: -0.8rem 0 1.4rem;
  max-width: 720px;
}

.modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.mode-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem;
}

.mode-card h3 { font-size: 1.1rem; }

.mode-tag {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.75rem;
  color: var(--accent-2);
  margin: 0.3rem 0 0.7rem;
  letter-spacing: 0.02em;
}

.mode-card p { color: var(--muted); font-size: 0.9rem; }
.mode-card p + p { margin-top: 0.6rem; }

.mode-note {
  font-size: 0.82rem !important;
  color: #6b7486 !important;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.mode-note a { color: var(--accent-2); }

/* ---------- Manual de comandos ---------- */

.manual-h {
  font-size: 1rem;
  margin: 1.6rem 0 0.7rem;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

table.manual {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--panel);
}

table.manual th, table.manual td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.manual tbody tr:last-child td { border-bottom: none; }

table.manual th {
  background: var(--bg-soft);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

table.manual td:first-child { color: var(--text); white-space: nowrap; }
table.manual td { color: var(--muted); }

table.manual code {
  font-family: Consolas, "Cascadia Mono", monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.08rem 0.4rem;
  font-size: 0.8rem;
  color: #a8c7ff;
  white-space: nowrap;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer a { color: var(--accent-2); }

.hidden { display: none !important; }
