:root {
  --bg: #f3f4ef;
  --panel: #ffffff;
  --ink: #19181a;
  --muted: #666165;
  --line: #d9d6cd;
  --accent: #1f6f5f;
  --accent-ink: #ffffff;
  --btn-green: #166a57;
  --btn-green-hover: #0f5a49;
  --btn-green-active: #0c4a3d;
  --btn-slate: #2f4358;
  --btn-slate-hover: #243649;
  --btn-blue: #1f5b9f;
  --btn-blue-hover: #18497f;
  --btn-red: #a02323;
  --btn-red-hover: #851b1b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: radial-gradient(circle at top right, #d8e6df 0%, var(--bg) 46%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body.busy,
body.busy * {
  cursor: progress !important;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h1 {
  margin: 0;
  font-size: 2rem;
}

.muted {
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.form-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.mode-file-row {
  flex-wrap: wrap;
}

.form-row label {
  min-width: 104px;
  text-transform: capitalize;
}

.mode-file-row .inline-label {
  min-width: auto;
  margin-left: 8px;
}

.inline-form-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.form-row > *,
.inline-form-group > * {
  min-width: 0;
}

.help-dot {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #9aa9ba;
  color: #36506a;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: help;
  user-select: none;
  background: #f7fafc;
}

.help-dot::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(360px, calc(100vw - 32px));
  padding: 7px 9px;
  border: 1px solid #c8d3de;
  border-radius: 8px;
  background: #fdfefe;
  color: #223242;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
  box-shadow: 0 6px 18px rgba(15, 30, 45, 0.12);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 40;
}

.help-dot:hover::after,
.help-dot:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.95rem;
  padding: 6px 8px;
  width: fit-content;
  max-width: 100%;
}

input[type="file"] {
  max-width: 100%;
}

#video-seed {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.95rem;
  padding: 8px 10px;
  width: 150px;
}

#run-btn {
  width: fit-content;
  align-self: start;
}

.btn-success {
  background-color: var(--btn-green);
  border-color: var(--btn-green);
}

.btn-success:hover,
.btn-success:focus {
  background-color: var(--btn-green-hover);
  border-color: var(--btn-green-hover);
}

.btn-success:active {
  background-color: var(--btn-green-active) !important;
  border-color: var(--btn-green-active) !important;
}

.btn-outline-secondary {
  color: var(--btn-slate);
  border-color: #9eacbc;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  color: #ffffff;
  background-color: var(--btn-slate);
  border-color: var(--btn-slate);
}

.btn-outline-primary {
  color: var(--btn-blue);
  border-color: #8fb4df;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  color: #ffffff;
  background-color: var(--btn-blue);
  border-color: var(--btn-blue);
}

.btn-outline-danger {
  color: var(--btn-red);
  border-color: #dba0a0;
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
  color: #ffffff;
  background-color: var(--btn-red);
  border-color: var(--btn-red);
}

.status-log {
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel-workbench {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.panel-workbench.text-mode .status-pane {
  flex: 0 0 360px;
}

.status-pane {
  flex: 1;
  height: 220px;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbf8;
  padding: 10px 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: start;
  overflow: hidden;
}

.status-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.status-tabs .btn {
  padding: 4px 10px;
}

.positive-pane {
  height: 100%;
}

#positive-prompt {
  width: 100%;
  height: calc(100% - 2px);
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.92rem;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #ffffff;
}

.status-log.running {
  color: #365f9b;
}

.status-log.done {
  color: #1f6f5f;
}

.status-log.partial {
  color: #9a6a10;
}

.status-log.failed {
  color: #8a1c1c;
}

.ref-preview {
  width: 240px;
  max-width: 100%;
  align-self: flex-start;
  min-height: 220px;
  max-height: 220px;
  height: 220px;
  align-content: start;
}

.ref-preview img {
  align-self: start;
}

.text-prompt-pane {
  flex: 1;
  min-height: 220px;
  max-height: 220px;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbf8;
  padding: 10px 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

.text-prompt-pane label {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #5d595d;
}

#text-prompt {
  width: 100%;
  height: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #fff;
}

.hidden {
  display: none !important;
}

.grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.grid.video-mode {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f5f5f5;
  cursor: default;
}

.video-card video,
.video-card .video-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f5f5f5;
}

.video-card video {
  background: #0f1116;
}

.card img.ready {
  cursor: zoom-in;
}

.state {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5d595d;
}

.img-modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 24, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}

.img-modal.open {
  display: flex;
}

.img-modal-card {
  position: relative;
  width: min(95vw, 1200px);
  max-height: 92vh;
}

.img-modal-image {
  width: 100%;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid #c9d4e2;
  background: #ffffff;
}

.img-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  background: rgba(25, 24, 26, 0.75);
  color: #ffffff;
  cursor: pointer;
  padding: 0;
}

.img-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: rgba(25, 24, 26, 0.75);
  color: #ffffff;
  cursor: pointer;
  padding: 0;
  font-size: 20px;
}

.img-modal-nav.prev {
  left: 10px;
}

.img-modal-nav.next {
  right: 10px;
}

.img-modal-label {
  margin-top: 8px;
  color: #f2f6fb;
  font-size: 0.9rem;
  text-align: center;
}

.img-modal-download {
  position: absolute;
  left: 10px;
  top: 10px;
}

.prompt-modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 24, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 32;
}

.prompt-modal.open {
  display: flex;
}

.prompt-modal-card {
  position: relative;
  width: min(92vw, 880px);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border: 1px solid #cfd8e2;
  border-radius: 10px;
  padding: 16px;
}

.prompt-modal-card h3 {
  margin: 0 0 10px;
}

.prompt-modal-text {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.4;
}

.prompt-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  background: rgba(25, 24, 26, 0.75);
  color: #ffffff;
  cursor: pointer;
  padding: 0;
}
