/* Grid Quantic (Tech / TCE) modal — warm-dark glass, aligned to tokens.css.
   A draggable, in-room floating panel mounted on document.body. The modal surface
   rides the WebGL liquid-glass lens (createLiquidGlass adds .liquid-glass--active,
   which strips the CSS fallback below); its inner panels sit on frosted glass for
   a readable, layered hierarchy. Confirmations render INSIDE the modal so they
   can never sit behind it. */

.tech-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(1080px, 94vw);
  height: min(720px, 88vh);
  display: none;
  flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  color: var(--color-text);
  overflow: hidden;
  isolation: isolate;
  /* Fallback only — once open, the modal-stack manager assigns the z-index
     (focused window on top), overriding this inline. */
  z-index: 1000;
}


/* ── Header (contextual: library vs editor) ─────────────────────────────────── */
.tech-modal__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  cursor: grab;
  user-select: none;
}
.tech-modal__head:active { cursor: grabbing; }
.tech-modal__title { flex: 1; display: flex; align-items: center; gap: 9px; font-size: var(--font-size-md); font-weight: 600; }
.tech-modal__title i { color: var(--color-primary); }
.tech-head__actions { display: flex; gap: 8px; }
.tech-modal__close {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border: none; background: transparent;
  font-size: 18px; color: var(--color-text-muted); cursor: pointer;
  border-radius: var(--radius-sm); transition: color .15s, background .15s;
}
.tech-modal__close:hover { color: var(--color-text); background: var(--frost-bg); }

.tech-modal__body { flex: 1; min-height: 0; display: flex; overflow: hidden; }

.tech-pick-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: var(--color-bg-elevated); color: var(--color-text);
  border: 1px solid var(--color-border-focus);
  padding: 8px 14px; border-radius: 999px; font-size: var(--font-size-sm);
  box-shadow: var(--shadow-md); pointer-events: none; z-index: 2;
}
/* Shown on-screen while the modal is hidden during a room pick. */
.tech-pick-hint--floating { position: fixed; bottom: 24px; z-index: 4300; }

/* ── Buttons (one cohesive family) ──────────────────────────────────────────── */
.tech-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border); background: var(--frost-bg);
  color: var(--color-text); font-size: var(--font-size-sm); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.tech-btn:hover { border-color: var(--color-border-focus); }
.tech-btn:active { transform: translateY(1px); }
.tech-btn--primary { background: var(--color-primary); color: var(--color-on-primary); border-color: transparent; font-weight: 700; }
.tech-btn--primary:hover { background: var(--color-primary-hover); }
.tech-btn--danger { background: var(--color-danger); color: #fff; border-color: transparent; font-weight: 700; }
.tech-btn--ghost { background: transparent; }
.tech-btn--pick { width: 100%; justify-content: center; }

.tech-icon-btn {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-secondary);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.tech-icon-btn:hover { background: var(--frost-bg); color: var(--color-text); border-color: var(--color-border-focus); }
.tech-icon-btn--danger:hover { color: var(--color-danger); border-color: var(--color-danger); }

.tech-mini-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border); background: transparent;
  color: var(--color-text-secondary); font-size: var(--font-size-xs); cursor: pointer;
}
.tech-mini-btn:hover { border-color: var(--color-border-focus); color: var(--color-text); }

/* ── Library (frosted floating list) ────────────────────────────────────────── */
.tech-lib { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tech-lib__list {
  flex: 1; overflow-y: auto; margin: 12px; padding: 12px;
  background: var(--frost-bg); backdrop-filter: var(--frost-blur); -webkit-backdrop-filter: var(--frost-blur);
  border: 1px solid var(--frost-border); border-radius: var(--radius-md);
  display: grid; gap: 10px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
}

.tech-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md);
  background: var(--color-bg-surface); border: 1px solid var(--color-border);
  cursor: pointer; transition: border-color .15s;
}
.tech-card:hover { border-color: var(--color-border-focus); }
.tech-card__main { flex: 1; min-width: 0; }
.tech-card__name { font-weight: 600; font-size: var(--font-size-sm); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tech-card__meta { display: flex; flex-wrap: wrap; gap: 9px; font-size: var(--font-size-xs); color: var(--color-text-muted); }
.tech-card--running .tech-card__state { color: var(--color-success); }
.tech-card--paused  { opacity: .68; }
.tech-card__actions { display: flex; gap: 4px; }
.tech-card__actions .tech-icon-btn { width: 26px; height: 26px; }

.tech-empty, .tech-config__empty, .tech-zone__empty { color: var(--color-text-muted); text-align: center; }
.tech-empty { padding: 48px 20px; grid-column: 1 / -1; }
.tech-empty i, .tech-config__empty i { font-size: 28px; color: var(--color-primary); margin-bottom: 10px; display: block; }

/* ── Editor (floating frosted side panels + center zones) ───────────────────── */
.tech-name {
  flex: 1; min-width: 0;
  padding: 7px 12px; border-radius: var(--radius-sm);
  background: var(--frost-bg); border: 1px solid var(--color-border);
  color: var(--color-text); font-size: var(--font-size-md); font-weight: 600;
}
.tech-name:focus { outline: none; border-color: var(--color-border-focus); }
.tech-save { font-size: var(--font-size-xs); color: var(--color-text-muted); min-width: 52px; text-align: right; }
.tech-save--ok { color: var(--color-success); }
.tech-save--err { color: var(--color-danger); }

.tech-editor__grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 228px 1fr 300px; gap: 12px; padding: 12px; }
.tech-palette, .tech-config {
  overflow-y: auto; padding: 12px;
  background: var(--frost-bg); backdrop-filter: var(--frost-blur); -webkit-backdrop-filter: var(--frost-blur);
  border: 1px solid var(--frost-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.tech-zones { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* Palette + search */
.tech-palette__search {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin-bottom: 10px; border-radius: var(--radius-sm);
  background: var(--color-bg-surface); border: 1px solid var(--color-border);
}
.tech-palette__search i { color: var(--color-text-muted); font-size: 12px; }
.tech-palette__search input { flex: 1; min-width: 0; background: transparent; border: none; color: var(--color-text); font-size: var(--font-size-sm); outline: none; }
.tech-palette__section { margin-bottom: 10px; }
.tech-palette__section > summary { cursor: pointer; font-weight: 700; font-size: var(--font-size-sm); padding: 6px 4px; list-style: none; }
.tech-palette__section > summary::-webkit-details-marker { display: none; }
.tech-palette__cat { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-dim); margin: 8px 4px 4px; }
.tech-pal-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; margin-bottom: 4px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border); background: var(--color-bg-surface);
  color: var(--color-text); font-size: var(--font-size-sm); cursor: grab; text-align: left;
}
.tech-pal-item:hover { border-color: var(--color-border-focus); }
.tech-pal-item i { color: var(--color-primary); width: 16px; text-align: center; }

/* Zones */
.tech-zone { border: 1px solid var(--frost-border); border-radius: var(--radius-md); background: var(--frost-bg); backdrop-filter: var(--frost-blur); -webkit-backdrop-filter: var(--frost-blur); }
.tech-zone__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 12px; border-bottom: 1px solid var(--color-border); font-weight: 700; font-size: var(--font-size-sm); }
.tech-zone__head small { font-weight: 400; color: var(--color-text-muted); font-size: var(--font-size-xs); }
.tech-zone__head i { color: var(--color-primary); }
.tech-zone__body { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 44px; }
.tech-zone__empty { padding: 12px; border: 1px dashed var(--color-border); border-radius: var(--radius-sm); font-size: var(--font-size-sm); }

/* Instance chip (trigger / effect / condition leaf) */
.tech-inst, .tech-node {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--color-bg-surface); border: 1px solid var(--color-border); cursor: pointer;
}
.tech-inst[draggable="true"] { cursor: grab; }
.tech-inst__icon { color: var(--color-primary); width: 18px; text-align: center; }
.tech-inst__text { flex: 1; min-width: 0; }
.tech-inst__text b { display: block; font-size: var(--font-size-sm); }
.tech-inst__text small { display: block; color: var(--color-text-muted); font-size: var(--font-size-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tech-inst__order { width: 20px; height: 20px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--color-primary-dim); color: var(--color-primary); font-size: 11px; font-weight: 700; }
.tech-inst__delay { display: inline-flex; align-items: center; gap: 4px; font-size: var(--font-size-xs); color: var(--color-accent); white-space: nowrap; }
.tech-inst--sel, .tech-node--sel { border-color: var(--color-border-focus); }
.tech-inst--active, .tech-node--active { border-color: var(--color-border-focus); box-shadow: var(--shadow-glow); background: var(--color-primary-dim); }

/* Condition tree */
.tech-group { border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 8px; }
.tech-group--root { border-style: dashed; }
.tech-group__bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tech-group__nodes { display: flex; flex-direction: column; gap: 8px; padding-left: 10px; border-left: 2px solid var(--color-primary-dim); }
.tech-op { min-width: 48px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--color-border-focus); background: var(--color-primary-dim); color: var(--color-primary); font-weight: 700; font-size: var(--font-size-xs); cursor: pointer; }

/* Effect pick-one group */
.tech-egroup { border: 1px dashed var(--color-border-focus); border-radius: var(--radius-sm); padding: 8px; }
.tech-egroup__bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tech-egroup__hint { color: var(--color-text-muted); font-size: var(--font-size-xs); }
.tech-egroup__nodes { display: flex; flex-direction: column; gap: 8px; padding-left: 10px; border-left: 2px solid var(--color-primary-dim); }
.tech-mode { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--color-border-focus); background: var(--color-primary-dim); color: var(--color-primary); font-weight: 700; font-size: var(--font-size-xs); cursor: pointer; }

/* Config form */
.tech-config__head { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.tech-config__head i { color: var(--color-primary); }
.tech-config__desc {
  margin: 0 0 12px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--frost-bg); border: 1px solid var(--frost-border);
  color: var(--color-text-secondary); font-size: var(--font-size-xs); line-height: 1.45;
}
.tech-config__empty small { color: var(--color-text-dim); }
.tech-field { margin-bottom: 12px; }
.tech-field__label { display: block; font-size: var(--font-size-xs); color: var(--color-text-secondary); margin-bottom: 5px; }
.tech-field__label small { color: var(--color-text-dim); }
.tech-req { color: var(--color-danger); margin-left: 2px; }
.tech-input { width: 100%; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--color-bg-surface); border: 1px solid var(--color-border); color: var(--color-text); font-size: var(--font-size-sm); }
.tech-input:focus { outline: none; border-color: var(--color-border-focus); }
.tech-input--color { height: 36px; padding: 3px; cursor: pointer; }
.tech-check { display: flex; align-items: center; gap: 8px; font-size: var(--font-size-sm); }
.tech-pick { display: flex; flex-direction: column; gap: 6px; }
.tech-pick__preview { font-size: var(--font-size-xs); color: var(--color-accent); }
.tech-pick__preview--empty { color: var(--color-text-dim); font-size: var(--font-size-xs); }

/* Multi-ref list (tiles / mobis) */
.tech-reflist { display: flex; flex-direction: column; gap: 8px; }
.tech-reflist__items { display: flex; flex-wrap: wrap; gap: 6px; }
.tech-reflist__item { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--color-primary-dim); color: var(--color-primary); font-size: var(--font-size-xs); font-weight: 600; }
.tech-reflist__x { background: none; border: none; color: inherit; cursor: pointer; padding: 0; display: inline-flex; opacity: .8; }
.tech-reflist__x:hover { opacity: 1; }
.tech-field--delay { border-top: 1px solid var(--color-border); padding-top: 12px; }
.tech-field--error .tech-input { border-color: var(--color-danger); }
.tech-field__err { display: block; margin-top: 4px; color: var(--color-danger); font-size: var(--font-size-xs); }
.tech-config__warn { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 8px 10px; border-radius: var(--radius-sm); background: rgba(242, 59, 44, .12); border: 1px solid var(--color-danger); color: var(--color-text); font-size: var(--font-size-xs); }
.tech-config__warn i { color: var(--color-danger); }
.tech-config__none { color: var(--color-text-muted); font-size: var(--font-size-sm); }

/* userList (who:specific usernames) */
.tech-userlist { display: flex; flex-direction: column; gap: 6px; }
.tech-userlist__row { display: flex; align-items: center; gap: 6px; }
.tech-userlist__row .tech-input { flex: 1; }
.tech-userlist__add { margin-left: 0; align-self: flex-start; }

/* In-modal confirm — child of .tech-modal (own stacking context) so always on top */
.tech-confirm { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.5); border-radius: var(--radius-lg); }
.tech-confirm__panel { width: min(360px, 86%); padding: 18px; border-radius: var(--radius-md); background: var(--color-bg-elevated); border: 1px solid var(--color-border); box-shadow: var(--shadow-lg); }
.tech-confirm__title { font-weight: 700; margin-bottom: 8px; }
.tech-confirm__msg { color: var(--color-text-muted); font-size: var(--font-size-sm); line-height: 1.4; margin-bottom: 14px; }
.tech-confirm__actions { display: flex; gap: 8px; justify-content: flex-end; }

/* richText / buttonList / modalRef config widgets */
.tech-richtext { display: flex; flex-direction: column; gap: 10px; }
.tech-textarea { resize: vertical; min-height: 72px; font-family: inherit; line-height: 1.4; }
.tech-richtext__label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: var(--font-size-xs); color: var(--color-text-secondary);
}
.tech-richtext__color { display: flex; align-items: center; gap: 8px; font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.tech-richtext__color input { width: 46px; height: 28px; padding: 2px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: var(--color-bg-surface); cursor: pointer; }

/* Clickable markdown palette above the message body — each chip previews its
   rendered look and inserts the markdown at the cursor on click. */
.tech-md-toolbar { display: flex; flex-wrap: wrap; gap: 4px; }
.tech-md-chip {
  padding: 3px 9px;
  font-size: var(--font-size-xs);
  color: var(--color-text);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.3;
}
.tech-md-chip:hover { border-color: var(--color-primary); background: var(--color-primary-dim); }
.tech-md-chip code { background: var(--frost-bg); padding: 0 4px; border-radius: 4px; font-size: .92em; }
.tech-md-chip__sub  { font-weight: 700; font-size: var(--font-size-sm); }
.tech-md-chip__link { color: var(--color-accent-cyan); text-decoration: underline; }
.tech-md-chip--info    { color: #4da3ff; }
.tech-md-chip--success { color: #3ecf6e; }
.tech-md-chip--warning { color: #f5b942; }
.tech-md-chip--danger  { color: #ff5d5d; }

/* Semantic colour blocks rendered inside player-modal messages ({info}…{/info}). */
.tech-md--info    { color: #4da3ff; }
.tech-md--success { color: #3ecf6e; }
.tech-md--warning { color: #f5b942; }
.tech-md--danger  { color: #ff5d5d; }
.tech-btnlist { display: flex; flex-direction: column; gap: 6px; }
.tech-btnrow { display: flex; align-items: center; gap: 6px; }
.tech-btnrow .tech-input { flex: 1; min-width: 0; }
.tech-btnlist__add { margin-left: 0; align-self: flex-start; }
.tech-field__hint { display: block; margin-top: 6px; color: var(--color-text-dim); font-size: var(--font-size-xs); line-height: 1.4; }

/* ── Player-facing modals (open_modal effect) ─────────────────────────────────
   The layer is a transparent grouping node (display: contents) so each modal
   root joins the ROOT stacking context — the modal-stack manager assigns their
   z-indexes, letting Forge modals interleave with every other floating window
   (focused one on top) instead of sitting in a hardcoded top band. */
#tech-pmodal-layer { display: contents; }
.tech-pmodal { position: fixed; inset: 0; pointer-events: none; }
.tech-pmodal--blocking { pointer-events: auto; display: grid; place-items: center; }
.tech-pmodal--blocking .tech-pmodal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.tech-pmodal--movable { pointer-events: none; }
.tech-pmodal__panel {
  position: relative; width: min(420px, 90vw); max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden; pointer-events: auto;
  background: var(--color-bg-elevated); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.tech-pmodal--movable .tech-pmodal__panel { position: fixed; transform: translate(-50%, 0); }
.tech-pmodal__head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--color-border); }
.tech-pmodal--movable .tech-pmodal__head { cursor: grab; user-select: none; }
.tech-pmodal--movable .tech-pmodal__head:active { cursor: grabbing; }
.tech-pmodal__title { flex: 1; font-weight: 700; font-size: var(--font-size-sm); }
.tech-pmodal__title i { color: var(--color-primary); margin-right: 6px; }
.tech-pmodal__close { width: 28px; height: 28px; display: grid; place-items: center; border: none; background: transparent; color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.tech-pmodal__close:hover { color: var(--color-text); background: var(--frost-bg); }
.tech-pmodal__body { padding: 14px; overflow-y: auto; }
.tech-pmodal__subtitle { font-size: var(--font-size-lg); font-weight: 700; margin-bottom: 8px; }
.tech-pmodal__md { line-height: 1.55; font-size: var(--font-size-sm); }
.tech-pmodal__md a { color: var(--color-accent-cyan); text-decoration: underline; }
.tech-pmodal__md code { background: var(--frost-bg); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.tech-pmodal__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 14px; border-top: 1px solid var(--color-border); }

/* Scrollbars */
.tech-modal ::-webkit-scrollbar { width: 8px; height: 8px; }
.tech-modal ::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .tech-modal { width: 96vw; height: 92vh; }
  .tech-head__actions .tech-btn span { display: none; }
  .tech-editor__grid { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .tech-palette { max-height: 150px; }
  .tech-config  { max-height: 220px; }
}
