:root {
  color-scheme: dark;

  /* === Dark theme (canvas default) — aliases to variables.css === */
  --bg:                  var(--color-surface-darkest);
  --panel:               var(--color-surface-panel);
  --panel-2:             var(--color-surface-panel-2);
  --panel-3:             var(--color-surface-panel-3);
  --line:                var(--color-line);
  --line-2:              var(--color-line-2);
  --text:                var(--color-text-inverse);
  --muted:               var(--color-muted-zinc);
  --muted-2:             var(--color-muted-zinc-2);

  /* === Light theme tokens (for login/home/profile) === */
  --bg-light:            var(--color-surface-white);
  --panel-light:         var(--color-surface-page);
  --sidebar-bg:          var(--color-surface-secondary);
  --sidebar-border:      var(--color-border);
  --text-dark:           var(--color-text-primary);
  --text-muted:          var(--color-text-muted);
  --text-label:          var(--color-text-label);
  --text-placeholder:    var(--color-text-placeholder);

  /* === Brand === */
  --brand-gradient:      var(--color-brand-gradient);
  --brand-indigo:        var(--color-primary);
  --brand-purple:        var(--color-brand-purple);
  --brand-violet:        var(--color-brand-violet);
  --brand-rose:          var(--color-brand-rose);
  --brand-yellow:        var(--color-brand-yellow);
  --brand-blue:          var(--color-brand-blue);

  /* === Accent === */
  --accent:              var(--color-text-inverse);
  --accent-h:            var(--color-brand-accent-h);
  --success:             var(--color-success);
  --focus:               var(--color-text-inverse);
  --warn:                var(--color-brand-warn);

  /* === Legacy brand aliases === */
  --brand:               var(--color-primary);
  --brand-h:             var(--color-primary-hover);

  /* === Layout === */
  --sidebar-w:           256px;
  --canvas-header-h:     56px;
  --canvas-left-toolbar-w: 58px;
  --canvas-right-panel-w:  288px;
}

/* ---- reset ---- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font: inherit;
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

/* ================================================================
   TOP BAR
   ================================================================ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.03);
  backdrop-filter: blur(12px);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* — mode switch link — */
.mode-switch-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  transition: all 150ms;
}
.mode-switch-link:hover {
  color: var(--text);
  border-color: var(--text);
  background: var(--panel-2);
}

/* — avatar — */
.avatar-wrap {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  transition: border-color 200ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.avatar-wrap:hover {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.08);
}

.avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.avatar-wrap img.has-avatar {
  display: block;
}

.avatar-placeholder {
  font-weight: 700;
  color: var(--muted);
  font-size: 15px;
}

.avatar-wrap img.has-avatar + .avatar-placeholder,
.avatar-wrap img.has-avatar ~ .avatar-placeholder {
  display: none;
}

.avatar-wrap.show-avatar .avatar-placeholder { display: none; }
.avatar-wrap.show-avatar img           { display: block; }

/* — username — */
.username {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 8px;
  transition: background 160ms ease;
}

.username:hover {
  background: var(--panel-2);
}

/* — credits — */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.credits-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.credits-badge:hover {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.credits-icon {
  font-size: 10px;
  letter-spacing: 0;
}

.credits-badge strong {
  font-size: 14px;
  color: var(--text);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", ui-monospace, monospace;
  font-weight: 600;
}

/* — total credits badge — */
.total-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: default;
  transition: border-color 160ms ease;
}

.total-badge:hover {
  border-color: var(--muted-2);
}

.total-icon {
  font-size: 14px;
}

.total-badge strong {
  font-size: 14px;
  color: var(--muted);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", ui-monospace, monospace;
  font-weight: 600;
}

/* ================================================================
   WORKSPACE LAYOUT
   ================================================================ */
.workspace {
  display: grid;
  grid-template-columns: minmax(380px, 0.85fr) minmax(440px, 1.15fr);
  gap: 20px;
  align-items: start;
}

/* ================================================================
   PANEL
   ================================================================ */
.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,0.03), 0 8px 32px rgba(0,0,0,0.04);
}

.form-panel,
.result-panel {
  padding: 24px;
}

/* — brand header — */
.brand,
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  justify-content: flex-start;
}

.mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.3px;
}

h2 {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.2px;
}

p, label span, .meta-grid span {
  color: var(--muted);
  margin: 0;
}

/* ================================================================
   FORM
   ================================================================ */
form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  font-size: 13px;
  font-weight: 500;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  transition: border-color 180ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 180ms cubic-bezier(0.4, 0, 0.2, 1), background 180ms ease;
}

textarea {
  min-height: 150px;
  padding: 12px 14px;
  resize: vertical;
  font-size: 14px;
  line-height: 1.6;
}

textarea.small {
  min-height: 88px;
}

input,
select {
  height: 42px;
  padding: 0 12px;
  font-size: 14px;
}

::placeholder {
  color: var(--muted-2);
  opacity: 1;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
  background: #fff;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---- buttons ---- */
button {
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 200ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

button:hover {
  background: var(--accent-h);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translateY(-1px);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  cursor: wait;
  opacity: 0.45;
  filter: none;
  transform: none;
}

.ghost-btn {
  width: auto;
  height: 32px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
}

.ghost-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

/* ================================================================
   FIRST / LAST FRAME
   ================================================================ */
.frame-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.frame-input {
  display: grid;
  gap: 6px;
}

.frame-input > span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.frame-picker {
  display: grid;
  place-items: center;
  min-height: 80px;
  border: 1.5px dashed var(--line-2);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
  transition: border-color 180ms ease, background 180ms ease;
}

.frame-picker:hover {
  border-color: var(--text);
  background: var(--panel-3);
}

.frame-picker.has-file {
  border-style: solid;
  border-color: var(--text);
  background: var(--panel-2);
}

.frame-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.frame-picker strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.frame-picker small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.frame-preview {
  display: grid;
  place-items: center;
}

.frame-preview img {
  width: 100%;
  max-height: 80px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.frame-preview .frame-name {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.frame-preview .frame-remove {
  margin-top: 3px;
  font-size: 11px;
  color: #999;
  cursor: pointer;
  background: none;
  border: none;
  padding: 2px 8px;
  height: auto;
  font-weight: 600;
}

.frame-preview .frame-remove:hover {
  text-decoration: underline;
}

/* ================================================================
   REFERENCE BOX
   ================================================================ */
.reference-box {
  display: grid;
  gap: 10px;
}

.reference-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.reference-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.reference-head small {
  display: block;
  margin-top: 2px;
  color: var(--muted-2);
  font-size: 11px;
}

.file-picker {
  display: grid;
  place-items: center;
  min-height: 104px;
  border: 1.5px dashed var(--line-2);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
  transition: border-color 180ms ease, background 180ms ease;
}

.file-picker:hover {
  border-color: var(--text);
  background: var(--panel-3);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker strong {
  display: block;
  color: var(--text);
  font-weight: 600;
}

.file-picker small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

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

.reference-item {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--panel-2);
}

.reference-item img,
.reference-item video,
.audio-thumb {
  width: 60px;
  height: 44px;
  border-radius: 6px;
  background: #e5e5ea;
  object-fit: cover;
}

.audio-thumb {
  display: grid;
  place-items: center;
  color: var(--warn);
  font-size: 11px;
  font-weight: 800;
}

.reference-item span {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-item button {
  width: 46px;
  height: 28px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
}

.reference-item button:hover {
  color: #999;
  border-color: #999;
  background: transparent;
  box-shadow: none;
}

/* ================================================================
   RESULT PANEL
   ================================================================ */
.badge {
  min-width: 82px;
  border-radius: 20px;
  border: 1px solid var(--line);
  padding: 7px 14px;
  text-align: center;
  color: var(--muted);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 13px;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.badge.running {
  color: #fff;
  background: var(--text);
  border-color: var(--text);
  animation: badge-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.badge.success {
  color: #fff;
  background: var(--text);
  border-color: var(--text);
}

.badge.failed {
  color: #fff;
  background: #555;
  border-color: #555;
}

.badge.submitting {
  color: #fff;
  background: var(--warn);
  border-color: var(--warn);
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* — video — */
.video-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f0f0f4;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty-state,
.video-loading {
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.video-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: task-spin 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
}

.video-loading-text {
  font-size: 13px;
  font-weight: 500;
}

.video-loading-timer {
  font-size: 11px;
  color: var(--muted-2);
  font-family: "SF Mono", monospace;
}

.video-error-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #999;
}

.video-error-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.video-error-actions .ghost-btn {
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  width: auto;
}

.video-error-actions .ghost-btn:hover {
  background: var(--panel-2);
  transform: none;
  box-shadow: none;
}

.play-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--line-2);
  position: relative;
}

.play-icon::after {
  content: "";
  position: absolute;
  left: 20px;
  top: 15px;
  border-left: 15px solid var(--muted-2);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

.video-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 4px;
}

.download-btn {
  width: auto;
  height: 40px;
  border: 1px solid var(--text);
  border-radius: 10px;
  padding: 0 24px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.download-btn:hover {
  background: var(--text);
  color: #fff;
  box-shadow: none;
  transform: translateY(-1px);
}

/* ================================================================
   TASK HISTORY
   ================================================================ */
.task-history-section {
  margin: 14px 0;
}

.task-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.task-history-actions {
  display: flex;
  gap: 6px;
}

.task-history-head h3 {
  font-size: 14px;
  color: var(--text);
  font-weight: 700;
  margin: 0;
}

.task-history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 132px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel-2);
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 4px;
}

.history-chip {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
  cursor: pointer;
  transition: border-color 160ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 160ms cubic-bezier(0.4, 0, 0.2, 1), transform 120ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.history-chip:hover {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}

.history-chip.cached {
  border-color: var(--text);
  background: var(--panel-2);
}

.history-chip.failed {
  border-color: #ddd;
  background: #f9f9f9;
  opacity: 0.7;
}

.history-chip-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-chip-prompt {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-chip-meta {
  font-size: 10px;
  color: var(--muted);
  font-family: "SF Mono", "Cascadia Code", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-chip-icon {
  flex-shrink: 0;
  font-size: 10px;
  width: 16px;
  text-align: center;
  margin-top: 1px;
}

.history-chip.cached .history-chip-icon {
  color: var(--text);
}

.history-chip.failed .history-chip-icon {
  color: #999;
}

/* history search */
.history-search {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.history-search input {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  background: var(--panel-2);
}

.history-search select {
  width: auto;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  background: var(--panel-2);
}

/* ================================================================
   TASK TOOLS
   ================================================================ */
.task-tools {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 10px;
  margin: 14px 0;
}

/* ================================================================
   META GRID
   ================================================================ */
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.meta-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
}

.meta-grid strong {
  display: block;
  min-height: 20px;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

/* ================================================================
   RAW OUTPUT
   ================================================================ */
details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

pre {
  max-height: 300px;
  margin: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 12px;
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
  background: var(--panel);
}

/* ================================================================
   ACTIVE TASKS
   ================================================================ */
.active-tasks-section {
  margin: 10px 0 14px;
}

.active-tasks-section h3 {
  font-size: 14px;
  color: var(--text);
  font-weight: 700;
  margin: 0 0 8px;
}

.active-tasks-section h3 span {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}

.active-tasks-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel-2);
}

.active-tasks-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 4px;
}

/* ---- active task chip ---- */
.active-task-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  background: var(--panel);
  font-size: 12px;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", ui-monospace, monospace;
  cursor: pointer;
  transition: border-color 160ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 160ms cubic-bezier(0.4, 0, 0.2, 1), background 160ms ease, transform 120ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.active-task-chip:hover {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}

.active-task-chip:active {
  transform: scale(0.97);
}

/* ---- chip states ---- */
.active-task-chip.task-running {
  border-color: var(--text);
  background: var(--panel-2);
}

.active-task-chip.task-success {
  border-color: var(--text);
  background: var(--panel-2);
}

.active-task-chip.task-failed {
  border-color: #999;
  background: #f5f5f5;
}

/* selected */
.active-task-chip.selected {
  border-width: 2px;
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

.active-task-chip.task-success.selected {
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

.active-task-chip.task-failed.selected {
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

/* ---- chip icon ---- */
.task-chip-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
}

.task-running .task-chip-icon {
  color: var(--text);
  background: rgba(0,0,0,0.06);
}

.task-success .task-chip-icon {
  color: var(--text);
  background: rgba(0,0,0,0.06);
}

.task-failed .task-chip-icon {
  color: #999;
  background: rgba(0,0,0,0.04);
}

/* spinner */
.spinner {
  display: block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: task-spin 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
}

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

/* ---- selected task detail ---- */
.selected-task-detail {
  /* show/hide container, no extra styling */
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
  .workspace,
  .grid.two,
  .reference-preview,
  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 600px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .meta-grid {
    grid-template-columns: 1fr;
  }
  .frame-inputs {
    grid-template-columns: 1fr;
  }
}

/* ================================================================
   MEDIA LIBRARY
   ================================================================ */
.media-library {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  overflow: hidden;
}

.media-library[open] {
  background: var(--panel);
}

.media-library summary {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 160ms ease;
}

.media-library summary:hover {
  background: var(--panel-3);
}

.media-library summary span {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
  margin-left: 6px;
}

/* — upload row — */
.media-upload-row {
  display: flex;
  gap: 8px;
  margin: 0 16px 12px;
}

/* — upload zone — */
.media-upload-zone {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
  cursor: pointer;
  text-align: center;
  transition: border-color 180ms ease, background 180ms ease;
  min-height: 32px;
  justify-content: center;
}

.media-upload-zone:hover,
.media-upload-zone.drag-over {
  border-color: #9ca3af;
}

.media-upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.media-upload-zone strong {
  font-size: 11px;
  color: #6b7280;
  font-weight: 500;
}

/* — grid — */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
  max-height: 320px;
  overflow-y: auto;
}

.media-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 16px 0;
}

/* — card — */
.media-card {
  display: grid;
  grid-template-rows: 80px auto auto;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  min-width: 0;
}

.media-card:hover {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.media-card-thumb {
  width: 100%;
  height: 80px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--panel-3);
}

.media-card-thumb.audio {
  display: grid;
  place-items: center;
  font-size: 28px;
  color: var(--muted);
}

.media-card-thumb.video {
  display: grid;
  place-items: center;
  font-size: 24px;
  color: var(--muted);
  background: var(--panel-2);
}

.media-card-name {
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.media-card-size {
  font-size: 10px;
  color: var(--muted);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", ui-monospace, monospace;
}

.media-card-actions {
  display: flex;
  gap: 4px;
}

.media-card-actions button {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
  font-size: 11px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 160ms ease, color 160ms ease;
}

.media-card-actions .copy-btn:hover {
  border-color: var(--text);
  color: var(--text);
  background: transparent;
  box-shadow: none;
}

.media-card-actions .delete-btn:hover {
  border-color: #999;
  color: #999;
  background: transparent;
  box-shadow: none;
}

@media (max-width: 600px) {
  .media-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ================================================================
   PRESET CHIPS
   ================================================================ */
.preset-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 2px;
}

.preset-chip {
  width: auto;
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.preset-chip:hover {
  border-color: var(--text);
  background: var(--panel-2);
  transform: none;
  box-shadow: none;
}

.preset-chip.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

/* ================================================================
   TOAST
   ================================================================ */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  animation: toast-in 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast-exit {
  animation: toast-out 200ms ease forwards;
}

.toast-error {
  background: #1a1a1a;
  border-left: 3px solid #999;
}

.toast-success {
  background: #1a1a1a;
  border-left: 3px solid #fff;
}

.toast-warning {
  background: #1a1a1a;
  border-left: 3px solid #888;
}

.toast-info {
  background: #1a1a1a;
  border-left: 3px solid #666;
}

.toast-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}

.toast-success .toast-icon { background: rgba(255,255,255,0.15); }
.toast-error .toast-icon { background: rgba(255,255,255,0.12); }
.toast-warning .toast-icon { background: rgba(255,255,255,0.12); }
.toast-info .toast-icon { background: rgba(255,255,255,0.12); }

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-message {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.toast-subtitle {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  margin-top: 2px;
  font-family: "SF Mono", monospace;
}

.toast-close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms;
}

.toast-close:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
  transform: none;
  box-shadow: none;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(255,255,255,0.1);
}

.toast-progress-bar {
  height: 100%;
  background: rgba(255,255,255,0.3);
  animation: toast-progress linear forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}
