/* ==========================================================================
   Code editor + live preview
   A transparent <textarea> sits exactly on top of a highlighted <pre>, so kids
   get colours while still using a plain, reliable text box.
   ========================================================================== */

.studio {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.studio.stacked { grid-template-columns: 1fr; }
@media (max-width: 900px) { .studio { grid-template-columns: 1fr; } }

.panel {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  background: var(--bg-2);
  border-bottom: 2px solid var(--line);
  font-weight: 900;
  font-size: .88rem;
  flex-wrap: wrap;
}
.panel-head .spacer { flex: 1; }
.panel-body { padding: 0; }

/* ---------------------------------------------------------------- editor */
.editor {
  --editor-font-size: 14.5px;
  --editor-line-height: 1.62;
  --editor-pad: 12px;
  position: relative;
  display: flex;
  flex-wrap: wrap;   /* the bee strip sits full-width UNDER the gutter+surface row */
  background: #fbfaff;
  min-height: 220px;
}
.editor .gutter,
.editor .surface { min-height: var(--editor-min-height, 200px); }
.editor .bee-strip { flex-basis: 100%; }
[data-theme="dark"] .editor { background: #1a1636; }

.editor .gutter {
  flex: none;
  width: 44px;
  padding: var(--editor-pad) 8px var(--editor-pad) 0;
  text-align: right;
  font-family: var(--mono);
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--bg-2) 60%, transparent);
  border-right: 2px solid var(--line);
  overflow: hidden;
  user-select: none;
  white-space: pre;
}

.editor .gutter > div { will-change: transform; }

.editor .surface {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: auto;
  max-height: var(--editor-max-height, 460px);
}

/* The highlighted <pre> is in normal flow and sets the size; the textarea is laid on top. */
.editor .layers {
  position: relative;
  min-width: 100%;
  width: max-content;
}

.editor pre.hl,
.editor textarea {
  margin: 0;
  padding: var(--editor-pad);
  font-family: var(--mono);
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  border: 0;
  min-width: 100%;
  box-sizing: border-box;
}

.editor pre.hl {
  position: relative;
  display: block;
  pointer-events: none;
  color: var(--ink);
  min-height: var(--editor-min-height, 200px);
}

.editor textarea {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--purple);
  resize: none;
  outline: none;
  overflow: hidden;
}
[data-theme="dark"] .editor textarea { caret-color: #ffd23f; }
.editor textarea::selection { background: rgba(124, 92, 255, .28); }

/* Token colours, light */
.tok-tag { color: #d6336c; }
.tok-name { color: #1971c2; font-weight: 700; }
.tok-attr { color: #e8590c; }
.tok-str { color: #2b8a3e; }
.tok-punct { color: #868e96; }
.tok-comment { color: #9aa0a6; font-style: italic; }
.tok-doctype { color: #7048e8; }
.tok-text { color: var(--ink); }
.tok-kw { color: #7048e8; font-weight: 700; }
.tok-num { color: #d9480f; }

[data-theme="dark"] .tok-tag { color: #ff8cc3; }
[data-theme="dark"] .tok-name { color: #7cc5ff; }
[data-theme="dark"] .tok-attr { color: #ffb86c; }
[data-theme="dark"] .tok-str { color: #86e5a8; }
[data-theme="dark"] .tok-punct { color: #8a83b8; }
[data-theme="dark"] .tok-comment { color: #7d76a8; }
[data-theme="dark"] .tok-doctype { color: #c9b8ff; }
[data-theme="dark"] .tok-kw { color: #c9b8ff; }
[data-theme="dark"] .tok-num { color: #ffb86c; }

/* Spelling-bee squiggle: probably-a-typo words get the classic wavy underline. */
.tok-err {
  text-decoration: underline wavy #ff5c5c 2px;
  text-underline-offset: 3px;
  text-decoration-skip-ink: none;
}

/* The bee strip: friendly live findings under the editor (typos, unclosed tags,
   syntax stumbles). Never blocks anything, it's a helper, not a gate. */
.bee-strip {
  border-top: 2px solid var(--line);
  background: rgba(255, 210, 63, .12);
  padding: 8px 14px;
  font-size: .85rem;
  font-weight: 700;
}
.bee-strip .line { padding: 2px 0; }
.bee-strip code {
  font-family: var(--mono);
  background: color-mix(in srgb, var(--bg-2) 70%, transparent);
  border-radius: 6px;
  padding: 1px 6px;
}

/* ---------------------------------------------------------------- static code samples */
pre.sample {
  margin: 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: #fbfaff;
  border: 2px solid var(--line);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  overflow-x: auto;
  tab-size: 2;
}
[data-theme="dark"] pre.sample { background: #1a1636; }
.sample-wrap { position: relative; }
.sample-wrap .caption { font-size: .82rem; color: var(--ink-soft); margin-top: 6px; font-weight: 700; }

/* ---------------------------------------------------------------- preview */
.preview-frame {
  width: 100%;
  height: var(--preview-height, 340px);
  border: none;
  background: #fff;
  display: block;
}
.preview-wrap { position: relative; background: #fff; }
[data-theme="dark"] .preview-wrap { background: #fff; }

.console-strip {
  border-top: 2px solid var(--line);
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 12.5px;
  max-height: 130px;
  overflow: auto;
  padding: 8px 12px;
}
.console-strip .line { padding: 2px 0; }
.console-strip .line.err { color: var(--red); font-weight: 700; }

.doctor {
  border-top: 2px solid var(--line);
  padding: 10px 14px;
  background: rgba(255, 210, 63, .14);
  font-size: .87rem;
  font-weight: 700;
}
.doctor .line { display: flex; gap: 8px; align-items: flex-start; }

.editor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-top: 2px solid var(--line);
  background: var(--bg-2);
}
