@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #232639;
  --surface3: #1e2133;
  --border:   #2e3250;
  --accent:   #6c63ff;
  --accent2:  #00d9a0;
  --text:     #e2e4f0;
  --muted:    #8890b0;
  --code-bg:  #0d0f1a;
  --white:    #ffffff;
  --danger:   #ff5f72;
  --warn:     #ffb347;
  --success:  #00d9a0;
  --line-num: #3a4060;
  --editor-h: calc(100vh - 112px); /* full height minus topbar + tab bar */
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ════════════════════════════
   TOP BAR
════════════════════════════ */
.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--white);
  text-decoration: none;
  flex-shrink: 0;
}

.logo-icon {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}

.topbar-divider {
  width: 1px; height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.topbar-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .18s;
  white-space: nowrap;
}

.btn-ghost {
  background: none;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.btn-run {
  background: var(--accent2);
  color: #0a0e1a;
  border-color: var(--accent2);
  font-size: 13px;
  padding: 7px 18px;
}
.btn-run:hover { background: #00eaad; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,217,160,.3); }
.btn-run:active { transform: none; box-shadow: none; }

.btn-icon {
  background: none;
  border-color: var(--border);
  color: var(--muted);
  padding: 6px 10px;
}
.btn-icon:hover { color: var(--text); border-color: var(--muted); }

/* ════════════════════════════
   EDITOR LAYOUT
════════════════════════════ */
.editor-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: var(--editor-h);
}

/* Left: code panes */
.code-side {
  display: flex;
  flex-direction: column;
  width: 50%;
  border-right: 2px solid var(--border);
  min-width: 300px;
  overflow: hidden;
}

/* Right: preview pane */
.preview-side {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── RESIZE HANDLE ── */
.resize-handle {
  width: 4px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background .15s;
  position: relative;
  z-index: 10;
}
.resize-handle:hover,
.resize-handle.dragging { background: var(--accent); }

/* ════════════════════════════
   EDITOR TABS
════════════════════════════ */
.editor-tabs {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 40px;
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  font-family: 'Inter', sans-serif;
  transition: color .15s, border-color .15s, background .15s;
  position: relative;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); background: var(--surface2); }

.tab-btn.active {
  color: var(--white);
  border-bottom-color: var(--accent);
  background: var(--surface2);
}

.tab-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tab-dot.html   { background: #e34f26; }
.tab-dot.css    { background: #2965f1; }
.tab-dot.js     { background: #f7df1e; }

.tab-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
}

.tab-action-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 5px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  transition: color .15s, background .15s;
}
.tab-action-btn:hover { color: var(--text); background: var(--border); }

/* ════════════════════════════
   CODE EDITOR PANE
════════════════════════════ */
.editor-pane-wrap {
  display: none;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.editor-pane-wrap.active { display: flex; }

.line-numbers {
  width: 44px;
  background: var(--code-bg);
  border-right: 1px solid var(--border);
  padding: 14px 0;
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
}

.line-numbers span {
  display: block;
  text-align: right;
  padding-right: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 21px;
  color: var(--line-num);
}

.code-textarea {
  flex: 1;
  background: var(--code-bg);
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 21px;
  color: var(--text);
  padding: 14px 16px;
  tab-size: 2;
  caret-color: var(--accent2);
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  width: 100%;
}

.code-textarea::selection { background: rgba(108,99,255,.35); }
.code-textarea::-webkit-scrollbar { width: 6px; height: 6px; }
.code-textarea::-webkit-scrollbar-track { background: transparent; }
.code-textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.code-textarea::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* status bar inside editor */
.editor-status {
  height: 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  flex-shrink: 0;
}

.editor-status span {
  font-size: 11px;
  color: var(--line-num);
  font-family: 'JetBrains Mono', monospace;
}

.editor-status .status-ok   { color: var(--success); }
.editor-status .status-err  { color: var(--danger); }

/* ════════════════════════════
   PREVIEW PANE
════════════════════════════ */
.preview-tabs {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 40px;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
}

.preview-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
}

.preview-url {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 320px;
}

.preview-url-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.preview-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.preview-content iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* loading overlay */
.preview-loading {
  position: absolute;
  inset: 0;
  background: var(--code-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}

.preview-loading.show { opacity: 1; pointer-events: all; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

/* ════════════════════════════
   CONSOLE
════════════════════════════ */
.console-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: height .2s ease;
  height: 0;
  overflow: hidden;
}

.console-panel.open { height: 160px; }

.console-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.console-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
}

.console-clear {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  padding: 2px 8px;
  border-radius: 4px;
  transition: color .15s;
}
.console-clear:hover { color: var(--text); }

.console-output {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.7;
}

.console-output::-webkit-scrollbar { width: 4px; }
.console-output::-webkit-scrollbar-thumb { background: var(--border); }

.console-line { display: flex; gap: 10px; align-items: flex-start; }
.console-line .con-icon { flex-shrink: 0; }
.console-line.log   { color: var(--text); }
.console-line.error { color: var(--danger); }
.console-line.warn  { color: var(--warn); }
.console-line.info  { color: #82aaff; }

.console-empty {
  color: var(--line-num);
  font-size: 12px;
  padding: 8px 0;
}

/* ════════════════════════════
   BOTTOM BAR
════════════════════════════ */
.bottombar {
  height: 24px;
  background: var(--accent);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
  flex-shrink: 0;
}

.bottombar span {
  font-size: 11px;
  color: rgba(255,255,255,.8);
}

.bottombar .bb-right {
  margin-left: auto;
  display: flex;
  gap: 16px;
}

/* ════════════════════════════
   TOAST NOTIFICATION
════════════════════════════ */
.toast {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ════════════════════════════
   FULLSCREEN MODE
════════════════════════════ */
body.fullscreen-preview .code-side,
body.fullscreen-preview .resize-handle { display: none; }
body.fullscreen-preview .preview-side  { width: 100%; }

body.fullscreen-editor .preview-side,
body.fullscreen-editor .resize-handle  { display: none; }
body.fullscreen-editor .code-side      { width: 100%; }

/* ════════════════════════════
   RESPONSIVE
════════════════════════════ */
@media (max-width: 700px) {
  .editor-layout { flex-direction: column; }
  .code-side { width: 100%; border-right: none; border-bottom: 2px solid var(--border); height: 50%; }
  .preview-side { height: 50%; }
  .resize-handle { display: none; }
  .topbar-sub { display: none; }
}