
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #ffffff;
  --bg-sidebar: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --editor-bg: #ffffff;
  --editor-gutter: #f1f5f9;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #ca8a04;
  --keyword: #d73a49;
  --string: #032f62;
  --function: #6f42c1;
  --number: #005cc5;
}

body.theme-dark {
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --bg: #0f172a;
  --bg-sidebar: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --editor-bg: #1e293b;
  --editor-gutter: #0f172a;
  --keyword: #ff7b72;
  --string: #a5d6ff;
  --function: #d2a8ff;
  --number: #79c0ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
a { text-decoration: none; color: inherit; }

/* Header */
.main-header { height: 60px; border-bottom: 1px solid var(--border); display: flex; align-items: center; background: var(--bg); z-index: 50; flex-shrink: 0; }
.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 0 1.5rem; }
.nav-wrapper { display: flex; justify-content: space-between; align-items: center; }
.logo { font-size: 1.25rem; font-weight: 800; color: var(--text); }
.logo span { color: var(--primary); }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); transition: color 0.2s; }
.nav-links a.active, .nav-links a:hover { color: var(--primary); }

/* Layout */
.playground-layout { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 60px); }

/* Sidebar */
.sidebar { width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 1rem; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.5rem; }
.select-input { width: 100%; padding: 0.5rem; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 0.9rem; }
.schema-list { flex: 1; overflow-y: auto; padding: 1rem; }
.table-node { margin-bottom: 1.5rem; }
.table-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; display: flex; align-items: center; color: var(--text); }
.table-name::before { content: '▤'; margin-right: 6px; color: var(--primary); }
.column-list { padding-left: 1.2rem; font-family: monospace; font-size: 0.8rem; color: var(--text-muted); }
.column-item { margin-bottom: 2px; display: flex; justify-content: space-between; }
.col-type { color: var(--primary); opacity: 0.7; }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); }

/* Editor Area */
.editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.editor-toolbar { height: 48px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 1rem; background: var(--bg); flex-shrink: 0; }
.toolbar-left, .toolbar-right { display: flex; gap: 0.5rem; align-items: center; }
.tab { padding: 0.5rem 1rem; background: var(--bg-sidebar); border-radius: 4px; font-size: 0.85rem; font-weight: 500; cursor: pointer; border: 1px solid transparent; }
.tab.active { background: var(--bg); border-color: var(--border); color: var(--primary); }

/* Custom Code Editor */
.code-editor-wrapper { position: relative; height: 300px; border-bottom: 1px solid var(--border); display: flex; background: var(--editor-bg); flex-shrink: 0; }
.line-numbers { width: 40px; background: var(--editor-gutter); border-right: 1px solid var(--border); text-align: right; padding: 10px 5px; font-family: monospace; color: var(--text-muted); font-size: 14px; line-height: 1.5; user-select: none; overflow: hidden; }
#sql-input, #highlighting { position: absolute; top: 0; left: 40px; width: calc(100% - 40px); height: 100%; padding: 10px; border: 0; margin: 0; font-family: 'Fira Code', monospace; font-size: 14px; line-height: 1.5; tab-size: 2; }
#sql-input { color: transparent; background: transparent; caret-color: var(--text); z-index: 1; resize: none; outline: none; white-space: pre; overflow: auto; }
#highlighting { z-index: 0; overflow: hidden; pointer-events: none; white-space: pre; color: var(--text); }

/* Results */
.results-toolbar { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--bg); flex-shrink: 0; }
.results-toolbar h3 { font-size: 0.9rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.badge { background: var(--editor-gutter); padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: normal; color: var(--text); }
.time-badge { color: var(--text-muted); font-size: 0.75rem; font-weight: normal; }
.results-area { flex: 1; overflow: auto; padding: 0; background: var(--bg); position: relative; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; text-align: left; }
th { position: sticky; top: 0; background: var(--bg-sidebar); border-bottom: 1px solid var(--border); padding: 0.75rem 1rem; font-weight: 600; color: var(--text-muted); z-index: 10; white-space: nowrap; }
td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; }
tr:hover { background-color: var(--editor-gutter); }
.null-cell { color: var(--text-muted); font-style: italic; }
.empty-state { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; color: var(--text-muted); width: 100%; padding: 2rem; }
.empty-state code { background: var(--editor-gutter); padding: 0.2rem 0.4rem; border-radius: 4px; font-family: monospace; }

/* Error Panel */
.error-panel { background: #fef2f2; border-top: 1px solid #fee2e2; padding: 1rem; color: var(--danger); font-family: monospace; font-size: 0.9rem; flex-shrink: 0; }
.error-panel.hidden { display: none; }

/* Buttons */
.btn { padding: 0.5rem 1rem; border-radius: 4px; font-weight: 600; font-size: 0.85rem; cursor: pointer; border: 1px solid transparent; transition: 0.2s; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); background: transparent; color: var(--text); }
.btn-outline:hover { border-color: var(--text-muted); }
.btn-danger { background: transparent; border-color: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.icon-btn { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; }

/* Theme Toggle */
.theme-btn { background: none; border: none; cursor: pointer; font-size: 1.2rem; }

/* Footer */
.main-footer { background: var(--bg-sidebar); border-top: 1px solid var(--border); padding: 3rem 0 1rem; flex-shrink: 0; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2rem; margin-bottom: 2rem; }
.footer-col h4 { font-size: 0.9rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 1rem; }
.footer-col a { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text); }
.footer-col a:hover { color: var(--primary); }
.footer-bottom { text-align: center; font-size: 0.8rem; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 1.5rem; }

/* Mobile */
.mobile-menu { display: none; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; flex-direction: column; gap: 4px; }
.menu-toggle span { display: block; width: 24px; height: 2px; background: var(--text); }

@media (max-width: 768px) {
  .playground-layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .schema-list { max-height: 150px; }
  .editor-area { height: auto; flex: 1; }
  .code-editor-wrapper { height: 200px; }
  .nav-links { display: none; }
  .menu-toggle { display: flex; }
  .mobile-menu { display: none; background: var(--bg); padding: 1rem; border-bottom: 1px solid var(--border); position: absolute; top: 60px; left: 0; width: 100%; z-index: 100; }
  .mobile-menu a { display: block; padding: 0.5rem 0; color: var(--text); font-weight: 600; }
  .footer-grid { grid-template-columns: 1fr; }
}

/* Tool Cards (used in Challenges/Features) */
.tool-card { border: 1px solid var(--border); padding: 2rem; border-radius: 8px; background: var(--bg); margin-bottom: 1.5rem; }
.tool-card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--text); }
.tool-card p { color: var(--text-muted); line-height: 1.5; }
