/* Patrones — estilo de Componentes (MIRÓ Labs), como Tipos: letra del sistema, bordes suaves, esquinas redondeadas,
   seleccionado como pastilla sobre fondo gris, tema claro y oscuro (clase .dark en <html>).
   Los colores salen de tokens.css (copiado de ~/dev/componentes). El patrón del lienzo no cambia con el tema.
   Escritorio: vista previa fija + panel de secciones desplegables. Móvil: apilado con barra de acciones fija. */

:root {
  /* nombres propios de Patrones; --muted y --accent quedan para los tokens de Componentes (fondos tenues) */
  --paper: var(--background);
  --ink: var(--foreground);
  --soft: var(--muted-foreground);
  --rule: var(--border);
  --rule-strong: var(--input);
  --well: color-mix(in srgb, var(--background), var(--color-black) 2.5%);
  --dots: color-mix(in srgb, var(--foreground) 6%, transparent);
  --error: var(--destructive-foreground);
  --r-sm: 7px;
  --r: 9px;
  --r-lg: 14px;
  --gap: 16px;
  --pad: 24px;
  --panel: clamp(360px, 30vw, 440px);
  --t-micro: 12px;
  --t-body: 14px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --lift: 0 1px 2px #0000000d;
}
.dark { --well: color-mix(in srgb, var(--background), var(--color-white) 3%); --lift: 0 1px 2px #00000040; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); }
html { color-scheme: light; }
html.dark { color-scheme: dark; }
body { color: var(--ink); font: var(--t-body)/1.5 var(--font-sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button, summary, label, input[type=range] { touch-action: manipulation; }
button { cursor: pointer; }
h1, h2, p, fieldset, legend, ul { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
ul { list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: absolute; left: var(--gap); top: 8px; z-index: 30; padding: 8px 12px; border-radius: var(--r); background: var(--ink); color: var(--paper); font-size: var(--t-micro); text-decoration: none; transform: translateY(-200%); }
.skip:focus { transform: none; }

/* ---------- estructura ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "bar bar" "stage panel"; height: 100dvh; }

.bar { grid-area: bar; display: flex; align-items: center; justify-content: space-between; gap: var(--gap); height: 56px; padding: 0 var(--gap) 0 var(--pad); border-bottom: 1px solid var(--rule); background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 20px; height: 20px; fill: currentColor; flex: none; }
.brand h1 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.tagline { color: var(--soft); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-end { display: flex; align-items: center; gap: 4px; flex: none; }
.home { font-size: 13px; color: var(--soft); text-decoration: none; padding: 0 8px; line-height: 34px; border-radius: var(--r); }
.home:hover { color: var(--ink); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: var(--r); background: transparent; color: var(--soft); }
.icon-btn:hover { background: var(--accent); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.dark .icon-sun, :root:not(.dark) .icon-moon { display: none; }

/* idioma: pastilla sobre fondo gris, como en Componentes */
.lang { display: inline-flex; padding: 2px; border-radius: var(--r); background: var(--muted); }
.lang button { border: 0; background: none; height: 28px; min-width: 32px; padding: 0 10px; border-radius: var(--r-sm); font-size: 12px; font-weight: 500; color: var(--soft); white-space: nowrap; }
.lang button:hover { color: var(--ink); }
.lang button[aria-pressed=true] { background: var(--paper); color: var(--ink); box-shadow: var(--lift); }
.dark .lang button[aria-pressed=true] { background: var(--input); }

/* ---------- vista previa ---------- */
.stage { grid-area: stage; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 14px; min-height: 0; padding: var(--pad); background: var(--well); background-image: radial-gradient(var(--dots) 1px, transparent 1px); background-size: 16px 16px; }
.frame { position: relative; min-height: 0; }
#posterCanvas { position: absolute; inset: 0; margin: auto; display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; background: var(--paper); border-radius: 3px; box-shadow: 0 0 0 1px var(--rule), 0 12px 32px -12px #00000030; }
.stage.dragover { outline: 2px dashed var(--ring); outline-offset: -12px; }
.caption { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: var(--t-micro); color: var(--soft); font-variant-numeric: tabular-nums; }
#variantLabel { color: var(--ink); font-weight: 500; }
kbd { font: 11px var(--font-sans); padding: 1px 5px; margin-right: 4px; border: 1px solid var(--rule); border-radius: 5px; color: var(--soft); }

/* ---------- panel ---------- */
.panel { grid-area: panel; display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; border-left: 1px solid var(--rule); background: var(--paper); }
.panel:focus { outline: none; }
.panel-body { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }

/* sección desplegable, como el acordeón de Componentes: el encabezado muestra el valor actual */
.sec { border-bottom: 1px solid var(--rule); }
.sec summary { display: grid; grid-template-columns: auto minmax(0, 1fr) 16px; align-items: center; gap: 12px; min-height: 52px; padding: 0 var(--pad); cursor: pointer; list-style: none; user-select: none; }
.sec summary::-webkit-details-marker { display: none; }
.sec summary:hover h2 { text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--rule-strong); }
.sec summary:focus-visible { outline-offset: -2px; border-radius: var(--r); }
.sec h2 { font-size: var(--t-body); font-weight: 500; }
.n { display: none; }
.val { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; font-size: 13px; color: var(--soft); white-space: nowrap; overflow: hidden; }
.val > span { overflow: hidden; text-overflow: ellipsis; }
.chev { width: 7px; height: 7px; justify-self: center; border-right: 1.5px solid var(--soft); border-bottom: 1.5px solid var(--soft); transform: translateY(-2px) rotate(45deg); transition: transform .2s var(--ease); }
.sec[open] > summary .chev { transform: translateY(2px) rotate(-135deg); }
.sec-inner { padding: 0 var(--pad) var(--pad); }
.stack { display: grid; gap: 20px; }
.note { font-size: var(--t-micro); color: var(--soft); line-height: 1.45; margin-bottom: 10px; }
.note.warn { color: var(--error); }
.message { font-size: var(--t-micro); color: var(--error); margin-top: 8px; }
.message:empty { display: none; }

/* 01 portada: tipo de objeto, subir imagen, ejemplos, recorte y cuentagotas */
.kind-field { margin-bottom: 12px; }
.dropzone { position: relative; display: grid; place-items: center; gap: 2px; min-height: 96px; padding: 12px; border: 1px dashed var(--rule-strong); border-radius: var(--r-lg); text-align: center; color: var(--soft); cursor: pointer; transition: border-color .15s, background-color .15s; }
.dropzone:hover { border-color: var(--ring); background: var(--accent); }
.dropzone.dragover { border-color: var(--ring); background: var(--accent); }
.dropzone:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone u { color: var(--ink); text-underline-offset: 3px; }
.dropzone small { font-size: var(--t-micro); color: var(--soft); }
.examples-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: var(--t-micro); color: var(--soft); }
.examples { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.example { width: 38px; height: 38px; padding: 0; border: 0; border-radius: var(--r-sm); background: none; }
.example img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--rule); opacity: .75; transition: opacity .15s; }
.example:hover img, .example[aria-pressed=true] img { opacity: 1; }
.example[aria-pressed=true] img { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.credit { margin: 8px 0 0; }
.credit a, .agent-docs a { color: var(--ink); text-underline-offset: 2px; }
.cover-thumb { width: 18px; height: 18px; object-fit: cover; flex: none; border-radius: 4px; }
.source { margin-top: 16px; display: grid; gap: 10px; }
.source .note { margin: 0; }
#sourceCanvas { display: block; margin: 0 auto; border-radius: var(--r-sm); cursor: crosshair; touch-action: none; box-shadow: 0 0 0 1px var(--rule); }
#sourceCanvas.picking { cursor: copy; }

/* 02 patrón: radios nativos (flechas del teclado incluidas) con miniatura en vivo */
.pattern-groups { display: grid; gap: var(--gap); }
.family-label { display: block; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); margin-bottom: 8px; }
.pattern-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px 8px; }
.pattern-card { position: relative; display: grid; gap: 6px; min-width: 0; cursor: pointer; font-size: var(--t-micro); line-height: 16px; color: var(--soft); }
.pattern-card input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.pattern-card canvas { display: block; width: 100%; aspect-ratio: 1; border-radius: var(--r); background: var(--well); box-shadow: 0 0 0 1px var(--rule); transition: box-shadow .15s; }
.pattern-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pattern-card:hover canvas { box-shadow: 0 0 0 1px var(--rule-strong); }
.pattern-card:has(input:checked) { color: var(--ink); font-weight: 500; }
.pattern-card:has(input:checked) canvas { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.pattern-card:has(input:focus-visible) canvas { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ring); }
#patternThumb { width: 18px; height: 18px; flex: none; border-radius: 4px; box-shadow: 0 0 0 1px var(--rule); }

/* 03 composición: control segmentado = grupo de radios, pastilla sobre fondo gris */
.field legend, .field > label, .range-head { display: flex; justify-content: space-between; width: 100%; margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--ink); }
.segmented { display: flex; padding: 2px; border-radius: var(--r); background: var(--muted); }
.segmented label { position: relative; flex: 1; min-width: 0; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented span { display: grid; place-items: center; height: 30px; padding: 0 8px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--soft); white-space: nowrap; transition: background-color .15s, color .15s; }
.segmented label:hover span { color: var(--ink); }
.segmented input:checked + span { background: var(--paper); color: var(--ink); box-shadow: var(--lift); }
.dark .segmented input:checked + span { background: var(--input); }
.segmented input:focus-visible + span { outline: 2px solid var(--ring); outline-offset: 0; }
.kinds span { height: 36px; padding: 0 4px; font-size: var(--t-micro); white-space: normal; text-align: center; line-height: 14px; }
.range-head output { color: var(--soft); font-weight: 400; }
input[type=range] { display: block; width: 100%; height: 24px; margin: 0; accent-color: var(--ink); cursor: pointer; }

/* 04 colores */
.swatches { display: flex; height: 36px; border-radius: var(--r); box-shadow: 0 0 0 1px var(--rule); }
.swatches label { position: relative; flex-basis: 0; min-width: 12px; cursor: pointer; }
.swatches label:first-child { border-radius: var(--r) 0 0 var(--r); }
.swatches label:last-child { border-radius: 0 var(--r) var(--r) 0; }
.swatches label:only-child { border-radius: var(--r); }
.swatches input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.swatches label:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; z-index: 1; }
.palette-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 12px; margin-top: 12px; font-size: var(--t-micro); color: var(--ink); font-variant-numeric: tabular-nums; }
.palette-legend li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.palette-legend i { width: 10px; height: 10px; flex: none; border-radius: 3px; box-shadow: 0 0 0 1px var(--rule); }
.palette-legend em { font-style: normal; color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-legend li .remove { margin-left: auto; flex: none; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--soft); line-height: 1; }
.palette-legend li .remove:hover { background: var(--accent); color: var(--ink); }
.mini-bar { display: flex; width: 64px; height: 10px; flex: none; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--rule); }
.mini-bar i { display: block; height: 100%; }

/* 05 datos: campos como el input de Componentes */
.fields { display: grid; grid-template-columns: minmax(0, 1fr) 88px; gap: 14px 12px; }
.fields .wide { grid-column: 1 / -1; }
.fields input { display: block; width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--input); border-radius: var(--r); background: var(--paper); box-shadow: var(--lift); transition: border-color .15s, box-shadow .15s; }
.dark .fields input { background: var(--muted); }
.fields input:hover { border-color: var(--rule-strong); }
.fields input:focus-visible { outline: 0; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent); }
::placeholder { color: color-mix(in srgb, var(--muted-foreground) 72%, transparent); }

/* 06 motion */
.progress { height: 4px; border-radius: 4px; background: var(--muted); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--ink); transition: width .15s linear; }
#motionStatus { color: var(--soft); margin-top: 0; }
#motionStatus.err { color: var(--error); }

/* 07 para agentes */
.recipe { max-height: 220px; overflow: auto; padding: 12px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--well); font: var(--t-micro)/1.45 var(--font-mono); color: var(--ink); white-space: pre; tab-size: 2; }
.recipe:focus-visible { outline-offset: -1px; }
.agent-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.agent-actions.two { grid-template-columns: 1fr 1fr; }
.stack > .agent-actions, .source > .agent-actions { margin-top: 0; }
.agent-docs { margin: 10px 0 0; }
#agentStatus { color: var(--soft); }

/* acciones: siempre visibles al pie del panel; botones como el de Componentes (primario y contorno) */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px var(--pad); border-top: 1px solid var(--rule); background: var(--paper); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; height: 40px; padding: 0 14px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--popover); color: var(--ink); font-size: var(--t-body); font-weight: 500; white-space: nowrap; box-shadow: var(--lift); transition: background-color .15s, transform .15s; }
.btn:hover { background: var(--accent); }
.btn:active { transform: scale(.98); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.btn.primary:hover { background: color-mix(in srgb, var(--primary) 90%, var(--background)); }
.btn.sm { height: 32px; padding: 0 8px; font-size: 13px; }
.btn:disabled { cursor: progress; opacity: .65; }
.privacy { padding: var(--gap) var(--pad); font-size: var(--t-micro); color: var(--soft); line-height: 1.45; }

/* ---------- móvil y tablet ---------- */
@media (max-width: 899px) {
  .app { display: block; height: auto; }
  .bar { position: sticky; top: 0; z-index: 10; padding: 0 var(--gap); padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .tagline { display: none; }
  .lang button { height: 36px; min-width: 38px; }
  .icon-btn { width: 40px; height: 40px; }
  .home { line-height: 40px; }
  .stage { padding: var(--gap); }
  .frame { display: grid; place-items: center; }
  #posterCanvas { position: static; max-height: 58svh; }
  .hint { display: none; }
  .panel { display: block; border-left: 0; }
  .panel-body { overflow: visible; }
  .sec summary, .sec-inner { padding-left: var(--gap); padding-right: var(--gap); }
  .actions { position: sticky; bottom: 0; z-index: 10; padding: 10px var(--gap) calc(10px + env(safe-area-inset-bottom)); }
  .privacy { padding: var(--gap); }
  .fields input { font-size: 16px; } /* evita el zoom automático de iOS */
  .segmented span { height: 40px; }
  .btn.sm { height: 40px; }
  /* los patrones en una tira horizontal: la página no crece */
  .pattern-groups { display: flex; gap: 20px; overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: var(--gap); margin: 0 calc(var(--gap) * -1); padding: 4px var(--gap) 8px; scrollbar-width: none; }
  .pattern-groups::-webkit-scrollbar { display: none; }
  .pattern-groups > div { flex: none; scroll-snap-align: start; }
  .pattern-grid { display: flex; gap: 10px; }
  .pattern-card { width: 64px; }
}
@media (max-width: 380px) { .home { display: none; } }
@media (hover: none) { .hint { display: none; } .dropzone:hover { background: none; } .icon-btn:hover { background: transparent; } .btn:hover { background: var(--popover); } .btn.primary:hover { background: var(--primary); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; } }
@media (forced-colors: active) { .segmented input:checked + span, .lang button[aria-pressed=true] { outline: 2px solid CanvasText; } .pattern-card:has(input:checked) canvas, .example[aria-pressed=true] img { outline: 3px solid Highlight; } }

/* 04 colores: las 348 combinaciones de Sanzo Wada (como en Tipos) */
.seg { display: inline-flex; padding: 2px; border-radius: var(--r); background: var(--muted); }
.seg button { border: 0; background: none; height: 28px; min-width: 30px; padding: 0 8px; border-radius: var(--r-sm); font-size: 12px; font-weight: 500; color: var(--soft); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed=true] { background: var(--paper); color: var(--ink); box-shadow: var(--lift); }
.dark .seg button[aria-pressed=true] { background: var(--input); }
.wada-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.wada-title { font-size: 13px; font-weight: 500; margin-right: auto; }
.wada-bar .btn.sm { width: auto; }
.wada-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px 6px; max-height: 260px; overflow-y: auto; scrollbar-width: thin; padding: 4px; margin-bottom: 8px; }
.wtl { content-visibility: auto; contain-intrinsic-size: auto 52px; display: grid; gap: 3px; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.wtl .sw { display: flex; height: 34px; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 1px var(--rule); }
.wtl .sw i { flex: 1; }
.wtl small { font-size: 11px; line-height: 13px; color: var(--soft); font-variant-numeric: tabular-nums; }
.wtl:hover .sw { box-shadow: 0 0 0 1px var(--rule-strong); }
.wtl[aria-pressed=true] .sw { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink); }
.wtl[aria-pressed=true] small { color: var(--ink); font-weight: 500; }
#wadaCredit { margin: 0 0 14px; }
#wadaCredit a { color: var(--ink); text-underline-offset: 3px; }
.field-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 500; }
