/* ==================================================
   CrePoP - Professional Tool Design System
   Inspired by Figma/Canva dark theme
   ================================================== */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #5c7318;
  --surface: #1e2218;
  --surface-hover: #292f21;
  --accent: #5c7318;
  --accent-hover: #74911e;
  --accent-light: rgba(92, 115, 24, 0.15);
  --text: #f8fafc;
  --text-secondary: #a3a89e;
  --border: #292f21;
  --border-hover: #3d4731;
  --success: #34d399;
  --error: #f87171;
  --panel: #0d0e0a;
  --shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ---------- Reset & Base ---------- */
* {
  box-sizing: border-box;
}

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

html {
  overflow-y: scroll;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  background-image: 
    radial-gradient(circle at 15% 20%, rgba(139, 166, 61, 0.4) 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(46, 57, 12, 0.6) 0%, transparent 50%),
    linear-gradient(135deg, #5c7318 0%, #2e390c 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  overflow-x: hidden;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 150ms ease;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn--lg {
  padding: 12px 24px;
  font-size: 14px;
}

.btn--full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ---------- Form Elements ---------- */
.field__label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.field__input {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 150ms ease, background 150ms ease;
}

.field__input:focus {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.field__input::placeholder {
  color: var(--text-secondary);
}

textarea.field__input {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

/* ---------- Select ---------- */
.select {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select select {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 28px 8px 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 150ms ease;
}

.select select:hover {
  border-color: var(--border-hover);
}

.select select:focus {
  border-color: var(--accent);
}

.select::after {
  content: "▾";
  position: absolute;
  right: 10px;
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ==================================================
   TOPBAR
   ================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 56px;
  min-height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: none;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__logo img {
  height: 28px;
  width: auto;
  object-fit: contain;
}

.topbar__logoText {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  transition: all 150ms ease;
  text-decoration: none;
}

.topbar__link:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border);
}

.topbar__link--active {
  color: var(--accent) !important;
  background: var(--accent-light) !important;
  border-color: transparent !important;
  font-weight: 500;
  box-shadow: none;
  position: relative;
}

.topbar__link--active::after {
  display: none;
}

/* ==================================================
   PAGE CONTAINER
   ================================================== */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* ==================================================
   HERO / WELCOME BANNER
   ================================================== */
.hero {
  padding: 40px 0 24px;
  text-align: center;
}

.hero__logoWrap {
  margin-bottom: 8px;
}

.hero__logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  filter: brightness(1.1);
}

.hero__title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.hero__word {
  font-weight: 700;
}

.hero__mark {
  color: var(--accent);
  font-size: 1.2rem;
}

.hero__subtitle {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==================================================
   QUICK CREATE / PROMPT BAR
   ================================================== */
.prompt {
  width: 100%;
  max-width: 680px;
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color 150ms ease;
}

.prompt:focus-within {
  border-color: var(--accent);
}

.prompt__icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: all 150ms ease;
}

.prompt__icon:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  color: var(--accent);
}

.prompt__icon svg {
  width: 20px;
  height: 20px;
}

.prompt__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.prompt__input {
  width: 100%;
  padding: 10px 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
}

.prompt__input::placeholder {
  color: var(--text-secondary);
}

.prompt__headline {
  font-size: 14px;
  color: var(--text);
}

.prompt__sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.prompt__cta {
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.prompt__cta:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.prompt__cta:active {
  transform: scale(0.98);
}

/* ==================================================
   RECENTS SECTION
   ================================================== */
.recents {
  margin-top: 48px;
}

.recents__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.recents__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}

.recents__hint,
.recents__viewAll {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 150ms ease;
}

.recents__viewAll:hover {
  color: var(--accent);
}

/* ---------- Card Grid (replaces Rail) ---------- */
.recents__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* ==================================================
   PROJECT CARD
   ================================================== */
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all 150ms ease;
  text-align: left;
  padding: 0;
  width: 100%;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.card:active {
  transform: translateY(0);
}

.thumb {
  aspect-ratio: 4 / 3;
  position: relative;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
}

.card__meta {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.card__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__time {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ==================================================
   MODAL
   ================================================== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 200;
}

.modal.is-open {
  display: grid;
  place-items: center;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

.modal__panel {
  position: relative;
  width: min(520px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.modal__close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: all 150ms ease;
}

.modal__close:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.modal__body {
  padding: 20px;
}

/* ---------- Form in Modal ---------- */
.form {
  display: grid;
  gap: 16px;
}

.form__row {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 8px;
}

/* ---------- Upload Zone ---------- */
.upload-zone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
  overflow: hidden;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-zone.drag-active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-zone__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-zone__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

.upload-zone__content svg {
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ---------- Prompt Area (after image upload) ---------- */
.prompt-area {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.prompt-area__preview {
  position: relative;
  width: 120px;
  min-width: 120px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.prompt-area__preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.prompt-area__remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 150ms ease;
}

.prompt-area__remove:hover {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.prompt-area__input {
  flex: 1;
  resize: none;
  min-height: 120px;
}

/* ==================================================
   GENERATE PAGE LAYOUT
   ================================================== */
.gen {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.gen__sidebar {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
}

.gen__section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gen__sectionTitle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

/* ---------- Reference Image ---------- */
.gen__ref {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gen__refTitle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.gen__refPreview {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.gen__refPreview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 150ms ease;
}

.gen__refPreview img:hover {
  opacity: 0.85;
}

.gen__refActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#genRefFile {
  display: none;
}

.gen__uploadBtn {
  display: inline-flex;
  align-items: center;
}

/* ---------- Prompt Area ---------- */
.gen__prompt {
  resize: vertical;
  min-height: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease;
}

.gen__prompt:focus {
  border-color: var(--accent);
}

.gen__prompt::placeholder {
  color: var(--text-secondary);
}

.gen__hint {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------- Optimizer Panel ---------- */
.gen__optimizer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gen__optTitle {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.gen__optAdvice {
  min-height: 100px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.gen__optAdvice:empty::before {
  content: "AI suggestions will appear here...";
  color: var(--text-secondary);
}

/* ---------- Canvas Area ---------- */
.gen__canvas {
  background: transparent;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
}

.gen__canvasMain {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* ---------- Preview Image ---------- */
.gen__preview {
  max-width: 100%;
  max-height: calc(100vh - 220px);
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.gen__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
}

.gen__placeholder svg {
  opacity: 0.5;
}

/* ---------- History Thumbnails ---------- */
.gen__history {
  display: flex;
  gap: 8px;
  padding: 12px;
  overflow-x: auto;
  background: var(--panel);
  border-radius: var(--radius-md);
  margin-top: 16px;
  flex-shrink: 0;
}

.gen__history::-webkit-scrollbar {
  height: 6px;
}

.gen__history::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 3px;
}

.gen__historyItem {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
}

.gen__historyItem:hover {
  border-color: var(--border-hover);
}

.gen__historyItem.is-current {
  border-color: var(--accent);
}

.gen__historyItem img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gen__historyItem.is-generating::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gen__historyItem.is-generating::before {
  content: "⏳";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  z-index: 1;
}

.gen__historyImgHolder {
  width: 100%;
  height: 100%;
  background: var(--surface);
}

.gen__historyEmpty {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  width: 100%;
  font-size: 13px;
}

.gen__historyMeta {
  display: none;
}

.gen__historyBadge {
  display: none;
}

/* ---------- Legacy Grid Layouts (for generate page) ---------- */
.gen__row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.gen__controls {
  display: grid;
  gap: 12px;
}

.gen__controlsGrid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
}

.gen__editor {
  display: grid;
  gap: 12px;
}

/* ---------- Output/Compare Section ---------- */
.gen__outputWrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.gen__outputTitle {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.gen__compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

.gen__compareItem {
  background: var(--panel);
}

.gen__compareItem + .gen__compareItem {
  border-left: 1px solid var(--border);
}

.gen__compareLabel {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.gen__compareItem img {
  width: 100%;
  height: 340px;
  object-fit: contain;
  display: block;
  background: var(--panel);
}

.gen__compareCanvas {
  position: relative;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  overflow: hidden;
}

.gen__compareCanvas .gen__placeholder {
  font-size: 13px;
  border: none;
  background: transparent;
}

.gen__compareCanvas.is-generating::after {
  content: "Generating...";
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-light);
}

/* ---------- Status Bar ---------- */
.gen__status {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.gen__status[data-type="error"] {
  color: var(--error);
}

.gen__status[data-type="success"] {
  color: var(--success);
}

.gen__status[data-type="loading"] {
  color: var(--accent);
}

/* ==================================================
   IMAGE MODAL (for enlarged preview)
   ================================================== */
#imageModal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 300;
}

#imageModal.is-open {
  display: grid;
  place-items: center;
}

#imageModal .modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
}

#imageModal img {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

/* ==================================================
   RESPONSIVE DESIGN
   ================================================== */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
  }

  .topbar__right {
    gap: 6px;
  }

  .topbar__link {
    font-size: 12px;
    padding: 5px 8px;
  }

  .page {
    padding: 0 12px 48px;
  }

  .hero {
    padding: 24px 0 16px;
  }

  .hero__title {
    font-size: 22px;
  }

  .hero__subtitle {
    font-size: 13px;
  }

  .prompt {
    grid-template-columns: 44px 1fr;
    gap: 10px;
    padding: 10px;
  }

  .prompt__icon {
    width: 44px;
    height: 44px;
  }

  .prompt__cta {
    grid-column: 1 / -1;
    justify-self: stretch;
    margin-top: 4px;
  }

  .recents__grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .recents__hint {
    display: none;
  }

  /* Generate page: stack sidebar on top */
  .gen {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: calc(100vh - 56px);
  }

  .gen__sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
    padding: 12px;
  }

  .gen__canvas {
    padding: 12px;
    min-height: 50vh;
  }

  .gen__preview {
    max-height: 50vh;
  }

  .gen__history {
    margin-top: 12px;
  }

  .gen__historyItem {
    flex: 0 0 64px;
    width: 64px;
    height: 64px;
  }

  .gen__controlsGrid {
    grid-template-columns: 1fr;
  }

  .gen__compare {
    grid-template-columns: 1fr;
  }

  .gen__compareItem + .gen__compareItem {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .gen__section {
    padding: 10px 0;
  }

  .gen__sectionTitle {
    font-size: 12px;
  }

  .gen__refPreview {
    max-height: 200px;
  }

  /* Auth modal */
  .auth-modal {
    width: calc(100% - 24px);
    padding: 20px 16px;
  }

  .select {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .topbar__logoText {
    display: none;
  }

  .topbar__logo img {
    height: 24px;
  }

  .recents__grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal__panel {
    width: calc(100% - 24px);
  }

  .gen__sidebar {
    padding: 10px;
  }

  .gen__canvas {
    padding: 10px;
  }

  .gen__preview {
    max-height: 45vh;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .btn--lg {
    padding: 10px 18px;
    font-size: 13px;
  }
}

/* ==================================================
   UTILITY CLASSES
   ================================================== */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Animation for loading states */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.is-loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Transition helper */
.fade-in {
  animation: fadeIn 200ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================================================
   AUTH MODAL (Registration/Login)
   ================================================== */
.auth-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 200ms ease-out;
}

.auth-modal {
  position: relative;
  width: 380px;
  max-width: calc(100% - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  animation: fadeIn 200ms ease-out;
}

.auth-modal h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 20px 0;
  text-align: center;
}

.auth-error {
  padding: 10px 12px;
  margin-bottom: 16px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 13px;
  text-align: center;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 150ms ease, background 150ms ease;
}

.auth-input:focus {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.auth-input::placeholder {
  color: var(--text-secondary);
}

.auth-submit {
  width: 100%;
  padding: 12px 16px;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 150ms ease;
}

.auth-submit:hover {
  background: var(--accent-hover);
}

.auth-submit:active {
  transform: scale(0.98);
}

.auth-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.auth-switch {
  margin: 16px 0 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 4px;
  cursor: pointer;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: all 150ms ease;
}

.auth-close:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

/* User info in topbar */
.topbar__user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__username {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: all 150ms ease;
  display: inline-block;
  position: relative;
}

.topbar__username:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.topbar__username.topbar__link--active {
  color: var(--accent) !important;
  background: var(--accent-light) !important;
  border-color: transparent !important;
  font-weight: 500;
  box-shadow: none;
}

.topbar__username.topbar__link--active::after {
  display: none;
}

.topbar__signout {
  font-size: 14px;
  font-weight: 500;
  color: var(--error);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  font-family: inherit;
}

.topbar__signout:hover {
  color: var(--error);
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.2);
}

/* ==================================================
   ADDITIONAL GENERATE PAGE STYLES
   ================================================== */

/* TopBar Center (for Generate page logo) */
.topbar__center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar__center .topbar__logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__center .topbar__logo img {
  height: 28px;
  width: auto;
}

/* Reference Image Placeholder */
.gen__refPlaceholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px;
}

/* Prompt Input Textarea */
.gen__promptInput {
  resize: vertical;
  min-height: 100px;
}

/* Generate Button (full width) */
.gen__generateBtn {
  margin-top: 4px;
}

/* Optimizer Actions */
.gen__optActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Canvas Preview Wrapper */
.gen__previewWrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* Image Modal Styles */
.modal__body--image {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 90vw;
  max-height: 90vh;
}

.modal__body--image img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

.modal__body--image .modal__close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  transition: all 150ms ease;
}

.modal__body--image .modal__close:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

/* Added by append_css.py */

.gen__history {
  display: flex;
  gap: 16px;
  padding: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  background: var(--surface);
}

.gen__history::-webkit-scrollbar {
  height: 8px;
}

.gen__history::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 999px;
}

.gen__historyItem {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
}

.gen__historyItem:hover {
  border-color: var(--border-hover);
}

.gen__historyItem img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gen__historyImgHolder {
  width: 100%;
  height: 100%;
  background: var(--panel);
}

.gen__historyItem.is-generating::after {
  content: "正在生成中...";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.gen__historyMeta {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.gen__historyBadge {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.gen__historyBadge.is-current {
  background: var(--accent);
  color: #fff;
}

.gen__historyMeta span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gen__historyEmpty {
  padding: 40px;
  text-align: center;
  color: rgba(0, 0, 0, 0.5);
  width: 100%;
  font-size: 14px;
}
