/* =====================================================================
   AGENTS LENS STUDIO -- editor.
   Three columns on a desktop: rail, stage, panel. One column on a phone,
   reordered so the card is the first thing you see.
   ===================================================================== */

.ed { min-height: 100dvh; display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ top */

.ed-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
  padding: 12px calc(env(safe-area-inset-right, 0px) + 20px)
           12px calc(env(safe-area-inset-left, 0px) + 20px);
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.4);
}

.ed-top-l { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ed-top-r { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.ed-logo { width: 42px; height: auto; display: block; flex-shrink: 0; }

.ed-name {
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.saved {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.3s ease;
  white-space: nowrap;
}
.saved.on { opacity: 0.75; }
.saved::before { content: '\2713 '; }

/* ----------------------------------------------------------------- body */

.ed-body {
  flex: 1;
  display: grid;
  grid-template-columns: 126px minmax(0, 1fr) 344px;
  align-items: stretch;
  min-height: 0;
}

/* ----------------------------------------------------------------- rail */

.ed-rail {
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  min-height: 0;
}

.rail-scroll {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  overflow-y: auto;
  min-height: 0;
}

.rail-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.thumb {
  position: relative;
  display: block;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  line-height: 0;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.thumb canvas { width: 62px; height: auto; display: block; border-radius: 4px; }
.thumb:hover { transform: translateY(-1px); }
.thumb.active { border-color: var(--gold); }

.thumb-n {
  position: absolute; left: -4px; top: -6px;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg-deep);
  border: 1px solid var(--line-2);
  color: var(--ink-3);
  font-size: 9px; font-weight: 700;
  line-height: 1;
}
.thumb.active .thumb-n { background: var(--gold); border-color: var(--gold); color: #14100a; }

.rail-tools { display: flex; gap: 2px; }
.rail-tools button {
  width: 20px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  color: var(--ink-4);
  font-size: 9px;
  transition: color 0.14s ease, background 0.14s ease;
}
.rail-tools button:hover:not(:disabled) { color: var(--gold); background: var(--gold-10); }
.rail-tools button:disabled { opacity: 0.28; }

/* Move and delete are 20x18 marks, which is right under a mouse and far too small under
   a thumb. On a touch screen they grow, and the space between them grows with them, so
   a near miss lands on nothing rather than on the control next door. Padding the hit box
   with a pseudo-element was tried first and does not work here: the rail is a scroll
   container, so anything overflowing the buttons gets clipped away. */
@media (pointer: coarse) {
  .rail-tools { gap: 6px; }
  .rail-tools button { height: 28px; font-size: 10px; }
}

.rail-add {
  flex-shrink: 0;
  padding: 9px 6px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.rail-add:hover:not(:disabled) { border-color: var(--gold-35); color: var(--gold); }
.rail-add:disabled { opacity: 0.35; }

/* ---------------------------------------------------------------- stage */

.ed-stage {
  display: flex; align-items: center; justify-content: center;
  padding: 26px 28px;
  min-width: 0; min-height: 0;
}

/* A canvas inherits letter-spacing into its text metrics, which would make the
   on-screen preview wrap differently from the detached export canvas. Reset it here
   as well as in renderInto, so a stray inherited value cannot reach a card. */
.ed-canvas, .thumb canvas {
  letter-spacing: normal;
  word-spacing: normal;
}

/* The preview is the export canvas at 1:1, scaled by CSS only. The height cap keeps
   the whole card on screen without a scroll; 0.8 is the 1080/1350 aspect. */
.ed-canvas {
  width: 100%;
  height: auto;
  max-width: min(100%, calc((100dvh - 190px) * 0.8));
  display: block;
  border-radius: 6px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

/* ---------------------------------------------------------------- panel */

.ed-panel {
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  min-height: 0;
}

.panel { flex: 1; padding: 22px 22px 8px; overflow-y: auto; min-height: 0; }

.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 16px; }
.panel-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.panel-count { font-size: 11px; color: var(--ink-4); }

.fld { display: block; }
.fld + .fld { margin-top: 18px; }

.fld-label {
  display: block;
  margin-bottom: 8px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--ink-3);
}

.fld-textarea {
  width: 100%;
  min-height: 190px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 14px; font-weight: 500;
  line-height: 1.55;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease;
}
.fld-textarea::placeholder { color: var(--ink-4); }
.fld-textarea:focus { border-color: var(--gold-35); }

.fld-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.fld-row .fld-label { margin-bottom: 0; }

.toggle {
  position: relative;
  width: 42px; height: 24px;
  flex-shrink: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line-2);
  transition: background 0.16s ease, border-color 0.16s ease;
}
.toggle.on { background: var(--gold-grad); border-color: transparent; }

.toggle-knob {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #f4f1ea;
  transition: transform 0.16s ease;
}
.toggle.on .toggle-knob { transform: translateX(18px); background: #14100a; }

.hint {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 2px solid var(--gold);
  background: var(--gold-10);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.5;
}

.panel-shared { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.panel-shared h3 {
  margin-bottom: 14px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--ink-4);
}

/* --------------------------------------------------------------- export */

.ed-export {
  flex-shrink: 0;
  display: flex; flex-direction: column; gap: 9px;
  padding: 18px 22px calc(env(safe-area-inset-bottom, 0px) + 20px);
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
}

/* --------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .ed-body { display: flex; flex-direction: column; }

  /* Card first, then the strip of slides, then the writing. */
  .ed-stage { order: 1; padding: 18px 18px 12px; }
  .ed-rail  { order: 2; }
  .ed-panel { order: 3; }

  .ed-canvas { max-width: min(100%, 360px); margin: 0 auto; }

  .ed-rail {
    flex-direction: row; align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-right: none;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .rail-scroll {
    flex-direction: row;
    align-items: flex-start;
    overflow-x: auto; overflow-y: hidden;
    padding-bottom: 2px;
  }
  .rail-item { flex-shrink: 0; }
  .rail-add { white-space: nowrap; align-self: center; }

  .ed-panel { border-left: none; }
  .panel { overflow: visible; }
  .fld-textarea { min-height: 130px; }

  /* Not sticky here. The page itself scrolls on a phone, and a pinned bar would sit
     on top of the textarea the agent is typing in. */
  .ed-export { padding-top: 20px; }
}

/* The top bar carries two labels for its back button and shows whichever fits. */
.lbl-short { display: none; }

@media (max-width: 460px) {
  .ed-top { padding-left: 14px; padding-right: 14px; gap: 8px; }
  .ed-name { font-size: 12px; }
  .btn-quiet { padding: 6px 8px; font-size: 11px; }
  .ed-logo { width: 34px; }
  .saved { display: none; }
  .lbl-full { display: none; }
  .lbl-short { display: inline; }
  .ed-stage { padding: 14px 14px 10px; }
  .panel { padding: 18px 16px 8px; }
  .ed-export { padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 16px); }
}
