/* QORM Playground — editor module chrome (loaded by editor.js).
   Shell tokens come from playground.css (--pg-*); the fallbacks below mirror
   them so the editor also renders correctly when mounted standalone.
   This is a normal online page component: no service worker, no offline
   caching (the sw in ../demo/ belongs to the offline demo only). */

.qe {
  --qe-mono: var(--pg-mono, ui-monospace, 'SF Mono', SFMono-Regular, Menlo,
                   Consolas, 'Liberation Mono', monospace);
  display: flex;
  flex-direction: row;
  min-height: 0;
  height: 100%;
  background: var(--pg-panel-2, #1e1e26);
  color: var(--pg-text, #e8e8ee);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', sans-serif;
  overflow: hidden;
}
/* Main column: tab strip, editor body, status bar (right of the file tree). */
.qe-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---- file tree (left sidebar) ---- */
.qe-tree {
  flex: none;
  width: 178px;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0 14px;
  background: rgba(0, 0, 0, 0.18);
  border-right: 1px solid var(--pg-border, #2a2a33);
  user-select: none;
}
.qe-tree-dir {
  padding: 8px 12px 3px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--pg-text-2, #94949f);
  opacity: 0.85;
}
.qe-tree-item {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 12px 4px 20px;
  border-left: 2px solid transparent;
  font: inherit;
  font-size: 12px;
  font-family: var(--qe-mono);
  color: var(--pg-text-2, #94949f);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.qe-tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.qe-tree-item:hover { color: var(--pg-text, #e8e8ee); background: rgba(255, 255, 255, 0.035); }
.qe-tree-item:focus-visible { outline: 2px solid var(--pg-accent, #0a84ff); outline-offset: -2px; }
.qe-tree-item.qe-active {
  color: var(--pg-accent, #0a84ff);
  font-weight: 600;
  background: rgba(10, 132, 255, 0.08);
  border-left-color: var(--pg-accent, #0a84ff);
}
.qe-tree-item.qe-err .qe-badge { display: inline-block; animation: qe-pop 0.18s ease; }
/* Very narrow splits (phone-width playground): the tree hides rather than
   squeeze the editor; the tab strip above still lists every file. */
@media (max-width: 760px) { .qe-tree { display: none; } }

/* ---- file row (tabs) ---- */
.qe-tabs {
  flex: none;
  display: flex;
  align-items: stretch;
  background: rgba(0, 0, 0, 0.28);
  border-bottom: 1px solid var(--pg-border, #2a2a33);
}
.qe-tabstrip {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.qe-tabstrip::-webkit-scrollbar { display: none; }
.qe-tab {
  flex: none;
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px 8px;
  font: inherit;
  font-size: 12px;
  color: var(--pg-text-2, #94949f);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.qe-tab:hover { color: var(--pg-text, #e8e8ee); background: rgba(255, 255, 255, 0.035); }
.qe-tab:focus-visible { outline: 2px solid var(--pg-accent, #0a84ff); outline-offset: -2px; }
.qe-tab.qe-active {
  color: var(--pg-accent, #0a84ff);
  border-bottom-color: var(--pg-accent, #0a84ff);
  font-weight: 600;
  background: rgba(10, 132, 255, 0.06);
}
.qe-tab-dir { opacity: 0.55; font-size: 11px; }
/* per-tab error badge ("!"), shown via .qe-err */
.qe-badge {
  display: none;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 8px;
  background: var(--pg-error, #ff453a);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.qe-tab.qe-err .qe-badge { display: inline-block; animation: qe-pop 0.18s ease; }
.qe-close {
  opacity: 0;
  color: var(--pg-text-2, #94949f);
  font-size: 13px;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 4px;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.qe-tab:hover .qe-close,
.qe-tab.qe-active .qe-close { opacity: 0.75; }
.qe-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.09); color: var(--pg-text, #e8e8ee); }
@media (hover: none) { .qe-close { opacity: 0.5; } }

/* "+ Scene" / "+ Action" */
.qe-addbtns {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 0 10px;
  border-left: 1px solid var(--pg-border, #2a2a33);
}
.qe-add {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--pg-text-2, #94949f);
  padding: 4px 7px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.qe-add:hover { color: var(--pg-accent, #0a84ff); background: rgba(10, 132, 255, 0.1); }
.qe-add:focus-visible { outline: 2px solid var(--pg-accent, #0a84ff); outline-offset: 1px; }

/* ---- editor area ---- */
.qe-body { flex: 1; min-height: 0; display: flex; position: relative; }
.qe-body-in { flex: 1; min-width: 0; display: flex; }
.qe-body-in > * { flex: 1; min-width: 0; }

/* ---- status bar ---- */
.qe-status {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--pg-text-2, #94949f);
  background: rgba(0, 0, 0, 0.28);
  border-top: 1px solid var(--pg-border, #2a2a33);
}
.qe-status-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.qe-status-file {
  font-family: var(--qe-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qe-chip {
  flex: none;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pg-text-2, #94949f);
  border: 1px solid var(--pg-border, #2a2a33);
  border-radius: 4px;
  padding: 1px 5px;
}
/* "plain" chip: visible only while running on the textarea fallback
   (CodeMirror CDN unreachable) */
.qe-mode {
  display: none;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pg-warn, #ff9f0a);
  border: 1px solid rgba(255, 159, 10, 0.4);
  border-radius: 4px;
  padding: 1px 5px;
}
.qe.qe-plain .qe-mode { display: inline-block; }
.qe-status-err {
  color: var(--pg-error, #ff453a);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qe-status-err:not(.qe-on) { display: none; }
.qe-status-right { flex: none; font-family: var(--qe-mono); }

/* ---- textarea fallback surface ---- */
.qe-tawrap { flex: 1; display: flex; min-width: 0; animation: qe-fade 0.12s ease; }
.qe-gutter {
  flex: none;
  width: 46px;
  padding: 10px 10px 10px 0;
  border-right: 1px solid var(--pg-border, #2a2a33);
  color: rgba(148, 148, 159, 0.6);
  font: 13px/1.65 var(--qe-mono);
  text-align: right;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}
.qe-ta {
  flex: 1;
  min-width: 0;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--pg-text, #e8e8ee);
  caret-color: var(--pg-accent, #0a84ff);
  font: 13px/1.65 var(--qe-mono);
  padding: 10px 14px;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}
.qe-ta::selection { background: rgba(10, 132, 255, 0.32); }

/* ---- CodeMirror surface ---- */
.qe .cm-editor { height: 100%; animation: qe-fade 0.12s ease; }
.qe .cm-editor.cm-focused { outline: none; }
.qe .cm-scroller { font-family: var(--qe-mono); font-size: 13px; line-height: 1.65; }
.qe .cm-content { padding: 10px 0; }
.qe .cm-gutters {
  background: transparent;
  border-right: 1px solid var(--pg-border, #2a2a33);
  color: rgba(148, 148, 159, 0.6);
}
.qe .cm-lineNumbers .cm-gutterElement { padding: 0 10px 0 8px; min-width: 30px; }
.qe .cm-tooltip {
  background: var(--pg-panel-2, #1e1e26);
  border: 1px solid var(--pg-border, #2a2a33);
  color: var(--pg-text, #e8e8ee);
  font-size: 12px;
}
.qe .cm-tooltip-lint { border-radius: 6px; }
.qe .cm-diagnostic-error { border-left-color: var(--pg-error, #ff453a); }

/* ---- scrollbars ---- */
.qe ::-webkit-scrollbar { width: 10px; height: 8px; }
.qe ::-webkit-scrollbar-thumb {
  background: rgba(148, 148, 159, 0.25);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.qe ::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 148, 159, 0.4); }
.qe ::-webkit-scrollbar-track,
.qe ::-webkit-scrollbar-corner { background: transparent; }

@keyframes qe-fade { from { opacity: 0; transform: translateY(2px); } }
@keyframes qe-pop { from { transform: scale(0.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .qe *, .qe *::before, .qe *::after { animation: none !important; transition: none !important; }
}
