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

:root {
  --bg:        #fff8f0;
  --panel:     #ffffff;
  --card:      #f5f0ff;
  --border:    #e0d0ff;
  --pink:      #ff3b7a;
  --blue:      #1a90ff;
  --lime:      #22dd88;
  --orange:    #ff8c00;
  --purple:    #8b2be2;
  --yellow:    #ffe000;
  --text:      #1a0a2e;
  --muted:     #8870aa;
  --danger:    #ff3b3b;
  --mono:      'Space Mono', monospace;
  --sans:      'Space Grotesk', sans-serif;
  --sidebar-w: 290px;
  --gallery-w: 310px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--gallery-w);
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Banner header ── */
.banner-header {
  grid-column: 1 / -1;
  background: #fff0f5;
  border-bottom: 3px solid var(--pink);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  height: 90px;
  flex-shrink: 0;
}
.banner-header img {
  height: 100%;
  width: 100%;
  object-fit: cover;
  object-position: center top;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--panel);
  border-right: 3px solid var(--purple);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
}
.sidebar.collapsed { width: 42px; }
.sidebar.collapsed .sidebar-body,
.sidebar.collapsed .sidebar-logo { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--purple);
  flex-shrink: 0;
}
.sidebar-logo {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  text-transform: uppercase;
}

.sidebar-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Fields ── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field.row { flex-direction: row; gap: 10px; }
.half { flex: 1; display: flex; flex-direction: column; gap: 5px; }

label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--purple);
  text-transform: uppercase;
}
.muted { color: var(--muted); font-weight: 400; text-transform: none; font-size: 10px; }

textarea, input[type="text"], input[type="number"], select {
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea:focus, input:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,144,255,0.15);
}
textarea { resize: vertical; min-height: 85px; }

/* ── Seed row ── */
.seed-row { display: flex; gap: 6px; }
.seed-row input { flex: 1; }

/* ── Generate button ── */
/* Honeypot — visually hidden but still in the DOM/accessibility tree off-screen.
   Not display:none, so naive bots fill it. */
.hp-field {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Content policy notice + ack checkbox */
.policy-notice {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.5);
}
.policy-notice p {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  margin: 0 0 8px;
}
.ack-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.ack-row input { margin-top: 2px; }

.generate-btn {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  border: none;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: 0 4px 14px rgba(139,43,226,0.3);
}
.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139,43,226,0.45);
}
.generate-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.spinner { display: inline-block; }
#spin-hex { animation: spin-hex 1.2s linear infinite; transform-origin: 10px 10px; }
#spin-tri { animation: spin-tri 1.2s ease-in-out infinite reverse; transform-origin: 10px 10px; }
@keyframes spin-hex { to { transform: rotate(360deg); } }
@keyframes spin-tri { 
  0%   { transform: rotate(0deg) scale(1); opacity: 0.4; }
  50%  { transform: rotate(180deg) scale(0.6); opacity: 0.9; }
  100% { transform: rotate(360deg) scale(1); opacity: 0.4; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Token meter ── */
.token-meter {
  background: #1a0a2e;
  border: 2px solid var(--purple);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.token-row { display: flex; justify-content: space-between; align-items: center; }
.token-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.12em;
}
.token-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
}
.token-val.in-val   { color: var(--blue); }
.token-val.out-val  { color: var(--lime); }
.token-val.tot-val  { color: var(--yellow); }
.token-val.cost-val { color: var(--pink, #ff3b7a); }

/* ── Error ── */
.error-box {
  background: #fff0f0;
  border: 2px solid var(--danger);
  color: #cc0000;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
}

/* ── Canvas area ── */
.canvas-area {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  padding: 20px;
  /* diagonal stripe bg — playful */
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 28px,
    rgba(139,43,226,0.04) 28px,
    rgba(139,43,226,0.04) 30px
  );
}
.image-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: 900px;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  text-align: center;
}
.empty-diamonds {
  display: flex;
  gap: 16px;
}
.empty-diamond {
  width: 32px; height: 32px;
  transform: rotate(45deg);
  border-radius: 4px;
}
.empty-state p { font-size: 13px; color: var(--muted); }

.result-img {
  max-width: 100%;
  max-height: calc(100vh - 240px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow:
    0 0 0 3px var(--pink),
    0 0 0 6px var(--blue),
    0 12px 40px rgba(0,0,0,0.15);
}

/* ── Image meta strip ── */
.img-meta {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.meta-tags { display: flex; flex-wrap: wrap; gap: 6px; min-height: 24px; }
.tag-chip {
  background: var(--purple);
  color: #fff;
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 9px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tag-chip button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 10px;
  padding: 0;
  line-height: 1;
}
.tag-chip button:hover { color: var(--yellow); }

.meta-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.inline-input {
  background: #fff;
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}
.inline-input:focus { border-color: var(--blue); }

/* ── Buttons ── */
.small-btn {
  background: #fff;
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all 0.12s;
  white-space: nowrap;
}
.small-btn:hover { border-color: var(--blue); color: var(--blue); transform: translateY(-1px); }
.small-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.icon-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  padding: 2px 7px;
  border-radius: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
  line-height: 1.4;
}
.icon-btn:hover { background: rgba(255,255,255,0.35); }
.icon-btn.dark {
  background: var(--card);
  color: var(--muted);
}
.icon-btn.dark:hover { background: var(--border); color: var(--text); }

/* ── Gallery panel ── */
.gallery-panel {
  background: var(--panel);
  border-left: 3px solid var(--blue);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
}
.gallery-panel.collapsed { width: 42px; }
.gallery-panel.collapsed .gallery-grid,
.gallery-panel.collapsed .folder-bar,
.gallery-panel.collapsed .tag-bar,
.gallery-panel.collapsed .folder-controls,
.gallery-panel.collapsed .search-input { display: none; }

.gallery-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--blue);
  flex-shrink: 0;
}
.search-input {
  flex: 1;
  background: rgba(255,255,255,0.9);
  border: 2px solid transparent;
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  outline: none;
}
.search-input:focus { border-color: #fff; }

/* ── Folder bar ── */
.folder-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  background: #f0f8ff;
}
.folder-chip {
  background: #fff;
  border: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.folder-chip:hover { border-color: var(--blue); color: var(--blue); }
.folder-chip.active { border-color: var(--blue); color: #fff; background: var(--blue); }
.folder-chip .del-folder {
  font-size: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.6);
  padding: 0;
  line-height: 1;
}
.folder-chip:not(.active) .del-folder { color: var(--muted); }
.folder-chip .del-folder:hover { color: var(--danger); }

/* ── Tag bar ── */
.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  min-height: 34px;
  background: #fdf5ff;
}
.tag-filter {
  background: #fff;
  border: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.12s;
  font-weight: 700;
}
.tag-filter:hover { border-color: var(--purple); color: var(--purple); }
.tag-filter.active { border-color: var(--purple); color: #fff; background: var(--purple); }

/* ── Gallery grid ── */
.gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-content: start;
}
.gallery-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
  grid-column: 1/-1;
  text-align: center;
}

.gallery-thumb {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.15s;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.gallery-thumb:hover { border-color: var(--pink); transform: scale(1.03); }
.gallery-thumb.active { border-color: var(--pink); box-shadow: 0 0 0 2px var(--purple); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-thumb .thumb-prompt {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(26,10,46,0.9));
  color: #fff;
  font-size: 9px;
  padding: 16px 5px 4px;
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1.3;
}
.gallery-thumb:hover .thumb-prompt { opacity: 1; }

/* SVG badge */
.svg-badge {
  position: absolute;
  top: 5px; right: 5px;
  background: var(--lime);
  color: #1a0a2e;
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s;
}
.gallery-thumb:hover .svg-badge { opacity: 1; }

/* ── Folder controls ── */
.folder-controls {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 2px solid var(--border);
  flex-shrink: 0;
  background: #f0f8ff;
}
.folder-controls .inline-input { flex: 1; }

/* ── Utilities ── */
.hidden { display: none !important; }
