/* Glyph editor — the playground editor's working surface, brought into the app.
   Dark chrome so the light glyph cards read as the document being worked on. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --text: #e2e4ef;
  --muted: #6b7094;
  --accent: #7c5dd8;
  --accent2: #f453c4;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-logo {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  background: linear-gradient(90deg, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.topbar-sep { color: var(--border); }
.topbar-sub { font-size: 0.8rem; color: var(--muted); }
.topbar-status { margin-left: auto; font-size: 0.78rem; color: var(--muted); }
.topbar-status.ok { color: var(--green); }
.topbar-status.err { color: var(--red); }
.topbar-status.busy { color: var(--yellow); }
.topbar-back {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}
.topbar-back:hover { color: var(--text); }

/* ── Gate ────────────────────────────────────────────────────────────────── */
.gate { max-width: 34rem; margin: 5rem auto; padding: 0 1.5rem; text-align: center; }
.gate-msg { font-size: 0.95rem; line-height: 1.65; color: var(--muted); margin-bottom: 1.25rem; }
.gate-link {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  text-decoration: none;
}

.shift-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 13, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 1rem;
}
.shift-modal-backdrop.hidden { display: none; }
.shift-modal {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #181b26, #141721);
  border: 1px solid rgba(124, 93, 216, 0.4);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  padding: 1rem;
}
.shift-modal-eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a9a0d2;
  margin-bottom: 0.4rem;
}
.shift-modal-title {
  font-size: 1.05rem;
  line-height: 1.3;
  color: #f4f5fb;
  margin-bottom: 0.45rem;
}
.shift-modal-copy {
  font-size: 0.82rem;
  line-height: 1.5;
  color: #b7bbcf;
  margin-bottom: 0.85rem;
}
.shift-modal-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}
.shift-choice {
  text-align: left;
  border: 1px solid rgba(124, 93, 216, 0.45);
  border-radius: 10px;
  background: rgba(124, 93, 216, 0.1);
  color: #ece9ff;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.shift-choice strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.2rem;
}
.shift-choice span {
  font-size: 0.72rem;
  color: #c8cde2;
}
.shift-choice:hover {
  transform: translateY(-1px);
  border-color: rgba(164, 138, 255, 0.9);
  background: rgba(124, 93, 216, 0.18);
}
.shift-choice.ghost {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
}

@media (max-width: 680px) {
  .shift-modal-actions {
    grid-template-columns: 1fr;
  }
}

.editor { max-width: 1500px; margin: 0 auto; padding: 1.25rem 1.25rem 5rem; }

/* ── Live preview ────────────────────────────────────────────────────────── */
.preview-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.result-heading {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.tester-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  outline: none;
}
.tester-input:focus { border-color: var(--accent); }
.tester-canvas {
  margin-top: 0.7rem;
  background: #fff;
  border-radius: 8px;
  min-height: 130px;
  display: flex;
  align-items: center;
  padding: 0.85rem 1rem;
  overflow-x: auto;
}
.tester-stage { margin: 0 auto; }
.tester-stage svg { display: block; }
.tester-hint { margin-top: 0.5rem; font-size: 0.72rem; color: var(--muted); }

.preview-bar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 0.85rem;
}
.slider-field { display: flex; align-items: center; gap: 0.6rem; flex: 1 1 18rem; }
.slider-name { font-size: 0.74rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.slider-val {
  font: 600 0.74rem/1 ui-monospace, monospace;
  color: var(--accent);
  min-width: 2.75rem;
  text-align: right;
}
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid var(--accent);
  cursor: pointer;
}

/* ── Source inspector ────────────────────────────────────────────────────── */
.source-inspector {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1.05rem;
  margin-bottom: 0.9rem;
}
.source-inspector-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: minmax(260px, 1fr) minmax(240px, 0.9fr);
}
.source-image-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.source-image {
  width: 100%;
  height: auto;
  display: block;
}
.source-meta {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: var(--surface2);
}
.source-meta-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.source-meta-copy {
  font-size: 0.73rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.source-detected-list {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 500 0.72rem/1.55 ui-monospace, monospace;
  color: #ced2e8;
}
.missing-assistant {
  margin-top: 0.7rem;
  border: 1px solid rgba(124, 93, 216, 0.35);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(43, 51, 80, 0.65), rgba(36, 39, 61, 0.85));
  padding: 0.65rem;
}
.missing-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.missing-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #f6f2ff;
}
.missing-copy {
  font-size: 0.7rem;
  color: #c7bcf3;
}
.missing-batch-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.55rem;
  flex-wrap: wrap;
}
.missing-action-btn {
  padding: 0.26rem 0.65rem;
  font-size: 0.7rem;
}
.missing-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.missing-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  border: 1px solid rgba(164, 138, 255, 0.5);
  border-radius: 999px;
  background: rgba(124, 93, 216, 0.12);
  color: #efebff;
  padding: 0.2rem 0.28rem 0.2rem 0.52rem;
  font-size: 0.7rem;
}
.missing-chip-label {
  font: 700 0.72rem/1 ui-monospace, monospace;
}
.missing-chip-btn {
  border: 1px solid rgba(164, 138, 255, 0.35);
  border-radius: 999px;
  background: rgba(124, 93, 216, 0.16);
  color: #efe9ff;
  font-size: 0.64rem;
  line-height: 1;
  padding: 0.16rem 0.44rem;
  cursor: pointer;
}
.missing-chip-btn:hover { background: rgba(124, 93, 216, 0.34); }
.missing-chip-btn:disabled { opacity: 0.45; cursor: default; }
.missing-chip-btn.primary {
  background: rgba(124, 93, 216, 0.48);
  border-color: rgba(164, 138, 255, 0.8);
}
.missing-chip-btn.primary:hover { background: rgba(139, 108, 230, 0.65); }
.missing-chip.resolved {
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(52, 211, 153, 0.16);
}
.missing-chip.resolved .missing-chip-label { color: #c8ffea; }
.missing-chip-state {
  font-size: 0.62rem;
  padding-right: 0.3rem;
  color: #9df5d2;
}
@media (max-width: 920px) {
  .source-inspector-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  position: sticky;
  top: 48px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.7rem 0;
  background: var(--bg);
}
.toolbar-right { margin-left: auto; display: flex; gap: 0.55rem; }
.filter-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.45rem 0.7rem;
  width: 12rem;
  outline: none;
}
.filter-input:focus { border-color: var(--accent); }
.dirty-flag { font-size: 0.76rem; font-weight: 600; color: var(--yellow); }

.edit-labels-btn {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 8px;
  padding: 0.45rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}
.edit-labels-btn:hover { border-color: var(--accent); color: var(--text); }
.edit-labels-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(124, 93, 216, 0.08); }

/* ── Missing-char composer ──────────────────────────────────────────────── */
.mapping-composer {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.75rem;
}
.mapping-composer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.mapping-title {
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 700;
}
.mapping-copy {
  font-size: 0.72rem;
  color: var(--muted);
}
.mapping-form-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.55fr) minmax(160px, 0.75fr) minmax(280px, 1fr);
  gap: 0.55rem;
  align-items: end;
}
.mapping-field {
  display: grid;
  gap: 0.28rem;
}
.mapping-field-label {
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.mapping-char, .mapping-source {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.76rem;
  outline: none;
}
.mapping-char {
  width: 100%;
  text-align: center;
  padding: 0.42rem 0.2rem;
  font-size: 0.86rem;
  font-weight: 700;
}
.mapping-source {
  min-width: 5.1rem;
  padding: 0.45rem 0.55rem;
}
.mapping-char:focus, .mapping-source:focus { border-color: var(--accent); }
.mapping-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.mapping-add-btn { padding: 0.35rem 0.75rem; font-size: 0.76rem; }
.mapping-explain {
  margin-top: 0.48rem;
  min-height: 1rem;
  font-size: 0.72rem;
  color: #a7afd2;
}
@media (max-width: 980px) {
  .mapping-form-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

.mapping-list {
  margin: 0.15rem 0 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.mapping-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid rgba(124, 93, 216, 0.45);
  border-radius: 999px;
  background: rgba(124, 93, 216, 0.12);
  color: #d9ccfb;
  font-size: 0.74rem;
  padding: 0.28rem 0.5rem 0.28rem 0.65rem;
}
.mapping-chip b {
  color: #fff;
  font-weight: 700;
}
.mapping-remove {
  border: none;
  background: transparent;
  color: #fca5a5;
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem;
}
.mapping-remove:hover { color: #fecaca; }

.btn {
  border-radius: 8px;
  padding: 0.45rem 1.1rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  border: 1px solid transparent;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--accent); }

.banner {
  margin-bottom: 0.9rem;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8rem;
  background: rgba(124, 93, 216, 0.12);
  border: 1px solid rgba(124, 93, 216, 0.35);
  color: #cbbdf5;
}
.banner[data-tone="error"] {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}
.banner[data-tone="success"] {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.4);
  color: #6ee7b7;
}

/* ── Legend / readout ────────────────────────────────────────────────────── */
.glyph-edit-help {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1.4fr);
  gap: 0.7rem;
  margin: 0.25rem 0 0.9rem;
}
.glyph-edit-legend, .glyph-edit-readout {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.65rem 0.75rem;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.6;
}
.glyph-edit-legend strong { color: var(--text); margin-right: 0.5rem; }
.glyph-edit-legend .key { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.75rem; }
.glyph-edit-legend .sw { width: 12px; height: 2px; border-radius: 2px; display: inline-block; }
.glyph-edit-legend .key.draggable {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.glyph-edit-legend .key-note { display: block; margin-top: 0.3rem; font-size: 0.7rem; opacity: 0.75; }
.glyph-edit-readout b { font-weight: 700; }
/* While a handle is being dragged the readout reports the live value. */
.glyph-edit-readout.live { color: var(--text); border-color: var(--accent); }
@media (max-width: 760px) { .glyph-edit-help { grid-template-columns: 1fr; } }

/* ── Glyph grid ──────────────────────────────────────────────────────────── */
.glyph-grid { display: flex; flex-wrap: wrap; gap: 10px; }

.glyph-card {
  width: 180px;
  border-radius: 10px;
  padding: 8px 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: #e8ecf6;
  text-align: center;
  position: relative;
  transition: transform 0.1s, box-shadow 0.1s;
}
.glyph-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35); z-index: 1; }
.glyph-card[data-edited="true"] { border: 1.5px solid var(--accent2); }
.glyph-card[data-deleted="true"] { opacity: 0.45; }
.glyph-card[hidden] { display: none; }

.glyph-badge {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 0.6rem;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  padding: 0 3px;
  color: rgba(0, 0, 0, 0.5);
}
.glyph-char {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
  min-height: 2.2rem;
  color: #111;
  position: relative;
}
.glyph-grid.editing .glyph-char { cursor: pointer; border-bottom: 1.5px dashed rgba(124, 93, 216, 0.5); }
.glyph-grid.editing .glyph-char:hover { background: rgba(124, 93, 216, 0.08); border-radius: 4px; }
.glyph-char-input {
  width: 2.2rem;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--accent);
  border-radius: 6px;
  outline: none;
  background: #fff;
  color: #111;
  padding: 0 2px;
  font-family: var(--font);
}

.glyph-delete-btn {
  display: none;
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #ef4444;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 0.7rem;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  font-weight: 700;
}
.glyph-delete-btn:hover { background: rgba(248, 113, 113, 0.35); }
.glyph-grid.editing .glyph-delete-btn { display: block; }

/* ── Card viewport: the draggable working area ───────────────────────────── */
.glyph-viewport {
  position: relative;
  width: 168px;
  height: 150px;
  overflow: visible;
  cursor: grab;
  margin: 4px auto 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  touch-action: none;
}
.glyph-viewport:hover { outline: 1px solid rgba(124, 93, 216, 0.4); }
.glyph-viewport:active { cursor: grabbing; }

/* Every card shares one viewBox, so glyphs are directly comparable and the
   guide lines sit at the same height in every card. */
.metric-svg {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  pointer-events: none;
  overflow: visible;
}

.metric-label {
  position: absolute;
  right: 2px;
  font-size: 9px;
  font-family: ui-monospace, monospace;
  line-height: 1;
  pointer-events: none;
  z-index: 6;
  opacity: 0.75;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.6);
  padding: 1px 2px;
  border-radius: 2px;
}
/* The tags for the editable guides double as the vertical drag handles. */
.metric-label[data-drag] {
  pointer-events: auto;
  cursor: ns-resize;
  opacity: 0.95;
  padding: 2px 3px;
  /* "x" is a single character, so give every tag the same grabbable width. */
  min-width: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 1px;
}
.metric-label[data-drag]:hover {
  background: #fff;
  opacity: 1;
  box-shadow: 0 0 0 1px currentColor;
}

.card-origin-line {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(248, 113, 113, 0.55);
  cursor: ew-resize;
  z-index: 9;
}
.card-origin-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #f87171;
  border-radius: 50%;
  transform: translateX(-50%);
  cursor: ew-resize;
  z-index: 10;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}
.card-origin-line:hover, .card-origin-dot:hover { background: #fca5a5; }

.card-advance-line {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(56, 189, 248, 0.6);
  cursor: ew-resize;
  z-index: 4;
}
.card-advance-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #38bdf8;
  border-radius: 50%;
  transform: translateX(-50%);
  cursor: ew-resize;
  z-index: 6;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}
.card-advance-line:hover, .card-advance-dot:hover { background: #7dd3fc; }

.card-scale-x-dot,
.card-scale-y-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.72);
}
.card-scale-x-dot {
  background: #fbbf24;
  cursor: ew-resize;
}
.card-scale-x-dot:hover { background: #fcd34d; }
.card-scale-y-dot {
  background: #22c55e;
  cursor: ns-resize;
}
.card-scale-y-dot:hover { background: #4ade80; }

.glyph-readouts {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 5px;
  font: 500 0.62rem/1 ui-monospace, monospace;
  color: rgba(0, 0, 0, 0.45);
}
.glyph-readouts b { font-weight: 700; color: rgba(0, 0, 0, 0.7); }
