/* ============================================
   Theme tokens
   ============================================ */

:root {
  /* Light palette */
  --bg: #f8f9fb;
  --bg-surface: #ffffff;
  --bg-hover: #f0f1f3;
  --border: #e2e4e9;
  --border-focus: #a0a4ab;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-text: #ffffff;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --success: #22c55e;
  --editor-bg: #fafbfc;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-hover: #252830;
  --border: #2e3039;
  --border-focus: #5a5d6a;
  --text: #e4e5e9;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-text: #ffffff;
  --error: #f87171;
  --error-bg: #1f1315;
  --error-border: #7f1d1d;
  --success: #4ade80;
  --editor-bg: #14161e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ============================================
   Reset & base
   ============================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  font-feature-settings: "ss01", "cv01";
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
}

/* ============================================
   Layout
   ============================================ */

.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ============================================
   Header
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  transition: border-color var(--transition);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.logo-arrow {
  color: var(--accent);
  margin: 0 2px;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ============================================
   Badge (WASM status)
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  transition: all var(--transition);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background var(--transition);
}

.badge.ready .badge-dot {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.badge.error .badge-dot {
  background: var(--error);
}

/* ============================================
   Theme toggle
   ============================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-focus);
}

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Show/hide sun/moon based on theme */
[data-theme="dark"] .sun-icon {
  display: block;
}

[data-theme="dark"] .moon-icon {
  display: none;
}

:root:not([data-theme="dark"]) .sun-icon {
  display: none;
}

:root:not([data-theme="dark"]) .moon-icon {
  display: block;
}

/* ============================================
   Main content
   ============================================ */

.main {
  flex: 1;
  padding: 24px 0;
}

.panels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  align-items: stretch;
}

/* ============================================
   Panel
   ============================================ */

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: all var(--transition);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: border-color var(--transition);
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  transition: border-color var(--transition);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* ============================================
   Editor (textareas)
   ============================================ */

.editor {
  flex: 1;
  width: 100%;
  min-height: 400px;
  padding: 16px;
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--editor-bg);
  tab-size: 4;
  transition: background var(--transition), color var(--transition);
}

.editor::placeholder {
  color: var(--text-faint);
}

.editor:focus {
  background: var(--bg-surface);
}

#c-output {
  cursor: default;
}

/* ============================================
   Transpile section (center button)
   ============================================ */

.transpile-section {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
  transform: translateY(-1px);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-focus);
}

.btn-sm {
  font-size: 0.75rem;
  padding: 4px 8px;
}

/* ============================================
   Error bar
   ============================================ */

.error-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 500;
  animation: slide-in 0.2s ease;
}

.error-bar[hidden] {
  display: none;
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Footer
   ============================================ */

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-faint);
  transition: border-color var(--transition);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.sep {
  opacity: 0.4;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
  .panels {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .transpile-section {
    padding: 12px 0;
  }

  .transpile-section .btn-primary {
    width: 100%;
    justify-content: center;
  }

  .header-left {
    flex-direction: column;
    gap: 2px;
  }

  .tagline {
    font-size: 0.75rem;
  }

  .editor {
    min-height: 250px;
  }
}

@media (max-width: 480px) {
  .layout {
    padding: 0 12px;
  }

  .badge {
    display: none;
  }
}