:root {
  --bg-0: #16161e;
  --bg-1: #1a1b26;
  --bg-2: #1e1e2e;
  --bg-3: #24283b;
  --border: #2a2b3d;
  --text: #c0caf5;
  --text-dim: #565f89;
  --accent: #7aa2f7;
  --green: #9ece6a;
  --red: #f7768e;
  --yellow: #e0af68;
  --orange: #ff9e64;
  --purple: #bb9af7;
  --cyan: #7dcfff;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg-0);
  color: var(--text);
}

#root { height: 100%; }

.ide-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 80% 0%, #1f2035 0%, var(--bg-0) 60%);
}

/* ===== Toolbar ===== */
.toolbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(180deg, #20212f, var(--bg-1));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 20px; }
.brand-name { font-weight: 700; letter-spacing: 0.3px; color: #fff; font-size: 15px; }
.tb-actions { display: flex; align-items: center; gap: 6px; }

.run-btn {
  background: linear-gradient(180deg, #9ece6a, #73b043);
  color: #10230a;
  border: none;
  padding: 6px 16px;
  border-radius: 7px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(158,206,106,0.3);
  transition: transform 0.1s, box-shadow 0.2s;
}
.run-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(158,206,106,0.45); }
.run-btn:active { transform: translateY(0); }

.tb-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 5px 12px;
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.tb-btn:hover { color: var(--text); background: var(--bg-3); }
.tb-btn.active { color: var(--accent); border-color: var(--border); background: rgba(122,162,247,0.1); }

.remix-link {
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 5px;
  font-family: 'JetBrains Mono', monospace;
  transition: color 0.15s;
}
.remix-link:hover { color: var(--purple); }

/* ===== Body ===== */
.ide-body { flex: 1; display: flex; min-height: 0; }

/* ===== Explorer ===== */
.explorer {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.exp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.exp-add {
  background: var(--bg-3); color: var(--text); border: none;
  width: 22px; height: 22px; border-radius: 5px; cursor: pointer;
  font-size: 15px; line-height: 1; transition: background 0.15s;
}
.exp-add:hover { background: var(--accent); color: var(--bg-0); }
.file-list { padding: 6px; overflow-y: auto; flex: 1; }

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s;
  position: relative;
}
.file-item:hover { background: var(--bg-3); }
.file-active { background: rgba(122,162,247,0.14); box-shadow: inset 3px 0 0 var(--accent); }
.file-icon { font-size: 13px; flex-shrink: 0; }
.file-name { font-family: 'JetBrains Mono', monospace; direction: ltr; flex: 1; text-align: left; }
.file-ops { display: none; gap: 2px; }
.file-item:hover .file-ops { display: flex; }
.file-ops button {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 4px; transition: all 0.12s;
}
.file-ops button:hover { color: var(--red); background: rgba(247,118,142,0.15); }

/* ===== Center column ===== */
.center-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-preview { flex: 1; display: flex; min-height: 0; }

/* ===== Editor Panel ===== */
.editor-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-2); }
.tab-bar {
  height: 36px; display: flex; align-items: stretch;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
}
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px; font-size: 12px; direction: ltr;
  font-family: 'JetBrains Mono', monospace; color: var(--text-dim);
}
.active-tab { background: var(--bg-2); color: var(--text); border-top: 2px solid var(--accent); }

.empty-editor {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 15px;
}

/* ===== Editor core ===== */
.editor-wrap {
  flex: 1; display: flex; min-height: 0; position: relative;
  direction: ltr; overflow: hidden;
}
.gutter {
  background: var(--bg-2);
  color: var(--text-dim);
  padding: 12px 0;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 44px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 21px;
}
.gutter-line { padding: 0 12px 0 10px; height: 21px; }

.code-area { flex: 1; position: relative; overflow: hidden; }

.code-highlight, .code-input {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  margin: 0;
  padding: 12px 14px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 14px;
  line-height: 21px;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  border: none;
}
.code-highlight {
  pointer-events: none;
  color: var(--text);
  z-index: 1;
}
.code-highlight code { font-family: inherit; }
.code-input {
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: #fff;
  resize: none;
  outline: none;
}
.code-input::selection { background: rgba(122,162,247,0.3); }

/* ===== Syntax tokens ===== */
.tok-tag { color: var(--red); }
.tok-attr { color: var(--green); }
.tok-string { color: var(--yellow); }
.tok-punct { color: #6c7086; }
.tok-comment { color: var(--text-dim); font-style: italic; }
.tok-selector { color: var(--green); }
.tok-property { color: var(--cyan); }
.tok-value { color: var(--orange); }
.tok-keyword { color: var(--purple); }
.tok-fn { color: var(--accent); }
.tok-number { color: var(--orange); }

/* ===== Autocomplete ===== */
.autocomplete {
  position: absolute;
  z-index: 20;
  background: #22243a;
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  overflow: hidden;
  min-width: 200px;
  direction: ltr;
  animation: pop 0.12s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.ac-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}
.ac-active { background: rgba(122,162,247,0.22); }
.ac-icon {
  color: var(--purple); font-size: 11px; width: 20px;
  background: rgba(187,154,247,0.12); border-radius: 4px;
  text-align: center; padding: 2px 0;
}
.ac-name { color: var(--text); font-weight: 500; }
.ac-desc {
  margin-left: auto; color: var(--text-dim); font-size: 11px;
  font-family: 'Vazirmatn', sans-serif; direction: rtl;
}

/* ===== Preview ===== */
.preview-panel {
  width: 42%; min-width: 200px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg-1);
}
.panel-head {
  height: 32px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; font-size: 12px; font-weight: 700; color: var(--text-dim);
  background: var(--bg-1); border-bottom: 1px solid var(--border);
}
.mini-btn {
  background: var(--bg-3); color: var(--text-dim); border: none;
  padding: 3px 10px; border-radius: 5px; cursor: pointer; font-size: 11px;
  font-family: inherit; transition: all 0.15s;
}
.mini-btn:hover { color: var(--text); background: var(--accent); color: var(--bg-0); }
.preview-frame { flex: 1; width: 100%; border: none; background: #fff; }
.log-count {
  background: var(--accent); color: var(--bg-0); border-radius: 10px;
  padding: 0 6px; font-size: 10px; margin-right: 4px;
}

/* ===== Console ===== */
.console-panel {
  height: 160px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-1); border-top: 1px solid var(--border);
}
.console-body {
  flex: 1; overflow-y: auto; padding: 6px 10px;
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px;
}
.console-empty {
  color: var(--text-dim); text-align: center; padding: 30px;
  font-family: 'Vazirmatn', sans-serif;
}
.log-line {
  display: flex; gap: 8px; padding: 3px 4px;
  border-bottom: 1px solid rgba(42,43,61,0.5); direction: rtl;
}
.log-time { color: var(--text-dim); font-size: 10px; flex-shrink: 0; }
.log-marker { flex-shrink: 0; }
.log-msg { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.log-error .log-msg, .log-error .log-marker { color: var(--red); }
.log-warn .log-msg, .log-warn .log-marker { color: var(--yellow); }
.log-log .log-marker { color: var(--green); }

/* ===== Status bar ===== */
.status-bar {
  height: 26px; flex-shrink: 0;
  display: flex; align-items: center; gap: 18px;
  padding: 0 14px; font-size: 11px;
  background: linear-gradient(180deg, var(--bg-3), #1b1c2b);
  border-top: 1px solid var(--border); color: var(--text-dim);
}
.status-bar span { font-family: 'JetBrains Mono', monospace; }
.lang-mode { margin-right: auto; color: var(--accent); font-weight: 700; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #10230a; padding: 10px 22px;
  border-radius: 10px; font-weight: 700; z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4); animation: pop 0.2s ease;
}

/* ===== Responsive ===== */
@media (max-width: 780px) {
  .editor-preview { flex-direction: column; }
  .preview-panel { width: 100%; height: 40%; border-right: none; border-top: 1px solid var(--border); }
  .explorer { width: 150px; }
  .console-panel { height: 120px; }
  .brand-name { display: none; }
  .tb-btn { padding: 5px 8px; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: #33344a; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #40415c; }