:root {
  --cm-font-size: 14px;
  --accent: #8b5cf6;
  --accent2: #ec4899;
  --bg: #0f1117;
  --bg2: #171a24;
  --bg3: #1e222e;
  --border: #2a2f3d;
  --text: #e4e7ef;
  --muted: #8b91a5;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: 'Vazirmatn', system-ui, sans-serif;
  overscroll-behavior: none;
}
body.theme-light {
  --bg: #f4f5f8; --bg2: #fff; --bg3: #eef0f5; --border: #d8dbe4;
  --text: #1a1d26; --muted: #6b7180;
}
#root { height: 100%; }
button { font-family: inherit; cursor: pointer; }
::-webkit-scrollbar { height: 5px; width: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 20% -10%, rgba(139,92,246,.12), transparent 40%),
              radial-gradient(circle at 90% 110%, rgba(236,72,153,.1), transparent 40%),
              var(--bg);
}

/* Header */
.cs-header {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 4px) 8px 6px;
  background: rgba(23,26,36,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
body.theme-light .cs-header { background: rgba(255,255,255,.85); }
.proj-name {
  flex: 1; text-align: center; font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-right { display: flex; gap: 2px; }
.icon-btn {
  background: transparent; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; transition: background .15s;
}
.icon-btn:active { background: var(--bg3); }
.icon-btn.small { width: 32px; height: 32px; }

/* Tabs */
.tab-bar {
  display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px 6px 10px; border-radius: 8px;
  background: var(--bg3); font-size: 12px; white-space: nowrap;
  border: 1px solid transparent; flex-shrink: 0;
}
.tab-active { border-color: var(--accent); background: rgba(139,92,246,.14); }
.tab-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tab-name { direction: ltr; font-family: 'JetBrains Mono', monospace; }
.tab-close { background: transparent; border: none; color: var(--muted); display: grid; place-items: center; padding: 2px; border-radius: 4px; }
.tab-close:active { background: rgba(255,255,255,.1); }
.tab-empty { color: var(--muted); font-size: 12px; padding: 4px; }

/* Main */
.cs-main { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.view-pane { position: absolute; inset: 0; display: flex; flex-direction: column; }
.cm-host { flex: 1; overflow: hidden; }
.CodeMirror {
  height: 100% !important;
  font-family: 'JetBrains Mono', monospace !important;
  font-size: var(--cm-font-size) !important;
  direction: ltr;
}
.CodeMirror-hints { font-family: 'JetBrains Mono', monospace; z-index: 9999; }

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--muted); font-size: 15px; padding: 20px;
}

/* Preview */
.preview-pane { background: var(--bg2); }
.preview-toolbar, .console-toolbar {
  display: flex; gap: 6px; padding: 8px; align-items: center;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  overflow-x: auto; scrollbar-width: none;
}
.console-toolbar { justify-content: space-between; font-size: 13px; color: var(--muted); }
.chip {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip-on { background: rgba(139,92,246,.2); border-color: var(--accent); color: var(--accent); }
.chip-run { background: var(--accent); color: #fff; border-color: var(--accent); margin-inline-start: auto; }
.preview-frame-wrap { flex: 1; overflow: auto; background: #fff; display: flex; justify-content: center; }
body.theme-light .preview-frame-wrap { background: #e5e7eb; }
.preview-iframe { border: none; height: 100%; background: #fff; }

/* Console */
.console-pane { background: #0a0c12; }
body.theme-light .console-pane { background: #1a1d26; color: #e4e7ef; }
.console-out {
  flex: 1; overflow: auto; padding: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; direction: ltr;
}
.console-empty { color: #5a6072; padding: 20px; text-align: center; direction: rtl; white-space: pre-line; }
.log { display: flex; gap: 8px; padding: 5px 8px; border-bottom: 1px solid rgba(255,255,255,.05); }
.log-badge { flex-shrink: 0; width: 16px; }
.log-msg { word-break: break-word; white-space: pre-wrap; }
.log-log { color: #c9d1e0; }
.log-info { color: #7dd3fc; }
.log-warn { color: #fbbf24; background: rgba(251,191,36,.06); }
.log-error { color: #f87171; background: rgba(248,113,113,.08); }
.log-error .log-badge, .log-warn .log-badge { font-weight: bold; }

/* Files */
.files-list { flex: 1; overflow: auto; padding: 10px; }
.files-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
}
.primary-btn:active { transform: scale(.97); }
.ghost-btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.file-row {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: 12px 10px; border-radius: 10px; margin-bottom: 4px;
  background: var(--bg2); border: 1px solid var(--border);
}
.file-row:active { background: var(--bg3); }
.file-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.file-name { flex: 1; direction: ltr; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.file-lang { font-size: 10px; color: var(--muted); background: var(--bg3); padding: 2px 6px; border-radius: 6px; }
.file-size { font-size: 10px; color: var(--muted); }
.file-menu {
  position: absolute; top: 100%; inset-inline-start: 10px; z-index: 20;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden; margin-top: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.file-menu button { background: transparent; border: none; color: var(--text); padding: 10px 20px; text-align: right; font-size: 13px; }
.file-menu button:active { background: var(--bg); }
.file-menu .danger { color: #f87171; }

/* More pane */
.more-pane { flex: 1; overflow: auto; padding: 14px; }
.more-pane h3 { font-size: 13px; color: var(--accent); margin: 18px 0 8px; font-weight: 700; }
.more-pane h3:first-child { margin-top: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; font-size: 13px; gap: 10px; }
.sel { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-family: inherit; }
.setting-row input[type=range] { flex: 1; max-width: 140px; accent-color: var(--accent); }
.toggle { width: 46px; height: 26px; border-radius: 999px; background: var(--bg3); border: 1px solid var(--border); position: relative; transition: .2s; }
.toggle-on { background: var(--accent); border-color: var(--accent); }
.toggle-knob { position: absolute; top: 2px; inset-inline-start: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle-on .toggle-knob { inset-inline-start: 22px; }
.more-btns { display: flex; flex-direction: column; gap: 8px; }
.help-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 13px; line-height: 1.9; }
.help-box ul { padding-inline-start: 20px; margin: 8px 0; color: var(--muted); }
.mascot { text-align: center; margin-top: 12px; color: var(--accent2); font-weight: 700; }
.remix-link { display: block; text-align: center; color: var(--accent); margin-top: 8px; text-decoration: none; font-weight: 700; }

/* Quick toolbar */
.quick-toolbar { flex-shrink: 0; background: var(--bg2); border-top: 1px solid var(--border); }
.symbol-row {
  display: flex; gap: 3px; overflow-x: auto; padding: 5px 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
}
.symbol-row::-webkit-scrollbar { display: none; }
.sym-btn {
  min-width: 38px; height: 38px; flex-shrink: 0;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; font-family: 'JetBrains Mono', monospace; font-size: 16px;
  display: grid; place-items: center;
}
.sym-btn:active { background: var(--accent); color: #fff; }
.sym-tab { color: var(--accent); }
.action-row {
  display: flex; gap: 4px; overflow-x: auto; padding: 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.action-row::-webkit-scrollbar { display: none; }
.act-btn {
  flex-shrink: 0; min-width: 52px; padding: 6px 4px;
  background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-radius: 8px; font-size: 9px;
}
.act-btn:active { background: var(--bg3); color: var(--accent); }
.act-label { white-space: nowrap; }

/* Status bar */
.status-bar {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 4px 12px; background: var(--bg3); border-top: 1px solid var(--border);
  font-size: 10px; color: var(--muted); flex-shrink: 0; overflow-x: auto;
  scrollbar-width: none; white-space: nowrap;
}
.status-bar::-webkit-scrollbar { display: none; }
.status-lang { font-weight: 700; }
.saved-on { color: #4ade80; }
.saved-off { color: #fbbf24; }

/* Bottom nav */
.bottom-nav {
  display: flex; padding-bottom: var(--safe-bottom);
  background: rgba(23,26,36,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
body.theme-light .bottom-nav { background: rgba(255,255,255,.92); }
.nav-btn {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 8px 2px 6px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 10px; transition: color .15s;
}
.nav-active { color: var(--accent); }
.nav-icon-wrap { position: relative; }
.nav-badge {
  position: absolute; top: -4px; inset-inline-end: -8px;
  background: #f87171; color: #fff; font-size: 9px; font-weight: 700;
  min-width: 15px; height: 15px; border-radius: 999px; display: grid; place-items: center; padding: 0 3px;
}
.nav-label { font-weight: 700; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; inset-inline-start: 0; height: 100%; width: 80%; max-width: 320px;
  background: var(--bg2); z-index: 50; transform: translateX(-105%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
  border-inline-end: 1px solid var(--border);
  padding-top: var(--safe-top);
}
[dir=rtl] .drawer { inset-inline-start: 0; transform: translateX(105%); }
.drawer-open { transform: translateX(0) !important; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; }
.files-drawer { padding-bottom: var(--safe-bottom); }

/* Bottom sheet */
.bottom-sheet {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 50;
  background: var(--bg2); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border); max-height: 75vh;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: slideUp .28s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet-handle-wrap { padding: 10px; display: grid; place-items: center; touch-action: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--muted); opacity: .5; }
.sheet-body { padding: 0 14px 16px; overflow: auto; }
.sheet-body h3 { margin: 0 0 12px; font-size: 15px; }
.palette-input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 12px 14px; border-radius: 12px; font-size: 15px;
  font-family: inherit; margin-bottom: 10px;
}
.palette-input:focus { outline: none; border-color: var(--accent); }
.palette-list { display: flex; flex-direction: column; gap: 4px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; text-align: right;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 14px;
}
.palette-item:active { background: rgba(139,92,246,.15); border-color: var(--accent); }
.pi-tag { font-size: 10px; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); flex-shrink: 0; }
.pi-cmd { background: rgba(139,92,246,.2); color: var(--accent); }
.menu-item {
  display: block; width: 100%; text-align: right;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 14px; border-radius: 10px; font-size: 14px; margin-bottom: 6px;
}
.menu-item:active { background: rgba(139,92,246,.15); }

/* Toast */
.toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); inset-inline: 0;
  margin: 0 auto; width: fit-content; max-width: 90%; z-index: 60;
  background: var(--accent); color: #fff; padding: 12px 24px;
  border-radius: 999px; font-size: 14px; font-weight: 700;
  box-shadow: 0 8px 30px rgba(139,92,246,.5); animation: toastIn .3s;
}
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } }