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

:root {
  --primary: #4f8cff;
  --primary-dark: #3d6dd9;
  --primary-alt: #7c5cff;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --bg-primary: #0a0e1a;
  --bg-secondary: #11182e;
  --bg-tertiary: #1e2a42;
  --glass-bg: rgba(20, 28, 48, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --border: #2a3a5c;
  --border-light: #3a4f72;
  --radius: 8px;
  --radius-lg: 16px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}
::-webkit-scrollbar-thumb {
  background: rgba(79, 140, 255, 0.3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(79, 140, 255, 0.55);
}

body {
  background: radial-gradient(ellipse at 60% 20%, #111c38 0%, #0a0e1a 60%, #11182e 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* Three.js background canvas */
#bg3d {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  border-bottom: 1px solid var(--glass-border);
  padding: 24px 0;
  margin-bottom: 32px;
  position: relative;
  z-index: 1;
}

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

.header-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.status-disconnected {
  background: rgba(30, 42, 66, 0.7);
  color: var(--text-secondary);
}

.status-connected {
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

/* Main Content */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
  z-index: 1;
}

/* Cards — glass treatment */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(79, 140, 255, 0.12);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(10, 14, 26, 0.4);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

/* Connect Card */
.connect-card {
  max-width: 600px;
}

.connect-card.collapsed {
  max-width: 400px;
}

.connect-card.collapsed .card-body {
  display: none;
}

.connect-card.collapsed .card-header {
  cursor: pointer;
}

.connect-card.collapsed .card-header:hover {
  background-color: rgba(15, 23, 42, 0.8);
}

.config-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  background: rgba(10, 14, 26, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  margin-bottom: 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.config-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.15);
}

.config-error {
  color: var(--error);
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius);
  display: none;
}

.config-error.show {
  display: block;
}

.button-group {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-alt) 100%);
  color: white;
  box-shadow: 0 2px 12px rgba(79, 140, 255, 0.25);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 140, 255, 0.45);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: rgba(30, 42, 66, 0.7);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(50, 65, 95, 0.8);
  border-color: rgba(79, 140, 255, 0.25);
  transform: translateY(-1px);
}

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

.btn-icon {
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Chips */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 18px;
  background: rgba(20, 28, 48, 0.65);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chip:hover {
  border-color: rgba(79, 140, 255, 0.5);
  background: rgba(79, 140, 255, 0.12);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(79, 140, 255, 0.2);
}

/* Inline Form */
.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  align-items: center;
  position: relative;
  z-index: 1;
}

.form-input {
  flex: 1;
  padding: 8px 12px;
  background: rgba(10, 14, 26, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.15);
}

/* Freeform Card */
.freeform-card {
  max-width: 600px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(10, 14, 26, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.15);
}

.form-select option {
  background-color: #11182e;
  color: var(--text-primary);
}

.args-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  background: rgba(10, 14, 26, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.args-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.15);
}

.required-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* Response Area */
.response-area {
  margin-top: 40px;
  position: relative;
  z-index: 1;
}

.response-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Result cards: glass + accent left border */
.result-card {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* GSAP handles entrance; keep CSS animation as fallback for no-JS */
@media (scripting: none) {
  .result-card {
    animation: slideIn 0.3s ease;
  }
}

.result-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* Green left border for OK results */
.result-card:has(.result-status.ok) {
  border-left-color: rgba(16, 185, 129, 0.6);
}

/* Red left border for ERROR results */
.result-card:has(.result-status.error) {
  border-left-color: rgba(239, 68, 68, 0.6);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-header {
  padding: 12px 16px;
  background: rgba(10, 14, 26, 0.4);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.result-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 200px;
}

.result-tool-name {
  font-weight: 600;
  color: var(--primary);
  font-size: 14px;
}

.result-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.result-target {
  font-size: 11px;
  font-family: 'SF Mono', Consolas, monospace;
  color: var(--text-secondary);
  opacity: 0.85;
  word-break: break-all;
}

.result-target .result-token {
  color: var(--primary);
}

.result-status {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.result-status.ok {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.result-status.error {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error);
}

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

.result-body {
  padding: 16px;
  max-height: 600px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(79, 140, 255, 0.3) transparent;
}

.json-tree {
  font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.7;
}

.json-node-head {
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
}

.json-node-head:hover {
  background: rgba(79, 140, 255, 0.07);
}

.json-index {
  color: var(--text-secondary);
  opacity: 0.7;
}

.json-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0 4px;
  display: inline-block;
  user-select: none;
}

.json-toggle:hover {
  color: var(--primary);
}

.json-key {
  color: #a78bfa;
}

.json-string {
  color: #86efac;
}

.json-number {
  color: #fbbf24;
}

.json-boolean {
  color: #f472b6;
}

.json-null {
  color: #9ca3af;
}

.json-collapsed {
  display: inline;
  color: var(--text-secondary);
  opacity: 0.8;
  font-style: italic;
}

.json-children {
  margin-left: 9px;
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.09);
}

.json-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.toggle-raw {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  padding: 0;
  font-weight: 500;
}

.toggle-raw:hover {
  color: var(--primary-dark);
}

.raw-json {
  display: none;
  background: rgba(10, 14, 26, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  margin-top: 12px;
}

.raw-json.show {
  display: block;
}

.raw-json {
  max-height: 480px;
  overflow-y: auto;
}

.raw-json pre {
  font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  margin: 0;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.copy-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.copy-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--primary);
}

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

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Tools List Modal */
.tools-list {
  max-height: 400px;
  overflow-y: auto;
}

.tools-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tools-table th {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(10, 14, 26, 0.4);
  font-weight: 600;
  color: var(--text-secondary);
}

.tools-table td {
  padding: 8px;
  border-bottom: 1px solid var(--glass-border);
}

.tools-table tr:hover {
  background: rgba(79, 140, 255, 0.06);
}

.tool-count-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .connect-card {
    max-width: 100%;
  }

  .freeform-card {
    max-width: 100%;
  }

  .result-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-info {
    flex-direction: column;
    gap: 4px;
  }

  .result-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .inline-form {
    flex-direction: column;
  }

  .form-input {
    width: 100%;
  }

  .chips-row {
    flex-direction: column;
  }

  .chip {
    width: 100%;
    text-align: center;
  }
}
