:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1e222d;
  --border: #2a2f3c;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #6c8cff;
  --accent-hot: #8b5cf6;
  --ok: #34d399;
  --err: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* An author `display` rule beats the UA stylesheet's [hidden]{display:none},
   so anything toggled via the hidden attribute needs this to actually hide. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Rubik", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #161a24, #12141c);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.2px; }
.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hot));
  box-shadow: 0 0 14px rgba(108, 140, 255, 0.75);
}
.model-chip {
  font-size: 12px; color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 999px;
  direction: ltr;
}

.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.logout-btn {
  font-size: 12px; font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 14px; border-radius: 999px;
  cursor: pointer;
}
.logout-btn:hover { color: var(--text); border-color: var(--accent); }

.credits {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 13px; border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s;
}
.credits:hover { border-color: var(--accent); }
.credits strong { font-variant-numeric: tabular-nums; font-weight: 650; }
.credits .credits-label { color: var(--muted); }
.credits .credits-val { color: var(--text); }
.credits.low .credits-val { color: var(--warn); }
.credits.empty .credits-val { color: var(--err); }
.credits .credits-note {
  color: var(--muted); font-size: 11px;
  border-inline-start: 1px solid var(--border); padding-inline-start: 8px;
}
.credits a { color: var(--accent); text-decoration: none; }
.credits a:hover { text-decoration: underline; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 80px; }

/* ---------------------------------------------------------------- dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 42px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}
.dropzone:hover, .dropzone.hover {
  border-color: var(--accent);
  background: #1a1f2e;
}
.dropzone.hover { transform: scale(1.006); }
.dz-icon {
  width: 54px; height: 54px; margin: 0 auto 12px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-hot));
}
.dz-title { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.dz-sub { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- settings */
.panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
/* Style switch: one click swaps the whole prompt. */
.style-field { margin-bottom: 18px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 150px;
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  padding: 10px 14px; font-size: 13.5px;
}
.seg button:hover { border-color: var(--accent); }
.seg button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-hot));
  border-color: transparent;
  color: #fff;
}

.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
@media (max-width: 760px) { .row { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 7px; }
.lbl { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.lbl em {
  font-style: normal; color: var(--accent);
  background: #222a42; padding: 1px 9px; border-radius: 6px;
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.hint { font-size: 11.5px; color: var(--muted); }

input[type=range] { accent-color: var(--accent); cursor: pointer; }
select, textarea, input[type=text] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13.5px;
}
select { cursor: pointer; }
textarea { width: 100%; resize: vertical; line-height: 1.6; direction: ltr; text-align: left; }
select:focus, textarea:focus, input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] {
  width: 100%; height: 38px; padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}

/* ------------------------------------------------------------ magnet frame */
.check {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; user-select: none;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

.frame-grid {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px;
  align-items: start;
}
/* One column on a phone, with the preview on top where the result is seen
   first, and each slider on a line of its own - wide enough for a thumb. */
@media (max-width: 760px) {
  .frame-grid { grid-template-columns: 1fr; }
  .frame-grid .frame-preview { order: -1; position: static; }
  .frame-row.sliders { grid-template-columns: 1fr; }
}
/* min-width: a range input's built-in width would otherwise hold the columns
   open and push the panel wider than a phone. */
.frame-grid > *, .frame-row > * { min-width: 0; }
.frame-fields { display: flex; flex-direction: column; gap: 14px; }
.frame-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.frame-row input[type=range] { width: 100%; }
.logo-row { display: flex; align-items: center; gap: 14px; }
.logo-row .ghost { padding: 8px 16px; font-size: 13px; }

.frame-reset { align-self: end; grid-column: span 2; text-align: start; padding-bottom: 10px; }
.hint.warn { color: var(--warn); }
.hint.warn:empty { display: none; }

/* The preview is the real print-size canvas, scaled down by the browser. The
   caption is dragged on it, so a touch there must not scroll the page. */
.frame-preview {
  width: 100%; height: auto; display: block;
  border-radius: 6px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
  cursor: grab;
  touch-action: none;
  position: sticky; top: 84px;
}

.prompt-box { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.prompt-box summary { cursor: pointer; font-size: 13px; font-weight: 600; user-select: none; }
.prompt-box textarea { margin-top: 11px; }
.muted { color: var(--muted); font-weight: 400; }
.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 12px; padding: 6px 0; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* ----------------------------------------------------------------- actions */
.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
button {
  font-family: inherit; font-size: 14px; font-weight: 600;
  border-radius: 10px; padding: 11px 22px; cursor: pointer;
  border: 1px solid transparent; transition: filter .15s, opacity .15s;
}
.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hot));
  color: #fff;
}
.primary:hover:not(:disabled) { filter: brightness(1.12); }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.ghost:hover { background: #262b38; }

/* ------------------------------------------------------------- error banner */
.errorbox {
  margin: 16px 0 0;
  padding: 13px 16px;
  border-radius: 11px;
  background: rgba(248, 113, 113, .1);
  border: 1px solid rgba(248, 113, 113, .35);
  color: #fca5a5;
  font-size: 13.5px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- progress */
.progress { margin-top: 22px; }
.bar {
  height: 7px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden;
}
.fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-hot));
  transition: width .35s ease;
}
.stats {
  display: flex; justify-content: space-between;
  font-size: 12.5px; margin-top: 8px;
}

/* -------------------------------------------------------------------- grid */
.grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: pop .28s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.thumb {
  position: relative;
  aspect-ratio: 1;
  background: #0c0e14;
  display: grid; place-items: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb img.src-preview { opacity: .28; filter: grayscale(.5); }
.thumb img.result { cursor: zoom-in; }

/* Sweeping shimmer while a job is in flight. */
.thumb.working::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(108,140,255,.22) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: sweep 1.25s linear infinite;
}
@keyframes sweep { from { background-position: 220% 0; } to { background-position: -120% 0; } }

.badge {
  position: absolute; top: 9px; inset-inline-end: 9px;
  font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(0,0,0,.72); backdrop-filter: blur(4px);
  z-index: 2;
}
.badge.queued { color: var(--muted); }
.badge.processing { color: var(--accent); }
.badge.done { color: var(--ok); }
.badge.error { color: var(--err); }
.badge.cancelled { color: var(--warn); }

.meta { padding: 9px 11px; border-top: 1px solid var(--border); }
.fname {
  font-size: 12px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  direction: ltr; text-align: right;
}
.sub { font-size: 11px; color: var(--muted); margin-top: 2px; min-height: 15px; }
.sub.err { color: var(--err); white-space: normal; }

.card-actions { display: flex; gap: 6px; padding: 0 11px 11px; }
.card-actions a, .card-actions button {
  flex: 1; text-align: center; font-size: 11.5px; font-weight: 600;
  padding: 6px 4px; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; cursor: pointer;
}
.card-actions a:hover, .card-actions button:hover { background: #262b38; }

.outdir {
  margin-top: 22px; font-size: 12px;
  direction: ltr; text-align: right;
  word-break: break-all;
}

/* ----------------------------------------------------------------- history */
.history {
  margin-top: 46px;
  border-top: 1px solid var(--border);
  padding-top: 22px;
}
.history-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.history-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
.history-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }

.hbatch {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.hbatch summary {
  cursor: pointer; user-select: none;
  padding: 12px 15px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
}
.hbatch summary::-webkit-details-marker { display: none; }
.hbatch summary .hname { font-weight: 600; direction: ltr; }
.hbatch summary .hcount {
  font-size: 11.5px; color: var(--accent);
  background: #222a42; padding: 2px 9px; border-radius: 999px;
}
.hbatch summary .spacer { flex: 1; }
.hbatch summary .hzip {
  font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 11px; text-decoration: none;
}
.hbatch summary .hzip:hover { color: var(--text); background: var(--surface-2); }
/* Offered only while the frame is switched on - it uses the current caption. */
.hbatch summary .hframed { display: none; color: var(--accent); cursor: pointer; background: none; font-weight: 400; }
body.frame-on .hbatch summary .hframed { display: inline-block; }

.hthumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 9px;
  padding: 0 15px 15px;
}
.hthumbs a {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background: #0c0e14; border: 1px solid var(--border);
  display: block; cursor: zoom-in;
  transition: border-color .15s, transform .15s;
}
.hthumbs a:hover { border-color: var(--accent); transform: translateY(-2px); }
.hthumbs img { width: 100%; height: 100%; object-fit: contain; display: block; }
.hempty { font-size: 12.5px; color: var(--muted); padding: 4px 2px; }

/* ---------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6,8,13,.93);
  display: grid; place-items: center;
  padding: 34px;
}
.lightbox img {
  max-width: 92vw; max-height: 88vh;
  border-radius: 10px; background: #fff;
}
.lightbox img { cursor: default; }
.lb-close {
  position: absolute; top: 18px; inset-inline-end: 22px;
  background: none; border: none; color: #fff;
  font-size: 36px; line-height: 1; cursor: pointer; padding: 6px 14px;
}
.lb-download {
  position: absolute; bottom: 26px; inset-inline-start: 50%;
  transform: translateX(50%);
  background: linear-gradient(135deg, var(--accent), var(--accent-hot));
  color: #fff; text-decoration: none;
  font-size: 13.5px; font-weight: 600;
  padding: 10px 26px; border-radius: 10px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
}
.lb-download:hover { filter: brightness(1.12); }
