/* ============================================================
   Zorp editor (piece A) — layered code editor
   Classes are prefixed ed-. Nothing here touches app.css.
   ============================================================ */

.ed {
  --ed-fs: 13.5px;
  --ed-lh: 22px;
  --ed-px: 14px;
  --ed-py: 12px;
  --ed-gut: 44px;
  --ed-bg: #0b0e12;
  --ed-panel: #0d1014;
  --ed-line: #1c222a;
  --ed-fg: #dbe4ee;
  --ed-dim: #6b7684;
  --ed-ghost: #8b96a4;
  --ed-lime: #c6f94b;
  --ed-cyan: #46e3ff;
  --ed-red: #ff6b6b;
  --ed-amber: #ffb347;
  --ed-ok: #6dffa3;
  --ed-sel: rgba(198, 249, 75, 0.2);

  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 1px solid var(--ed-line);
  border-radius: 12px;
  background: var(--ed-bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: var(--ed-fs);
  line-height: var(--ed-lh);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.ed:focus-within {
  border-color: rgba(198, 249, 75, 0.55);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(198, 249, 75, 0.08);
}
.ed[data-lang="py"] { --ed-accent: var(--ed-cyan); }
.ed[data-lang="js"] { --ed-accent: var(--ed-lime); }

/* ---------- main row ---------- */
.ed-main {
  position: relative;
  display: flex;
  align-items: stretch;
  min-width: 0;
}

/* ---------- coach strip (ghosts that do not fit on their line) ---------- */
.ed-coach {
  border-top: 1px solid var(--ed-line);
  background: rgba(255, 255, 255, 0.022);
  padding: 5px 0;
  display: grid;
  gap: 1px;
}
.ed-coach[hidden] { display: none; }
.ed-coach-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px 12px 3px 10px;
  border-left: 2px solid transparent;
  cursor: pointer;
  min-width: 0;
}
.ed-coach-row:hover { background: rgba(255, 255, 255, 0.035); }
.ed-coach-row.err { border-left-color: var(--ed-red); }
.ed-coach-row.warn { border-left-color: var(--ed-amber); }
.ed-coach-row.hint { border-left-color: #ffe066; }
.ed-coach-row.ok { border-left-color: var(--ed-ok); }
.ed-coach-row.info { border-left-color: #8b96a3; }
.ed-coach-l {
  flex: 0 0 auto;
  font: 600 10px/1 ui-monospace, Menlo, monospace;
  color: #5b6673;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.ed-coach-m {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  font-style: italic;
  color: #9aa5b1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-coach-row.err .ed-coach-m { color: #ff9d9d; }
.ed-coach-row.warn .ed-coach-m { color: var(--ed-amber); }
.ed-coach-row.hint .ed-coach-m { color: #ffe066; }
.ed-coach-row.ok .ed-coach-m { color: var(--ed-ok); }
.ed-coach .ed-chip { position: static; flex: 0 0 auto; }

/* ---------- gutter ---------- */
.ed-gutter {
  position: relative;
  flex: 0 0 var(--ed-gut);
  width: var(--ed-gut);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
  border-right: 1px solid rgba(28, 34, 42, 0.9);
  user-select: none;
}
.ed-guts { padding: var(--ed-py) 0; will-change: transform; }
.ed-gr {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: var(--ed-lh);
  padding-right: 7px;
}
.ed-num {
  font-size: 0.86em;
  color: #4e5865;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}
.ed-gr[data-k="err"] .ed-num,
.ed-gr[data-k="warn"] .ed-num { color: #9aa5b1; }
.ed-gr[data-k="cur"] .ed-num { color: var(--ed-lime); }

.ed-mk {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.16s ease, transform 0.16s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.ed-mk.on { opacity: 1; transform: scale(1); }
.ed-mk svg { display: block; width: 100%; height: 100%; }
.ed-mk-err { color: var(--ed-red); }
.ed-mk-warn { color: var(--ed-amber); }
.ed-mk-hint { color: #ffe066; }
.ed-mk-ok { color: var(--ed-ok); }
.ed-mk-info { color: #8b96a3; }
.ed-mk-cur { color: var(--ed-lime); }
.ed-mk-cur i {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}
/* err dot pulses once when it appears */
.ed-gr[data-k="err"] .ed-mk.on svg { animation: ed-pop 0.34s ease-out; }
@keyframes ed-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- code area ---------- */
.ed-code {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.ed-hl {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: var(--ed-py) var(--ed-px);
  font: inherit;
  line-height: var(--ed-lh);
  white-space: pre;
  color: var(--ed-fg);
  pointer-events: none;
  will-change: transform;
  tab-size: 4;
}
.ed-hl code { display: block; font: inherit; }

.ed-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: var(--ed-py) var(--ed-px);
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--ed-lime);
  font: inherit;
  line-height: var(--ed-lh);
  letter-spacing: normal;
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  tab-size: 4;
  z-index: 3;
  scrollbar-width: none;
  -webkit-text-fill-color: transparent;
}
.ed-input::-webkit-scrollbar { display: none; }
.ed-input::selection { background: var(--ed-sel); }
.ed-input::placeholder { color: #3b444f; -webkit-text-fill-color: #3b444f; }

/* tokens */
.ed-hl .k { color: #ff79c6; }
.ed-hl .s { color: #f1fa8c; }
.ed-hl .n { color: #bd93f9; }
.ed-hl .c { color: #55616f; font-style: italic; }
.ed-hl .b {
  color: var(--ed-red);
  background: rgba(255, 107, 107, 0.13);
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.13);
}

/* ---------- marks layer ---------- */
.ed-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  will-change: transform;
  z-index: 2;
  overflow: visible;
}
.ed-cur {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--ed-lh);
  background: linear-gradient(90deg, rgba(198, 249, 75, 0.13), rgba(198, 249, 75, 0.05) 55%, rgba(198, 249, 75, 0));
  box-shadow: inset 2px 0 0 var(--ed-lime);
  animation: ed-cur-in 0.22s ease-out;
}
@keyframes ed-cur-in {
  from { opacity: 0; transform: translateX(-4px); }
  to { opacity: 1; transform: none; }
}

.ed-squig {
  position: absolute;
  height: 4px;
  background-repeat: repeat-x;
  background-size: 8px 4px;
  opacity: 0.95;
  animation: ed-squig-in 0.22s ease-out;
}
.ed-squig.err {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='4' viewBox='0 0 8 4'><path d='M0 3 Q2 0 4 3 T8 3' fill='none' stroke='%23ff6b6b' stroke-width='1.5' stroke-linecap='round'/></svg>");
}
.ed-squig.warn {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='4' viewBox='0 0 8 4'><path d='M0 3 Q2 0 4 3 T8 3' fill='none' stroke='%23ffb347' stroke-width='1.5' stroke-linecap='round'/></svg>");
}
@keyframes ed-squig-in {
  from { opacity: 0; }
  to { opacity: 0.95; }
}

.ed-ghost {
  position: absolute;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(7, 8, 10, 0.82);
  color: var(--ed-ghost);
  font-style: italic;
  white-space: nowrap;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  animation: ed-ghost-in 0.26s ease-out;
}
.ed-ghost.hint { color: #ffe066; }
.ed-ghost.warn { color: var(--ed-amber); }
.ed-ghost.err { color: #ff8f8f; }
.ed-ghost.ok { color: var(--ed-ok); }
.ed-ghost.info { color: #97a2af; }
.ed-ghost .ed-pre { color: #55606d; font-style: normal; margin-right: 1px; }
@keyframes ed-ghost-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

.ed-chip {
  position: absolute;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid rgba(198, 249, 75, 0.4);
  background: rgba(198, 249, 75, 0.13);
  color: var(--ed-lime);
  font: 600 11px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  animation: ed-ghost-in 0.26s ease-out;
  transition: background 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}
.ed-chip:hover { background: rgba(198, 249, 75, 0.22); box-shadow: 0 0 14px rgba(198, 249, 75, 0.22); }
.ed-chip:active { transform: scale(0.96); }
.ed-chip svg { width: 11px; height: 11px; }
.ed-chip.done {
  border-color: rgba(109, 255, 163, 0.45);
  background: rgba(109, 255, 163, 0.16);
  color: var(--ed-ok);
}

.ed-out {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 46%;
  height: 17px;
  padding: 0 7px;
  border-radius: 5px;
  background: rgba(70, 227, 255, 0.1);
  border: 1px solid rgba(70, 227, 255, 0.22);
  color: #9fe9fb;
  font-size: 0.8em;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  animation: ed-ghost-in 0.24s ease-out;
}
.ed-out .ed-out-a { color: rgba(70, 227, 255, 0.65); }

/* fix applied: diff flash */
.ed-flash {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--ed-lh);
  background: linear-gradient(90deg, rgba(109, 255, 163, 0.44), rgba(109, 255, 163, 0.16) 50%, rgba(109, 255, 163, 0));
  box-shadow: inset 2px 0 0 var(--ed-ok);
  animation: ed-flash 1s ease-out forwards;
}
@keyframes ed-flash {
  0% { opacity: 0; transform: scaleX(0.86); transform-origin: left; }
  14% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}
.ed-fixed {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(109, 255, 163, 0.16);
  border: 1px solid rgba(109, 255, 163, 0.4);
  color: var(--ed-ok);
  font: 600 10px/1 ui-sans-serif, system-ui, sans-serif;
  white-space: nowrap;
  animation: ed-fixed 1.15s ease-out forwards;
}
@keyframes ed-fixed {
  0% { opacity: 0; transform: translateY(4px); }
  16% { opacity: 1; transform: none; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-3px); }
}

/* screen reader status */
.ed-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* right edge fade when a line is wider than the box */
.ed-code.ed-scrollx::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 22px;
  background: linear-gradient(90deg, transparent, rgba(11, 14, 18, 0.9));
  pointer-events: none;
  z-index: 2;
}

/* ---------- phone ---------- */
@media (max-width: 560px) {
  .ed {
    --ed-fs: 16px;       /* keeps iOS from zooming the page on focus */
    --ed-lh: 25px;
    --ed-px: 12px;
    --ed-py: 10px;
    --ed-gut: 36px;
    border-radius: 10px;
  }
  .ed-gr { padding-right: 4px; gap: 2px; }
  .ed-mk { width: 15px; height: 15px; flex-basis: 15px; }
  .ed-chip { height: 28px; padding: 0 11px; font-size: 12px; }
  .ed-ghost { padding: 0 4px; font-size: 0.88em; }
  .ed-out { max-width: 62%; }
}

@media (prefers-reduced-motion: reduce) {
  .ed *, .ed *::before, .ed *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
