/* ═══════════════════════════════════════════════════════════
   Wrapper editorial alrededor de LifeViewer.
   Alineado al design system Chamillion:
     · DM Serif Display (display) + DM Mono (chrome)  — vía
       widget-common.css que ya las importa
     · Steel blue accent (#6b9ebb dark / #4a7a9a light)
     · Charcoal cool dark / parchment cálido light
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:           #0c0e11;
  --bg-soft:      #14171c;
  --text:         #e8e6e1;
  --text-mid:     #c8c6c1;
  --subtext:      #8a8a8e;
  --muted:        #555;
  --border:       #2a2a2e;
  --border-soft:  #1f2127;
  --accent:       #6b9ebb;
  --accent-soft:  rgba(107, 158, 187, 0.10);
  --tip-bg:       #1e1e22;
  --tip-border:   #2a2a2e;
}

[data-theme="light"] {
  --bg:           #f4e9da;
  --bg-soft:      #ede3d6;
  --text:         #1e1410;
  --text-mid:     #3d2b22;
  --subtext:      #6b5a4e;
  --muted:        #a89080;
  --border:       #d4c4b0;
  --border-soft:  #e0d4c4;
  --accent:       #4a7a9a;
  --accent-soft:  rgba(74, 122, 154, 0.10);
  --tip-bg:       #ede3d6;
  --tip-border:   #d4c4b0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html.embedded { overflow-x: hidden; }
html.embedded body { overflow-x: hidden; }

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 24px 36px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

html.embedded .standalone-only { display: none; }
html.embedded .container { padding: 14px 0 4px; gap: 16px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ── Eyebrow (mono, uppercase, tracking) ──────────────────── */
.eyebrow {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Header (standalone) ──────────────────────────────────── */
.head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}

.headline {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(28px, 3.4vw, 40px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text);
}
.headline em {
  font-style: italic;
  color: var(--accent);
}

.subtitle {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--subtext);
  margin: 4px 0 0;
  max-width: 56ch;
}

/* ── Primer (vocab) ───────────────────────────────────────── */
.primer {
  margin: 0;
  padding: 14px 16px;
  font-family: 'DM Serif Display', serif;
  font-size: 16px;
  font-style: italic;
  line-height: 1.55;
  color: var(--text-mid);
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  max-width: 64ch;
}

.term {
  cursor: help;
  font-style: normal;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.78em;
  letter-spacing: 0.04em;
  color: var(--accent);
  padding: 1px 2px;
  border-bottom: 1px dotted var(--accent);
  transition: background 160ms ease, color 160ms ease;
}
.term:hover, .term:focus-visible {
  background: var(--accent-soft);
  outline: none;
}
.term:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 1px;
  border-radius: 2px;
}

/* ── Pattern bar ──────────────────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pattern-bar {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding-top: 4px;
}

.pattern-btn {
  height: 44px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease,
    background 160ms ease, transform 80ms ease;
}
.pattern-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.pattern-btn:active { transform: translateY(1px); }
.pattern-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pattern-btn--nav {
  flex-shrink: 0;
  width: 44px;
  padding: 0 0 2px;
  font-family: 'DM Serif Display', serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--subtext);
  line-height: 1;
}

.pattern-dropdown {
  flex: 1;
  min-width: 0;
  position: relative;
}

.pattern-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 14px;
  text-align: center;
}
.pattern-trigger-tag {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding-right: 10px;
  margin-right: 2px;
  border-right: 1px solid var(--border);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}
.pattern-trigger #pattern-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pattern-chevron {
  flex-shrink: 0;
  color: var(--accent);
  transition: transform 160ms ease;
}
.pattern-trigger[aria-expanded="true"] .pattern-chevron {
  transform: rotate(180deg);
}

.pattern-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: min(60vh, 380px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 38px -16px rgba(0, 0, 0, 0.55),
              0 6px 14px -8px rgba(0, 0, 0, 0.4);
  padding: 6px 0;
  animation: pattern-panel-in 160ms ease-out;
}
@keyframes pattern-panel-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .pattern-panel { animation: none; }
  .pattern-chevron { transition: none; }
  .pattern-btn { transition: color 160ms ease, border-color 160ms ease, background 160ms ease; }
  .pattern-btn:active { transform: none; }
}

.pattern-panel .pp-group-label {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 16px 6px;
}
.pattern-panel .pp-group:first-child .pp-group-label { padding-top: 4px; }

.pattern-panel .pp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  background: transparent;
  border: none;
  text-align: left;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.pattern-panel .pp-item::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
  transition: background 120ms ease;
}
.pattern-panel .pp-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.pattern-panel .pp-item[aria-selected="true"] {
  color: var(--accent);
}
.pattern-panel .pp-item[aria-selected="true"]::before {
  background: var(--accent);
}
.pattern-panel .pp-item:focus-visible {
  outline: none;
  background: var(--accent-soft);
  color: var(--accent);
}

@media (max-width: 520px) {
  .pattern-bar { gap: 4px; }
  .pattern-btn { height: 40px; font-size: 12px; }
  .pattern-btn--nav { width: 40px; font-size: 20px; }
  .pattern-trigger { padding: 0 10px; gap: 8px; }
  .pattern-panel .pp-item { font-size: 12px; padding: 7px 14px; }
  .pattern-panel .pp-group-label { padding: 8px 14px 4px; }
}

/* En móvil estrecho la etiqueta "PATRÓN" del trigger se come ancho
 * que necesita el nombre del patrón ("Crystallization and decay" no
 * cabe). La ocultamos — el icono de chevron y el contexto bastan. */
@media (max-width: 420px) {
  .pattern-trigger-tag { display: none; }
  .pattern-trigger { padding: 0 8px; gap: 6px; }
  .pattern-btn--nav { width: 36px; font-size: 18px; }
  .pattern-btn { font-size: 11.5px; }
}

/* ── Descripción del patrón ──────────────────────────────── */
.pattern-desc {
  margin: -6px 0 0;
  font-family: 'DM Serif Display', serif;
  font-size: 14px;
  font-style: italic;
  color: var(--subtext);
  line-height: 1.55;
  max-width: 64ch;
}

.pattern-desc a {
  font-style: normal;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  margin-left: 8px;
  white-space: nowrap;
}
.pattern-desc a:hover { opacity: 0.78; }

/* ── Viewer wrapper ──────────────────────────────────────── */
.viewer {
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg);
  padding: 14px;
}
html.embedded .viewer {
  border-radius: 0;
  border-left: none;
  border-right: none;
  padding: 14px 0 0;
}

/* LifeViewer textarea — off-screen pero con layout. */
#rle {
  position: absolute;
  left: -99999px;
  top: -99999px;
  width: 800px;
  height: 100px;
}

.viewer canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  border-radius: 4px;
  /* Game of Life es por naturaleza una rejilla discreta — al escalar
   * el canvas (720×460) a anchos fraccionales (móvil), pixelated da
   * células nítidas en vez de la papilla de bilinear default. */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.credit {
  margin: 0;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: center;
  padding-top: 4px;
}
.credit a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.credit a:hover { opacity: 0.78; }

/* ── Tooltip portátil para .term ─────────────────────────── */
.tip-box {
  position: fixed;
  z-index: 9999;
  max-width: 280px;
  padding: 10px 14px;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  font-weight: 400;
  color: var(--text-mid);
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.tip-box.visible { opacity: 1; }
.tip-box b {
  color: var(--accent);
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.1em;
}

/* ── Capture mode (widget-specific) ──────────────────────── */
html.capture .pattern-hint { display: none; }
html.capture .credit { display: none; }
html.capture .term { color: var(--text); border-bottom-color: transparent; }

@media (max-width: 600px) {
  .container { padding: 22px 16px 28px; }
  .headline { font-size: 26px; }
  .subtitle { font-size: 12px; }
  .primer { font-size: 14px; padding: 12px 14px; }
  .pattern-desc { font-size: 13px; }
  #pattern { font-size: 19px; }
  .pattern-nav { width: 28px; font-size: 19px; }
  /* En embedded móvil reducimos el padding del viewer para que el
   * canvas use el ancho íntegro del iframe — cada píxel cuenta para
   * que el Game of Life se lea bien. */
  html.embedded .viewer { padding: 8px 0 0; }
  html.embedded .container { gap: 12px; padding: 10px 0 4px; }
}
