/* Estilos compartidos por index.html (bloques) y jr.html (JR). */

:root {
  /* Ventanas claras (matrices, monitor serie) */
  --bg: #f4f5f7; --panel: #ffffff; --fg: #1f2328; --muted: #656d76; --line: #d0d7de;
  --ok: #1a7f37; --err: #cf222e; --warn: #9a6700;
  --code-bg: #0f1522; --code-fg: #e6e6e6; --term-bg: #1f1f1f; --term-fg: #d8d8d8;
  /* Tema azul, como el editor de referencia */
  --navy-950: #111725; --navy-900: #1b2238; --navy-850: #222a44; --navy-800: #2a3352; --navy-700: #36406a;
  --violet: #5b3fd6; --violet-hover: #4c33bd; --ink: #ffffff; --ink-muted: #aab3c9;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--navy-950); color: var(--fg); font: 14px/1.45 "DM Sans", system-ui, -apple-system, sans-serif;
       display: grid; grid-template-rows: auto auto 1fr; }
body > header { grid-row: 1; } .banner { grid-row: 2; } body > main { grid-row: 3; }
.banner { padding: 10px 16px; background: #fff4d6; color: #5c4400; border-bottom: 1px solid #f0d58a; font-weight: 600; }
.banner[hidden] { display: none; }
select, button, input { font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--fg); padding: 6px 10px; }
select { max-width: 260px; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px;
         background: var(--navy-800); color: var(--ink); border-bottom: 4px solid var(--violet); }
header h1 { font-size: 17px; margin: 0 4px 0 0; letter-spacing: .01em; }
.brand { display: flex; align-items: center; }
.brand img { display: block; height: 38px; width: auto; }
#board-state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-muted); }
#board-state[hidden] { display: none; }
.board-dot { width: 9px; height: 9px; border-radius: 50%; background: #f2a33a; }
#board-state.ok .board-dot { background: #5ee08a; }
header button, header select { background: transparent; color: var(--ink); border-color: rgba(255,255,255,.28); }
header button:hover:not(:disabled) { background: rgba(255,255,255,.08); }
header select option { color: var(--fg); }
header button.primary { background: var(--violet); border-color: var(--violet); color: #fff; font-weight: 700; padding: 7px 18px; }
header button.primary:hover:not(:disabled) { background: var(--violet-hover); }
#profile-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px;
                background: #10c9a4; color: #0b2b26; font-weight: 700; font-size: 13px; }
#status { font-weight: 600; }
#status.ok { color: #5ee08a; } #status.err { color: #ff8a8a; }
.header-end { margin-left: auto; display: flex; align-items: center; gap: 8px; }

main { display: grid; grid-template-columns: 110px minmax(0, 1fr) 0; min-height: 0; }
main.code-open { grid-template-columns: 110px minmax(0, 1fr) 380px; }

/* Categorías: barra azul; la elegida se pinta entera con su color */
.cat-col { position: relative; min-height: 0; display: flex; background: var(--navy-850); }
#categories { flex: 1; display: flex; flex-direction: column; padding: 6px 0; overflow-y: auto; }
.cat-button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px 5px;
              border: 0; border-radius: 0; background: transparent; color: var(--ink); font-size: 13px; line-height: 1.2; }
.cat-button:hover { background: rgba(255,255,255,.06); }
.cat-button[aria-expanded="true"] { background: var(--cat); }
.cat-button > span:last-child { max-width: 100px; text-align: center; overflow-wrap: anywhere; }
.cat-dot { width: 17px; height: 17px; border-radius: 50%; background: var(--cat); }
/* Grupo con subcategorías (Entradas → Digitales / Analógicas): filas un poco más claras */
.cat-button.cat-group, .cat-button.cat-sub { background: rgba(255,255,255,.05); }
.cat-button.cat-group[aria-expanded="true"], .cat-button.cat-sub[aria-expanded="true"] { background: var(--cat); }
.cat-button[hidden] { display: none; }
.cat-button[aria-expanded="true"] .cat-dot { background: #fff; }

/* Tacho: aparece sobre las categorías mientras se arrastra un bloque */
#trash { position: absolute; inset: 0; z-index: 30; display: none; place-items: center; pointer-events: none;
         background: rgba(214, 218, 225, .82); }
body.dragging-block #trash { display: grid; }
#trash svg { width: 70px; height: 82px; color: #6c7383; transition: transform .12s, color .12s; }
#trash .lid { transition: transform .12s; transform-origin: 8px 14px; }
body.over-trash #trash svg { color: #d93b3b; transform: scale(1.12); }
body.over-trash #trash .lid { transform: rotate(-18deg) translateY(-3px); }

/* Botón «Crear variable…» del panel */
.blocklyFlyoutButtonBackground { fill: #f3f3f4 !important; stroke: #d0d3da !important; }
.blocklyFlyoutButton .blocklyText { fill: #575e75 !important; }
.blocklyFlyoutButtonShadow { fill: transparent !important; }
.blocklyFlyoutButton:hover .blocklyFlyoutButtonBackground { fill: #ffffff !important; }

/* Ventana para escribir el nombre de una variable */
.prompt-overlay { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 16px; background: rgba(8, 11, 20, .75); }
.prompt-dialog { width: min(900px, 100%); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px;
                 padding: 40px clamp(20px, 6vw, 80px); background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.prompt-input { flex: 0 1 240px; border: 0; border-bottom: 2px solid var(--violet); border-radius: 0; background: transparent;
                text-align: center; font-size: 19px; color: var(--violet); padding: 4px; outline: none; }
.prompt-actions { display: flex; gap: 32px; }
/* Ventana para crear funciones */
.func-dialog { flex-direction: column; align-items: stretch; padding: 0; gap: 0; width: min(1100px, 100%); }
.func-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px; padding: 40px clamp(20px, 4vw, 48px); }
.func-count { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--violet); }
.func-label { font-weight: 700; font-size: 15px; }
.func-stepper { display: flex; align-items: center; gap: 14px; }
.func-step { width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0; background: var(--violet); color: #fff; font: 700 20px/1 system-ui, sans-serif; }
.func-n { min-width: 16px; text-align: center; font-size: 22px; color: var(--violet); }
.func-types { display: grid; grid-template-columns: repeat(3, auto); }
.func-type { border: 0; border-radius: 0; background: #6b6bff; color: #fff; font-weight: 700; font-size: 13px; padding: 9px 14px; }
.func-type[aria-checked="true"] { background: #1400ff; }
.func-params { display: flex; flex-wrap: wrap; gap: 24px 36px; padding: 32px clamp(20px, 4vw, 48px) 48px; border-top: 2px solid #e2e2e8; }
.func-params[hidden] { display: none; }
.func-param { display: flex; align-items: end; }
.func-param .prompt-input { flex: 0 1 180px; width: 180px; }
.func-param-type { border: 0; border-radius: 0; background: #1400ff; color: #fff; font-weight: 700; font-size: 13px; padding: 9px 18px; }
.prompt-actions button { border: 0; background: transparent; color: var(--violet); font-weight: 700; font-size: 19px; padding: 6px; }

/* Bloque que se arrastra: semitransparente, para ver dónde va a quedar */
.blocklyDragging, .blocklyBlockDragSurface > g { opacity: .62; }

/* Lienzo y panel de bloques en azul */
.stage { position: relative; min-height: 0; min-width: 0; }
#workspace { position: absolute; inset: 0; }
.blocklyMainBackground { fill: var(--navy-950) !important; stroke: none !important; }
.blocklyFlyoutBackground { fill: var(--navy-850) !important; fill-opacity: 1 !important; }
.blocklyScrollbarHandle { fill: var(--navy-700) !important; }
.flyout-title .blocklyFlyoutLabelText, .blocklyFlyoutLabelText { fill: #fff !important; font-size: 19px !important; font-weight: 700 !important; }
.blocklyText, .blocklyDropdownText { font-weight: 700 !important; }
#code-toggle { position: absolute; top: 12px; right: 14px; z-index: 20; width: 48px; height: 48px; border-radius: 50%;
               border: 0; background: var(--violet); color: #fff; font: 700 18px/1 ui-monospace, Menlo, monospace;
               box-shadow: 0 2px 8px rgba(0,0,0,.35); white-space: nowrap; padding: 0; }
#code-toggle[aria-expanded="true"] { background: #3d2aa3; }
#warn-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
              background: #e8a317; color: #1f2328; font: 700 12px/20px system-ui, sans-serif; }
#warn-badge:empty { display: none; }

aside { display: none; flex-direction: column; min-height: 0; min-width: 0; background: var(--navy-900); color: var(--ink); }
main.code-open aside { display: flex; }
aside h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); margin: 0; padding: 10px 12px 6px; }
#code { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 10px 12px; background: var(--code-bg); color: var(--code-fg);
        font: 12.5px/1.5 ui-monospace, Menlo, monospace; white-space: pre; }
#warnings { margin: 0; padding: 0 12px; list-style: none; color: #f2c14e; font-size: 13px; }
#warnings li { padding: 4px 0; }
#warnings li::before { content: "⚠ "; }
details { border-top: 1px solid rgba(255,255,255,.1); }
summary { cursor: pointer; padding: 8px 12px; color: var(--ink-muted); font-size: 13px; }
#log { margin: 0; padding: 0 12px 10px; max-height: 200px; overflow: auto; white-space: pre-wrap; font: 12px/1.4 ui-monospace, Menlo, monospace; color: var(--ink-muted); }

/* Ventana «Seleccioná un perfil» */
.profile-overlay { position: fixed; inset: 0; z-index: 1100; display: grid; place-items: center; padding: 16px; background: rgba(8, 11, 20, .7); }
.profile-dialog { width: min(1080px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
                  background: var(--navy-900); color: var(--ink); border-radius: 6px; overflow: hidden; box-shadow: 0 16px 50px rgba(0,0,0,.5); }
.profile-head { position: relative; padding: 18px 56px; background: #8774f7; text-align: center; }
.profile-head h2 { margin: 0; font-size: 24px; font-weight: 500; }
.profile-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: #fff; font-size: 22px; }
.profile-tabs { display: flex; justify-content: center; background: #7a63ea; }
.profile-tabs span { padding: 14px 18px 12px; font-weight: 700; letter-spacing: .04em; border-bottom: 3px solid #fff; }
.profile-grid { flex: 1; min-height: 0; overflow: auto; padding: 24px 32px; display: grid; gap: 24px;
                grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.profile-card { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 18px 20px 20px;
                border: 0; border-radius: 4px; background: var(--navy-800); color: var(--ink); text-align: left; }
.profile-card:hover:not(:disabled) { background: var(--navy-700); }
.profile-card[aria-checked="true"] { background: #10c9a4; }
.profile-card:disabled { opacity: .45; }
.profile-card strong { font-size: 20px; letter-spacing: .02em; }
.profile-tag { padding: 2px 10px; border-radius: 3px; background: #10c9a4; color: #fff; font-size: 17px; }
.profile-card[aria-checked="true"] .profile-tag { background: #fff; color: #111; }
.profile-check { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%; display: none;
                 place-items: center; background: #fff; color: #10c9a4; font-weight: 900; }
.profile-card[aria-checked="true"] .profile-check { display: grid; }
.profile-foot { display: flex; justify-content: flex-end; padding: 16px 32px; background: #1a2135; }
.profile-start { border: 0; border-radius: 4px; background: #fff; color: var(--navy-900); font-weight: 800; font-size: 19px; padding: 10px 26px; }
/* Tapa dibujada del libro */
.book { align-self: center; position: relative; width: 104px; height: 140px; border-radius: 2px 6px 6px 2px; background: #eceef2;
        box-shadow: inset 6px 0 0 #d4d7de, 4px 4px 10px rgba(0,0,0,.35); padding: 10px 10px 0 12px; overflow: hidden; }
.book-logo { font: 700 13px/1.05 system-ui, sans-serif; color: #6d6f7a; }
.st-s { display: inline-block; padding: 0 3px; background: #8b5cf6; color: #fff; border-radius: 2px; margin-right: 1px; }
.st-team i { display: inline-block; width: 14px; text-align: center; font-style: normal; color: #fff; margin-right: 1px; }
.st-team i:nth-child(1) { background: #22b8cf; } .st-team i:nth-child(2) { background: #f59f00; }
.st-team i:nth-child(3) { background: #40c057; } .st-team i:nth-child(4) { background: #e8590c; }
.book-num { position: absolute; top: 8px; right: 8px; min-width: 20px; padding: 1px 4px; border-radius: 3px; background: #8b5cf6;
            color: #fff; font: 800 16px/1.2 system-ui, sans-serif; text-align: center; }
.book-art { position: absolute; left: 12px; right: 8px; bottom: 12px; height: 66px; border-radius: 4px;
            background: linear-gradient(160deg, #9ad0f5 0%, #c7e7c1 55%, #8cc472 100%); }
.book-all { display: grid; place-items: center; background: var(--violet); box-shadow: 4px 4px 10px rgba(0,0,0,.35); padding: 0; }
.book-all span { color: #fff; font: 800 34px/1 ui-monospace, Menlo, monospace; }

/* Ventanas (editor de matrices y monitor serie) */
.matrix-overlay, .serial-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px;
                  background: rgba(15, 17, 22, .55); }
.matrix-dialog, .serial-dialog { background: var(--panel); color: var(--fg); border-radius: 12px; padding: 18px; max-width: 100%;
                 box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.matrix-dialog h2, .serial-dialog h2 { margin: 0 0 4px; font-size: 18px; }
/* Editor de la matriz, como el del editor de referencia */
.matrix-overlay { background: rgba(8, 11, 20, .82); }
.matrix-overlay .matrix-dialog { position: relative; background: transparent; box-shadow: none; padding: 44px 0 0; color: #fff;
                                 display: flex; flex-direction: column; align-items: center; gap: 0; }
.matrix-close { position: absolute; top: 0; left: 50%; transform: translateX(-50%); border: 0; background: transparent;
                color: #fff; font-size: 30px; line-height: 1; padding: 4px 10px; }
.matrix-grid { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: clamp(4px, 1.1vw, 16px);
               padding: clamp(14px, 3vw, 40px); background: #3a4258; border: 1px solid #4b546d; border-radius: 10px;
               box-shadow: 0 10px 30px rgba(0,0,0,.45); touch-action: none; user-select: none;
               width: min(calc(var(--cols) * 76px), calc(100vw - 32px)); }
.matrix-cell { aspect-ratio: 3 / 2; padding: 0; border: 0; border-radius: 6px; background: #a8a9ae; cursor: pointer;
               box-shadow: 0 3px 6px rgba(0,0,0,.25); }
.matrix-cell.on { background: #5ec8f2; box-shadow: 0 0 10px rgba(94,200,242,.7); }
.matrix-cell:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.matrix-carousel { display: flex; align-items: center; gap: clamp(8px, 2vw, 24px); padding: 20px clamp(12px, 3vw, 34px);
                   background: #13264a; width: min(730px, calc(100vw - 32px)); justify-content: center; }
.matrix-nav { width: 36px; height: 36px; flex: none; border-radius: 50%; border: 0; background: #fff; color: #13264a;
              font: 900 26px/1 system-ui, sans-serif; padding: 0 0 3px; }
.matrix-thumbs { display: flex; gap: clamp(8px, 2vw, 20px); min-width: 0; }
.matrix-thumb { flex: 1 1 0; min-width: 0; width: 170px; padding: 0; border: 0; border-radius: 2px; background: #3a4258; }
.matrix-thumb:hover { outline: 2px solid #5ec8f2; }
.matrix-thumb svg { display: block; width: 100%; height: auto; }
.matrix-tools { display: flex; align-items: center; gap: 18px; padding-top: 22px; }
.matrix-tool { display: grid; place-items: center; width: 64px; height: 64px; padding: 6px; border-radius: 6px;
               border: 3px solid transparent; color: #fff; }
.matrix-tool svg { width: 100%; height: 100%; }
.tool-faces { background: #4d9ff5; } .tool-shapes { background: #f5be3c; }
.matrix-tool.active { border-color: #fff; }
.tool-plain { background: transparent; width: 44px; height: 44px; }
.serial-overlay[hidden] { display: none; }
.serial-dialog { width: min(900px, 100%); display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 32px); }
.serial-head { display: flex; align-items: center; gap: 12px; }
.serial-head h2 { margin: 0; flex: 1; }
.serial-state { font-size: 13px; color: var(--muted); }
.serial-state.ok { color: var(--ok); } .serial-state.err { color: var(--err); }
.serial-send { display: flex; gap: 8px; }
.serial-send input { flex: 1; min-width: 0; }
.serial-out { margin: 0; height: min(420px, 50vh); overflow: auto; padding: 10px 12px; border-radius: 8px;
              background: var(--term-bg); color: var(--term-fg); font: 13px/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-all; }
.serial-options { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.serial-options label { display: flex; align-items: center; gap: 6px; }

@media (max-width: 820px) {
  main, main.code-open { grid-template-columns: 1fr; grid-template-rows: auto 62vh auto; }
  #categories { flex-direction: row; padding: 0 4px; }
  .cat-button { min-width: 84px; }
  #code { max-height: 40vh; }
  .header-end { margin-left: 0; width: 100%; }
}

/* Ventana de perfiles por pasos (modo → libro → capítulo) */
.profile-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.profile-back { position: absolute; top: 18px; right: 24px; z-index: 1; width: 52px; height: 52px; border: 0; border-radius: 4px;
                background: #fff; color: var(--navy-900); font: 700 26px/1 system-ui, sans-serif; }
.profile-back[hidden] { display: none; }
.profile-body .profile-grid { padding-top: 84px; }
.profile-start[hidden] { display: none; }
.mode-art { align-self: center; width: 140px; height: 140px; border-radius: 8px; background: #1b2238; display: flex; padding: 16px; gap: 6px; }
.mode-jr { align-items: center; justify-content: center; }
.mode-jr i { width: 28px; height: 34px; border-radius: 5px; }
.mode-bloques { flex-direction: column; justify-content: center; }
.mode-bloques i { height: 18px; border-radius: 4px; }
