/* Visual Prompt Builder — Styles */

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

:root {
  --bg: #0D1117;
  --card: #1F2937;
  --card-inner: #111827;
  --accent: #8B5CF6;
  --accent-pink: #EC4899;
  --text: #F3F4F6;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --border: #374151;
  --success: #34D399;
  --error: #EF4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

/* --- Header --- */
.header {
  text-align: center;
  margin-bottom: 32px;
}

.header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header p {
  color: var(--text-secondary);
  margin-top: 4px;
  font-size: 0.95rem;
}

/* --- Tool Updates --- */
#updates-section {
  background: linear-gradient(135deg, #1a1a2e 0%, #1e1b34 100%);
  border: 1px solid #3b3572;
  margin-bottom: 24px;
  position: relative;
  overflow: visible;
}

#updates-section::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 12px;
  padding: 1px;
  background: linear-gradient(135deg, #6366F1 0%, #4F46E5 50%, #6366F1 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.5;
}

#updates-section .accordion-header {
  padding: 12px 20px;
}

#updates-section .accordion-header:hover {
  background: rgba(99, 102, 241, 0.08);
}

#updates-section .accordion-header h3 {
  color: #A5B4FC;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
}

#updates-section .accordion-content {
  text-align: center;
}

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

.last-check-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.last-check-badge.stale {
  background: rgba(251, 191, 36, 0.15);
  color: #FBBF24;
}

.last-check-badge:empty {
  display: none;
}

.updates-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

#check-updates-btn {
  width: 100%;
  padding: 12px;
  border: 2px solid #6366F1;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #6366F1;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#check-updates-btn:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.1);
}

#check-updates-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#updates-progress {
  text-align: center;
  padding: 12px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.update-results-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

.update-item {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid #3b3572;
  border-radius: 8px;
  padding: 12px;
}

.update-item-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.update-item-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: #C7D2FE;
}

.update-item-status {
  font-size: 0.8rem;
}

.update-badge-new {
  display: inline-block;
  background: #6366F1;
  color: white;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
}

.update-badge-ok {
  font-size: 1rem;
}

.update-item-summary {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- Tab Bar --- */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--card);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --- Sections / Cards --- */
.section {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.section-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* --- API Key --- */
.api-key-row {
  display: flex;
  gap: 8px;
}

.api-key-row input {
  flex: 1;
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.api-key-row input:focus {
  border-color: var(--accent);
}

.api-key-row input::placeholder {
  color: var(--text-muted);
}

.btn-small {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}

.btn-small:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn-save {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.btn-save:hover {
  opacity: 0.85;
}

.api-status {
  font-size: 0.8rem;
  margin-top: 6px;
  min-height: 1.2em;
}

.api-status.saved {
  color: var(--success);
}

.api-instructions {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.api-instructions ol {
  padding-left: 18px;
}

.api-instructions a {
  color: var(--accent);
  text-decoration: none;
}

.api-instructions a:hover {
  text-decoration: underline;
}

/* --- Tool Selector --- */
#tool-buttons,
#re-tool-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 16px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.tool-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tool-btn.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
  color: var(--text);
}

/* --- Textarea --- */
textarea {
  width: 100%;
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

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

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

#description-input {
  min-height: 100px;
}

#extra-input {
  min-height: 60px;
}

/* --- Accordions --- */
.accordion {
  background: var(--card);
  border-radius: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.accordion-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.accordion-header .arrow {
  color: var(--text-muted);
  transition: transform 0.2s;
  font-size: 0.8rem;
}

.accordion.open .accordion-header .arrow {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion.open .accordion-body {
  max-height: 2000px;
}

.accordion-content {
  padding: 0 20px 20px;
}

/* --- Option Grids --- */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.option-card {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.option-card:hover {
  border-color: var(--accent);
}

.option-card.selected {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.12);
}

.option-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.option-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* --- Aspect ratio grid --- */
#aspect-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

/* --- Upload Area --- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.05);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.upload-icon {
  font-size: 2rem;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.image-previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.image-previews:empty {
  display: none;
}

.image-preview {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}

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

.image-preview .remove-img {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s;
}

.image-preview .remove-img:hover {
  background: var(--error);
}

/* --- Generate Button --- */
#generate-btn,
#re-generate-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  transition: opacity 0.2s, transform 0.1s;
  margin: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#generate-btn:hover:not(:disabled),
#re-generate-btn:hover:not(:disabled) {
  opacity: 0.9;
}

#generate-btn:active:not(:disabled),
#re-generate-btn:active:not(:disabled) {
  transform: scale(0.99);
}

#generate-btn:disabled,
#re-generate-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Spinner --- */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* --- Recommendation Bar --- */
#recommendation-bar {
  margin-bottom: 16px;
  padding: 16px;
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 10px;
}

#recommendation-bar.hidden {
  display: none;
}

.rec-chosen {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.rec-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.rec-tool-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.rec-reason {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.rec-override {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.rec-override-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#override-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.override-pill {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.2s;
}

.override-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* --- Output --- */
#output-section {
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

#output-section.hidden {
  display: none;
}

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

.output-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

#copy-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.2s;
}

#copy-btn:hover {
  opacity: 0.85;
}

#copy-btn.copied {
  background: var(--success);
}

#output-text {
  background: var(--card-inner);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* --- Refine --- */
.refine-section textarea {
  margin-bottom: 10px;
}

#refine-btn {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#refine-btn:hover:not(:disabled) {
  background: rgba(139, 92, 246, 0.1);
}

#refine-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Error --- */
#error-msg {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--error);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

#error-msg.hidden {
  display: none;
}

/* --- History --- */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

#history-count {
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 100px;
  min-width: 20px;
  text-align: center;
}

#clear-history-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.2s, border-color 0.2s;
}

#clear-history-btn:hover {
  color: var(--error);
  border-color: var(--error);
}

.history-item {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  position: relative;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.history-tool {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.history-prompt {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  max-height: 60px;
  overflow: hidden;
  margin-bottom: 8px;
}

.copy-history-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.copy-history-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.copy-history-btn.copied {
  border-color: var(--success);
  color: var(--success);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 16px;
}

/* --- Tips --- */
.tips-list {
  list-style: none;
  padding: 0;
}

.tips-list li {
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 4px 0;
  padding-left: 20px;
  position: relative;
}

.tips-list li::before {
  content: "\2192";
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* --- Reference Tab --- */

/* Sub-navigation pills */
.ref-subnav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  justify-content: center;
}

.ref-subnav-btn {
  padding: 8px 20px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.ref-subnav-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.ref-subnav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.ref-view {
  display: none;
}

.ref-view.active {
  display: block;
}

.ref-intro {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

.ref-pdf-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 20px;
}

.ref-pdf-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ref-pdf-link {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
  padding: 4px 12px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  transition: all 0.2s;
}

.ref-pdf-link:hover {
  background: var(--accent);
  color: white;
}

.ref-section-header {
  margin-bottom: 12px;
}

.ref-section-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.ref-section-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ref-category-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 16px 0 8px;
  padding-left: 4px;
}

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.ref-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ref-card:hover {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.06);
  transform: translateY(-1px);
}

.ref-card-emoji {
  font-size: 1.3rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.ref-card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ref-card-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.ref-card-desc {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.ref-card-tap {
  font-size: 0.65rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
  margin-top: 2px;
}

.ref-card:hover .ref-card-tap {
  opacity: 1;
}

/* Reference Rules */
.ref-rules {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-top: 20px;
}

.ref-rules h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.ref-rules ol {
  padding-left: 18px;
  margin: 0;
}

.ref-rules li {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 3px 0;
  line-height: 1.5;
}

.ref-rules code {
  background: var(--card-inner);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent);
}

/* --- Reference Link List (accordions) --- */
.ref-link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ref-link-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-style: italic;
}

.ref-rules-list {
  padding-left: 18px;
  margin: 0;
}

.ref-rules-list li {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 3px 0;
  line-height: 1.5;
}

.ref-rules-list code {
  background: var(--card-inner);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent);
}

/* --- Detail Modal --- */
.ref-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ref-modal.hidden {
  display: none !important;
}

.ref-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.ref-modal-content {
  position: relative;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: modalSlideUp 0.25s ease-out;
}

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

.ref-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.ref-modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.ref-modal-emoji {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 8px;
}

.ref-modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text);
}

.ref-modal-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* --- Grid Builder Tab --- */
.grid-builder-intro {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}

.grid-title-input {
  width: 100%;
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.grid-title-input:focus {
  border-color: var(--accent);
}

.grid-title-input::placeholder {
  color: var(--text-muted);
}

.grid-preview {
  display: grid;
  gap: 12px;
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  justify-items: center;
}

.grid-preview.cols-1 { grid-template-columns: 1fr; max-width: 280px; margin: 0 auto; }
.grid-preview.cols-2 { grid-template-columns: repeat(2, 1fr); max-width: 480px; margin: 0 auto; }
.grid-preview.cols-3 { grid-template-columns: repeat(3, 1fr); }

.grid-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  position: relative;
}

.grid-cell-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #f0f0f0;
}

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

.grid-cell-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s;
  z-index: 2;
}

.grid-cell-remove:hover {
  background: var(--error);
}

.grid-cell-label {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid #ccc;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  color: #333;
  padding: 4px 2px;
  outline: none;
}

.grid-cell-label:focus {
  border-bottom-color: var(--accent);
}

.grid-cell-label::placeholder {
  color: #aaa;
  font-weight: 400;
}

.grid-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  justify-content: center;
}

.grid-clear-btn {
  padding: 12px 24px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.grid-clear-btn:hover {
  border-color: var(--error);
  color: var(--error);
}

.grid-download-btn {
  padding: 12px 32px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  cursor: pointer;
  transition: opacity 0.2s;
}

.grid-download-btn:hover {
  opacity: 0.9;
}

/* --- Realism Divider --- */
.realism-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 24px 0 12px;
  position: relative;
}

.realism-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-pink), transparent);
  z-index: 0;
}

.realism-divider > span:first-child {
  background: var(--bg);
  padding: 0 16px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
  z-index: 1;
}

.realism-divider-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  position: relative;
  z-index: 1;
  background: var(--bg);
  padding: 0 8px;
}

/* --- Hidden utility --- */
.hidden {
  display: none !important;
}

/* --- Mobile --- */
@media (max-width: 600px) {
  .container {
    padding: 16px 12px 60px;
  }

  .header h1 {
    font-size: 1.5rem;
  }

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

  #aspect-grid {
    grid-template-columns: 1fr 1fr;
  }

  #tool-buttons,
  #re-tool-buttons {
    gap: 6px;
  }

  .tool-btn {
    font-size: 0.8rem;
    padding: 6px 12px;
  }

  .api-key-row {
    flex-direction: column;
  }

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

  .ref-modal-content {
    padding: 24px 18px;
  }

  .grid-preview.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-actions {
    flex-direction: column;
  }

  .tab-bar {
    flex-wrap: wrap;
  }
}
