:root {
  --bg-0: #04020d;
  --bg-1: #0a1021;
  --bg-panel: rgba(12, 16, 34, 0.8);
  --bg-panel-strong: rgba(14, 20, 42, 0.9);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(155, 138, 255, 0.5);
  --text-primary: #f5f7ff;
  --text-muted: rgba(218, 225, 255, 0.7);
  --text-soft: rgba(198, 206, 242, 0.48);
  --accent: #8d7cff;
  --accent-soft: rgba(141, 124, 255, 0.18);
  --error: #ff8c9a;
  --success: #57e0a5;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  height: 100vh;
  min-height: 620px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at 12% -10%, rgba(140, 96, 255, 0.28), transparent 55%),
    radial-gradient(circle at 88% 18%, rgba(72, 176, 255, 0.22), transparent 60%),
    linear-gradient(150deg, var(--bg-0), var(--bg-1));
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
}

.surface {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
}

.neural-network {
  position: absolute;
  inset: 0;
  opacity: 0.7;
  mix-blend-mode: screen;
}

.halo {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.55;
}

.halo-a {
  width: 36rem;
  height: 36rem;
  top: -10rem;
  left: -8rem;
  background: radial-gradient(circle, rgba(150, 118, 255, 0.55), transparent 70%);
  animation: float-a 8s ease-in-out infinite;
}

.halo-b {
  width: 28rem;
  height: 28rem;
  bottom: 6rem;
  right: 12%;
  background: radial-gradient(circle, rgba(83, 184, 255, 0.32), transparent 65%);
  animation: float-b 10s ease-in-out infinite;
}

.halo-c {
  width: 22rem;
  height: 22rem;
  top: 54%;
  left: 58%;
  background: radial-gradient(circle, rgba(255, 158, 218, 0.28), transparent 72%);
  animation: float-c 12s ease-in-out infinite;
}

@keyframes float-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.1); }
}

@keyframes float-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-30px, 20px) scale(0.9); }
}

@keyframes float-c {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(15px, 25px) scale(1.05); }
}

.texture {
  position: absolute;
  inset: 0;
  opacity: 0.18;
}

.texture-scan {
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.05) 0,
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 6px
  );
}

.texture-grid {
  background-image: linear-gradient(rgba(141, 124, 255, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(141, 124, 255, 0.12) 1px, transparent 1px);
  background-size: 120px 120px;
  mix-blend-mode: screen;
}

.viewport {
  width: min(1160px, 100%);
  height: 100%;
  padding: clamp(20px, 4vw, 32px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(16px, 3vw, 22px);
  position: relative;
  z-index: 1;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-md);
  background: linear-gradient(120deg, rgba(12, 16, 36, 0.82), rgba(12, 16, 36, 0.38));
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.9rem;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(141, 124, 255, 0.95), rgba(67, 47, 190, 0.85));
  color: #0f0828;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow: 0 18px 38px rgba(8, 8, 26, 0.6);
  position: relative;
  overflow: hidden;
}

.brand-mark::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.brand-mark:hover::before {
  transform: translateX(100%);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand-name {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  font-weight: 600;
}

.brand-tag {
  font-size: 0.72rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.credits-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(87, 224, 165, 0.1);
  border: 1px solid rgba(87, 224, 165, 0.3);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--success);
  letter-spacing: 0.05em;
}

.credits-icon {
  font-size: 0.9rem;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.auth-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.auth-btn svg {
  width: 16px;
  height: 16px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.sign-out-btn {
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sign-out-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.profile-link {
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-decoration: none;
  transition: all 0.2s ease;
}

.profile-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.toolbar-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--text-soft);
}

.toolbar-link {
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.78rem;
  transition: color 0.2s ease, transform 0.2s ease;
}

.toolbar-link:hover,
.toolbar-link:focus-visible {
  color: var(--text-primary);
  transform: translateY(-2px);
  outline: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: clamp(16px, 3vw, 24px);
  height: 100%;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px rgba(5, 7, 20, 0.65);
  backdrop-filter: blur(22px);
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: clamp(1.4rem, 2.8vw, 2.1rem);
  flex: 1;
  min-height: 0;
}

.controls-head {
  display: grid;
  gap: 0.5rem;
}

.field-idea {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

.field-idea textarea {
  flex: 1;
  min-height: 220px;
  height: 100%;
  overflow: auto;
}

.eyebrow {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.controls-head h1 {
  margin: 0;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: clamp(1.8rem, 3.2vw, 2.6rem);
  line-height: 1.1;
}

.controls-copy {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

#prompt-form {
  display: grid;
  gap: 1.1rem;
  flex: 1;
  grid-template-rows: minmax(0, 1fr) auto auto;
  min-height: 0;
}

.field {
  display: grid;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.76rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-soft);
}

textarea,
select {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 15, 30, 0.85);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  resize: none;
}

select {
  height: 52px;
  min-height: 52px;
  line-height: 1;
}

textarea:focus,
select:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transform: translateY(-1px);
}

textarea::placeholder {
  color: rgba(214, 222, 255, 0.36);
}

.select-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.form-footer {
  display: grid;
  gap: 0.55rem;
}

#generate-btn {
  min-height: 56px;
  height: 56px;
  border: none;
  border-radius: 999px;
  padding: 0 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  font-size: 0.94rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  background: linear-gradient(135deg, #ffffff, rgba(245, 240, 255, 0.78));
  color: #0f1024;
  box-shadow: 0 22px 52px rgba(10, 10, 32, 0.6);
  transition: transform 0.2s ease, box-shadow 0.22s ease;
  line-height: 1.2;
}

#generate-btn:hover,
#generate-btn:focus-visible {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 28px 62px rgba(10, 10, 32, 0.66);
  outline: none;
}

#generate-btn:disabled {
  opacity: 0.65;
  transform: none;
  box-shadow: none;
  cursor: wait;
}

.outputs {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.2vw, 20px);
  height: 100%;
  min-height: 0;
}

.results {
  background: var(--bg-panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: clamp(1.3rem, 2.2vw, 1.9rem);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  flex: 1;
  min-height: 0;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, 1fr);
  gap: 1rem;
  height: 200px;
  flex-shrink: 0;
}

.cell {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(150deg, rgba(16, 20, 44, 0.92), rgba(12, 16, 34, 0.75));
  color: inherit;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, rgba(141, 124, 255, 0.1) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cell:hover::before {
  opacity: 1;
}

.cell:hover,
.cell:focus-visible {
  transform: translateY(-6px) scale(1.02);
  border-color: rgba(141, 124, 255, 0.65);
  box-shadow: 0 25px 50px rgba(8, 10, 24, 0.6), 0 0 0 1px rgba(141, 124, 255, 0.2);
  outline: none;
}

.cell.selected {
  border-color: rgba(141, 124, 255, 0.9);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 30px 60px rgba(8, 10, 24, 0.7);
  transform: translateY(-2px);
}

.cell-axes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-soft);
  margin-bottom: 0.5rem;
}

.cell-axis {
  display: block;
  line-height: 1.2;
}

.cell-title {
  margin: 0;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  display: none; /* Hide title since we're showing axes */
}

.cell-preview {
  margin: 0;
  color: rgba(225, 230, 255, 0.75);
  font-size: 0.94rem;
  line-height: 1.4;
  display: none; /* Hide preview in grid, show in full preview */
}

.prompt-preview {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(141, 124, 255, 0.22);
  background: rgba(12, 16, 34, 0.78);
  position: relative;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.prompt-preview::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(141, 124, 255, 0.6), transparent);
  animation: scan-line 3s ease-in-out infinite;
}

@keyframes scan-line {
  0% { left: -100%; }
  50% { left: 100%; }
  100% { left: -100%; }
}

#preview-body {
  margin: 0;
  background: transparent;
  border: none;
  padding: 0;
  font-family: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(229, 233, 255, 0.88);
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translate(-50%, 120%);
  background: rgba(10, 14, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: 0 18px 34px rgba(7, 9, 20, 0.6);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
  opacity: 0;
  z-index: 10;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast.success {
  background: rgba(87, 224, 165, 0.9);
  color: var(--quantum-void);
  border-color: var(--success);
}

.toast.error {
  background: rgba(255, 140, 154, 0.9);
  color: var(--quantum-void);
  border-color: var(--error);
}

.hidden {
  display: none !important;
}

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

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

@media (max-width: 1100px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .viewport {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .outputs {
    gap: 1.2rem;
  }

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

  .select-stack {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .controls {
    padding: 1.2rem 1.3rem;
  }

  .results {
    padding: 1.2rem 1.3rem;
  }
}