:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #939aa8;
  --accent: #5b8cff;
  --accent-text: #ffffff;
  --danger: #ff6b6b;
  --danger-bg: #2a1a1c;
  --ok: #4ade80;
  --warn: #fbbf24;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] {
  display: none !important;
}

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

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- buttons and inputs ---------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 14px;
  transition: border-color 0.15s, background 0.15s;
}

button:hover:not(:disabled) {
  border-color: #3c4453;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

button.ghost {
  background: transparent;
  padding: 6px 12px;
  font-size: 13px;
}

button.danger {
  border-color: #5a2a2f;
  color: var(--danger);
  background: transparent;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

textarea {
  resize: none;
  width: 100%;
}

/* Height is driven by refreshPromptSize(); these are the floor and the ceiling. */
#prompt {
  min-height: 150px;
  max-height: 40vh;
  overflow-y: auto;
  line-height: 1.6;
}

/* ---------- key gate ---------- */

.gate {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
}

.gate-card {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.gate-card h1 {
  margin: 0 0 12px;
  font-size: 20px;
}

.gate-card form {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.gate-card input {
  flex: 1;
}

.error-text {
  color: var(--danger);
  margin: 12px 0 0;
  font-size: 14px;
}

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

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

.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.badge.ok {
  color: var(--ok);
  border-color: #24503a;
}

.badge.bad {
  color: var(--danger);
  border-color: #5a2a2f;
}

/* ---------- chat log ---------- */

.log {
  overflow-y: auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
}

.empty-state h2 {
  font-size: 18px;
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0 0 8px;
}

/* One generation renders as one full-width card. No left/right bubbles: the dialogue shape
   would imply a conversation history that the API does not have. */
.card {
  width: min(760px, 100%);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px 14px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card-head .meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.card-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.card-prompt {
  margin-top: 10px;
}

.prompt-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.prompt-text.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.link-button {
  border: none;
  background: none;
  padding: 4px 0;
  font-size: 12px;
  color: var(--accent);
}

.link-button:hover {
  text-decoration: underline;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

/* The job id chip: a button, but it must read as a chip rather than an action. */
.chip.chip-action {
  background: transparent;
  cursor: pointer;
  line-height: inherit;
}

.chip.chip-action:hover {
  color: var(--text);
  border-color: #3c4453;
}

.chip.chip-action.copied {
  color: var(--ok);
  border-color: #24503a;
}

.ref-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ref-item {
  width: 92px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.ref-item img,
.ref-item video {
  display: block;
  width: 100%;
  height: 62px;
  object-fit: cover;
  background: #000;
}

.ref-item .ref-fallback {
  height: 62px;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--muted);
}

.ref-item .ref-name {
  font-size: 10px;
  padding: 4px 5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- job status ---------- */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.status-dot.running {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.done {
  background: var(--ok);
}

.status-dot.bad {
  background: var(--danger);
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

.action-link {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.action-link:hover {
  border-color: #3c4453;
}

.job-error {
  margin-top: 10px;
  background: var(--danger-bg);
  border: 1px solid #5a2a2f;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  color: #ffc9c9;
  word-break: break-word;
}

.job-error .code {
  font-family: var(--mono);
  font-size: 11px;
  display: block;
  opacity: 0.75;
  margin-bottom: 2px;
}

.job-video {
  margin-top: 10px;
  width: 100%;
  max-height: 60vh;
  border-radius: 8px;
  background: #000;
  display: block;
}

/* ---------- composer ---------- */

.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px 14px;
}

.composer > *,
.composer form {
  width: min(760px, 100%);
  margin-inline: auto;
}

.composer-error {
  background: var(--danger-bg);
  border: 1px solid #5a2a2f;
  color: #ffc9c9;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  margin-bottom: 10px;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.mode-tab {
  font-size: 13px;
  padding: 5px 12px;
  background: transparent;
}

.mode-tab[aria-selected="true"] {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--text);
}

/* Standing reminder that generations do not share state. The card layout carries most of this
   message; this line closes the gap for anyone who still reads the page as a chat. */
.prompt-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.prompt-hint {
  font-size: 12px;
  color: var(--muted);
}

.prompt-meta-right {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: none;
}

.prompt-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 6px 5px 8px;
  background: var(--surface-2);
  font-size: 12px;
}

.attachment .name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment select {
  padding: 2px 4px;
  font-size: 11px;
  border-radius: 6px;
}

.attachment .size {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.attachment .remove {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0 4px;
  font-size: 15px;
  line-height: 1;
}

.attachment .remove:hover {
  color: var(--danger);
}

.composer-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 10px;
}

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

.field > span:first-child {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.field.grow {
  flex: 1;
}

.field select,
.field input {
  padding: 6px 8px;
  font-size: 13px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  font-size: 13px;
  color: var(--muted);
}

.checkbox input {
  width: 15px;
  height: 15px;
  padding: 0;
  accent-color: var(--accent);
}

.seed-group {
  display: flex;
  gap: 4px;
}

.seed-group input {
  width: 108px;
}

.seed-group button {
  padding: 6px 9px;
}

@media (max-width: 640px) {
  .topbar-title .mono {
    display: none;
  }

  .composer-controls {
    gap: 8px;
  }

  .seed-group input {
    width: 84px;
  }

  /* The composer must not swallow the log on a phone; max-height overrides the inline height
     that refreshPromptSize() sets. */
  #prompt {
    min-height: 100px;
    max-height: 30vh;
  }

  .chip.chip-action {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
