/* ---------------------------------------------------------------------------
   IMAGE INTAKE — "light table" theme
   Graphite surfaces, darkroom-safelight amber, condensed-caps masthead,
   monospace edge-codes for anything the machine says (gates, URLs, dates).
--------------------------------------------------------------------------- */

:root {
  --bg: #16181d;
  --surface: #1e2128;
  --surface-2: #232730;
  --line: #2c3038;
  --ink: #e8e6e1;
  --muted: #8b8f98;
  --amber: #e8a33d;
  --amber-dim: #a97a34;
  --ok: #7fb069;
  --err: #cf6a6a;

  --font-display: "Avenir Next Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono { font-family: var(--font-mono); font-size: 0.82em; letter-spacing: 0.01em; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--amber-dim); color: var(--amber); }
button:disabled { opacity: 0.4; cursor: default; }
button.linklike {
  background: none; border: none; padding: 0;
  color: var(--amber); text-decoration: underline; text-underline-offset: 3px;
}

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* --- masthead ------------------------------------------------------------ */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  padding: 1.4rem 2rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.9rem;
  letter-spacing: 0.22em;
  line-height: 1;
}

.tagline { color: var(--muted); font-size: 0.85rem; margin-top: 0.35rem; }

.masthead-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.token-field { display: flex; align-items: center; gap: 0.5rem; }
.token-field label { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.token-field input {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--amber-dim);
  border-radius: var(--radius);
  padding: 0.3rem 0.5rem;
  width: 14rem;
  max-width: 40vw;
}

.conn { display: flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; color: var(--muted); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn[data-state="ok"] .conn-dot { background: var(--ok); }
.conn[data-state="warn"] .conn-dot { background: var(--amber); }
.conn[data-state="err"] .conn-dot { background: var(--err); }

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

main { flex: 1; width: min(1060px, 100%); margin: 0 auto; padding: 1.6rem 2rem 3rem; }

footer {
  border-top: 1px solid var(--line);
  padding: 0.8rem 2rem;
  color: var(--muted);
  font-size: 0.75rem;
}

/* --- dropzone (signature: safelight glow on dragover) --------------------- */

.dropzone {
  position: relative;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 2.6rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.dropzone:hover { border-color: var(--amber-dim); }
.dropzone.dragover {
  border-color: var(--amber);
  border-style: solid;
  background: #211f19;
  box-shadow: 0 0 0 1px var(--amber), 0 0 48px rgba(232, 163, 61, 0.22),
              inset 0 0 64px rgba(232, 163, 61, 0.07);
}

/* film-frame corner ticks */
.dz-frame span {
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  transition: border-color 160ms ease;
}
.dz-frame span:nth-child(1) { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.dz-frame span:nth-child(2) { top: 10px; right: 10px; border-left: none; border-bottom: none; }
.dz-frame span:nth-child(3) { bottom: 10px; left: 10px; border-right: none; border-top: none; }
.dz-frame span:nth-child(4) { bottom: 10px; right: 10px; border-left: none; border-top: none; }
.dropzone.dragover .dz-frame span, .dropzone:hover .dz-frame span { border-color: var(--amber); }

.dz-title { font-size: 1.05rem; font-weight: 600; }
.dz-sub { color: var(--muted); margin-top: 0.3rem; }
.dz-specs { color: var(--muted); margin-top: 0.9rem; font-size: 0.78rem; }

.gate-legend { color: var(--muted); font-size: 0.72rem; margin: 0.7rem 2px 0; }

/* --- edit-on-upload control ------------------------------------------------ */

.intake-opts {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin: 0.9rem 2px 0;
}
.edit-field { display: flex; align-items: center; gap: 0.55rem; }
.edit-field[hidden] { display: none; } /* .edit-field's display:flex would otherwise beat the hidden attribute */
.edit-field input[type="text"] {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  min-width: 22ch;
}
.edit-field input[type="text"]:hover { border-color: var(--amber-dim); }
.edit-field input[type="text"]:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.edit-label { color: var(--amber); letter-spacing: 0.06em; }
.edit-field select {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
}
.edit-field select:hover { border-color: var(--amber-dim); }
.edit-field select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.edit-hint { color: var(--muted); font-size: 0.72rem; }

/* --- generate-from-prompt -------------------------------------------------- */

.generate { margin: 1.1rem 2px 0; display: flex; flex-direction: column; gap: 0.5rem; }
.gen-head { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; }
.gen-row { display: flex; gap: 0.6rem; align-items: stretch; }
.gen-row textarea {
  flex: 1; min-width: 0; resize: vertical;
  font-family: var(--font-body); font-size: 0.85rem; line-height: 1.4;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
}
.gen-row textarea::placeholder { color: var(--muted); }
.gen-row textarea:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.gen-side { display: flex; flex-direction: column; gap: 0.4rem; width: 10.5rem; flex: none; }
.gen-side select {
  font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 0.35rem 0.5rem;
}
.gen-side select:hover { border-color: var(--amber-dim); }
.gen-side #genBtn { flex: 1; }

/* --- upload cards ---------------------------------------------------------- */

.cards { list-style: none; margin-top: 1rem; display: grid; gap: 0.7rem; }

.card {
  display: flex;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
}
.card[data-state="uploading"] { border-left-color: var(--amber); }
.card[data-state="done"]      { border-left-color: var(--ok); }
.card[data-state="blocked"],
.card[data-state="failed"]    { border-left-color: var(--err); }

.card-thumb {
  width: 76px; height: 76px; flex: none;
  background:
    repeating-conic-gradient(var(--surface-2) 0% 25%, var(--bg) 0% 50%) 0 0 / 16px 16px;
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }

.card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }

.card-head { display: flex; align-items: baseline; gap: 0.7rem; }
.card-name { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-dims { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.card-dismiss {
  margin-left: auto; padding: 0 0.4rem;
  background: none; border: none; color: var(--muted); line-height: 1.2;
}
.card-dismiss:hover { color: var(--err); }

/* the edge-code gate strip */
.gate { font-size: 0.74rem; color: var(--muted); letter-spacing: 0.04em; }
.gate .g-pass { color: var(--ok); }
.gate .g-warn { color: var(--amber); }
.gate .g-block { color: var(--err); }

.card-status { font-size: 0.8rem; color: var(--muted); }
.card[data-state="blocked"] .card-status,
.card[data-state="failed"] .card-status { color: var(--err); }
.card[data-state="done"] .card-status { color: var(--ok); }

.progress { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: var(--amber);
  transition: width 120ms linear;
}
.card[data-state="done"] .progress-fill { background: var(--ok); }
.card[data-state="checking"] .progress, .card[data-state="blocked"] .progress { visibility: hidden; }

/* generation has no upload byte-count — sweep an indeterminate bar instead */
.card.busy .progress-fill { width: 40%; animation: gen-slide 1.1s ease-in-out infinite; }
@keyframes gen-slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

.card-result { margin-top: 0.2rem; }
.variant-rows { list-style: none; display: grid; gap: 2px; }
.variant-rows li {
  display: flex; gap: 0.6rem; align-items: baseline;
  font-size: 0.72rem; color: var(--muted);
  cursor: copy; padding: 1px 2px; border-radius: 2px;
}
.variant-rows li:hover { background: var(--surface-2); color: var(--ink); }
.variant-rows .v-name { color: var(--amber); width: 3.4rem; flex: none; }
.variant-rows .v-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.variant-rows li.missing .v-name { color: var(--err); }

.result-actions, .card-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.result-actions button, .card-actions button, .lib-actions button { font-size: 0.75rem; padding: 0.25rem 0.6rem; }
button.copied { border-color: var(--ok); color: var(--ok); }

/* --- library --------------------------------------------------------------- */

.library { margin-top: 2.6rem; }

.lib-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.lib-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.24em;
  color: var(--muted);
}
.lib-controls { display: flex; align-items: center; gap: 0.5rem; }
.lib-controls .mono { color: var(--muted); font-size: 0.75rem; }

.lib-note { color: var(--muted); font-size: 0.85rem; margin-top: 0.9rem; }

.lib-grid {
  list-style: none;
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.8rem;
}

.lib-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.lib-thumb {
  aspect-ratio: 1;
  background:
    repeating-conic-gradient(var(--surface-2) 0% 25%, var(--bg) 0% 50%) 0 0 / 18px 18px;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }

.lib-meta {
  display: flex; flex-direction: column; gap: 1px;
  padding: 0.5rem 0.6rem 0.2rem;
  font-size: 0.7rem;
}
.lib-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-date { color: var(--muted); }

.lib-actions { display: flex; gap: 0.4rem; padding: 0.5rem 0.6rem 0.6rem; }
.lib-actions .lib-del:hover { border-color: var(--err); color: var(--err); }
.lib-actions .lib-del.arm { border-color: var(--err); color: var(--err); }

/* --- responsive / a11y ------------------------------------------------------ */

@media (max-width: 640px) {
  .masthead { flex-direction: column; align-items: flex-start; padding: 1.1rem 1rem 0.9rem; }
  .masthead-status { justify-content: flex-start; }
  main { padding: 1.2rem 1rem 2.5rem; }
  footer { padding: 0.8rem 1rem; }
  .card { flex-direction: column; }
  .card-thumb { width: 100%; height: 140px; }
  .gen-row { flex-direction: column; }
  .gen-side { width: 100%; flex-direction: row; }
  .gen-side #genBtn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
