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

:root {
  --bg-base: #07070a;
  --bg-surface: #0d0d12;
  --bg-elevated: #13131a;
  --bg-hover: #1a1a24;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(249, 115, 22, 0.3);
  --text-primary: #f0f0f5;
  --text-secondary: #8b8b9e;
  --text-tertiary: #5c5c6e;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-muted: rgba(249, 115, 22, 0.12);
  --accent-glow: rgba(249, 115, 22, 0.25);
  --success: #3fb950;
  --success-muted: rgba(63, 185, 80, 0.1);
  --danger: #f85149;
  --danger-muted: rgba(248, 81, 73, 0.1);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ----- Screens ----- */
#login-screen, #setup-screen {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

#login-screen {
  display: none;
}

.setup-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.setup-card h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

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

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 14px;
  line-height: 1.5;
}

.setup-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.setup-card input::placeholder {
  color: var(--text-tertiary);
}

.setup-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.setup-card button {
  width: 100%;
}

.hint {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 16px;
}

/* ----- Discord Button ----- */
.discord-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 24px;
  background: #5865F2;
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  font-family: inherit;
}

.discord-btn:hover {
  background: #4752c4;
  box-shadow: 0 4px 16px rgba(88, 101, 242, 0.3);
  transform: translateY(-1px);
}

.discord-btn:active {
  transform: translateY(0);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--danger-muted);
  border: 1px solid rgba(248, 81, 73, 0.2);
  border-radius: var(--radius);
}

/* ----- User Info ----- */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ----- Balance ----- */
.balance-display {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: var(--success-muted);
  border: 1px solid rgba(63, 185, 80, 0.2);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--success);
  white-space: nowrap;
}

.balance-icon {
  font-size: 12px;
  font-weight: 700;
}

/* ----- Cost Display ----- */
.cost-display {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 8px 0;
  font-variant-numeric: tabular-nums;
}

/* ----- Header ----- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

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

.header-left .logo {
  height: 28px;
  width: auto;
}

.header-left h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

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

/* ----- Main Layout ----- */
.main-layout {
  display: flex;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 24px 24px;
  align-items: stretch;
  height: calc(100vh - 64px);
}

.main-content {
  flex: 1;
  min-width: 0;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  overflow: hidden auto;
}

.generation-form {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
  flex: 1;
}

.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.params-grid .chip-group {
  align-items: flex-start;
}

.params-grid .chip-group-label {
  min-width: 0;
  margin-bottom: 2px;
}

.params-grid .model-row {
  align-self: end;
  margin-bottom: 2px;
}

.negative-wrapper {
  margin-top: -6px;
}

.negative-wrapper textarea {
  padding: 10px 14px;
  font-size: 13px;
  min-height: 52px;
  resize: none;
}

.history-sidebar {
  width: 360px;
  flex-shrink: 0;
  position: sticky;
  top: 56px;
  max-height: calc(100vh - 64px);
  overflow: hidden auto;
}

.history-sidebar #history-section {
  margin-top: 0;
}

/* Drop Zone */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.drop-zone svg {
  width: 28px;
  height: 28px;
  opacity: 0.4;
  transition: opacity 0.2s;
}

.drop-zone:hover svg {
  opacity: 0.7;
}

.drop-zone p {
  font-size: 12px;
}

.drop-zone span.hint {
  font-size: 11px;
}

.drop-zone img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius);
  object-fit: contain;
}

.remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

/* Image previews grid */
.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 100%;
}

.preview-item {
  position: relative;
  display: inline-block;
}

.preview-item img {
  width: 80px;
  height: 80px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border-default);
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.preview-remove:hover {
  opacity: 1;
}

/* Prompt Wrapper */
.prompt-wrapper {
  position: relative;
}

.prompt-wrapper textarea {
  padding-bottom: 28px;
}

.char-counter {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: color 0.2s;
}

.char-counter.limit-near {
  color: var(--danger);
  font-weight: 600;
}

/* Textarea */
textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  line-height: 1.6;
}

textarea::placeholder {
  color: var(--text-tertiary);
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* Style/Model/Controls Rows */
.style-row,
.ratio-row,
.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.style-row .label,
.ratio-row .label,
.model-row .label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.style-row select,
.model-row select {
  flex: 1;
  min-width: 0;
}

/* Controls Row */
.controls-row {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  gap: 12px;
  flex-wrap: wrap;
}

.resolution-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.resolution-group .label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

/* ----- Radio Labels ----- */
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: color 0.2s;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.radio-label:hover {
  background: var(--bg-hover);
}

.radio-label input[type="radio"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.radio-label:has(input:checked) {
  color: var(--text-primary);
  background: var(--accent-muted);
}

/* ----- Batch Count ----- */
.count-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-group .label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
}

.stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 32px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
  line-height: 1;
}

.stepper-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.stepper-value {
  min-width: 28px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 4px;
  line-height: 32px;
  user-select: none;
}

/* ----- Buttons ----- */
button, a.btn-small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  font-family: inherit;
  font-weight: 500;
  line-height: 1;
}

button:hover, a.btn-small:hover {
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 12px 28px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

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

.btn-small {
  padding: 7px 14px;
  font-size: 12px;
}

/* ----- Select ----- */
select {
  padding: 8px 32px 8px 12px;
  background: var(--bg-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b8b9e' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

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

/* ----- Chip Selectors ----- */
.chip-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--border-default);
  border-radius: 20px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1.3;
}

.chip-option:hover {
  border-color: var(--accent);
  background: var(--accent-muted);
  color: var(--text-primary);
}

.chip-option.chip-active {
  border-color: var(--accent);
  background: var(--accent-muted);
  color: var(--text-primary);
}

/* ----- Chip Groups (style, ratio, type) ----- */
.chip-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-group-label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
  white-space: nowrap;
}

/* ----- Batch Tag ----- */
.qi-batch {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  margin-left: 6px;
  padding: 2px 6px;
  background: var(--accent-muted);
  border-radius: 4px;
  letter-spacing: 0.3px;
}

/* ----- Queue ----- */
#queue-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.queue-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.queue-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.queue-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  transition: background 0.2s;
}

.queue-queued::before {
  background: var(--text-tertiary);
}

.queue-generating::before {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(249, 115, 22, 0.3);
}

.queue-done::before {
  background: var(--success);
}

.queue-error::before {
  background: var(--danger);
}

.qi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.qi-model {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  word-break: break-word;
}

.qi-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.2px;
}

.qi-status-queued {
  background: rgba(139, 148, 158, 0.08);
  color: var(--text-secondary);
}

.qi-status-generating {
  background: var(--accent-muted);
  color: var(--accent);
}

.qi-status-done {
  background: var(--success-muted);
  color: var(--success);
}

.qi-status-error {
  background: var(--danger-muted);
  color: var(--danger);
}

.qi-prompt {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
  word-break: break-word;
  line-height: 1.5;
}

.qi-resolution {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  word-break: break-word;
}

.qi-result {
  margin-top: 10px;
}

.qi-result img {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius);
  display: block;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.qi-actions {
  display: flex;
  gap: 8px;
}

.qi-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(249, 115, 22, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 10px 0;
}

.qi-error {
  font-size: 13px;
  color: var(--danger);
  margin-top: 6px;
  word-break: break-word;
  padding: 8px 12px;
  background: var(--danger-muted);
  border-radius: var(--radius-sm);
}

/* ----- History ----- */
#history-section {
  margin-top: 36px;
}

.section-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.history-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--border-default);
  border-radius: 0 2px 2px 0;
  transition: background 0.2s;
}

.history-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.history-item:hover::before {
  background: var(--accent);
}

.hi-img {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

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

.hi-meta {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

.hi-prompt {
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
  margin-bottom: 4px;
}

.hi-detail {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
  word-break: break-word;
}

.hi-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 4px;
}

.hi-action-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-family: inherit;
  line-height: 1;
  text-decoration: none;
}

.hi-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.hi-download:hover {
  color: var(--text-primary);
}

.hi-repeat:hover {
  color: var(--accent);
  background: var(--accent-muted);
}

.hi-delete:hover {
  color: var(--danger);
  background: var(--danger-muted);
}

/* ----- Balance Warning ----- */
.balance-warning {
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
  white-space: nowrap;
  padding: 6px 10px;
  background: var(--danger-muted);
  border: 1px solid rgba(248, 81, 73, 0.2);
  border-radius: var(--radius-sm);
}

/* ----- Progress Bar ----- */
.progress-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.progress-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.progress-bar-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ----- History Search ----- */
.history-toolbar {
  margin-bottom: 12px;
}

.history-search {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.history-search::placeholder {
  color: var(--text-tertiary);
}

.history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* ----- Animations ----- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.queue-item {
  animation: fadeInUp 0.35s ease;
}

.qi-status-generating {
  animation: statusPulse 1.2s ease-in-out infinite;
}

/* ----- Result Area ----- */
.result-area {
  margin-top: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.result-image-wrapper {
  display: flex;
  justify-content: center;
}

.result-image-wrapper img {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* ----- Loading Spinner ----- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(249, 115, 22, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ----- Responsive ----- */
@media (max-width: 960px) {
  .main-layout {
    flex-direction: column;
  }

  header {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .header-right {
    flex-wrap: wrap;
  }

  .params-grid > * {
    min-width: 0;
  }

  .history-sidebar .hi-img {
    width: 56px;
    height: 56px;
  }

  .history-sidebar .hi-prompt {
    font-size: 13px;
    display: -webkit-box;
  }

  .history-sidebar .hi-detail {
    font-size: 11px;
  }

  .history-sidebar .section-title {
    font-size: 17px;
  }
}

@media (max-width: 640px) {
  header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    text-align: center;
    padding: 12px 16px;
  }

  .header-right {
    flex-wrap: wrap;
    justify-content: center;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .resolution-group {
    justify-content: center;
    flex-wrap: wrap;
  }

  .setup-card {
  padding: 8px 24px 24px;
  }

  .main-layout {
    padding: 20px 16px;
  }

  .generation-form {
    padding: 20px;
  }

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

  .history-item {
    flex-wrap: wrap;
  }

  .history-item .hi-actions {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
    margin-top: 6px;
  }

  .history-item::before,
  .queue-item::before {
    top: 4px;
    bottom: 4px;
  }
}

/* ----- Custom Tooltip ----- */
[data-tooltip] {
  cursor: help;
}

.tooltip {
  position: fixed;
  padding: 5px 10px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  pointer-events: none;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.15s;
}

.tooltip.visible {
  opacity: 1;
}

/* ----- Toast Notification ----- */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ----- Lightbox ----- */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

#lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

#lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

#lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}

#lightbox-close:hover {
  opacity: 1;
}

/* ----- History image clickable ----- */
.hi-img {
  cursor: pointer;
}
