/* Animate — spell-driven video timeline (phone-first) */

#panel-animate.panel[hidden] {
  display: none !important;
}

#panel-animate.panel.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--an-header-offset, 8rem));
  max-height: calc(100dvh - var(--an-header-offset, 8rem));
  overflow: hidden;
  padding: 0;
  margin: 0;
}

body.an-tab-active #panel-animate.panel.active {
  min-height: calc(100dvh - var(--an-header-offset, 5.5rem));
  max-height: calc(100dvh - var(--an-header-offset, 5.5rem));
}

body.an-tab-active .site-footer {
  display: none;
}

body.an-tab-active .site-header .subtitle {
  display: none;
}

.an-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  background: var(--bg);
  -webkit-user-select: none;
  user-select: none;
}

.an-shell input,
.an-shell textarea {
  -webkit-user-select: text;
  user-select: text;
}

.an-top {
  flex: 0 0 auto;
  padding: 0.5rem max(0.65rem, env(safe-area-inset-left, 0.65rem)) 0.4rem
    max(0.65rem, env(safe-area-inset-right, 0.65rem));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.an-top-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.an-top-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.an-top-hint {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.an-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.an-dur-btn {
  min-height: 40px;
  padding: 0.35rem 0.65rem;
  font: inherit;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.an-dur-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(201, 162, 39, 0.12);
  font-weight: 600;
}

.an-res-btn {
  min-height: 40px;
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.an-res-btn.active {
  border-color: #7eb8ff;
  color: #9ec9ff;
  background: rgba(80, 140, 220, 0.12);
  font-weight: 600;
}

.an-dur-badge {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #f0e6c8;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 39, 0.45);
  background: rgba(40, 32, 12, 0.55);
  white-space: nowrap;
}

.an-autopilot-check {
  color: #9fd4b0 !important;
}

body.an-autopilot-on .an-dur-badge {
  border-color: rgba(100, 200, 140, 0.55);
  color: #b8f0c8;
  animation: an-badge-pulse 1.6s ease-in-out infinite;
}

@keyframes an-badge-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(100, 200, 140, 0.15);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(100, 200, 140, 0.12);
  }
}

.an-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

.an-prompt-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.an-prompt {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.an-mention-menu {
  position: fixed;
  z-index: 10050;
  min-width: 11rem;
  max-width: min(18rem, calc(100vw - 1.5rem));
  max-height: 12rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: 10px;
  background: rgba(10, 12, 20, 0.97);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(201, 162, 39, 0.12);
}

.an-mention-menu[hidden] {
  display: none !important;
}

.an-mention-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
}

.an-mention-item:hover,
.an-mention-item.an-mention-active {
  background: rgba(201, 162, 39, 0.18);
}

.an-mention-item.an-mention-active {
  outline: 1px solid rgba(201, 162, 39, 0.45);
  outline-offset: -1px;
}

.an-mention-thumb {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  object-fit: cover;
  background: #000;
}

.an-mention-thumb.an-mention-thumb-empty {
  display: inline-block;
  background: rgba(201, 162, 39, 0.15);
}

.an-mention-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.an-mention-name {
  font-weight: 600;
  color: #e8d8a0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-mention-tag {
  font-size: 0.62rem;
  color: var(--text-muted);
}

.an-mention-badge {
  flex: 0 0 auto;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.12rem 0.3rem;
  border-radius: 999px;
  background: rgba(62, 107, 66, 0.85);
  color: #d8f0da;
}

.an-mention-empty {
  padding: 0.45rem 0.55rem;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.an-paste-row {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.an-paste {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.an-btn {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.35rem 0.65rem;
  font: inherit;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.an-btn.accent {
  border-color: var(--accent);
  color: var(--accent);
}

.an-btn.an-on {
  border-color: #e6c15a;
  background: rgba(230, 193, 90, 0.22);
  color: #e6c15a;
}

.an-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.an-status {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1.1em;
}

.an-status.pending { color: var(--accent); }
.an-status.error { color: #e8a090; }
.an-status.ok { color: #8ec9a0; }

.an-progress-wrap {
  margin-top: 0.35rem;
}

.an-progress-wrap[hidden] {
  display: none !important;
}

.an-progress-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.an-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(201, 162, 39, 0.65), var(--accent));
  transition: none;
}

.an-progress-fill.is-finishing {
  background-image: linear-gradient(
    90deg,
    rgba(201, 162, 39, 0.45),
    #f3e2a4,
    var(--accent),
    rgba(201, 162, 39, 0.45)
  );
  background-size: 220% 100%;
  animation: an-progress-sheen 0.7s linear infinite;
}

.an-progress-fill.is-done {
  width: 100%;
  animation: none;
}

@keyframes an-progress-sheen {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

.an-progress-detail {
  margin: 0.25rem 0 0;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.an-workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.an-column {
  min-width: 0;
  min-height: 0;
}

.an-column-stage {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
}

.an-column-tray {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border);
  container-type: inline-size;
  container-name: an-tray;
}

.an-stage-wrap {
  flex: 0 1 auto;
  min-height: 0;
  padding: 0.4rem max(0.5rem, env(safe-area-inset-left, 0.5rem)) 0.3rem
    max(0.5rem, env(safe-area-inset-right, 0.5rem));
}

.an-drop-zone {
  position: relative;
  min-height: min(28dvh, 12rem);
  max-height: min(38dvh, 16rem);
  border: 2px dashed rgba(201, 162, 39, 0.35);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: manipulation;
}

.an-drop-zone.an-drop-active {
  border-color: var(--accent);
  background: rgba(201, 162, 39, 0.1);
  box-shadow: inset 0 0 40px rgba(201, 162, 39, 0.12);
}

.an-drop-zone.an-generating {
  border-style: solid;
  border-color: rgba(201, 162, 39, 0.55);
  box-shadow: inset 0 0 48px rgba(201, 162, 39, 0.08);
  cursor: crosshair;
}

.an-drop-zone.an-box-on {
  border-style: solid;
  border-color: #e6c15a;
}

.an-sparkle-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

.an-place-row,
.an-object-row {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.an-place-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.an-mention-kind-character { background: rgba(120, 180, 220, 0.25); }
.an-mention-kind-object { background: rgba(200, 140, 80, 0.25); }
.an-mention-kind-room { background: rgba(100, 180, 120, 0.25); }
.an-mention-kind-chain {
  background: rgba(201, 162, 39, 0.45);
  color: #fff8dc;
}

.an-mention-name-chain {
  color: var(--accent) !important;
}

.an-mention-tag-chain {
  color: var(--accent) !important;
  font-weight: 700;
}

.an-gen-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.42;
  filter: saturate(1.15) contrast(1.05);
  transform-origin: center center;
  animation: an-kenburns 14s ease-in-out infinite alternate;
  pointer-events: none;
}

.an-gen-preview[hidden] {
  display: none !important;
}

@keyframes an-kenburns {
  0% { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.12) translate(-2%, -1.5%); }
}

.an-gen-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1rem;
  text-align: center;
  background: linear-gradient(
    180deg,
    rgba(8, 10, 18, 0.55) 0%,
    rgba(8, 10, 18, 0.78) 55%,
    rgba(8, 10, 18, 0.88) 100%
  );
  pointer-events: auto;
}

.an-gen-overlay[hidden] {
  display: none !important;
}

.an-gen-pulse {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 39, 0.35);
  animation: an-gen-pulse 2.2s ease-out infinite;
  pointer-events: none;
}

@keyframes an-gen-pulse {
  0% { transform: scale(0.85); opacity: 0.75; }
  70% { transform: scale(1.15); opacity: 0.15; }
  100% { transform: scale(1.2); opacity: 0; }
}

.an-gen-phase {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.an-gen-timer {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: 0.88rem;
  color: #e8d8a0;
  font-variant-numeric: tabular-nums;
}

.an-gen-eta {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 18rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.an-gen-cancel {
  position: relative;
  z-index: 1;
  margin-top: 0.35rem;
  min-width: 6.5rem;
}

.an-drop-zone.an-generating .an-drop-hint {
  display: none;
}

.an-drop-zone.an-generating .an-player {
  opacity: 0.15;
}

.an-theater-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem max(0.75rem, env(safe-area-inset-left, 0.75rem))
    max(0.65rem, env(safe-area-inset-bottom, 0.65rem))
    max(0.75rem, env(safe-area-inset-right, 0.75rem));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.82));
  pointer-events: auto;
}

.an-theater-bar[hidden] {
  display: none !important;
}

.an-theater-meta {
  font-size: 0.82rem;
  color: #e8d8a0;
  font-variant-numeric: tabular-nums;
}

.an-theater-exit {
  min-height: 40px;
  border-color: rgba(255, 255, 255, 0.35);
  color: #f0f0f0;
}

body.an-theater-active {
  overflow: hidden;
}

body.an-theater-active .site-header,
body.an-theater-active .site-footer,
body.an-theater-active .an-top,
body.an-theater-active .an-timeline-panel,
body.an-theater-active .an-tray {
  display: none !important;
}

body.an-theater-active #panel-animate.panel.active {
  min-height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  margin: 0;
}

body.an-theater-active .an-shell {
  height: 100dvh;
}

body.an-theater-active .an-stage-wrap {
  flex: 1 1 auto;
  padding: 0;
  min-height: 0;
}

body.an-theater-active .an-drop-zone {
  min-height: 100dvh;
  max-height: 100dvh;
  border: none;
  border-radius: 0;
  background: #000;
}

body.an-theater-active .an-drop-hint,
body.an-theater-active .an-gen-overlay,
body.an-theater-active .an-gen-preview {
  display: none !important;
}

body.an-theater-active .an-player {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
}

body.an-theater-active .an-drop-zone:fullscreen,
body.an-theater-active .an-drop-zone:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: #000;
}

.an-drop-hint {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
  max-width: 16rem;
  pointer-events: none;
}

.an-drop-zone.an-has-video .an-drop-hint {
  display: none;
}

.an-drop-zone .an-player {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
}

.an-player {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: #000;
  -webkit-touch-callout: default;
}

.an-player.an-player-alt {
  z-index: 1;
  pointer-events: none;
}

.an-player.an-player-active {
  z-index: 3;
}

.an-timeline-panel {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: rgba(8, 10, 18, 0.92);
  padding: 0.35rem max(0.5rem, env(safe-area-inset-left, 0.5rem)) 0.25rem
    max(0.5rem, env(safe-area-inset-right, 0.5rem));
}

.an-timeline-head {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.an-timeline-meta {
  display: block;
  line-height: 1.35;
  word-break: break-word;
}

.an-timeline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.an-saved-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.an-saved-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.an-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.an-saved-list[hidden] {
  display: none !important;
}

.an-saved-num {
  min-width: 1.8rem;
  height: 1.8rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 39, 0.7);
  background: rgba(201, 162, 39, 0.14);
  color: inherit;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.an-box-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  cursor: crosshair;
  touch-action: none;
}

.an-box-layer[hidden] {
  display: none !important;
}

.an-box-preview-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.an-box-preview-row[hidden] {
  display: none !important;
}

.an-box-preview-row img {
  width: 7.5rem;
  height: 4.5rem;
  object-fit: contain;
  background: #000;
  border: 1px solid rgba(230, 193, 90, 0.75);
  border-radius: 6px;
}

.an-box-preview-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.an-box-band {
  position: absolute;
  border: 2px solid #e6c15a;
  background: rgba(230, 193, 90, 0.22);
  pointer-events: none;
}

.an-timeline-head strong {
  color: var(--accent);
  font-weight: 600;
}

.an-timeline-scroll {
  flex: 0 0 auto;
  min-height: 5.5rem;
  height: 5.5rem;
  max-height: 5.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
}

.an-timeline-track {
  position: relative;
  height: 5rem;
  min-width: 100%;
}

.an-timeline-ruler {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.58rem;
  color: var(--text-muted);
  pointer-events: none;
}

.an-ruler-tick {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 2px;
  line-height: 1.1rem;
}

.an-segments-layer {
  position: absolute;
  top: 1.25rem;
  left: 0;
  right: 0;
  bottom: 0.25rem;
}

.an-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(201, 162, 39, 0.6);
  z-index: 4;
  pointer-events: none;
}

.an-segment {
  position: absolute;
  top: 0.15rem;
  bottom: 0.15rem;
  min-width: 28px;
  border: 1px solid rgba(201, 162, 39, 0.55);
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.25), rgba(40, 30, 60, 0.85));
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.an-segment.an-seg-pending {
  opacity: 0.75;
  border-style: dashed;
  animation: an-seg-shimmer 1.8s ease-in-out infinite;
}

@keyframes an-seg-shimmer {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

.an-segment.an-seg-active {
  box-shadow: 0 0 0 2px var(--accent);
}

.an-seg-thumb {
  flex: 1 1 auto;
  width: 100%;
  object-fit: cover;
  opacity: 0.85;
  pointer-events: none;
}

.an-seg-label {
  flex: 0 0 auto;
  font-size: 0.55rem;
  padding: 0.1rem 0.2rem;
  background: rgba(0, 0, 0, 0.65);
  color: #e8d8a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.an-character-row {
  padding: 0.45rem 0.65rem 0.35rem;
  border-bottom: 1px solid rgba(201, 162, 39, 0.12);
}

.an-character-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.an-character-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.an-cast-roster-count {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.an-cast-roster-count.an-cast-live {
  color: #8ec9a0;
  font-weight: 600;
}

.an-cast-hint {
  margin: 0 0 0.4rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.an-character-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  -webkit-overflow-scrolling: touch;
}

.an-character-chip {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 4.6rem;
  padding: 0.35rem 0.3rem 0.4rem;
  border: 2px dashed rgba(120, 128, 150, 0.45);
  border-radius: 10px;
  background: rgba(8, 10, 18, 0.55);
  cursor: pointer;
  opacity: 0.52;
  filter: grayscale(0.75) brightness(0.82);
  transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease, transform 0.15s ease;
}

.an-character-chip:hover {
  opacity: 0.78;
  filter: grayscale(0.35) brightness(0.95);
}

.an-character-chip.on-cast {
  opacity: 1;
  filter: none;
  border: 3px solid var(--accent);
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.22) 0%, rgba(12, 14, 22, 0.95) 100%);
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.35), 0 6px 20px rgba(201, 162, 39, 0.28);
  transform: translateY(-2px);
}

.an-character-chip.on-cast::after {
  content: "ON CAST";
  position: absolute;
  top: -0.45rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: #3d6b42;
  color: #d8f0da;
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.an-character-chip.off-cast::before {
  content: "off";
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  font-size: 0.48rem;
  color: rgba(180, 185, 200, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.an-character-chip img {
  width: 2.6rem;
  height: 2.6rem;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #000;
}

.an-character-chip.on-cast img {
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.55);
}

.an-character-chip-name {
  font-size: 0.6rem;
  color: var(--text-muted);
  max-width: 4.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.an-character-chip.on-cast .an-character-chip-name {
  color: #e8d8a0;
  font-weight: 600;
}

.an-character-empty {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.an-cast-panel {
  padding: 0.45rem 0.65rem 0.5rem;
  border-bottom: 1px solid rgba(201, 162, 39, 0.18);
  background: rgba(8, 10, 18, 0.72);
}

.an-cast-panel[hidden] {
  display: none !important;
}

.an-cast-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.an-cast-panel-head span {
  font-size: 0.68rem;
  font-weight: 600;
  color: #e8d8a0;
}

.an-cast-clear-btn {
  min-height: 30px;
  font-size: 0.62rem;
  padding: 0.2rem 0.45rem;
}

.an-beat-intro {
  margin: 0 0 0.4rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.an-beat-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.45rem;
}

.an-beat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.an-beat-quick-btn {
  min-height: 28px;
  padding: 0.15rem 0.4rem;
  font-size: 0.6rem;
}

.an-cast-list,
.an-beat-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: none;
  overflow-y: visible;
}

.an-beat-intro-action { color: #e87878; }
.an-beat-intro-dialogue { color: #68c878; }
.an-beat-intro-reaction { color: #e8a858; }

.an-beat-add-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.an-beat-add-btn {
  min-height: 32px;
  font-size: 0.68rem;
  font-weight: 600;
  border-width: 2px;
}

.an-beat-add-action {
  border-color: rgba(200, 80, 80, 0.75);
  color: #f0a0a0;
  background: rgba(200, 80, 80, 0.12);
}

.an-beat-add-dialogue {
  border-color: rgba(80, 168, 104, 0.75);
  color: #a8e8b8;
  background: rgba(80, 168, 104, 0.12);
}

.an-beat-add-reaction {
  border-color: rgba(216, 144, 72, 0.75);
  color: #f0c890;
  background: rgba(216, 144, 72, 0.12);
}

.an-beat-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid rgba(201, 162, 39, 0.32);
  border-radius: 10px;
  background: rgba(12, 14, 22, 0.92);
  border-left: 4px solid var(--accent);
}

.an-beat-card.an-beat-type-action {
  border-left-color: #c85050;
  box-shadow: inset 0 0 0 1px rgba(200, 80, 80, 0.08);
}

.an-beat-card.an-beat-type-dialogue {
  border-left-color: #50a868;
  box-shadow: inset 0 0 0 1px rgba(80, 168, 104, 0.08);
}

.an-beat-card.an-beat-type-reaction {
  border-left-color: #d89048;
  box-shadow: inset 0 0 0 1px rgba(216, 144, 72, 0.08);
}

.an-beat-card.an-beat-follow {
  outline: 1px dashed rgba(106, 158, 200, 0.45);
  outline-offset: 1px;
}

.an-beat-type-select {
  flex: 0 0 auto;
  min-width: 5.5rem;
  max-width: 6.5rem;
  padding: 0.2rem 0.35rem;
  font: inherit;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  border-width: 2px;
  cursor: pointer;
}

.an-beat-type-select-action {
  color: #ffd0d0;
  background: rgba(200, 80, 80, 0.28);
  border-color: rgba(200, 80, 80, 0.65);
}

.an-beat-type-select-dialogue {
  color: #d0f8d8;
  background: rgba(80, 168, 104, 0.28);
  border-color: rgba(80, 168, 104, 0.65);
}

.an-beat-type-select-reaction {
  color: #ffe8c8;
  background: rgba(216, 144, 72, 0.28);
  border-color: rgba(216, 144, 72, 0.65);
}

.an-beat-head {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto auto auto;
  gap: 0.3rem;
  align-items: center;
}

.an-beat-num {
  font-size: 0.62rem;
  font-weight: 700;
  color: #e8d8a0;
  min-width: 3.2rem;
}

.an-beat-move {
  display: flex;
  gap: 0.15rem;
}

.an-beat-move .an-btn {
  min-height: 26px;
  padding: 0.1rem 0.35rem;
  font-size: 0.68rem;
  line-height: 1;
}

.an-beat-char-select {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
}

.an-beat-rm {
  min-height: 28px;
  font-size: 0.62rem;
  white-space: nowrap;
}

.an-beat-follow-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.62rem;
  color: var(--text-muted);
}

.an-beat-follow-row input {
  accent-color: var(--accent);
}

.an-beat-fields {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.an-beat-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 0.75rem;
}

.an-beat-input-action {
  border: 2px solid rgba(200, 80, 80, 0.65);
  background: rgba(200, 80, 80, 0.1);
  color: #ffe0e0;
  border-radius: 8px;
}

.an-beat-input-dialogue {
  border: 2px solid rgba(80, 168, 104, 0.7);
  background: rgba(80, 168, 104, 0.14);
  color: #e8ffe8;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  min-height: 2.6rem;
  resize: vertical;
  line-height: 1.35;
}

.an-beat-input-reaction {
  border: 2px solid rgba(216, 144, 72, 0.7);
  background: rgba(216, 144, 72, 0.12);
  color: #fff0d8;
  border-radius: 14px;
}

.an-beat-field-action label { color: #e87878; }
.an-beat-field-dialogue label { color: #68c878; }
.an-beat-field-reaction label { color: #e8a858; }

.an-cast-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 10px;
  background: rgba(12, 14, 22, 0.92);
  box-shadow: inset 0 0 0 1px rgba(201, 162, 39, 0.08);
}

.an-cast-card-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.an-cast-card-thumb {
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: #000;
}

.an-cast-card-head {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.an-cast-card-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: #e8d8a0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-cast-card-badge {
  flex: 0 0 auto;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.3rem;
  border-radius: 999px;
  background: rgba(62, 107, 66, 0.85);
  color: #d8f0da;
}

.an-cast-card-rm {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0.15rem 0.4rem;
  font-size: 0.62rem;
}

.an-cast-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.an-cast-field label {
  font-size: 0.58rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.an-cast-input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
}

.an-tray {
  flex: 0 0 auto;
  background: var(--bg-elevated);
  padding: 0.4rem 0 max(0.5rem, env(safe-area-inset-bottom, 0.5rem));
}

.an-tray-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.65rem 0.4rem;
  align-items: center;
}

.an-spell-search {
  flex: 1 1 10rem;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.an-spell-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.22);
}

.an-spell-search::-webkit-search-cancel-button {
  cursor: pointer;
}

.an-spell-strip-empty {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.5rem 0.25rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.an-tray-count {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex: 1 1 100%;
  text-align: right;
  min-width: 0;
}

.an-spell-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.25rem 0.65rem 0.35rem;
  -webkit-overflow-scrolling: touch;
  min-height: 5.5rem;
}

.an-spell {
  flex: 0 0 auto;
  width: 4.5rem;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  cursor: grab;
  touch-action: none;
  overflow: hidden;
}

.an-spell.an-spell-dragging { opacity: 0.45; }

.an-spell-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  pointer-events: none;
}

.an-spell-label {
  display: block;
  font-size: 0.58rem;
  padding: 0.15rem 0.2rem;
  text-align: center;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.an-drag-ghost {
  position: fixed;
  z-index: 9999;
  width: 4.5rem;
  pointer-events: none;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  opacity: 0.92;
}

.an-drag-ghost img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

/* Stacked column — scroll as one unit; cap stage so tray/beats stay reachable */
@media (max-width: 879px) {
  .an-workspace {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .an-column-stage {
    flex: 0 0 auto;
  }

  .an-column-tray {
    flex: 0 0 auto;
    overflow-y: visible;
  }

  .an-drop-zone {
    min-height: min(20dvh, 9rem);
    max-height: min(26dvh, 12.5rem);
  }

  .an-timeline-scroll {
    height: 5.5rem;
    max-height: 5.5rem;
  }
}

/* Side-by-side: stage + timeline left, cast/script/spells scroll right */
@media (min-width: 880px) {
  .an-workspace {
    flex-direction: row;
    align-items: stretch;
    overflow: hidden;
  }

  .an-column-stage {
    flex: 1 1 58%;
    min-width: 0;
    border-top: none;
  }

  .an-column-tray {
    flex: 0 0 clamp(17rem, 38%, 24rem);
    min-width: 17rem;
    border-top: none;
    border-left: 1px solid var(--border);
  }

  .an-stage-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 8rem;
  }

  .an-drop-zone {
    flex: 1 1 auto;
    min-height: 10rem;
    max-height: none;
    height: auto;
  }

  .an-timeline-scroll {
    height: 5.5rem;
    max-height: 5.5rem;
  }
}

@media (min-width: 769px) {
  #panel-animate.panel.active {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .an-spell { width: 5.25rem; }
}

/* Narrow tray or viewport — stack beat controls, avoid overlap */
@container an-tray (max-width: 28rem) {
  .an-beat-head {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "num type select select"
      "moves moves dup rm";
  }

  .an-beat-num { grid-area: num; }
  .an-beat-type-select { grid-area: type; }
  .an-beat-move { grid-area: moves; }
  .an-beat-char-select { grid-area: select; }
  .an-beat-dup { grid-area: dup; justify-self: start; }
  .an-beat-rm { grid-area: rm; justify-self: end; }

  .an-cast-panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .an-cast-clear-btn {
    width: 100%;
  }

  .an-beat-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .an-beat-add-group {
    width: 100%;
  }

  .an-beat-add-group .an-beat-add-btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 900px) {
  .an-paste-row {
    flex-direction: column;
    align-items: stretch;
  }

  .an-paste-row .an-btn {
    width: 100%;
  }

  .an-beat-add-group {
    width: 100%;
  }

  .an-beat-add-group .an-beat-add-btn {
    flex: 1 1 auto;
  }

  .an-beat-head {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "num type select select"
      "moves moves dup rm";
  }

  .an-beat-num { grid-area: num; }
  .an-beat-type-select { grid-area: type; }
  .an-beat-move { grid-area: moves; }
  .an-beat-char-select { grid-area: select; }
  .an-beat-dup { grid-area: dup; justify-self: start; }
  .an-beat-rm { grid-area: rm; justify-self: end; }

  .an-cast-panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .an-cast-clear-btn {
    width: 100%;
  }

  .an-beat-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

}

/* Short window — compact chrome, let tray scroll */
@media (max-height: 760px) {
  body.an-tab-active .an-top-hint,
  body.an-tab-active #an-dur-hint {
    display: none;
  }

  .an-cast-hint,
  .an-beat-intro {
    display: none;
  }

  .an-drop-zone {
    min-height: 9rem;
    max-height: 14rem;
  }

  .an-character-chip.on-cast::after {
    font-size: 0.42rem;
    top: -0.35rem;
  }
}

/* Very short — shrink stage further */
@media (max-height: 580px) {
  .an-drop-zone {
    min-height: 7rem;
    max-height: 10rem;
  }

  .an-spell-strip {
    min-height: 4.5rem;
  }
}