:root {
  color-scheme: light;
  --bg: #eef7fb;
  --panel: rgba(255,255,255,0.78);
  --panel-2: rgba(246,252,255,0.92);
  --text: #0f2c36;
  --muted: #62808a;
  --line: rgba(20,120,150,0.16);
  --accent: #0ea5b7;
  --accent-2: #0b6881;
  --danger: #c2413a;
  --shadow: rgba(19,78,96,0.15);
}

.dark {
  color-scheme: dark;
  --bg: #0d1b22;
  --panel: rgba(20,35,45,0.88);
  --panel-2: rgba(25,40,50,0.94);
  --text: #dce8ed;
  --muted: #7a959f;
  --line: rgba(100,160,180,0.18);
  --accent: #16c1d4;
  --accent-2: #10a0b4;
  --shadow: rgba(0,0,0,0.4);
}

* { box-sizing: border-box; min-width: 0; }

html, body { min-height: 100%; height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(120,180,220,0.25), transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(160,200,240,0.2), transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(140,190,230,0.15), transparent 50%),
    linear-gradient(135deg, #e8f0f7 0%, #dce8f2 50%, #eaf2f8 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
}

@keyframes bgFloat {
  0%,100% { background-position: 0% 0%, 100% 0%, 50% 100%, 0% 0%; }
  50% { background-position: 5% 3%, 95% -3%, 45% 97%, 0% 0%; }
}

body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(circle at 30% 40%, rgba(180,210,240,0.3), transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(160,195,230,0.2), transparent 50%);
  animation: bgFloat 20s ease-in-out infinite;
}

body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.08), transparent 70%);
}

.dark body {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(30,60,90,0.35), transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(25,50,80,0.3), transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(20,45,70,0.25), transparent 50%),
    linear-gradient(135deg, #0c1a24 0%, #101e2a 50%, #0d1822 100%);
}

.shell { width: min(1280px, calc(100vw - 32px)); margin: 0 auto; height: 100vh; padding: 18px 0; overflow: hidden; }

.hidden { display: none !important; }

button, input, textarea, select { font: inherit; }

input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,0.35); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: var(--text); outline: none; transition: all .3s;
}
input, select { min-height: 40px; padding: 0 14px; }
textarea { min-height: 132px; resize: vertical; padding: 14px; line-height: 1.6; }

input:focus, textarea:focus, select:focus {
  border-color: var(--accent); background: rgba(255,255,255,0.5); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}

button {
  min-height: 40px; border: 1px solid rgba(255,255,255,0.4); border-radius: 10px;
  background: rgba(14,165,183,0.18); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--accent-2); cursor: pointer; font-weight: 600; transition: all .3s;
}
button:hover { background: rgba(14,165,183,0.28); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); transform: translateY(-1px); }
button:disabled { opacity: .5; cursor: wait; transform: none; }

.ghost { border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.15); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); color: var(--text); }
.ghost:hover { background: rgba(255,255,255,0.3); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* Login */
.login-panel {
  width: min(440px,100%); margin: 10vh auto 0; padding: 32px; text-align: center;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 20px;
  background: rgba(255,255,255,0.28); backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  box-shadow: 0 8px 40px var(--shadow);
}
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.login-form input, .login-form button { width: 100%; }
.error { color: var(--danger); font-size: .85rem; margin: 8px 0 0; }

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 48px; height: 48px; border-radius: 12px; overflow: hidden; background: var(--panel-2); flex-shrink: 0; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand h1 { font-size: 1.4rem; margin: 0; }
.brand p { color: var(--muted); margin: 4px 0 0; }

.brand.compact strong { display: block; font-size: .95rem; }
.brand.compact span { font-size: .78rem; color: var(--muted); }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 14px; padding: 12px 20px; border-radius: 16px;
  background: rgba(255,255,255,0.2); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.25); box-shadow: 0 4px 24px var(--shadow);
}
.settings-nav { position: relative; }
.settings-menu {
  position: absolute; right: 0; top: 110%; z-index: 10;
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 12px;
  background: rgba(255,255,255,0.75); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 30px var(--shadow); min-width: 140px;
}

/* Workspace */
.workspace {
  display: grid; grid-template-columns: minmax(340px,0.72fr) minmax(460px,1.28fr);
  gap: 18px; height: calc(100vh - 116px); overflow: hidden;
}
.app-view { display: flex; flex-direction: column; height: calc(100vh - 36px); }

.prompt-zone, .result-zone {
  height: 100%; overflow: auto;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 16px;
  background: rgba(255,255,255,0.18); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 24px var(--shadow);
}
.prompt-zone { padding: 18px; }
.result-zone { padding: 18px; display: flex; flex-direction: column; }

.section-title h2 { font-size: 1rem; margin: 0 0 4px; }
.section-title p { color: var(--muted); font-size: .82rem; margin: 0; }

/* Task steps */
.task-step { padding: 14px; margin-bottom: 12px; border: 1px solid rgba(255,255,255,0.25); border-radius: 14px; background: rgba(255,255,255,0.15); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.step-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.step-head span { font-size: .75rem; color: var(--accent); font-weight: 700; }
.step-head strong { font-size: .9rem; }

.controls { display: flex; gap: 8px; margin-bottom: 10px; }
.controls select { flex: 1; }
.custom-size { display: flex; align-items: center; gap: 4px; }
.custom-size input { width: 80px; }
.custom-size span { color: var(--muted); }

/* Upload */
.upload-box {
  display: block; padding: 16px; border: 2px dashed var(--line); border-radius: 12px;
  text-align: center; cursor: pointer; color: var(--muted); transition: border-color .2s;
  background: rgba(255,255,255,0.2); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.upload-box:hover, .upload-box.is-dragging { border-color: var(--accent); }
.upload-box span, .upload-box strong { display: block; }
.upload-box strong { font-size: .8rem; margin-top: 4px; }

.reference-preview { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.reference-preview .thumb-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,0.25);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: .78rem;
}
.reference-preview .thumb-chip img { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.reference-preview .thumb-chip button { padding: 0 6px; border: none; background: none; color: var(--muted); font-size: 1.1rem; }

/* Prompts */
.prompt-templates { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.prompt-templates button {
  padding: .3rem .7rem; font-size: .78rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--muted); cursor: pointer; font-weight: 400; transition: all .2s;
}
.prompt-templates button:hover { border-color: var(--accent); color: var(--accent); }

/* Result */
.result-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.result-head span { color: var(--muted); font-size: .8rem; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }
.loading-state .thinking-gif { width: 48px; height: 48px; margin-bottom: 12px; }
.thinking-copy span { font-weight: 700; display: block; }
.thinking-copy p { font-size: .85rem; }
.progress-timer { display: flex; gap: 12px; justify-content: center; font-size: .82rem; margin-top: 8px; }

.result-error { padding: 12px; border: 1px solid var(--danger); border-radius: 8px; background: rgba(194,65,58,0.08); text-align: center; color: var(--danger); }
.result-error strong { display: block; }
.result-error p { font-size: .85rem; margin: 4px 0 0; }

.result-image { max-width: 100%; border-radius: 10px; cursor: zoom-in; margin: 0 auto; display: block; }
.download-btn { display: block; margin: 10px auto 0; padding: 8px 24px; }

/* History */
.history-panel { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.history-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.history-title span { color: var(--muted); font-size: .8rem; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 12px;
  background: rgba(255,255,255,0.12); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  cursor: pointer; transition: border-color .2s;
}
.history-item:hover { border-color: var(--accent); }
.history-item img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.history-item .meta { flex: 1; min-width: 0; }
.history-item .meta span { display: block; font-size: .72rem; color: var(--muted); }
.history-item .meta strong { display: block; font-size: .8rem; margin-top: 2px; }
.history-item .acts { display: flex; gap: 4px; flex-shrink: 0; }
.history-item .acts button { padding: 4px 8px; font-size: .72rem; font-weight: 400; }
.history-item .acts select { width: auto; padding: 2px 4px; font-size: .7rem; min-height: auto; }
.history-comments { padding: 4px 0 0 58px; }
.comment-bubble { padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,0.15); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border: 1px solid var(--line); margin-bottom: 3px; font-size: .8rem; }
.comment-bubble strong { color: var(--accent); margin-right: 6px; }
.comment-bubble small { display: block; color: var(--muted); }
.comment-form-inline { display: flex; gap: 4px; margin-top: 4px; }
.comment-form-inline input { flex: 1; padding: 4px 8px; font-size: .78rem; }
.comment-form-inline button { padding: 4px 10px; font-size: .75rem; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.pagination button { padding: 4px 12px; font-size: .8rem; font-weight: 400; }
.pagination span { font-size: .8rem; color: var(--muted); }

/* Admin */
.admin-panel {
  max-width: 700px; margin: 0 auto; padding: 24px;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 16px;
  background: rgba(255,255,255,0.18); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 24px var(--shadow); overflow: auto; max-height: calc(100vh - 120px);
}
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.config-grid .wide { grid-column: span 2; }
.config-grid label { font-size: .82rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.config-grid button { grid-column: span 2; }
.key-status { font-size: .78rem; color: var(--muted); }
.admin-divider { border-top: 1px solid var(--line); margin: 16px 0; }
.users-table { display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 10px;
  background: rgba(255,255,255,0.12); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  flex-wrap: wrap;
}
.user-row select, .user-row input[type="number"] { width: auto; padding: 4px 8px; font-size: .78rem; }
.user-row button { font-size: .72rem; padding: 4px 8px; font-weight: 400; }

.avatar-card { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.avatar-preview { width: 48px; height: 48px; border-radius: 50%; overflow: hidden; border: 2px solid var(--line); }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-copy strong { display: block; font-size: .9rem; }
.avatar-copy span { color: var(--muted); font-size: .78rem; }
.avatar-upload { font-size: .8rem; color: var(--accent); cursor: pointer; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 8px 20px; background: var(--text); color: var(--bg); border-radius: 8px;
  font-size: .85rem; z-index: 999;
}
.toast.is-error { background: var(--danger); color: #fff; }

/* Lightbox */
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox-overlay img { max-width: 92vw; max-height: 80vh; border-radius: 8px; }
.lightbox-close { position: absolute; top: 16px; right: 24px; font-size: 2rem; background: none; border: none; color: #fff; cursor: pointer; opacity: .7; }
.lightbox-close:hover { opacity: 1; }
.lightbox-overlay p { color: rgba(255,255,255,.6); margin: 8px 0 0; font-size: .85rem; max-width: 600px; text-align: center; }

.shared-badge { padding: 1px 6px; border-radius: 4px; background: rgba(14,165,183,0.12); color: var(--accent); font-size: .7rem; }

@media (max-width: 768px) {
  .workspace { grid-template-columns: 1fr; }
  .shell { padding: 10px 0; }
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
}

/* Refined glass skin */
:root {
  --bg: #eef6fb;
  --panel: rgba(255, 255, 255, 0.42);
  --panel-2: rgba(255, 255, 255, 0.58);
  --text: #102a37;
  --muted: #5d7582;
  --line: rgba(255, 255, 255, 0.46);
  --accent: #168ba0;
  --accent-2: #0c6579;
  --danger: #c2413a;
  --shadow: rgba(36, 76, 96, 0.18);
  --glass-blur: 22px;
  --glass-edge: rgba(255, 255, 255, 0.7);
}

html.dark {
  --bg: #0b1720;
  --panel: rgba(15, 31, 43, 0.52);
  --panel-2: rgba(20, 39, 52, 0.66);
  --text: #e7f1f5;
  --muted: #93aab4;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #60d5e8;
  --accent-2: #9eeaf4;
  --shadow: rgba(0, 0, 0, 0.36);
  --glass-edge: rgba(255, 255, 255, 0.22);
}

body {
  background:
    radial-gradient(circle at 18% 18%, rgba(135, 205, 225, 0.46), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(159, 180, 244, 0.34), transparent 30%),
    radial-gradient(circle at 68% 84%, rgba(132, 218, 184, 0.28), transparent 31%),
    linear-gradient(135deg, #eff8fb 0%, #e8f1f8 48%, #f7fbff 100%);
  letter-spacing: 0;
}

html.dark body {
  background:
    radial-gradient(circle at 16% 18%, rgba(42, 115, 138, 0.46), transparent 30%),
    radial-gradient(circle at 84% 14%, rgba(72, 85, 154, 0.34), transparent 32%),
    radial-gradient(circle at 68% 86%, rgba(26, 99, 85, 0.28), transparent 32%),
    linear-gradient(135deg, #08131c 0%, #102230 52%, #091722 100%);
}

body::before {
  background:
    radial-gradient(circle at 28% 38%, rgba(255, 255, 255, 0.38), transparent 42%),
    radial-gradient(circle at 72% 64%, rgba(255, 255, 255, 0.2), transparent 42%);
  filter: blur(10px);
  opacity: 0.75;
  animation: bgFloat 28s ease-in-out infinite;
}

body::after {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 42%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 80px);
  opacity: 0.56;
}

input,
textarea,
select,
button,
.ghost,
.login-panel,
.topbar,
.settings-menu,
.prompt-zone,
.result-zone,
.task-step,
.upload-box,
.thumb-chip,
.history-item,
.comment-bubble,
.admin-panel,
.user-row,
.avatar-card {
  border-color: var(--line);
  background: linear-gradient(135deg, var(--panel-2), rgba(255, 255, 255, 0.18));
  backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  box-shadow:
    0 20px 50px var(--shadow),
    inset 0 1px 0 var(--glass-edge),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
}

input,
textarea,
select {
  color: var(--text);
  background: rgba(255, 255, 255, 0.34);
}

input:focus,
textarea:focus,
select:focus {
  background: rgba(255, 255, 255, 0.54);
  border-color: rgba(22, 139, 160, 0.55);
  box-shadow:
    0 0 0 3px rgba(96, 213, 232, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

button {
  background: rgba(255, 255, 255, 0.34);
  color: var(--accent-2);
  box-shadow:
    0 10px 26px rgba(20, 96, 120, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.68);
}

button:hover {
  background: rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(28px) saturate(1.25);
  -webkit-backdrop-filter: blur(28px) saturate(1.25);
  transform: translateY(-2px);
}

.topbar {
  position: relative;
  z-index: 50;
  background: rgba(255, 255, 255, 0.34);
}

.settings-nav {
  z-index: 60;
}

.settings-menu {
  z-index: 1000;
  background: rgba(255, 255, 255, 0.72);
}

html.dark .settings-menu {
  background: rgba(16, 34, 48, 0.84);
}

.prompt-zone,
.result-zone,
.admin-panel,
.login-panel {
  border-radius: 22px;
}

.task-step,
.history-item,
.upload-box,
.user-row {
  border-radius: 16px;
}

.history-item {
  transition: transform 0.24s ease, border-color 0.24s ease, background 0.24s ease, box-shadow 0.24s ease;
}

.history-item:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.32);
  box-shadow:
    0 22px 44px rgba(35, 76, 96, 0.18),
    inset 0 1px 0 var(--glass-edge);
}

.field-hint {
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

.prompt-templates button,
.history-item .acts button,
.pagination button,
.user-row button {
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }
}

/* Polished workflow layer */
.workspace {
  grid-template-columns: minmax(360px, 0.8fr) minmax(520px, 1.2fr);
  gap: 20px;
}

.prompt-zone,
.result-zone,
.admin-panel,
.login-panel {
  border: 1px solid rgba(255, 255, 255, 0.52);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.22)),
    rgba(255, 255, 255, 0.24);
}

.task-step {
  transition: transform 420ms cubic-bezier(0.18, 1.22, 0.24, 1), box-shadow 280ms ease, background 280ms ease;
}

.task-step:hover {
  transform: translateY(-3px) scale(1.006);
  background: rgba(255, 255, 255, 0.28);
}

.upload-box {
  position: relative;
  display: grid;
  gap: 6px;
  place-items: center;
  min-height: 116px;
  padding: 22px 18px;
  overflow: hidden;
  border: 1px dashed rgba(22, 139, 160, 0.38);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.72), transparent 42%),
    rgba(255, 255, 255, 0.24);
  transition: transform 420ms cubic-bezier(0.18, 1.22, 0.24, 1), border-color 240ms ease, background 240ms ease, box-shadow 240ms ease;
}

.upload-box::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: var(--accent-2);
  font-size: 1.55rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.84), 0 12px 26px rgba(35, 76, 96, 0.12);
}

.upload-box:hover,
.upload-box.is-dragging {
  transform: translateY(-4px) scale(1.01);
  border-color: rgba(22, 139, 160, 0.72);
  background: rgba(255, 255, 255, 0.38);
}

.upload-box input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.upload-box span {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 800;
}

.upload-box strong {
  color: var(--muted);
  font-weight: 500;
}

.reference-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
}

.reference-preview .thumb-chip {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  min-height: 52px;
  padding: 7px;
  border-radius: 14px;
  animation: springIn 460ms cubic-bezier(0.18, 1.24, 0.2, 1) both;
}

.reference-preview .thumb-chip span,
.reference-preview .thumb-chip small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-preview .thumb-chip button {
  min-height: 28px;
  width: 28px;
  border-radius: 50%;
  line-height: 1;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  align-items: start;
  gap: 10px;
  max-height: 330px;
  overflow: auto;
  padding: 2px 4px 8px;
}

.history-item.small-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
  padding: 8px;
  cursor: default;
  animation: springIn 520ms cubic-bezier(0.18, 1.24, 0.2, 1) both;
  transition: transform 420ms cubic-bezier(0.18, 1.22, 0.24, 1), box-shadow 260ms ease, background 260ms ease, border-color 260ms ease;
}

.history-item.small-card:hover {
  transform: translateY(-6px) scale(1.018);
}

.history-thumb {
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 13px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: none;
}

.history-thumb img,
.history-item.small-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 13px;
  transition: transform 420ms cubic-bezier(0.18, 1.22, 0.24, 1), filter 260ms ease;
}

.history-item.small-card:hover .history-thumb img {
  transform: scale(1.055);
  filter: brightness(1.08);
}

.history-item .meta {
  display: grid;
  gap: 3px;
}

.history-item .meta strong {
  display: -webkit-box;
  min-height: 2.6em;
  overflow: hidden;
  color: var(--text);
  line-height: 1.35;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-item .acts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.history-item .acts button,
.history-item .acts select {
  width: 100%;
  min-height: 28px;
  padding: 0 7px;
  border-radius: 9px;
  font-size: 0.72rem;
}

.history-item .acts select {
  grid-column: span 2;
}

.history-comments {
  padding: 0;
}

.comment-form-inline {
  display: grid;
  grid-template-columns: 1fr auto;
}

.comment-form-inline input {
  min-height: 30px;
}

.comment-form-inline button {
  min-height: 30px;
}

.pagination {
  grid-column: 1 / -1;
}

button,
.settings-menu,
.prompt-templates button {
  transition: transform 400ms cubic-bezier(0.18, 1.22, 0.24, 1), background 240ms ease, box-shadow 240ms ease, border-color 240ms ease;
}

.settings-menu:not(.hidden) {
  animation: menuSpring 420ms cubic-bezier(0.18, 1.22, 0.24, 1) both;
}

@keyframes springIn {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  70% {
    opacity: 1;
    transform: translateY(-2px) scale(1.012);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes menuSpring {
  0% {
    opacity: 0;
    transform: translateY(-8px) scale(0.92);
  }
  72% {
    opacity: 1;
    transform: translateY(2px) scale(1.035);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-item.small-card,
  .reference-preview .thumb-chip,
  .settings-menu:not(.hidden) {
    animation: none;
  }
}

/* Awwwards-grade B2B studio skin */
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #dc2626;
  --shadow: rgba(15, 23, 42, 0.04);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #60a5fa;
  --accent-2: #93c5fd;
  --danger: #f87171;
  --shadow: rgba(0, 0, 0, 0.22);
}

html,
body {
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

body::before,
body::after {
  display: none;
}

.shell {
  width: min(1440px, 100vw);
  height: 100vh;
  padding: 0;
}

.app-view {
  height: 100vh;
}

.topbar {
  height: 64px;
  margin: 0;
  padding: 0 24px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

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

.brand.compact span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.settings-toggle,
.ghost {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  font-weight: 500;
}

.settings-toggle:hover,
.ghost:hover {
  background: var(--panel-2);
  transform: none;
}

.settings-menu {
  top: calc(100% + 8px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.1);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.workspace {
  grid-template-columns: minmax(360px, 40fr) minmax(560px, 60fr);
  gap: 24px;
  height: calc(100vh - 64px);
  padding: 24px;
  overflow: hidden;
  background: var(--bg);
}

.prompt-zone,
.result-zone,
.admin-panel,
.login-panel,
.task-step,
.history-item.small-card,
.upload-box,
.reference-preview .thumb-chip,
.comment-bubble,
.user-row,
.avatar-card {
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 2px 8px var(--shadow);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.prompt-zone,
.result-zone {
  height: 100%;
  overflow: hidden;
  padding: 20px;
}

.prompt-zone form {
  display: grid;
  grid-template-rows: minmax(172px, 1fr) auto auto;
  gap: 24px;
  height: calc(100% - 44px);
}

.section-title {
  margin-bottom: 16px;
}

.section-title h2 {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.section-title p {
  color: var(--muted);
  font-size: 13px;
}

.task-step {
  margin: 0;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.task-step:hover {
  background: var(--panel);
  transform: none;
}

.step-head {
  gap: 8px;
  margin-bottom: 12px;
}

.step-head span {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

.step-head strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

input,
textarea,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

textarea {
  min-height: 120px;
  height: 100%;
  padding: 12px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  resize: none;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
  font-size: 14px;
  font-weight: 400;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: none;
}

.prompt-templates {
  display: none;
}

.upload-box {
  min-height: 88px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--text);
  box-shadow: none;
}

.upload-box::before {
  display: none;
}

.upload-box:hover,
.upload-box.is-dragging {
  border-color: var(--accent);
  background: #eff6ff;
  transform: none;
}

html.dark .upload-box:hover,
html.dark .upload-box.is-dragging {
  background: rgba(59, 130, 246, 0.12);
}

.upload-box span {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.upload-box strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.reference-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  max-height: 116px;
  overflow: auto;
  margin-top: 10px;
}

.reference-preview .thumb-chip {
  grid-template-columns: 36px 1fr auto;
  min-height: 48px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
  animation: none;
}

.reference-preview .thumb-chip img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.reference-preview .thumb-chip span,
.reference-preview .thumb-chip small {
  color: var(--muted);
  font-size: 12px;
}

.reference-preview .thumb-chip button {
  width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

.reference-preview .thumb-chip button:hover {
  background: var(--danger);
  color: #ffffff;
}

.controls {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr 0.95fr;
  gap: 8px;
  margin-bottom: 8px;
}

.custom-size {
  grid-column: 1 / -1;
}

.field-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: none;
  font-weight: 600;
}

button:hover {
  background: var(--accent-2);
  transform: none;
}

button:active {
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.18);
}

.result-zone {
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto minmax(220px, 0.84fr);
  gap: 16px;
}

.result-head {
  margin: 0;
}

.result-head strong {
  font-size: 16px;
  font-weight: 700;
}

.result-head span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state,
.loading-state,
.result-error,
.result-image {
  align-self: stretch;
  justify-self: stretch;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: 0 2px 8px var(--shadow);
}

.empty-state p {
  color: var(--muted);
  font-size: 14px;
}

.result-image {
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 2px 8px var(--shadow);
}

.download-btn {
  justify-self: center;
  margin: 0;
  min-height: 36px;
  padding: 0 16px;
}

.history-panel {
  min-height: 0;
  margin: 0;
  padding-top: 0;
  border-top: 0;
}

.history-title {
  margin-bottom: 12px;
}

.history-list {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 0 2px 4px;
}

.history-item.small-card {
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  opacity: 1;
  animation: none;
  transition: box-shadow 200ms var(--ease), opacity 200ms var(--ease), background 200ms var(--ease);
}

.history-item.small-card:hover {
  opacity: 0.98;
  transform: none;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.history-thumb,
.history-thumb img,
.history-item.small-card img {
  border-radius: 8px;
}

.history-thumb img,
.history-item.small-card img {
  transition: none;
}

.history-item.small-card:hover .history-thumb img {
  transform: none;
  filter: none;
}

.history-item .meta span,
.history-item .meta strong {
  color: var(--muted);
  font-size: 12px;
}

.history-item .meta strong {
  min-height: 2.4em;
  font-weight: 400;
}

.history-item .acts {
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.history-item .acts button,
.history-item .acts select {
  min-height: 28px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-size: 12px;
  font-weight: 500;
}

.hist-reuse,
.hist-share {
  color: var(--accent) !important;
}

.hist-del {
  color: var(--danger) !important;
}

.history-item .acts select {
  grid-column: span 2;
  border: 1px solid var(--line);
  color: var(--muted);
}

.comment-bubble,
.comment-form-inline {
  display: none;
}

.toast {
  border-radius: 8px;
  background: var(--text);
  color: var(--panel);
}

* {
  transition-duration: 200ms;
  transition-timing-function: var(--ease);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  html,
  body {
    overflow: auto;
  }
}

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

/* Fix history card clipping in the right pane */
.result-zone {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
}

.empty-state,
.loading-state,
.result-error,
.result-image {
  flex: 1 1 0;
  min-height: 0;
}

.empty-state {
  min-height: 0;
}

.result-image {
  max-height: min(42vh, 360px);
}

.history-panel {
  display: flex;
  min-height: 238px;
  flex: 0 0 38%;
  flex-direction: column;
}

.history-title {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-filters {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.history-filter {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  box-shadow: none;
}

.history-filter:hover,
.history-filter.is-active {
  background: var(--panel);
  color: var(--accent);
}

.history-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
  padding-bottom: 12px;
}

.history-item.small-card {
  min-height: 0;
  align-self: start;
}

@media (max-height: 760px) {
  .history-panel {
    min-height: 220px;
    flex-basis: 44%;
  }

  .result-image {
    max-height: 34vh;
  }
}

/* Interaction refinements: references, @ picker, compact menus */
.prompt-zone form {
  grid-template-rows: minmax(138px, 0.85fr) minmax(150px, 0.78fr) auto;
}

.task-step {
  min-height: 0;
}

.task-step:nth-of-type(2) {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.task-step:nth-of-type(2) .upload-box {
  flex: 0 0 auto;
  min-height: 68px;
  padding: 12px;
}

.task-step:nth-of-type(2) .reference-preview {
  flex: 1 1 auto;
  min-height: 0;
}

.reference-preview {
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  max-height: none;
}

.reference-preview .thumb-chip {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  align-content: start;
  padding: 4px;
}

.reference-preview .thumb-chip img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.reference-preview .thumb-chip span,
.reference-preview .thumb-chip small {
  padding: 0 2px;
}

.reference-preview .thumb-chip .thumb-remove {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 2;
  width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  background: rgba(248, 250, 252, 0.92);
  color: var(--muted);
  line-height: 1;
}

.reference-preview .thumb-chip .thumb-remove:hover {
  background: var(--danger);
  color: #ffffff;
}

.reference-picker {
  position: absolute;
  z-index: 20;
  display: grid;
  width: min(360px, calc(100% - 32px));
  max-height: 180px;
  gap: 6px;
  overflow: auto;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.reference-picker button {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 4px 8px 4px 4px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.reference-picker button:hover {
  background: var(--panel-2);
}

.reference-picker img {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  object-fit: cover;
}

.history-item.small-card {
  position: relative;
}

.history-more {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

html.dark .history-more {
  background: rgba(15, 23, 42, 0.88);
}

.history-more:hover {
  background: var(--panel-2);
  color: var(--text);
}

.history-item .acts {
  position: absolute;
  top: 40px;
  right: 8px;
  z-index: 5;
  display: grid;
  width: 128px;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.history-item .acts.hidden {
  display: none;
}

.history-item .acts button,
.history-item .acts select,
.history-item .acts select {
  grid-column: auto;
  width: 100%;
  min-height: 30px;
  text-align: left;
}

.hist-chain {
  color: var(--muted) !important;
}

.history-item .acts button:hover,
.history-item .acts select:hover {
  background: var(--panel-2);
}

@media (max-height: 760px) {
  .prompt-zone form {
    grid-template-rows: minmax(120px, 0.75fr) minmax(124px, 0.64fr) auto;
    gap: 14px;
  }

  .reference-preview {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  }
}

@media (max-width: 820px) {
  .shell,
  .app-view {
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .workspace {
    display: flex;
    height: auto;
    min-height: calc(100vh - 64px);
    flex-direction: column;
    padding: 16px;
    overflow: visible;
  }

  .result-zone {
    order: 1;
    min-height: 72vh;
  }

  .prompt-zone {
    order: 2;
    overflow: visible;
  }

  .prompt-zone form {
    display: flex;
    height: auto;
    flex-direction: column;
  }

  .history-panel {
    flex: 0 0 auto;
    min-height: 236px;
    max-height: 42vh;
  }

  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .spec-row {
    grid-template-columns: 1fr;
  }

  .spec-row #generateButton {
    width: 100%;
  }
}

/* Stabilize the generation filmstrip so records never collapse or pile up */
.result-zone::before {
  inset: 18px 18px 212px;
}

.history-panel {
  min-height: 182px;
  flex: 0 0 182px;
  overflow: visible;
}

.history-list {
  display: flex !important;
  flex-flow: row nowrap;
  align-items: flex-start;
  gap: 12px;
  height: 136px;
  min-height: 136px;
  max-height: 136px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 14px;
}

.history-item.small-card {
  display: grid;
  flex: 0 0 118px;
  width: 118px;
  min-width: 118px;
  max-width: 118px;
  height: 122px;
  min-height: 122px;
  grid-template-rows: 78px 1fr;
  gap: 6px;
  overflow: visible;
}

.history-thumb {
  width: 100%;
  height: 78px;
  min-height: 78px;
}

.history-thumb img,
.history-item.small-card img {
  width: 100%;
  height: 78px;
  aspect-ratio: auto;
  object-fit: cover;
}

.history-item .meta {
  min-height: 0;
  overflow: hidden;
}

.history-item .meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .meta strong {
  display: block;
  min-height: 0;
  overflow: hidden;
  color: var(--text);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .acts {
  top: 34px;
  max-height: none;
}

.pagination {
  align-self: center;
  flex: 0 0 150px;
}

@media (max-height: 780px) {
  .result-zone::before {
    bottom: 196px;
  }

  .history-panel {
    min-height: 166px;
    flex-basis: 166px;
  }

  .history-list {
    height: 122px;
    min-height: 122px;
    max-height: 122px;
  }

  .history-item.small-card {
    flex-basis: 106px;
    width: 106px;
    min-width: 106px;
    max-width: 106px;
    height: 110px;
    min-height: 110px;
    grid-template-rows: 68px 1fr;
  }

  .history-thumb,
  .history-thumb img,
  .history-item.small-card img {
    height: 68px;
    min-height: 68px;
  }
}

@media (max-width: 820px) {
  .result-zone::before {
    inset: 14px 14px 196px;
  }

  .history-panel {
    min-height: 170px;
    flex-basis: 170px;
    max-height: none;
  }

  .history-list {
    display: flex !important;
    grid-template-columns: none;
    height: 124px;
    min-height: 124px;
    max-height: 124px;
  }
}

/* Loading mascot should keep its original running proportions */
.loading-state .thinking-gif {
  width: min(132px, 32vw);
  height: auto;
  max-height: 96px;
  object-fit: contain;
  margin-bottom: 10px;
}

/* More room for reference thumbnails and compact generation controls */
.prompt-zone form {
  grid-template-rows: minmax(124px, 0.72fr) minmax(220px, 1.2fr) auto;
}

.task-step:nth-of-type(3) {
  padding: 14px 16px;
}

.spec-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  align-items: start;
}

.spec-row .controls {
  grid-template-columns: minmax(140px, 1.35fr) 76px 86px;
  margin: 0;
}

.spec-row #generateButton {
  width: 112px;
  min-height: 40px;
  white-space: nowrap;
}

.task-step:nth-of-type(2) .upload-box {
  min-height: 60px;
  padding: 10px;
}

.task-step:nth-of-type(2) .reference-preview {
  max-height: 100%;
  padding-right: 2px;
}

.reference-preview {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.reference-preview .thumb-chip {
  min-height: 124px;
}

.reference-preview .thumb-chip img {
  min-height: 82px;
}

@media (max-height: 760px) {
  .prompt-zone form {
    grid-template-rows: minmax(106px, 0.62fr) minmax(178px, 1fr) auto;
    gap: 12px;
  }

  .reference-preview {
    grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  }

  .reference-preview .thumb-chip {
    min-height: 108px;
  }

  .reference-preview .thumb-chip img {
    min-height: 70px;
  }
}

/* Workspace redesign: canvas-first professional tool */
:root {
  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef4fb;
  --ring: rgba(59, 130, 246, 0.18);
  --deep-shadow: rgba(15, 23, 42, 0.08);
}

html.dark {
  --surface-1: #111827;
  --surface-2: #172033;
  --surface-3: #0f172a;
  --ring: rgba(96, 165, 250, 0.22);
  --deep-shadow: rgba(0, 0, 0, 0.34);
}

body {
  background:
    radial-gradient(circle at 16% 0%, rgba(59, 130, 246, 0.08), transparent 28%),
    linear-gradient(180deg, #f8fafc 0%, #eef4fb 100%);
}

html.dark body {
  background:
    radial-gradient(circle at 16% 0%, rgba(96, 165, 250, 0.12), transparent 28%),
    linear-gradient(180deg, #0b1220 0%, #101827 100%);
}

.workspace {
  grid-template-columns: minmax(360px, 0.38fr) minmax(620px, 0.62fr);
  gap: 20px;
  padding: 20px;
  background: transparent;
}

.prompt-zone,
.result-zone {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  box-shadow: 0 18px 50px var(--deep-shadow);
}

.prompt-zone {
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.prompt-zone .section-title {
  margin-bottom: 14px;
}

.prompt-zone .section-title h2 {
  font-size: 16px;
}

.prompt-zone form {
  grid-template-rows: minmax(220px, 1.1fr) minmax(150px, 0.74fr) auto;
  gap: 14px;
  height: calc(100% - 48px);
}

.task-step {
  border: 1px solid var(--line);
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.task-step:first-of-type {
  padding: 18px;
}

.task-step:first-of-type textarea {
  min-height: 0;
  border: 0;
  padding: 2px 0 0;
  background: transparent;
  font-size: 15px;
  line-height: 1.72;
}

.task-step:first-of-type textarea:focus {
  box-shadow: none;
}

.step-head {
  margin-bottom: 10px;
}

.step-head span {
  display: inline-grid;
  width: 28px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent);
  font-size: 12px;
}

html.dark .step-head span {
  background: rgba(96, 165, 250, 0.14);
}

.task-step:nth-of-type(2) {
  padding: 12px;
}

.task-step:nth-of-type(2) .upload-box {
  min-height: 50px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
}

.reference-preview {
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 7px;
}

.reference-preview .thumb-chip {
  min-height: 86px;
  border-radius: 10px;
  background: var(--surface-2);
}

.reference-preview .thumb-chip img {
  min-height: 54px;
  border-radius: 8px;
}

.reference-preview .thumb-chip span {
  display: none;
}

.task-step:nth-of-type(3) {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 12px;
  border-color: color-mix(in srgb, var(--accent) 20%, var(--line));
  box-shadow: 0 -10px 28px rgba(15, 23, 42, 0.06);
}

.task-step:nth-of-type(3) .step-head,
.task-step:nth-of-type(3) .field-hint {
  display: none;
}

.spec-row {
  grid-template-columns: minmax(0, 1fr) 124px;
  align-items: center;
}

.spec-row .controls {
  grid-template-columns: minmax(138px, 1.3fr) 72px 82px;
}

.spec-row #generateButton {
  width: 124px;
  min-height: 44px;
  border-radius: 12px;
  box-shadow: 0 10px 22px var(--ring);
}

.result-zone {
  position: relative;
  gap: 14px;
  padding: 18px;
}

.result-zone::before {
  content: "";
  position: absolute;
  inset: 18px 18px 172px;
  z-index: 0;
  border-radius: 18px;
  background:
    linear-gradient(45deg, rgba(148, 163, 184, 0.08) 25%, transparent 25% 50%, rgba(148, 163, 184, 0.08) 50% 75%, transparent 75%) 0 0 / 28px 28px,
    var(--surface-2);
  border: 1px solid var(--line);
  pointer-events: none;
}

.result-head,
.empty-state,
.loading-state,
.result-error,
.result-image,
.download-btn {
  position: relative;
  z-index: 1;
}

.result-head {
  height: 34px;
  padding: 0 2px;
}

.empty-state,
.loading-state,
.result-error,
.result-image {
  flex: 1 1 auto;
  min-height: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.empty-state {
  color: var(--muted);
}

.empty-state span {
  display: inline-grid;
  width: 76px;
  height: 76px;
  margin-bottom: 12px;
  place-items: center;
  border-radius: 22px;
  background: var(--surface-1);
  color: var(--accent);
  box-shadow: 0 12px 34px var(--deep-shadow);
  font-weight: 700;
}

.loading-state {
  align-content: center;
  justify-items: center;
  text-align: center;
}

.loading-state .thinking-gif {
  width: min(164px, 28vw);
  max-height: 118px;
}

.thinking-copy {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.thinking-copy span {
  font-size: 18px;
  letter-spacing: 0;
}

.progress-timer {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-1) 82%, transparent);
}

.result-image {
  width: 100%;
  max-height: calc(100vh - 310px);
  object-fit: contain;
  filter: drop-shadow(0 18px 34px rgba(15, 23, 42, 0.14));
}

.download-btn {
  position: absolute;
  right: 30px;
  top: 62px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
}

html.dark .download-btn {
  background: rgba(248, 250, 252, 0.16);
}

.history-panel {
  position: relative;
  z-index: 2;
  min-height: 142px;
  flex: 0 0 142px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.history-title {
  margin-bottom: 8px;
}

.history-title strong {
  font-size: 14px;
}

.history-filters {
  border: 0;
  background: var(--surface-2);
}

.history-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 2px 2px 12px;
  scroll-snap-type: x proximity;
}

.history-item.small-card {
  width: 128px;
  min-width: 128px;
  padding: 6px;
  scroll-snap-align: start;
  border: 1px solid var(--line);
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.history-item.small-card:hover {
  border-color: color-mix(in srgb, var(--accent) 44%, var(--line));
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.09);
}

.history-thumb {
  border-radius: 10px;
}

.history-thumb img,
.history-item.small-card img {
  border-radius: 10px;
}

.history-item .meta strong {
  min-height: 2.2em;
  color: var(--text);
  font-size: 11px;
}

.history-item .meta span {
  font-size: 11px;
}

.chain-step {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 2;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.92);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}

.history-more {
  opacity: 0;
  transform: translateY(-2px);
}

.history-item.small-card:hover .history-more,
.history-more[aria-expanded="true"] {
  opacity: 1;
  transform: translateY(0);
}

.history-item .acts {
  width: 142px;
  z-index: 20;
}

.history-item .acts button:first-child {
  color: var(--accent) !important;
}

.pagination {
  min-width: 180px;
}

@media (max-height: 780px) {
  .prompt-zone form {
    grid-template-rows: minmax(170px, 1fr) minmax(118px, 0.62fr) auto;
    gap: 12px;
  }

  .history-panel {
    flex-basis: 126px;
    min-height: 126px;
  }

  .result-zone::before {
    bottom: 156px;
  }

  .history-item.small-card {
    width: 112px;
    min-width: 112px;
  }

  .result-image {
    max-height: calc(100vh - 284px);
  }
}

@media (max-width: 820px) {
  .workspace {
    gap: 14px;
    padding: 12px;
  }

  .result-zone {
    min-height: 68vh;
  }

  .result-zone::before {
    inset: 14px 14px 154px;
  }

  .history-panel {
    flex-basis: 132px;
    min-height: 132px;
  }

  .history-list {
    display: flex;
  }

  .prompt-zone {
    padding: 14px;
  }

  .task-step:first-of-type textarea {
    min-height: 180px;
  }

  .spec-row,
  .spec-row .controls {
    grid-template-columns: 1fr;
  }

  .spec-row #generateButton {
    width: 100%;
  }
}

/* Final polish: filmstrip clipping and Thinking layout */
.result-zone::before {
  inset: 18px 18px 226px;
}

.history-panel {
  min-height: 194px;
  flex: 0 0 194px;
  overflow: visible;
  padding-bottom: 10px;
}

.history-list {
  display: flex !important;
  flex-flow: row nowrap;
  align-items: flex-start;
  gap: 12px;
  height: 146px;
  min-height: 146px;
  max-height: 146px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 20px;
}

.history-item.small-card {
  display: grid;
  flex: 0 0 118px;
  width: 118px;
  min-width: 118px;
  max-width: 118px;
  height: 118px;
  min-height: 118px;
  grid-template-rows: 76px 1fr;
  gap: 6px;
  overflow: visible;
}

.history-thumb,
.history-thumb img,
.history-item.small-card img {
  width: 100%;
  height: 76px;
  min-height: 76px;
  aspect-ratio: auto;
  object-fit: cover;
}

.history-item .meta {
  min-height: 0;
  overflow: hidden;
}

.history-item .meta span,
.history-item .meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .meta strong {
  display: block;
  min-height: 0;
  line-height: 1.25;
}

.history-item .acts {
  top: 34px;
  z-index: 30;
}

.loading-state {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 24px 38px;
  text-align: center;
}

.loading-state .thinking-gif {
  display: block;
  width: clamp(104px, 15vw, 148px);
  height: auto;
  max-height: 116px;
  margin: 0;
  object-fit: contain;
}

.thinking-copy {
  display: grid;
  gap: 4px;
  justify-items: center;
  margin: 0;
}

.thinking-copy span {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.thinking-copy p {
  max-width: 280px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.progress-timer {
  margin-top: 2px;
}

@media (max-height: 780px) {
  .result-zone::before {
    bottom: 210px;
  }

  .history-panel {
    min-height: 178px;
    flex-basis: 178px;
  }

  .history-list {
    height: 132px;
    min-height: 132px;
    max-height: 132px;
    padding-bottom: 18px;
  }

  .history-item.small-card {
    flex-basis: 108px;
    width: 108px;
    min-width: 108px;
    max-width: 108px;
    height: 106px;
    min-height: 106px;
    grid-template-rows: 66px 1fr;
  }

  .history-thumb,
  .history-thumb img,
  .history-item.small-card img {
    height: 66px;
    min-height: 66px;
  }

  .loading-state .thinking-gif {
    width: clamp(92px, 13vw, 124px);
    max-height: 96px;
  }
}

@media (max-width: 820px) {
  .result-zone::before {
    inset: 14px 14px 210px;
  }

  .history-panel {
    min-height: 182px;
    flex-basis: 182px;
    max-height: none;
  }

  .history-list {
    display: flex !important;
    grid-template-columns: none;
    height: 134px;
    min-height: 134px;
    max-height: 134px;
  }

  .loading-state {
    padding: 22px 18px 32px;
  }

  .loading-state .thinking-gif {
    width: 112px;
    max-height: 92px;
  }
}

/* History text readability: show meaningful prompt text without clipping */
.result-zone::before {
  inset-bottom: 252px;
}

.history-panel {
  min-height: 220px;
  flex-basis: 220px;
}

.history-list {
  height: 174px;
  min-height: 174px;
  max-height: 174px;
  padding-bottom: 22px;
}

.history-item.small-card {
  flex-basis: 156px;
  width: 156px;
  min-width: 156px;
  max-width: 156px;
  height: 150px;
  min-height: 150px;
  grid-template-rows: 88px 1fr;
}

.history-thumb,
.history-thumb img,
.history-item.small-card img {
  height: 88px;
  min-height: 88px;
}

.history-item .meta {
  display: grid;
  gap: 3px;
}

.history-item .meta span {
  display: block;
  min-height: 15px;
  line-height: 1.25;
}

.history-item .meta strong {
  display: -webkit-box;
  min-height: 32px;
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.38;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

@media (max-height: 780px) {
  .result-zone::before {
    bottom: 232px;
  }

  .history-panel {
    min-height: 202px;
    flex-basis: 202px;
  }

  .history-list {
    height: 158px;
    min-height: 158px;
    max-height: 158px;
  }

  .history-item.small-card {
    flex-basis: 142px;
    width: 142px;
    min-width: 142px;
    max-width: 142px;
    height: 136px;
    min-height: 136px;
    grid-template-rows: 78px 1fr;
  }

  .history-thumb,
  .history-thumb img,
  .history-item.small-card img {
    height: 78px;
    min-height: 78px;
  }
}

@media (max-width: 820px) {
  .result-zone::before {
    inset: 14px 14px 236px;
  }

  .history-panel {
    min-height: 206px;
    flex-basis: 206px;
  }

  .history-list {
    height: 160px;
    min-height: 160px;
    max-height: 160px;
  }

  .history-item.small-card {
    flex-basis: 146px;
    width: 146px;
    min-width: 146px;
    max-width: 146px;
  }
}

/* Cleaner generation waiting state */
.loading-state {
  background: transparent !important;
  box-shadow: none !important;
  border: 0 !important;
}

.loading-state .thinking-gif {
  width: clamp(112px, 13vw, 142px);
  max-height: 108px;
}

.thinking-copy span {
  font-size: 17px;
}

.thinking-copy p {
  color: var(--muted);
}

.progress-timer {
  display: inline-flex;
  gap: 10px;
  justify-content: center;
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.progress-timer span:first-child {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

@media (max-height: 780px) {
  .loading-state {
    gap: 8px;
    padding-bottom: 28px;
  }

  .loading-state .thinking-gif {
    width: clamp(92px, 12vw, 118px);
    max-height: 88px;
  }
}
