/* ============ Reset & Variables ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0c0f;
  --bg-raised: #16161a;
  --bg-input: #1e1e24;
  --border: #2a2a32;
  --border-focus: #6366f1;
  --text: #e4e4e7;
  --text-muted: #8b8b96;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Header ============ */
header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  background: var(--bg-raised);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.logo-icon {
  color: var(--accent);
  font-size: 1.5rem;
}
.header-tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-weight: 600;
  opacity: 0.8;
}

/* ============ Auth buttons ============ */
.header-auth {
  display: flex;
  align-items: center;
}
.auth-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.auth-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.auth-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.auth-btn.primary:hover {
  background: var(--accent-hover);
}
.user-badge {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  padding: 0.35rem 0.6rem;
  background: var(--accent-glow);
  border-radius: var(--radius-sm);
}

/* ============ Main ============ */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px 4px 0 0;
}
.tab-badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-glow);
  color: var(--accent);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============ Panel Layout ============ */
.panel-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}
@media (max-width: 820px) {
  .panel-layout {
    grid-template-columns: 1fr;
  }
  .preview-pane {
    order: -1;
    position: static !important;
  }
}

/* ============ Controls ============ */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.art-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--bg-raised);
}
.field-group legend {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 0.4rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}
label:first-child { margin-top: 0.3rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  display: block;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  margin-top: 0.25rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}
textarea { resize: vertical; }

input[type="color"] {
  display: block;
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  padding: 2px;
  margin-top: 0.25rem;
}

input[type="range"] {
  display: block;
  width: calc(100% - 3rem);
  margin-top: 0.35rem;
  accent-color: var(--accent);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: 0.3rem;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.range-val {
  font-size: 0.7rem;
  color: var(--accent);
  font-family: var(--mono);
  min-width: 2.5rem;
  text-align: right;
}

/* ============ Row layouts ============ */
.row { display: flex; gap: 0.75rem; align-items: flex-end; }
.half { flex: 1; }
.third { flex: 1; }
.check-label {
  display: flex;
  align-items: center;
  font-size: 0.8rem;
  min-height: 2.1rem;
}

/* ============ Mode toggles ============ */
.mode-toggle {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 0.5rem;
}
.mode-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}
.mode-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mode-fields { display: none; }
.mode-fields.active { display: block; }

/* ============ Sub sections ============ */
.sub-section {
  margin-top: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}
.sub-section summary {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.sub-section[open] summary { margin-bottom: 0.4rem; }

/* ============ File upload ============ */
.file-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  margin-top: 0.4rem;
}
.file-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  transition: border-color 0.15s;
}
.file-label:hover .file-btn { border-color: var(--accent); }
.file-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ Generate button ============ */
.generate-btn {
  width: 100%;
  padding: 0.7rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.generate-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.generate-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.generate-btn .spinner {
  width: 14px; height: 14px;
  border-width: 2px;
}

/* ============ Preview ============ */
.preview-pane {
  position: sticky;
  top: 1.5rem;
}
.preview-box {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: hidden;
}
.preview-box svg {
  max-width: 100%;
  height: auto !important;
  width: auto !important;
  max-height: 500px;
  border-radius: var(--radius-sm);
}
.preview-box img {
  max-width: 100%;
  max-height: 500px;
  border-radius: var(--radius-sm);
}
.preview-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.action-btn {
  flex: 1;
  padding: 0.55rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.action-btn:hover { background: var(--accent-hover); }
.action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.action-btn.secondary {
  background: transparent;
  color: var(--accent);
}
.action-btn.secondary:hover {
  background: var(--accent-glow);
}

/* ============ Art timer ============ */
.art-timer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.art-notice {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  font-size: 0.78rem;
}

/* ============ Auth Gate (Art tab) ============ */
.art-auth-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 1.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.gate-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  filter: grayscale(0);
}
.art-auth-gate h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.art-auth-gate p {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 320px;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}
.gate-buttons {
  width: 100%;
  max-width: 280px;
}

/* ============ Usage meter ============ */
.usage-meter {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.usage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.usage-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.usage-count {
  font-size: 0.8rem;
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 500;
}
.usage-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}
.usage-remaining {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ============ Modal ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.active {
  display: flex;
}
.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  position: relative;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}
.modal-close:hover { color: var(--text); }
.modal h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}
.modal form {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.modal .generate-btn {
  margin-top: 1rem;
}
.auth-error {
  color: var(--danger);
  font-size: 0.78rem;
  min-height: 1.2rem;
  margin-top: 0.5rem;
}
.auth-toggle-row {
  text-align: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.auth-toggle-row a {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
}
.auth-toggle-row a:hover {
  color: var(--text);
}
.auth-toggle-row strong {
  color: var(--accent);
}

/* ============ Footer ============ */
footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ============ Toast notifications ============ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--danger);
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideUp 0.3s ease;
  pointer-events: auto;
}
.toast.success { background: var(--success); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ MCP Banner ============ */
.mcp-banner {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.mcp-banner-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  align-items: center;
}
.mcp-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  background: var(--accent-glow);
}
.mcp-banner-text h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  letter-spacing: -0.02em;
}
.mcp-banner-text p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.mcp-code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: rgba(99, 102, 241, 0.06);
  border-bottom: 1px solid var(--border);
}
.code-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--mono);
}
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  display: flex;
  align-items: center;
}
.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.mcp-code-block pre {
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
}
.mcp-code-block code {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text);
  line-height: 1.6;
  white-space: pre;
}

/* ============ Presets Grid ============ */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
.preset-btn {
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.3rem 0.4rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.preset-btn:hover {
  border-color: var(--border);
  background: var(--bg-raised);
}
.preset-btn.active {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.preset-swatch {
  width: 100%;
  height: 24px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}
.swatch-half {
  flex: 1;
}
.preset-name {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.preset-btn.active .preset-name {
  color: var(--accent);
}

/* ============ Advanced Settings ============ */
.advanced-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.advanced-toggle {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.advanced-toggle::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s;
}
.advanced-section[open] .advanced-toggle::before {
  transform: rotate(90deg);
}
.advanced-toggle::-webkit-details-marker {
  display: none;
}
.advanced-toggle:hover {
  color: var(--text);
}
.advanced-inner {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ============ Mobile ============ */
@media (max-width: 820px) {
  .mcp-banner-inner {
    grid-template-columns: 1fr;
  }
  .presets-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 480px) {
  .header-inner {
    flex-wrap: wrap;
  }
  .header-auth {
    width: 100%;
    justify-content: flex-end;
  }
  .presets-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
