/* ==========================================================================
   In-lesson code runner (docs/CODE-RUNNER-DESIGN.md §9) — styles for the
   .lesson-exercise widget hydrated by /javascripts/runner.js. Built on the
   editorial tokens; code surfaces stay on the paper palette to match the
   lesson's own code blocks.
   ========================================================================== */

/* Flush with the prose measure — same convention as .lesson-drill. */
.lesson-exercise { margin: 34px 0; }

/* `hidden` must actually hide: class display rules would otherwise out-specify
   the UA's [hidden]{display:none} and leave collapsed chrome on screen. */
.lesson-exercise [hidden] { display: none !important; }

.lx-card {
  background: var(--surface, #fffdf9);
  border: 1px solid var(--border-strong, #d8d0bf);
  border-radius: var(--r, 12px);
  overflow: hidden;
  box-shadow: var(--shadow-1, 0 1px 2px rgba(26, 23, 18, .05));
}
.lx-card.is-solved { border-color: color-mix(in srgb, var(--good, #15803d) 45%, var(--border-strong, #d8d0bf)); }

/* ---- header ---- */
.lx-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px;
  background: var(--surface-2, #f3efe7);
  border-bottom: 1px solid var(--border, #e7e1d4);
}
.lx-title {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-body, sans-serif); font-weight: 600; letter-spacing: .01em;
  color: var(--text, #1a1712);
}
.lx-badge {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand, #0f766e); color: var(--text-on-brand, #fffdf9);
  font-size: .72rem; font-weight: 700;
}
.lx-head-right { display: flex; align-items: center; gap: 10px; }
.lx-langs {
  display: inline-flex; gap: 4px; background: var(--bg, #faf8f4);
  border: 1px solid var(--border, #e7e1d4); border-radius: 999px; padding: 2px;
}
.lx-lang {
  font: 500 .76rem/1 var(--font-body, sans-serif); padding: 5px 11px; border-radius: 999px;
  border: 0; background: transparent; color: var(--text-muted, #5e574a);
}
.lx-lang[aria-pressed="true"] { background: var(--brand, #0f766e); color: var(--text-on-brand, #fffdf9); }
.lx-local {
  font-size: .78rem; color: var(--text-faint, #8c8475);
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.lx-local b { font-weight: 600; color: var(--text-muted, #5e574a); }
.lx-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--good, #15803d); display: inline-block;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good, #15803d) 18%, transparent);
}

/* ---- body ---- */
.lx-body { padding: 16px 16px 14px; }
.lx-prompt { margin: 0 0 14px; color: var(--text, #1a1712); }

/* collapsed teaser: the starter, read-only */
.lx-teaser { position: relative; }
.lx-teaser pre {
  margin: 0; padding: 16px 18px;
  background: var(--surface-2, #f3efe7); color: var(--text, #1a1712);
  border: 1px solid var(--border, #e7e1d4); border-radius: 8px;
  font-family: var(--font-mono, monospace); font-size: .84rem; line-height: 1.6;
  overflow: hidden; max-height: 320px;
}
.lx-teaser::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 74px; border-radius: 0 0 8px 8px;
  background: linear-gradient(to bottom, rgba(243, 239, 231, 0), rgba(243, 239, 231, .97));
}
/* A short stub has nothing to hide — no clamp, no veil. */
.lx-teaser.is-short pre { max-height: none; }
.lx-teaser.is-short::after { display: none; }
.lx-teaser-cta { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.lx-teaser-note { font-size: .9rem; color: var(--text-faint, #8c8475); }

/* ---- editor ---- */
.lx-editor {
  border: 1px solid var(--border-strong, #d8d0bf); border-radius: 8px; overflow: hidden;
  background: var(--bg-elev, #fffdf9);
}
.lx-editor:empty { display: none; }
.lx-editor .cm-editor { font-family: var(--font-mono, monospace); font-size: .86rem; }
.lx-editor .cm-editor.cm-focused { outline: none; }
.lx-editor .cm-scroller { max-height: 420px; line-height: 1.6; }
.lx-fallback {
  width: 100%; min-height: 220px; border: 0; padding: 14px 16px; resize: vertical;
  background: var(--bg-elev, #fffdf9); color: var(--text, #1a1712);
  font-family: var(--font-mono, monospace); font-size: .86rem; line-height: 1.6;
}

/* ---- toolbar ---- */
.lx-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.lx-tools .spacer { flex: 1 1 auto; }
.lx-btn {
  font: 600 .84rem/1 var(--font-body, sans-serif); border-radius: 8px; padding: 10px 15px;
  border: 1px solid var(--border-strong, #d8d0bf); background: var(--bg-elev, #fffdf9);
  color: var(--text, #1a1712); cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s ease, border-color .15s ease;
}
.lx-btn:hover:not([disabled]) { background: var(--surface-2, #f3efe7); }
.lx-btn:focus-visible { outline: none; box-shadow: var(--ring, 0 0 0 3px rgba(15, 118, 110, .28)); }
.lx-btn[disabled] { opacity: .5; cursor: not-allowed; }
.lx-btn.primary {
  background: var(--brand, #0f766e); border-color: var(--brand, #0f766e);
  color: var(--text-on-brand, #fffdf9);
}
.lx-btn.primary:hover:not([disabled]) { background: var(--brand-strong, #115e59); border-color: var(--brand-strong, #115e59); }
.lx-btn.quiet { border-color: transparent; background: transparent; color: var(--text-muted, #5e574a); font-weight: 500; }
.lx-btn.quiet:hover:not([disabled]) { background: var(--surface-2, #f3efe7); color: var(--text, #1a1712); }
.lx-kbd {
  font: 500 .7rem/1 var(--font-mono, monospace); color: var(--text-faint, #8c8475);
  border: 1px solid var(--border, #e7e1d4); border-bottom-width: 2px; border-radius: 5px;
  padding: 3px 5px; background: var(--bg, #faf8f4);
}
.lx-draft { font-size: .78rem; color: var(--text-faint, #8c8475); }

/* ---- runtime boot strip ---- */
.lx-boot {
  display: none; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 13px;
  border: 1px solid var(--border, #e7e1d4); border-radius: 8px; background: var(--bg, #faf8f4);
  font-size: .9rem; color: var(--text-muted, #5e574a);
}
.lx-boot.show { display: flex; }
.lx-boot .bar { flex: 1 1 auto; height: 4px; border-radius: 4px; background: var(--surface-2, #f3efe7); overflow: hidden; }
.lx-boot .bar i {
  display: block; height: 100%; width: 34%; border-radius: 4px;
  background: var(--grad, linear-gradient(135deg, #0f766e 0%, #0d9488 100%));
  animation: lxslide 1.15s ease infinite;
}
@keyframes lxslide { 0% { margin-left: -34%; } 100% { margin-left: 100%; } }

/* ---- results ---- */
.lx-results { display: none; margin-top: 14px; border-top: 1px solid var(--border, #e7e1d4); padding-top: 14px; }
.lx-results.show { display: block; }
.lx-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.lx-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font: 600 .84rem/1 var(--font-body, sans-serif); padding: 7px 12px; border-radius: 999px;
}
.lx-pill.pass { background: color-mix(in srgb, var(--good, #15803d) 13%, transparent); color: var(--good, #15803d); }
.lx-pill.fail { background: color-mix(in srgb, var(--danger, #b91c1c) 11%, transparent); color: var(--danger, #b91c1c); }
.lx-pill.warn { background: color-mix(in srgb, var(--warn, #b45309) 13%, transparent); color: var(--warn, #b45309); }
.lx-took { font-size: .78rem; color: var(--text-faint, #8c8475); font-variant-numeric: tabular-nums; }

.lx-tests { list-style: none; margin: 0; padding: 0; }
.lx-test { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; }
.lx-test + .lx-test { margin-top: 2px; }
.lx-test.fail { background: color-mix(in srgb, var(--danger, #b91c1c) 6%, transparent); }
.lx-mark {
  flex: 0 0 auto; width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center; font-size: .62rem; font-weight: 800; margin-top: 3px; color: #fff;
}
.lx-test.pass .lx-mark { background: var(--good, #15803d); }
.lx-test.fail .lx-mark { background: var(--danger, #b91c1c); }
.lx-test-name { font-family: var(--font-mono, monospace); font-size: .8rem; color: var(--text, #1a1712); word-break: break-word; }
.lx-test-msg { font-size: .9rem; color: var(--danger, #b91c1c); margin-top: 3px; font-family: var(--font-mono, monospace); }

.lx-fatal {
  background: color-mix(in srgb, var(--danger, #b91c1c) 7%, var(--bg-elev, #fffdf9));
  color: var(--text, #1a1712); border-radius: 8px; padding: 13px 15px;
  border: 1px solid color-mix(in srgb, var(--danger, #b91c1c) 22%, transparent);
  border-left: 3px solid var(--danger, #b91c1c);
  font-family: var(--font-mono, monospace); font-size: .8rem; line-height: 1.6; white-space: pre-wrap;
}
.lx-fatal b {
  display: block; color: var(--danger, #b91c1c);
  font-family: var(--font-body, sans-serif); font-weight: 600; font-size: .9rem; margin-bottom: 6px;
}

.lx-stdout { margin-top: 12px; }
.lx-stdout summary { cursor: pointer; font-size: .9rem; color: var(--text-muted, #5e574a); font-weight: 500; }
.lx-stdout pre {
  margin: 8px 0 0; padding: 12px 14px; background: var(--surface-2, #f3efe7); border-radius: 8px;
  font-family: var(--font-mono, monospace); font-size: .8rem; line-height: 1.6; white-space: pre-wrap;
  max-height: 200px; overflow: auto; color: var(--text-muted, #5e574a);
}

.lx-win {
  display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--good, #15803d) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--good, #15803d) 28%, transparent);
  font-size: .9rem; color: var(--text, #1a1712);
}
.lx-win .tick {
  width: 22px; height: 22px; border-radius: 50%; background: var(--good, #15803d); color: #fff;
  display: grid; place-items: center; font-size: .72rem; font-weight: 800; flex: 0 0 auto;
}

@media (max-width: 720px) {
  .lx-head { flex-direction: column; align-items: stretch; gap: 9px; }
  .lx-head-right { justify-content: space-between; }
  .lx-tools .lx-kbd { display: none; }
  .lx-btn { flex: 1 1 auto; justify-content: center; }
  .lx-btn.quiet { flex-basis: auto; }
}

/* ---- attach: fences — tabbed try/solution blocks (.lesson-runnable) ---- */
.lesson-runnable { margin: 22px 0; }
.lx-tabs { display: inline-flex; gap: 4px; background: var(--bg, #faf8f4);
  border: 1px solid var(--border, #e7e1d4); border-radius: 999px; padding: 2px; }
.lx-tab {
  font: 600 .8rem/1 var(--font-body, sans-serif); padding: 7px 14px; border-radius: 999px;
  border: 0; background: transparent; color: var(--text-muted, #5e574a); cursor: pointer;
}
.lx-tab[aria-pressed="true"] { background: var(--brand, #0f766e); color: var(--text-on-brand, #fffdf9); }
.lx-tab:focus-visible { outline: none; box-shadow: var(--ring, 0 0 0 3px rgba(15, 118, 110, .28)); }
.lx-solcode pre {
  margin: 0; padding: 14px 16px; background: var(--surface-2, #f3efe7);
  border: 1px solid var(--border, #e7e1d4); border-radius: 8px;
  font-family: var(--font-mono, monospace); font-size: .84rem; line-height: 1.6; overflow-x: auto;
}
.lx-solcode pre code { background: transparent; padding: 0; }
