/* ==========================================================================
   codeanim.css — self-writing code panel
   Uses design tokens already defined in :root by another stylesheet:
   --bg --surface --surface-2 --text --muted --accent --border
   --border-bright --radius
   ========================================================================== */

/* ---- Panel shell ------------------------------------------------------- */
.ca {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  isolation: isolate;
}

/* Slow, low-opacity light sweep across the top edge — reads as "alive"
   without competing for attention. Sits on a pseudo-element so it never
   affects layout or interferes with .ca__bar's own border. */
.ca::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  opacity: 0.45;
  pointer-events: none;
  z-index: 2;
  animation: ca-sweep 7s ease-in-out infinite alternate;
}

@keyframes ca-sweep {
  from { background-position: -60% 0; }
  to   { background-position: 160% 0; }
}

/* ---- Title bar ----------------------------------------------------------*/
.ca__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding-inline: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.ca__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.ca__dot:nth-child(1) { background: #ff5f57; }
.ca__dot:nth-child(2) { background: #febc2e; }
.ca__dot:nth-child(3) { background: #28c840; }

.ca__file {
  margin-left: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

.ca__status {
  margin-left: auto;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.ca__status.is-running {
  color: var(--accent);
  animation: ca-pulse 1.6s ease-in-out infinite;
}

.ca__status.is-done {
  color: #28c840;
  animation: none;
}

@keyframes ca-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ---- Code body ----------------------------------------------------------*/
.ca__body {
  margin: 0;
  padding: 20px 22px;
  font-size: 0.85rem;
  line-height: 1.75;
  min-height: 260px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ---- Syntax token colors -------------------------------------------------
   Distinct, harmonious against --surface (#121214). */
.t-kw   { color: #c792ea; }              /* keywords — soft violet */
.t-str  { color: #a3e635; }              /* strings — muted lime */
.t-num  { color: #f0b35e; }              /* numbers — warm amber */
.t-fn   { color: #22d3ee; }              /* functions — accent cyan */
.t-com  { color: var(--muted); font-style: italic; } /* comments */
.t-op   { color: #f5f5f5; opacity: 0.75; } /* operators — dim text */
.t-plain { color: var(--text); }

/* ---- Typing caret ---------------------------------------------------- */
.ca__caret {
  display: inline-block;
  width: 8px;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: ca-blink 1s step-end infinite;
}

@keyframes ca-blink {
  0%, 49%  { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---- Output panel ---------------------------------------------------- */
.ca__out {
  border-top: 1px solid var(--border);
  padding: 14px 22px;
  background: #0b0b0d;
  font-size: 0.8rem;
  color: #28c840;
}

/* ---- Reduced motion: kill everything that moves ----------------------- */
@media (prefers-reduced-motion: reduce) {
  .ca::before {
    animation: none;
  }
  .ca__caret {
    animation: none;
    opacity: 0;
  }
  .ca__status.is-running {
    animation: none;
  }
}

/* ---- Small-viewport safety: no horizontal page overflow --------------- */
@media (max-width: 360px) {
  .ca {
    max-width: 100%;
  }
  .ca__body {
    padding: 16px;
  }
}
