:root {
  --bg: #0b0a12;
  --surface: #12101a;
  --surface-2: #1a1625;
  --border: rgba(167, 139, 250, 0.18);
  --text: #e8e4f0;
  --muted: #9b93b0;
  --accent: #a78bfa;
  --accent-deep: #7c3aed;
  --success: #34d399;
  --danger: #f87171;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Sora", system-ui, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-glow: 0 0 24px rgba(124, 58, 237, 0.25);
  --top-bar-h: 3.25rem;
  --tab-bar-h: 2.75rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
}

/* ── Ambient orb ─────────────────────────────────────────────── */

.ambient-orb {
  position: fixed;
  top: -20%;
  right: -10%;
  width: min(55vw, 480px);
  height: min(55vw, 480px);
  border-radius: 50%;
  background: radial-gradient(
    circle at center,
    rgba(124, 58, 237, 0.22) 0%,
    rgba(167, 139, 250, 0.08) 40%,
    transparent 70%
  );
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
}

.ambient-orb::after {
  content: "";
  position: absolute;
  bottom: -60%;
  left: -40%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: radial-gradient(
    circle at center,
    rgba(167, 139, 250, 0.12) 0%,
    transparent 65%
  );
  filter: blur(40px);
}

/* ── Top bar ─────────────────────────────────────────────────── */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--top-bar-h);
  padding: 0 1.25rem;
  background: rgba(18, 16, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: auto;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.brand-icon {
  font-size: 1.125rem;
  line-height: 1;
}

.brand-name {
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hub-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.hub-link:hover {
  color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
}

.hub-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Status chip ─────────────────────────────────────────────── */

#status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  white-space: nowrap;
}

#status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

#status-chip.is-ready {
  color: var(--success);
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.25);
}

#status-chip.is-ready::before {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

#status-chip.is-loading {
  color: var(--accent);
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.3);
}

#status-chip.is-loading::before {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

#status-chip.is-error {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.25);
}

#status-chip.is-error::before {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ── Tab bar ─────────────────────────────────────────────────── */

.tab-bar {
  position: sticky;
  top: var(--top-bar-h);
  z-index: 90;
  display: flex;
  gap: 0;
  height: var(--tab-bar-h);
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab-bar [role="tab"] {
  position: relative;
  appearance: none;
  background: none;
  border: none;
  padding: 0 1.25rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
}

.tab-bar [role="tab"]:hover {
  color: var(--text);
}

.tab-bar [role="tab"][aria-selected="true"] {
  color: var(--accent);
}

.tab-bar [role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0.75rem;
  right: 0.75rem;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  border-radius: 2px 2px 0 0;
  box-shadow: var(--shadow-glow);
}

.tab-bar [role="tab"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

/* ── Main layout ─────────────────────────────────────────────── */

.studio-main {
  flex: 1;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel[hidden] {
  display: none;
}

/* ── Panels / view containers ────────────────────────────────── */

.view-panel,
.table-wrap,
.export-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.view-panel {
  min-height: 280px;
  padding: 1rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* ── Fetch split ─────────────────────────────────────────────── */

.fetch-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .fetch-split {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Toolbars ────────────────────────────────────────────────── */

.fetch-toolbar,
.selectors-toolbar,
.export-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-inline {
  flex-shrink: 0;
}

.field-grow {
  flex: 1;
  min-width: min(100%, 200px);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Form controls ───────────────────────────────────────────── */

input[type="url"],
input[type="text"],
select,
textarea {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="url"],
input[type="text"] {
  width: 100%;
  min-width: 0;
}

.field-group:not(.field-inline) input[type="url"] {
  min-width: min(100%, 320px);
}

select {
  cursor: pointer;
  padding-right: 2rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239b93b0' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

textarea[hidden] {
  display: none;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
}

input::placeholder,
textarea::placeholder {
  color: rgba(155, 147, 176, 0.6);
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-deep) 0%, var(--accent) 100%);
  border-color: rgba(167, 139, 250, 0.35);
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: rgba(167, 139, 250, 0.35);
  background: rgba(167, 139, 250, 0.06);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Table ───────────────────────────────────────────────────── */

.table-wrap {
  overflow: auto;
}

#selector-results {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

#selector-results thead {
  background: var(--surface-2);
}

#selector-results th {
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

#selector-results td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  vertical-align: top;
}

#selector-results tbody tr:last-child td {
  border-bottom: none;
}

#selector-results tbody tr:hover {
  background: rgba(167, 139, 250, 0.04);
}

#selector-results td:nth-child(1) {
  color: var(--accent);
  white-space: nowrap;
}

#selector-results td:nth-child(2) {
  max-width: 280px;
  word-break: break-word;
}

#selector-results td:nth-child(3) {
  color: var(--muted);
  font-size: 0.75rem;
}

/* ── Export preview ──────────────────────────────────────────── */

.export-preview {
  min-height: 280px;
  max-height: 480px;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.export-preview:not(:empty) {
  color: var(--text);
}

/* ── Footer ──────────────────────────────────────────────────── */

.site-footer {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 1.25rem 1rem 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border);
  background: rgba(18, 16, 26, 0.6);
}

.site-footer p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ── Responsive tweaks ───────────────────────────────────────── */

@media (max-width: 767px) {
  .top-bar {
    padding: 0 1rem;
  }

  .tab-bar {
    padding: 0 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-bar [role="tab"] {
    padding: 0 0.875rem;
    flex-shrink: 0;
  }

  .studio-main {
    padding: 1rem;
  }

  .fetch-toolbar,
  .selectors-toolbar,
  .export-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-row {
    width: 100%;
  }

  .btn-row .btn {
    flex: 1;
  }

  #test-btn {
    width: 100%;
  }
}
