/* ── Design Tokens ── */
:root {
  --bg-primary: #0b0f1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(22, 30, 48, 0.8);
  --border: rgba(99, 102, 241, 0.15);
  --border-focus: rgba(99, 102, 241, 0.4);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #818cf8;
  --accent-glow: rgba(129, 140, 248, 0.3);
  --success: #34d399;
  --font-ui: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', 'Consolas', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(129, 140, 248, 0.05), transparent);
}

/* ── Layout ── */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  margin-bottom: 24px;
}
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}
.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e2e8f0, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 2px;
}
.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.control-group label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-size: 0.82rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
select:hover, select:focus {
  border-color: var(--border-focus);
  outline: none;
}
.control-group input {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.82rem;
  font-family: var(--font-mono);
  min-width: 220px;
}
.control-group input:hover,
.control-group input:focus {
  border-color: var(--border-focus);
  outline: none;
}

/* ── Main Grid ── */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) auto minmax(420px, 1fr);
  grid-template-areas:
    "input divider output"
    "preview preview preview"
    "reactpreview reactpreview reactpreview"
    "debug debug debug";
  gap: 12px;
  align-items: stretch;
  min-height: 0;
}

.input-panel { grid-area: input; }
.output-panel { grid-area: output; }
.preview-panel { grid-area: preview; }
.react-preview-panel { grid-area: reactpreview; }
.debug-panel { grid-area: debug; }
.divider { grid-area: divider; }

/* ── Panels ── */
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  overflow: hidden;
  transition: border-color var(--transition);
  min-width: 0;
}
.panel:hover { border-color: var(--border-focus); }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header h2 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.panel-actions { display: flex; gap: 6px; }

/* ── Textarea & Output ── */
textarea, .output-pre {
  flex: 1;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  min-height: 400px;
}
textarea {
  background: transparent;
  color: var(--text-primary);
  border: none;
  resize: none;
  outline: none;
}
textarea::placeholder { color: var(--text-muted); }
.output-pre {
  background: transparent;
  color: var(--success);
  margin: 0;
}
.markdown-preview {
  flex: 1;
  padding: 16px;
  overflow: auto;
  min-height: 400px;
  line-height: 1.6;
  color: var(--text-primary);
}
.markdown-preview p,
.markdown-preview ul,
.markdown-preview ol,
.markdown-preview pre,
.markdown-preview table {
  margin: 0 0 12px 0;
}
.markdown-preview pre,
.markdown-preview code {
  font-family: var(--font-mono);
  font-size: 13px;
}
.markdown-preview pre {
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow: auto;
}
.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
}
.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--border-focus);
  padding: 6px 8px;
  text-align: left;
}
.placeholder-text { color: var(--text-muted); font-style: italic; }

/* ── Divider ── */
.divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  gap: 8px;
  flex-shrink: 0;
}
.divider-line {
  width: 1px;
  flex: 1;
  background: linear-gradient(to bottom, transparent, var(--border), transparent);
}
.arrow { font-size: 1.1rem; }

/* ── Buttons ── */
.btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover { background: rgba(99, 102, 241, 0.08); color: var(--text-primary); border-color: var(--border-focus); }
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover { transform: scale(1.05); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-primary:active { transform: scale(0.98); }
.btn-accent {
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.25);
}
.btn-accent:hover { background: rgba(52, 211, 153, 0.2); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-focus);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 100;
  backdrop-filter: blur(12px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: block; }

/* ── Footer ── */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 0;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.stats {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.footer-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.footer-info a {
  color: var(--accent);
  text-decoration: none;
}
.footer-info a:hover { text-decoration: underline; }

/* ── Antigravity Block ── */
.ag-section {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 280px;
}
.ag-editor-panel,
.ag-right-panel {
  min-width: 0;
}
.ag-editor-input {
  flex: 1;
  min-height: 280px;
  padding: 16px;
  border: none;
  outline: none;
  resize: vertical;
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: "Menlo", "Consolas", "Monaco", monospace;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}
.ag-right-placeholder {
  flex: 1;
  min-height: 280px;
  background: rgba(15, 23, 42, 0.35);
}
.ag-right-preview {
  min-height: 280px;
}
.ag-right-preview {
  background: #ffffff;
  color: #111827;
}
.ag-right-preview pre,
.ag-right-preview code {
  font-family: "Menlo", "Consolas", "Monaco", monospace !important;
  font-size: 13px !important;
  line-height: 20.8px !important;
  letter-spacing: 0 !important;
  font-kerning: auto !important;
  font-feature-settings: normal !important;
  white-space: pre !important;
}
.ag-right-preview pre {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
}
.ag-style-dump {
  min-height: 170px;
  max-height: 300px;
  border-top: 1px solid var(--border);
  color: #cbd5e1;
}
.ag-width-dump {
  min-height: 170px;
  max-height: 320px;
  border-top: 1px solid var(--border);
  color: #86efac;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .app { padding: 16px; }
  .main {
    grid-template-columns: 1fr;
    grid-template-areas:
      "input"
      "divider"
      "output"
      "preview"
      "reactpreview"
      "debug";
  }
  .divider { flex-direction: row; padding: 8px 0; }
  .divider-line { height: 1px; width: auto; background: linear-gradient(to right, transparent, var(--border), transparent); }
  .header-content { flex-direction: column; align-items: flex-start; }
  textarea, .output-pre, .markdown-preview { min-height: 250px; }
  .ag-section { grid-template-columns: 1fr; }
  .ag-editor-input, .ag-right-preview { min-height: 220px; }
}

@media (max-width: 1200px) and (min-width: 769px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-areas:
      "input"
      "divider"
      "output"
      "preview"
      "reactpreview"
      "debug";
  }
  .divider { flex-direction: row; padding: 8px 0; }
  .divider-line {
    height: 1px;
    width: auto;
    background: linear-gradient(to right, transparent, var(--border), transparent);
  }
  .ag-section { grid-template-columns: 1fr; }
}
