/* ---- AI Comic Drama - Polished Minimalist Redesign ---- */

.cd-mode .tool-hero {
  display: none;
}

.cd-mode .tool-detail-head {
  display: none;
}

.cd-mode {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  backdrop-filter: none;
}

.cd-root {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.cd-root,
.cd-root * {
  box-sizing: border-box;
}

.cd-back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-bottom: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cd-back-link:hover {
  background: #f1f5f9;
  color: #334155;
}

.cd-back-link:active {
  background: #e2e8f0;
}

.cd-back-link svg {
  width: 18px;
  height: 18px;
  color: #6366f1;
}

.cd-page {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.cd-page.hidden,
.cd-dialog.hidden {
  display: none;
}

.cd-form-card,
.cd-stage-card,
.cd-result-card,
.cd-history-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #fff;
}

.cd-form-header,
.cd-stage-header,
.cd-panel-head,
.cd-block-head,
.cd-dialog-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.cd-form-header-icon,
.cd-block-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex-shrink: 0;
}

.cd-form-header-icon {
  background: #ede9fe;
  color: #6366f1;
}

.cd-block-icon {
  background: #e0f2fe;
  color: #0284c7;
}

.cd-form-header-icon svg,
.cd-block-icon svg {
  width: 16px;
  height: 16px;
}

.cd-form-header > div:last-child,
.cd-stage-copy {
  flex: 1;
  min-width: 0;
}

.cd-form-header h3,
.cd-stage-copy h3,
.cd-panel-head h3,
.cd-block-head h4,
.cd-dialog-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.cd-form-header p,
.cd-stage-subtitle {
  margin: 4px 0 0;
  font-size: 0.78rem;
  line-height: 1.6;
  color: #64748b;
}

.cd-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cd-field > span {
  font-size: 0.78rem;
  font-weight: 600;
  color: #334155;
}

.cd-title-input,
.cd-textarea {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #334155;
  font: inherit;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.cd-title-input {
  min-height: 44px;
  padding: 0 12px;
}

.cd-textarea-wrap {
  width: 100%;
}

.cd-textarea {
  min-height: 128px;
  padding: 12px;
  line-height: 1.6;
  resize: vertical;
}

.cd-textarea--small {
  min-height: 96px;
}

.cd-title-input:focus,
.cd-textarea:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  background: #fff;
}

.cd-field-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cd-field-hint {
  font-size: 0.72rem;
  line-height: 1.5;
  color: #94a3b8;
}

.cd-char-count {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: #94a3b8;
}

.cd-char-count.cd-near-limit {
  color: #d97706;
}

.cd-char-count.cd-at-limit {
  color: #dc2626;
}

.cd-submit-btn,
.cd-inline-btn,
.cd-btn-sm,
.cd-download-btn {
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  transition: all 0.2s ease;
}

.cd-submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: #6366f1;
  color: #fff;
  cursor: pointer;
}

.cd-submit-btn:hover,
.cd-download-btn:hover {
  opacity: 0.92;
}

.cd-submit-btn:disabled,
.cd-inline-btn:disabled,
.cd-btn-sm:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.cd-submit-btn--secondary {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #475569;
}

.cd-stage-header {
  align-items: center;
}

.cd-inner-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #64748b;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cd-inner-back:hover {
  background: #f1f5f9;
  color: #334155;
}

.cd-inner-back svg {
  width: 16px;
  height: 16px;
}

.cd-stage-tag,
.cd-panel-tag {
  margin: 0 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.cd-stage-toolbar,
.cd-result-meta,
.cd-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cd-stage-toolbar {
  flex-wrap: wrap;
}

.cd-stage-count,
.cd-panel-count,
.cd-result-time {
  font-size: 0.74rem;
  font-weight: 600;
  color: #64748b;
}

.cd-inline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
}

.cd-inline-btn:hover {
  background: #f1f5f9;
  color: #334155;
}

.cd-form-card .message,
.cd-stage-card .message,
.cd-result-card .message {
  margin: 0;
}

.cd-character-list,
.cd-recent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cd-character-card,
.cd-recent-item,
.cd-block,
.cd-state-card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
}

.cd-character-card,
.cd-block,
.cd-state-card {
  padding: 14px;
}

.cd-character-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.cd-character-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ede9fe, #dbeafe);
  color: #4f46e5;
  font-size: 1.35rem;
  font-weight: 800;
  overflow: hidden;
  flex-shrink: 0;
}

.cd-character-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cd-avatar-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cd-avatar-loading::after {
  content: "";
  width: 22px;
  height: 22px;
  border: 3px solid rgba(99, 102, 241, 0.18);
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: cd-spin 0.8s linear infinite;
}

.cd-character-copy {
  flex: 1;
  min-width: 0;
}

.cd-character-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.cd-character-top strong,
.cd-recent-info strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  color: #1e293b;
}

.cd-character-desc,
.cd-character-voice,
.cd-recent-info span,
.cd-block-text,
.cd-state-meta,
.cd-error-text {
  font-size: 0.78rem;
  line-height: 1.65;
  color: #64748b;
}

.cd-character-desc {
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.cd-character-voice {
  margin-top: 6px;
}

.cd-character-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.cd-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid transparent;
  background: #fff;
  cursor: pointer;
}

.cd-btn-outline {
  border-color: #cbd5e1;
  color: #475569;
}

.cd-btn-outline:hover {
  border-color: #6366f1;
  color: #4f46e5;
}

.cd-btn-danger {
  margin-left: auto;
  border-color: #fecaca;
  color: #dc2626;
}

.cd-btn-danger:hover {
  background: #fef2f2;
}

.cd-block-head {
  align-items: center;
}

.cd-block-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.cd-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.cd-status-badge.is-pending {
  background: #eef2ff;
  color: #4f46e5;
}

.cd-status-badge.is-success {
  background: #ecfdf3;
  color: #15803d;
}

.cd-status-badge.is-failed {
  background: #fef2f2;
  color: #dc2626;
}

.cd-state-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cd-state-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.cd-state-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

.cd-state-header.is-pending {
  color: #4f46e5;
}

.cd-state-header.is-success {
  color: #15803d;
}

.cd-state-header.is-failed {
  color: #dc2626;
}

.cd-state-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e293b;
}

.cd-progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.cd-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #818cf8, #6366f1);
}

.cd-video-wrap {
  overflow: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #0f172a;
}

.cd-video-player {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: #020617;
}

.cd-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  background: #0f172a;
  color: #fff;
  text-decoration: none;
}

.cd-error-text {
  margin: 0;
}

.cd-recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cd-recent-item:hover {
  background: #f1f5f9;
}

.cd-recent-info {
  min-width: 0;
}

.cd-recent-info span {
  display: block;
  margin-top: 4px;
}

.cd-recent-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cd-recent-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff;
  color: #dc2626;
  cursor: pointer;
}

.cd-recent-delete:hover {
  background: #fef2f2;
}

.cd-history-empty {
  padding: 18px 14px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.6;
  color: #94a3b8;
}

.cd-dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.cd-dialog-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(2px);
}

.cd-dialog-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 420px);
  max-height: calc(100vh - 48px);
  padding: 18px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #fff;
  overflow-y: auto;
}

.cd-dialog-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cd-portrait-clickable {
  cursor: pointer;
}

.cd-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  width: 100vw;
  min-height: 100vh;
  height: 100dvh;
  padding: 0;
}

.cd-lightbox.hidden {
  display: none;
}

.cd-lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
}

.cd-lightbox-content {
  position: relative;
  z-index: 1;
  width: 100vw;
  min-height: 100vh;
  height: 100dvh;
  max-width: none;
}

.cd-lightbox-viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(env(safe-area-inset-top, 0px), 16px)
    16px
    max(env(safe-area-inset-bottom, 0px), 16px)
    16px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.cd-lightbox-viewport.is-zoomed {
  cursor: grab;
}

.cd-lightbox-content img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 14px;
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.04s linear;
  user-select: none;
  -webkit-user-drag: none;
}

.cd-lightbox-close {
  position: absolute;
  top: max(env(safe-area-inset-top, 0px), 16px);
  right: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  background: #fff;
  color: #475569;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
}

.cd-lightbox-close:hover {
  background: #f1f5f9;
  color: #1e293b;
}

@keyframes cd-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes cd-pulse {
  0%,
  100% {
    opacity: 0.72;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .cd-form-card,
  .cd-stage-card,
  .cd-result-card,
  .cd-history-panel {
    padding: 14px;
  }

  .cd-stage-header,
  .cd-character-main,
  .cd-recent-item,
  .cd-result-meta {
    align-items: flex-start;
  }

  .cd-character-top,
  .cd-panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .cd-character-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cd-btn-danger {
    margin-left: 0;
  }

  .cd-dialog {
    padding: 16px;
  }
}
