:root {
  --bg: #1e1e20;
  --bg2: #2c2c2e;
  --panel: #29292c;
  --border: #3d3d41;
  --text: #f2f2f2;
  --muted: #a5a5ab;
  --red: #E30613;
  --red-dark: #9C0F25;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Barlow', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

h2 {
  font-family: 'Barlow Semi Condensed', 'Barlow', sans-serif;
  font-size: 17px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 22px 0 10px;
}
h2:first-child { margin-top: 0; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.error { color: #ff6b6b; font-size: 14px; white-space: pre-wrap; }
a { color: #ff8a8a; }

/* ---------- Login ---------- */
#login-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #35181c 0%, var(--bg) 60%);
  z-index: 50;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  text-align: center;
}

.logo {
  font-family: 'Barlow Semi Condensed', sans-serif;
  font-weight: 700; font-size: 22px; letter-spacing: .06em;
}
.logo span { color: var(--red); padding: 0 4px; }

/* ---------- Header ---------- */
header {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 24px;
  background: var(--bg2);
  border-bottom: 2px solid var(--red);
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  background: none; border: none; color: var(--muted);
  font: 600 15px 'Barlow', sans-serif;
  padding: 8px 16px; cursor: pointer; border-radius: var(--radius);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--red); color: #fff; }

.banner {
  background: var(--red-dark); color: #fff;
  padding: 10px 24px; font-size: 14px;
}
.banner a { color: #fff; font-weight: 600; }

/* ---------- Layout ---------- */
main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel.narrow { max-width: 720px; }
.create-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  align-items: start;
}
@media (max-width: 980px) { .create-grid { grid-template-columns: 1fr; } }

.row { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); flex: 1; min-width: 120px; }

/* ---------- Inputs ---------- */
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: 400 15px 'Barlow', sans-serif;
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--red); color: #fff;
  border: none; border-radius: var(--radius);
  font: 600 15px 'Barlow', sans-serif;
  padding: 11px 20px; cursor: pointer;
  text-decoration: none; display: inline-block; text-align: center;
}
.btn-primary:hover { background: #c00511; }
.btn-primary.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 14px; }
.btn-primary:disabled { opacity: .5; cursor: wait; }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: 600 14px 'Barlow', sans-serif;
  padding: 9px 16px; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--red); }

/* segmented buttons */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: 600 14px 'Barlow', sans-serif;
  padding: 10px 16px; cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--red); border-color: var(--red); color: #fff; }
.preset-seg button.active { background: var(--red-dark); border-color: var(--red); }

/* ---------- Thumbnails ---------- */
.thumb-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  margin-top: 12px;
}
.thumb-grid.large { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.thumb {
  position: relative; border-radius: var(--radius); overflow: hidden;
  border: 2px solid var(--border); cursor: pointer;
  aspect-ratio: 1; background: var(--bg);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .name {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 10px; padding: 3px 5px;
  background: rgba(0,0,0,.65); color: #ddd;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.selectable .thumb.selected { border-color: var(--red); box-shadow: 0 0 0 2px var(--red); }
.selectable .thumb.selected::after {
  content: '✓'; position: absolute; top: 6px; right: 6px;
  background: var(--red); color: #fff; border-radius: 50%;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.thumb .del {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,.7); color: #fff; border: none; border-radius: 6px;
  width: 26px; height: 26px; cursor: pointer; font-size: 13px;
  display: none;
}
.thumb:hover .del { display: block; }
.thumb .del:hover { background: var(--red); }

/* ---------- Dropzone ---------- */
#dropzone {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 36px; text-align: center; color: var(--muted);
  cursor: pointer; margin: 14px 0;
}
#dropzone.drag { border-color: var(--red); color: var(--text); background: rgba(227,6,19,.06); }

/* ---------- Spinner ---------- */
#gen-status { display: flex; align-items: center; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--red);
  animation: spin
0.9s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Lightbox ---------- */
#lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px;
}
#lightbox img { max-width: 92vw; max-height: 72vh; border-radius: 8px; }
#lightbox-meta { color: var(--muted); font-size: 13px; max-width: 800px; text-align: center; white-space: pre-wrap; }
.lightbox-actions { display: flex; gap: 12px; }

/* ---------- Preset editor ---------- */
.preset-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.preset-block input { margin-bottom: 8px; font-weight: 600; }
.preset-block textarea { font-size: 13px; }
