/* Alfred Hero Animation - 4-scene loop (Inbox → Classify → Playbook → Done)
 * Adapted from docs/alfred_hero.html in alfred-application.
 * Site palette: --cyan #22d3ee, --indigo #818cf8, warm amber #f59e0b.
 */

.alfred-anim-stage {
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, rgba(34,211,238,.04), rgba(129,140,248,.04));
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  margin-left: auto;
  font-family: inherit;
}
[data-theme="light"] .alfred-anim-stage {
  background: linear-gradient(135deg, rgba(8,145,178,.05), rgba(99,102,241,.05));
}

/* --- Alfred medallion --- */
.alfred-anim-stage .med {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid rgba(34,211,238,.7);
  box-shadow: 0 0 24px rgba(34,211,238,.25), 0 0 60px rgba(34,211,238,.08);
  background: #0a0f1a;
  opacity: 0;
  transform: translateY(20px);
  transition: all .8s cubic-bezier(.4,0,.2,1);
  z-index: 10;
}
.alfred-anim-stage .med.visible { opacity: 1; transform: translateY(0); }
.alfred-anim-stage .med img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transition: opacity .6s;
}
/* welcome_alfred is a full-body asset; zoom + anchor the head. */
.alfred-anim-stage .med .med-working {
  object-position: center top;
  transform: scale(2.1);
  transform-origin: 50% 8%;
}
/* e3 is a portrait crop - softer zoom. */
.alfred-anim-stage .med .med-done {
  object-position: center top;
  transform: scale(1.25);
  transform-origin: 50% 20%;
}
.alfred-anim-stage .med .med-done { opacity: 0; }
.alfred-anim-stage .med.done .med-working { opacity: 0; }
.alfred-anim-stage .med.done .med-done { opacity: 1; }

/* --- Speech bubble --- */
.alfred-anim-stage .speech {
  position: absolute;
  top: 50px;
  left: 25px;
  background: rgba(8,12,24,.97);
  border: 1px solid rgba(34,211,238,.55);
  border-radius: 14px 14px 14px 4px;
  padding: 12px 18px;
  max-width: 260px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  opacity: 0;
  transform: translateX(-16px) scale(.94);
  transition: all .5s cubic-bezier(.4,0,.2,1);
  z-index: 20;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
[data-theme="light"] .alfred-anim-stage .speech {
  background: rgba(255,255,255,.98);
  border-color: rgba(8,145,178,.35);
  color: var(--heading);
  box-shadow: 0 8px 24px rgba(15,23,42,.12);
}
.alfred-anim-stage .speech.visible { opacity: 1; transform: translateX(0) scale(1); }
.alfred-anim-stage .speech .accent { color: var(--cyan); font-weight: 600; }
.alfred-anim-stage .speech .warm { color: #f59e0b; font-weight: 600; }

/* --- Scene panel --- */
.alfred-anim-stage .scene-panel {
  position: absolute;
  top: 24px;
  right: 24px;
  bottom: 24px;
  width: 56%;
  background: rgba(15,23,42,.7);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  opacity: 0;
  transform: translateY(12px);
  transition: all .6s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  backdrop-filter: blur(6px);
  z-index: 5;
}
[data-theme="light"] .alfred-anim-stage .scene-panel {
  background: rgba(255,255,255,.85);
  box-shadow: 0 4px 14px rgba(15,23,42,.06);
}
.alfred-anim-stage .scene-panel.visible { opacity: 1; transform: translateY(0); }

/* --- Scene 1: Inbox --- */
.alfred-anim-stage .inbox-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.alfred-anim-stage .inbox-header .count {
  background: rgba(245,158,11,.15);
  border: 1px solid rgba(245,158,11,.3);
  color: #f59e0b;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 100px;
  font-weight: 700;
}
.alfred-anim-stage .mail-item {
  padding: 7px 10px;
  margin-bottom: 5px;
  background: rgba(255,255,255,.03);
  border-left: 2px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  opacity: 0;
  transform: translateX(-8px);
  transition: all .4s cubic-bezier(.4,0,.2,1);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
}
[data-theme="light"] .alfred-anim-stage .mail-item { background: rgba(15,23,42,.03); }
.alfred-anim-stage .mail-item.visible { opacity: 1; transform: translateX(0); }
.alfred-anim-stage .mail-item.unread { border-left-color: var(--cyan); background: rgba(34,211,238,.05); }
.alfred-anim-stage .mail-item.urgent { border-left-color: #ef4444; background: rgba(239,68,68,.06); }
.alfred-anim-stage .mail-from { font-weight: 600; color: var(--heading); }
.alfred-anim-stage .mail-subject { grid-column: 1; color: var(--muted); font-size: 10.5px; margin-top: 1px; }
.alfred-anim-stage .mail-time { grid-column: 2; grid-row: 1; color: var(--muted); font-size: 10px; }

/* --- Scene 2: Classify --- */
.alfred-anim-stage .classify-item {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11px;
  opacity: 0;
  transform: scale(.92);
  transition: all .45s cubic-bezier(.34,1.56,.64,1);
}
[data-theme="light"] .alfred-anim-stage .classify-item { background: rgba(15,23,42,.03); }
.alfred-anim-stage .classify-item.visible { opacity: 1; transform: scale(1); }
.alfred-anim-stage .classify-icon {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  background: rgba(34,211,238,.12);
}
.alfred-anim-stage .classify-icon.member { background: rgba(34,211,238,.14); }
.alfred-anim-stage .classify-icon.invoice { background: rgba(129,140,248,.16); }
.alfred-anim-stage .classify-icon.spam { background: rgba(239,68,68,.14); }
.alfred-anim-stage .classify-icon.request { background: rgba(245,158,11,.14); }
.alfred-anim-stage .classify-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alfred-anim-stage .classify-arrow { color: var(--muted); }
.alfred-anim-stage .classify-confidence { color: #22c55e; font-weight: 700; font-size: 10.5px; }

/* --- Scene 3: Playbook --- */
.alfred-anim-stage .playbook-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--cyan);
  margin-bottom: 10px;
  letter-spacing: .5px;
}
.alfred-anim-stage .playbook-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  margin-bottom: 4px;
  border-radius: 6px;
  opacity: 0;
  transform: translateX(-8px);
  transition: all .4s ease;
}
.alfred-anim-stage .playbook-step.visible { opacity: 1; transform: translateX(0); }
.alfred-anim-stage .step-status {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
  transition: all .3s;
}
.alfred-anim-stage .step-status.done { border-color: #22c55e; color: #22c55e; background: rgba(34,197,94,.1); }
.alfred-anim-stage .step-status.active { border-color: var(--cyan); color: var(--cyan); background: rgba(34,211,238,.12); }
.alfred-anim-stage .step-text { font-size: 11.5px; color: var(--text); }
.alfred-anim-stage .playbook-step.done .step-text { color: var(--muted); }

/* --- Scene 4: Done --- */
.alfred-anim-stage .done-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 6px 10px;
}
.alfred-anim-stage .done-check {
  font-size: 40px;
  color: #22c55e;
  line-height: 1;
  opacity: 0;
  transform: scale(.4);
  transition: all .5s cubic-bezier(.34,1.56,.64,1);
}
.alfred-anim-stage .done-check.visible { opacity: 1; transform: scale(1); }
.alfred-anim-stage .done-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--heading);
  margin: 6px 0 12px;
  opacity: 0;
  transition: opacity .5s;
}
.alfred-anim-stage .done-text.visible { opacity: 1; }
.alfred-anim-stage .done-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.alfred-anim-stage .done-stat {
  opacity: 0;
  transform: translateY(8px);
  transition: all .4s;
}
.alfred-anim-stage .done-stat.visible { opacity: 1; transform: translateY(0); }
.alfred-anim-stage .done-stat-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--cyan);
  line-height: 1;
}
.alfred-anim-stage .done-stat-label {
  font-size: 9.5px;
  color: var(--muted);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* --- Progress dots --- */
.alfred-anim-stage .progress-dots {
  position: absolute;
  bottom: 12px;
  right: 18px;
  display: flex;
  gap: 6px;
  z-index: 30;
}
.alfred-anim-stage .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: all .3s;
}
.alfred-anim-stage .dot.active {
  width: 18px;
  border-radius: 100px;
  background: var(--cyan);
}

/* --- Scan line effect --- */
.alfred-anim-stage .scanline {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  box-shadow: 0 0 20px var(--cyan);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
}

/* --- Responsive: below 900px, stage goes under hero text --- */
@media (max-width: 900px) {
  .alfred-anim-stage {
    max-width: 100%;
    margin: 32px 0 0;
  }
}

/* Below ~720px the floating layout gets too cramped - switch to a grid:
 * scene panel on top (full width), medallion + speech bubble as a chat
 * row below, progress dots aligned right. */
@media (max-width: 720px) {
  .alfred-anim-stage {
    aspect-ratio: auto;
    display: grid;
    grid-template-areas:
      "panel  panel"
      "med    speech"
      "dots   dots";
    grid-template-columns: 76px 1fr;
    grid-template-rows: auto auto auto;
    gap: 12px;
    padding: 16px;
    min-height: auto;
  }
  .alfred-anim-stage .scene-panel {
    grid-area: panel;
    position: relative;
    top: auto; right: auto; bottom: auto;
    width: 100%;
    min-height: 260px;
    padding: 12px 14px;
  }
  .alfred-anim-stage .med {
    grid-area: med;
    position: relative;
    left: auto; bottom: auto;
    width: 72px; height: 72px;
    align-self: start;
  }
  .alfred-anim-stage .speech {
    grid-area: speech;
    position: relative;
    top: auto; left: auto;
    max-width: 100%;
    align-self: center;
    font-size: 12.5px;
    padding: 10px 14px;
    border-radius: 14px 14px 14px 4px;
  }
  .alfred-anim-stage .progress-dots {
    grid-area: dots;
    position: relative;
    right: auto; bottom: auto;
    justify-content: flex-end;
  }
  .alfred-anim-stage .done-stat-num { font-size: 16px; }
}
