/* Faceplate editor (js/faceplate-editor.js mountEditor). Murphy Research tokens (dark): warm
   near-black ground, Coro gold as the one accent, Archivo + IBM Plex Mono (the host loads those;
   the faceplate fonts come from faceplate.css). Everything is scoped to .fp-editor, and the layout
   follows the editor's own width (container queries), so it sits in a page or an app step alike.
   A host restyles it by overriding the tokens on .fp-editor. No mask-image, backdrop-filter or
   clip-path. */
.fp-editor {
  --s000: #121110; --s100: #1a1816; --s200: #23201d; --s300: #2e2a26; --hair: #3a3531;
  --ink: #f4efe7; --muted: #b3a99b; --faint: #93897c;
  --coro: #e8a33d; --on-coro: #201605; --coro-deep: #8a5514; --warn: #facc15;
  --heat: 0 0 0 1px rgba(232, 163, 61, 0.45), 0 8px 32px -8px rgba(232, 163, 61, 0.22);
  --frame: 0 24px 60px -18px rgba(0, 0, 0, 0.55), 0 4px 14px rgba(0, 0, 0, 0.35);
  --r-sm: 6px; --r-md: 10px; --r-lg: 18px;
  --sans: "Archivo", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}

.fp-editor { container: fp-editor / inline-size; max-width: 1600px; margin: 0 auto; padding: 0 24px 32px;
  background: var(--s000); color: var(--ink); font: 15px/1.45 var(--sans); position: relative; }
.fp-editor, .fp-editor * { box-sizing: border-box; }
.fp-editor [hidden] { display: none !important; }
.fp-editor button, .fp-editor input { font: inherit; color: inherit; }
.fp-editor code { font-family: var(--mono); font-size: 0.92em; }
.fp-editor :focus-visible { outline: 2px solid var(--coro); outline-offset: 2px; }
.fp-editor.fp-editor-embedded { padding: 0; background: transparent; }
.fp-editor .bar-slim { justify-content: flex-end; padding: 0 0 12px; }
.fp-editor .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; }
.fp-editor .muted { color: var(--muted); font-weight: 400; }
.fp-editor .eyebrow { font: 500 11px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--coro); }


/* ---- top bar ---- */
.fp-editor .bar { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; padding: 16px 0; border-bottom: 1px solid var(--hair); }
.fp-editor .brand { display: flex; flex-direction: column; gap: 6px; }
.fp-editor .brand h1 { margin: 0; font-size: 22px; line-height: 1; font-weight: 800; letter-spacing: -0.01em; }
.fp-editor .file { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.fp-editor .file .eyebrow { color: var(--faint); }
.fp-editor .file-name { font: 500 14px/1.2 var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-editor .actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.fp-editor .btn { min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--hair); background: var(--s200);
  font-weight: 600; cursor: pointer; }
.fp-editor .btn:hover:not(:disabled) { background: var(--s300); }
.fp-editor .btn:disabled { opacity: 0.45; cursor: default; }
.fp-editor .btn.primary { background: var(--coro); border-color: var(--coro); color: var(--on-coro); }
.fp-editor .btn.primary:hover:not(:disabled) { background: #f0b257; }
.fp-editor .btn.big { min-height: 52px; padding: 0 28px; font-size: 16px; }

.fp-editor .segs { display: inline-flex; border: 1px solid var(--hair); border-radius: 999px; padding: 3px; background: var(--s100); }
.fp-editor .segs:empty { display: none; }
.fp-editor .seg { min-height: 44px; min-width: 76px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font-weight: 600; cursor: pointer; }
.fp-editor .seg.on { background: var(--s300); color: var(--ink); box-shadow: inset 0 0 0 1px var(--coro); }
.fp-editor .kind-fixed { font: 500 12px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--hair); border-radius: 999px; padding: 14px 16px; }

.fp-editor .notice { margin: 16px 0 0; padding: 12px 16px; border-radius: var(--r-md); background: var(--s200); border-left: 3px solid var(--warn); }

/* ---- empty state ---- */
.fp-editor .empty { max-width: 560px; margin: 12vh auto 0; text-align: center; }
.fp-editor .empty h2 { margin: 12px 0 8px; font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.01em; }
.fp-editor .empty p.muted { margin: 0 0 28px; }

/* ---- the four zones ---- */
/* the three top zones share one grid; history sits below it, so the sticky list and preview
   stop at the bottom of .work-top and never ride over the history strip */
.fp-editor .work { display: flex; flex-direction: column; gap: 24px; margin-top: 24px; }
.fp-editor .work-top { display: grid; gap: 24px; grid-template-columns: 208px minmax(0, 1fr) 340px;
  grid-template-areas: "tpl stage ctl"; align-items: start; }
.fp-editor .zone-templates { grid-area: tpl; }
.fp-editor .zone-stage { grid-area: stage; }
.fp-editor .zone-controls { grid-area: ctl; }
.fp-editor .zone-history { grid-area: hist; }
.fp-editor .zone-title { margin: 0 0 12px; font: 500 12px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.fp-editor .zone-title .muted { text-transform: none; letter-spacing: 0; font-family: var(--sans); font-size: 13px; color: var(--faint); }

.fp-editor .templates { display: flex; flex-direction: column; gap: 12px; }
.fp-editor .tpl { display: block; width: 100%; padding: 8px 8px 10px; border-radius: var(--r-md); border: 1px solid var(--hair);
  background: var(--s200); cursor: pointer; text-align: left; }
.fp-editor .tpl:hover { background: var(--s300); }
.fp-editor .tpl.on { box-shadow: var(--heat); border-color: var(--coro); }
.fp-editor .tpl svg, .fp-editor .ver svg { display: block; width: 100%; height: auto; }
.fp-editor .tpl-name { display: block; margin-top: 8px; font-weight: 600; font-size: 14px; }
/* a draft template (not yet approved for the player): a small gold caps tag after the name */
.fp-editor .tpl-draft { display: inline-block; margin-left: 8px; padding: 3px 6px 2px; border: 1px solid var(--coro-deep);
  border-radius: var(--r-sm); font: 500 10px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--coro); vertical-align: 2px; }

.fp-editor .stage { background: var(--s300); border-radius: var(--r-lg); box-shadow: var(--frame); padding: 20px; }
.fp-editor .preview { min-height: 200px; }
.fp-editor .preview .fp-face { width: 100%; }
.fp-editor .hint { margin: 10px 0 20px; color: var(--faint); font-size: 13px; }
.fp-editor .ideas { display: flex; flex-wrap: wrap; gap: 10px; }
.fp-editor .idea { min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--coro-deep); background: var(--s200);
  color: var(--ink); font-weight: 600; cursor: pointer; }
.fp-editor .idea:hover:not(:disabled) { background: var(--s300); border-color: var(--coro); }
.fp-editor .idea:disabled { opacity: 0.4; cursor: default; border-color: var(--hair); }

/* ---- hand controls ---- */
.fp-editor .controls { display: flex; flex-direction: column; gap: 12px; }
.fp-editor .group { background: var(--s100); border: 1px solid var(--hair); border-radius: var(--r-md); padding: 14px 16px 16px; }
.fp-editor .group-label { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.fp-editor .sub { margin: 12px 0 8px; color: var(--muted); font-size: 13px; }
.fp-editor .field + .field { margin-top: 12px; }
.fp-editor .field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.fp-editor .field input { width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--hair);
  background: var(--s000); font-family: var(--mono); font-size: 15px; }
.fp-editor .field input:focus { border-color: var(--coro); outline: none; }
.fp-editor .field-name input { font-family: var(--sans); font-weight: 700; font-size: 17px; }
.fp-editor .rule { margin: 8px 0 0; font-size: 12.5px; color: var(--faint); }

.fp-editor .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.fp-editor .chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--hair); background: var(--s200); font-size: 14px; font-weight: 500; cursor: pointer; }
.fp-editor .chip:hover { background: var(--s300); }
.fp-editor .chip.on { border-color: var(--coro); box-shadow: inset 0 0 0 1px var(--coro); }
.fp-editor .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }

.fp-editor .swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.fp-editor .swatch { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--s100); box-shadow: 0 0 0 1px var(--hair); cursor: pointer; padding: 0; }
.fp-editor .swatch.on { box-shadow: 0 0 0 2px var(--coro); }
.fp-editor .colour { display: inline-flex; align-items: center; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 13px; cursor: pointer; }
.fp-editor .colour input { width: 56px; height: 44px; padding: 2px; border: 1px solid var(--hair); border-radius: var(--r-sm); background: var(--s000); cursor: pointer; }

.fp-editor .slider { display: flex; align-items: center; gap: 12px; }
.fp-editor .slider input { flex: 1; min-height: 44px; accent-color: var(--coro); }
.fp-editor .slider output { font: 500 14px/1 var(--mono); width: 44px; text-align: right; color: var(--muted); }

/* ---- history ---- */
.fp-editor .history { position: relative; display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 12px; }
.fp-editor .ver { position: relative; flex: 0 0 152px; padding: 6px; border-radius: var(--r-sm); border: 1px solid var(--hair);
  background: var(--s200); cursor: pointer; }
.fp-editor .ver:hover { background: var(--s300); }
.fp-editor .ver.on { border-color: var(--coro); box-shadow: var(--heat); }
.fp-editor .ver.later { opacity: 0.55; }
.fp-editor .ver-n { position: absolute; left: 10px; top: 8px; font: 500 11px/1 var(--mono); background: rgba(18, 17, 16, 0.8);
  color: var(--ink); padding: 3px 5px; border-radius: 4px; }

/* ---- smaller screens ---- */
@container fp-editor (max-width: 1180px) {
  .fp-editor .work-top { grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "tpl tpl" "stage ctl"; }
  .fp-editor .templates { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .fp-editor .tpl { flex: 0 0 200px; }
}
@container fp-editor (max-width: 880px) {
  .fp-editor .work-top { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tpl" "stage" "ctl"; }
  .fp-editor .controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
  .fp-editor .stage { padding: 12px; }
}

/* knob and switch labels sit two to a row */
.fp-editor .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.fp-editor .field-grid .field + .field { margin-top: 0; }
/* wide screens: the preview stays in view while the hand controls scroll */
@container fp-editor (min-width: 1181px) { .fp-editor .zone-stage, .fp-editor .zone-templates { position: sticky; top: 16px; } }

/* ---- the faceplate list scrolls on its own, with a slim warm scrollbar ---- */
@container fp-editor (min-width: 1181px) {
  .fp-editor .templates { max-height: calc(100vh - 88px); overflow-y: auto; padding-right: 8px; overscroll-behavior: contain; }
}
.fp-editor .templates, .fp-editor .history { scrollbar-width: thin; scrollbar-color: var(--s300) transparent; }
.fp-editor .templates:hover, .fp-editor .history:hover { scrollbar-color: var(--coro-deep) transparent; }
.fp-editor .templates::-webkit-scrollbar, .fp-editor .history::-webkit-scrollbar { width: 10px; height: 10px; }
.fp-editor .templates::-webkit-scrollbar-track, .fp-editor .history::-webkit-scrollbar-track { background: transparent; }
.fp-editor .templates::-webkit-scrollbar-thumb, .fp-editor .history::-webkit-scrollbar-thumb {
  background: var(--s300); border-radius: 999px; border: 3px solid var(--s000); }
.fp-editor .templates::-webkit-scrollbar-thumb:hover, .fp-editor .history::-webkit-scrollbar-thumb:hover { background: var(--coro-deep); }

/* ---- text style rows ---- */
.fp-editor .style-row { margin-top: 10px; padding-top: 2px; }
.fp-editor .style-row .sub { margin: 10px 0 6px; }
.fp-editor .style-fonts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fp-editor .fontbtn { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: 52px; padding: 6px 10px;
  border-radius: var(--r-sm); border: 1px solid var(--hair); background: var(--s200); cursor: pointer; text-align: left; min-width: 0; }
.fp-editor .fontbtn:hover { background: var(--s300); }
.fp-editor .fontbtn.on { border-color: var(--coro); box-shadow: inset 0 0 0 1px var(--coro); }
.fp-editor .fontbtn-name { font-size: 19px; line-height: 1.1; white-space: nowrap; }
.fp-editor .fontbtn-fam { font: 400 10.5px/1.2 var(--mono); color: var(--faint); overflow-wrap: anywhere; max-width: 100%; }
.fp-editor .style-line { display: flex; flex-wrap: wrap; gap: 4px 24px; }
.fp-editor .style-sizes .chip { min-width: 44px; justify-content: center; padding: 0 10px; }
.fp-editor .style-colours .swatches { gap: 6px; }
.fp-editor .style-colours .colour { margin-top: 8px; }
.fp-editor .check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.fp-editor .check input { width: 18px; height: 18px; accent-color: var(--accent, #e8a33d); margin: 0; }

/* ---- Save before a file is open: plainly off, not a dim orange ---- */
.fp-editor .btn.primary:disabled { background: var(--s200); border-color: var(--hair); color: var(--faint); opacity: 1; }

/* ---- drag-and-drop ---- */
.fp-editor .drop-hint { margin: 14px 0 0; color: var(--faint); font-size: 13px; }
.fp-editor.dropping::after { content: "Drop the .nam to open it"; position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; border: 2px dashed var(--coro); border-radius: var(--r-lg);
  background: rgba(18, 17, 16, 0.88); color: var(--ink); font-weight: 700; font-size: 20px; pointer-events: none; }

/* ---- phones ---- */
@container fp-editor (max-width: 640px) {
  .fp-editor .bar { gap: 14px; }
  .fp-editor .brand h1 { font-size: 19px; }
  .fp-editor .actions { width: 100%; }
  .fp-editor .actions .btn { flex: 1; padding: 0 12px; }
  .fp-editor .segs { width: 100%; }
  .fp-editor .seg { flex: 1; }
  .fp-editor .empty { margin-top: 48px; }
  .fp-editor .empty h2 { font-size: 24px; line-height: 30px; }
  .fp-editor .tpl { flex: 0 0 156px; }
  .fp-editor .ver { flex: 0 0 120px; }
  .fp-editor .field-grid { grid-template-columns: 1fr; }
  .fp-editor .style-fonts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fp-editor .hint { margin-bottom: 14px; }
}
@media (max-width: 640px) { .fp-editor:not(.fp-editor-embedded) { padding: 0 16px 24px; } }
