@layer views {
  /* ── code, everywhere: blocks in lessons and the tutor, and the editor's colours ── */
  .code-block {
    font-family: var(--mono); font-size: 13.5px; line-height: 1.6; tab-size: 4;
    background: var(--code-bg) !important; border: 1px solid var(--code-line); border-radius: var(--r-input);
    padding: 12px 14px; overflow-x: auto; white-space: pre; color: var(--fg);
  }
  .rich .code-block code { font-family: inherit; font-size: inherit; }
  .rich :not(pre) > code { font-family: var(--mono); font-size: .9em; }
  .tk-kw { color: var(--tk-kw); }
  .tk-str { color: var(--tk-str); }
  .tk-num { color: var(--tk-num); }
  .tk-com { color: var(--tk-com); font-style: italic; }
  .tk-fn { color: var(--tk-fn); }
  .tk-builtin { color: var(--tk-builtin); }
  .tk-const { color: var(--tk-const); }
  .tk-op { color: var(--tk-op); }

  /* ── the editor: a text box over a coloured copy of itself, line numbers to the left ── */
  .ed {
    --ed-font: 14px; --ed-line: 1.6; --ed-pad: 14px;
    position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; height: 100%;
    background: var(--code-bg); font-family: var(--mono); font-size: var(--ed-font); line-height: var(--ed-line);
  }
  .ed-gutter { overflow: hidden; padding: var(--ed-pad) 10px var(--ed-pad) 12px; border-right: 1px solid var(--code-line); user-select: none; }
  .ed-nums { display: grid; justify-items: end; color: var(--faint); will-change: transform; }
  .ed-nums span { height: calc(var(--ed-line) * var(--ed-font)); font-size: .86em; line-height: calc(var(--ed-line) * var(--ed-font)); }
  .ed-body { position: relative; min-width: 0; overflow: hidden; }
  .ed-layer { position: absolute; inset: 0 auto auto 0; min-width: 100%; pointer-events: none; will-change: transform; }
  .ed-hl, .ed-input {
    margin: 0; padding: var(--ed-pad); font: inherit; line-height: inherit; tab-size: 4;
    white-space: pre; overflow-wrap: normal; word-break: normal; letter-spacing: 0;
  }
  .ed-hl { color: var(--fg); }
  .ed-hl code { font: inherit; background: none; padding: 0; }
  .ed-input {
    position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: none; overflow: auto;
    background: transparent; color: transparent; caret-color: var(--fg); -webkit-text-fill-color: transparent;
    overscroll-behavior: contain;
    &::selection { background: color-mix(in oklch, var(--grad-b) 30%, transparent); -webkit-text-fill-color: transparent; }
  }
  .ed-mark { position: absolute; left: 0; right: 0; background: color-mix(in oklch, var(--wrong) 14%, transparent); box-shadow: inset 3px 0 0 var(--wrong); }
  .ed[data-focus] { box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--grad-b) 40%, transparent); }

  /* ── the key bar above a phone's keyboard ── */
  .keybar {
    position: fixed; z-index: 60; left: 0; right: 0; bottom: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: color-mix(in oklch, var(--surface-2) 94%, transparent);
    border-top: 1px solid var(--line-2); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    &[hidden] { display: none; }
  }
  .kb-scroll { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; &::-webkit-scrollbar { display: none; } }
  .kb-key {
    flex: none; min-width: 42px; height: 40px; padding: 0 10px; border-radius: 9px; border: 0;
    background: var(--surface); color: var(--fg); font-family: var(--mono); font-size: 16px; font-weight: 600;
    box-shadow: 0 1px 0 var(--line-2); touch-action: manipulation;
    &:active { background: var(--line-2); }
  }
  /* with the key bar up, the editor keeps its last lines above it */
  .lp:has(.keybar:not([hidden])) .ed-input { padding-bottom: 64px; }

  /* ── the output under the editor ── */
  .con { display: grid; grid-template-rows: auto minmax(0, 1fr); border-top: 1px solid var(--line); background: var(--bg); min-height: 0; }
  .lp-code { grid-template-rows: minmax(96px, 1fr) auto; }
  .con[data-open="true"] { height: min(40dvh, 340px); }
  .con-head {
    display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 14px; border: 0; background: none; color: var(--fg); text-align: left;
    & > svg { width: 14px; height: 14px; margin-left: auto; color: var(--muted); rotate: -90deg; transition: rotate var(--t-fast); }
  }
  .con[data-open="true"] .con-head > svg { rotate: 90deg; }
  .con-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--muted);
    & .spin { width: 12px; height: 12px; } }
  .con-pass { color: var(--right); }
  .con-fail { color: var(--wrong); }
  .con-body { overflow: auto; padding: 0 14px 14px; display: grid; gap: 10px; align-content: start; overscroll-behavior: contain; }
  .con[data-open="false"] .con-body { display: none; }
  .con-hint { color: var(--muted); font-size: var(--fs-body-sm); }
  .con-out, .con-error pre, .con-compare pre, .con-diff pre {
    margin: 0; font-family: var(--mono); font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
  }
  .con-out { color: var(--fg); }
  .con-error { padding: 10px 12px; border-radius: var(--r-input); background: color-mix(in oklch, var(--wrong) 9%, transparent); border: 1px solid color-mix(in oklch, var(--wrong) 30%, transparent);
    & pre { color: var(--wrong); } }
  .con-ok { display: inline-flex; align-items: center; gap: 6px; color: var(--right); font-weight: 700; font-size: var(--fs-body-sm); & svg { width: 15px; height: 15px; } }
  .con-compare { display: grid; gap: 4px; padding: 10px 12px; border-radius: var(--r-input); background: var(--surface-2); }
  .con-checks { list-style: none; display: grid; gap: 6px; }
  .con-checks li {
    display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 9px 12px; border-radius: var(--r-input);
    background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-body-sm);
    & > svg { width: 15px; height: 15px; margin-top: 2px; }
    &[data-ok="true"] > svg { color: var(--right); }
    &[data-ok="false"] { border-color: color-mix(in oklch, var(--wrong) 35%, var(--line)); }
    &[data-ok="false"] > svg { color: var(--wrong); }
    & b { font-weight: 600; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
  }
  .con-detail { display: block; color: var(--wrong); font-family: var(--mono); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
  .con-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; & > div { min-width: 0; padding: 8px 10px; border-radius: var(--r-item); background: var(--surface-2); } }
  .con-stuck { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: var(--fs-body-sm); font-weight: 600; }

  @media (max-width: 899px) {
    .con[data-open="true"] { height: min(44dvh, 380px); }
  }
  @media (pointer: coarse) {
    .ed { --ed-font: 14.5px; }
  }
}
