:root {
  --bg: #0f1117;
  --sidebar: #1a1d27;
  --card: #1e2130;
  --border: #2a2d3e;
  --accent: #7c6aff;
  --accent2: #ff6a9e;
  --accent3: #00d4aa;
  --accent4: #ffa940;
  --text: #e2e8f0;
  --muted: #8892a4;
  --code: #141620;
  --err: #ff6b6b;
  --warn: #ffa940;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.light {
  --bg: #f5f5f0;
  --sidebar: #ffffff;
  --card: #f0f0eb;
  --border: #ddd;
  --text: #1a1a2e;
  --muted: #666;
  --code: #e8e8e0;
  --accent: #5a4fcf;
  --accent3: #00a080;
  --accent4: #d4880a;
  --err: #cc3333;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
  transition:
    background var(--transition),
    color var(--transition);
}

#sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition:
    background var(--transition),
    width 0.35s ease,
    min-width 0.35s ease,
    transform 0.35s ease;
  position: relative;
  z-index: 100;
}

#sidebar.closed {
  width: 0 !important;
  min-width: 0 !important;
  border-left: none;
  overflow: hidden;
  padding: 0;
}

#sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}

#search-box {
  width: 100%;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition:
    border-color 0.2s,
    background var(--transition);
}

#search-box:focus {
  border-color: var(--accent);
}

#search-box::placeholder {
  color: var(--muted);
}

#topic-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

#topic-list::-webkit-scrollbar {
  width: 4px;
}

#topic-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.cat-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 10px 6px;
}

.topic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
  font-size: 13px;
  color: var(--muted);
}

.topic-item:hover {
  background: var(--card);
  color: var(--text);
}

.topic-item.active {
  background: rgba(124, 106, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(124, 106, 255, 0.25);
}

.topic-badge {
  margin-right: auto;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(124, 106, 255, 0.12);
  color: var(--accent);
  border: 1px solid rgba(124, 106, 255, 0.15);
  transition: all 0.3s ease;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.topic-item:hover .topic-badge {
  background: rgba(124, 106, 255, 0.25);
  border-color: rgba(124, 106, 255, 0.4);
  transform: scale(1.05);
}

.topic-item.active .topic-badge {
  background: rgba(124, 106, 255, 0.25);
  border-color: rgba(124, 106, 255, 0.5);
  color: var(--accent);
  box-shadow: 0 0 20px rgba(124, 106, 255, 0.15);
}

.topic-badge[data-level="شروع"] {
  background: rgba(0, 212, 170, 0.15);
  color: #00d4aa;
  border-color: rgba(0, 212, 170, 0.25);
}
.topic-badge[data-level="پایه"] {
  background: rgba(74, 144, 226, 0.15);
  color: #4a90e2;
  border-color: rgba(74, 144, 226, 0.25);
}
.topic-badge[data-level="مهم"] {
  background: rgba(255, 169, 64, 0.15);
  color: #ffa940;
  border-color: rgba(255, 169, 64, 0.25);
}
.topic-badge[data-level="پیشرفته"] {
  background: rgba(255, 107, 107, 0.15);
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.25);
}
.topic-badge[data-level="مدرن"] {
  background: rgba(124, 106, 255, 0.15);
  color: #7c6aff;
  border-color: rgba(124, 106, 255, 0.25);
}
.topic-badge[data-level="OOP"] {
  background: rgba(255, 106, 158, 0.15);
  color: #ff6a9e;
  border-color: rgba(255, 106, 158, 0.25);
}
.topic-badge[data-level="DOM"] {
  background: rgba(0, 200, 200, 0.15);
  color: #00c8c8;
  border-color: rgba(0, 200, 200, 0.25);
}
.topic-badge[data-level="Async"] {
  background: rgba(255, 160, 0, 0.15);
  color: #ffa000;
  border-color: rgba(255, 160, 0, 0.25);
}
.topic-badge[data-level="مرورگر"] {
  background: rgba(100, 200, 100, 0.15);
  color: #64c864;
  border-color: rgba(100, 200, 100, 0.25);
}

#sidebar-toggle {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px 0 0 8px;
  padding: 12px 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: -2px 0 15px rgba(124, 106, 255, 0.3);
  writing-mode: vertical-lr;
  letter-spacing: 2px;
  opacity: 1;
  visibility: visible;
}

#sidebar-toggle:hover {
  background: #9b6aff;
  padding: 16px 8px;
  box-shadow: -4px 0 25px rgba(124, 106, 255, 0.5);
}

#sidebar-toggle.closed {
  right: 0;
  border-radius: 8px 0 0 8px;
  background: var(--accent);
}

#console-toggle-btn {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0 8px 8px 0;
  padding: 12px 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 2px 0 15px rgba(124, 106, 255, 0.3);
  writing-mode: vertical-lr;
  letter-spacing: 2px;
  opacity: 1;
  visibility: visible;
}

#console-toggle-btn:hover {
  background: #9b6aff;
  padding: 16px 8px;
  box-shadow: 4px 0 25px rgba(124, 106, 255, 0.5);
}

#console-toggle-btn.closed {
  left: 0;
  border-radius: 0 8px 8px 0;
  background: var(--accent);
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#top-bar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background var(--transition);
  flex-shrink: 0;
}

#content-title {
  font-size: 17px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#content-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.top-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

#run-btn {
  background: linear-gradient(135deg, var(--accent), #9b6aff);
  color: #fff;
}

#run-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(124, 106, 255, 0.4);
}

#theme-btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

#theme-btn:hover {
  background: var(--border);
}

#body-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#lesson {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

#lesson::-webkit-scrollbar {
  width: 4px;
}

#lesson::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.ls h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ls h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent3);
  margin: 16px 0 8px;
}

.ls p {
  color: var(--muted);
  line-height: 1.9;
  margin-bottom: 10px;
  font-size: 14px;
}

.ls ul {
  padding-right: 22px;
  color: var(--muted);
  line-height: 2.2;
  font-size: 14px;
}

.ls ul li {
  list-style-type: disc;
}

.hl {
  color: var(--accent4);
  font-weight: 600;
}

.tip {
  background: rgba(0, 212, 170, 0.08);
  border: 1px solid rgba(0, 212, 170, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--accent3);
}

.warn {
  background: rgba(255, 169, 64, 0.08);
  border: 1px solid rgba(255, 169, 64, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--warn);
}

.err-box {
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--err);
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.compare-table th {
  background: rgba(124, 106, 255, 0.15);
  color: var(--accent);
  padding: 9px 12px;
  text-align: right;
  border: 1px solid var(--border);
}

.compare-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.compare-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.code-block {
  background: var(--code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  overflow: hidden;
  transition: background var(--transition);
}

.code-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.dots {
  display: flex;
  gap: 5px;
}

.dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.d-r {
  background: #ff5f57;
}
.d-y {
  background: #febc2e;
}
.d-g {
  background: #28c840;
}

.code-run {
  padding: 3px 10px;
  background: rgba(124, 106, 255, 0.2);
  border: 1px solid rgba(124, 106, 255, 0.3);
  border-radius: 6px;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.code-run:hover {
  background: rgba(124, 106, 255, 0.4);
}

.code-block pre {
  padding: 16px;
  overflow-x: auto;
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.8;
  color: #abb2bf;
  direction: ltr;
  text-align: left;
}

#console-panel {
  width: 340px;
  min-width: 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--card);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#console-panel.closed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
  overflow: hidden;
}

#con-hdr {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

#con-hdr span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.con-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent3);
  animation: pulse 2s infinite;
  display: inline-block;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

#clear-btn {
  padding: 6px 16px;
  background: #ff6b6b;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

#clear-btn:hover {
  background: #ff5252;
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 107, 107, 0.5);
}
#clear-btn:active {
  transform: scale(0.95);
}

#con-out {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-family: "Cascadia Code", monospace;
  font-size: 12px;
  direction: ltr;
}

#con-out::-webkit-scrollbar {
  width: 3px;
}

#con-out::-webkit-scrollbar-thumb {
  background: var(--border);
}

.cline {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 5px;
  margin-bottom: 3px;
  border-right: 2px solid transparent;
  animation: sli 0.2s ease;
  word-break: break-all;
  font-size: 12px;
}

@keyframes sli {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.cline.log {
  color: var(--text);
  border-right-color: var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.cline.error {
  color: var(--err);
  border-right-color: var(--err);
  background: rgba(255, 107, 107, 0.05);
}

.cline.warn {
  color: var(--warn);
  border-right-color: var(--warn);
  background: rgba(255, 169, 64, 0.05);
}

.cline.info {
  color: var(--accent3);
  border-right-color: var(--accent3);
  background: rgba(0, 212, 170, 0.05);
}

.cempty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}

#con-input-area {
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  flex-shrink: 0;
}

#con-input-area span {
  color: var(--accent3);
  font-family: monospace;
  font-size: 14px;
}

#con-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: "Cascadia Code", monospace;
  font-size: 12px;
  direction: ltr;
}

#con-input::placeholder {
  color: var(--muted);
}

#tg-badge {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: linear-gradient(135deg, #0088cc, #006aaa);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 28px;
  text-decoration: none;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 24px rgba(0, 136, 204, 0.5);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#tg-badge:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 8px 36px rgba(0, 136, 204, 0.7);
}

#tg-badge svg {
  width: 20px;
  height: 20px;
}

#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

#welcome .ic {
  font-size: 60px;
  margin-bottom: 18px;
}

#welcome h2 {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}

#welcome p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.9;
  max-width: 440px;
  margin-bottom: 28px;
}

.scards {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.sc {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  text-align: center;
}

.sc .n {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
}

.sc .l {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

@media (max-width: 768px) {
  body {
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
  }

  #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    transform: translateX(100%);
    z-index: 200;
    border-radius: 0;
    box-shadow: -4px 0 40px rgba(0, 0, 0, 0.5);
    transition: transform 0.35s ease;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar.closed {
    transform: translateX(100%);
    width: 280px !important;
    min-width: 280px !important;
  }

  #sidebar-toggle {
    display: none !important;
  }

  #mobile-sidebar-btn {
    display: flex !important;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }

  #mobile-sidebar-btn:hover {
    background: #9b6aff;
  }

  #main {
    flex: 1;
    min-width: 0;
  }

  #console-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    transform: translateX(-100%);
    z-index: 200;
    border-radius: 0;
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
    transition: transform 0.35s ease;
    border-right: none;
  }

  #console-panel.open {
    transform: translateX(0);
  }

  #console-panel.closed {
    transform: translateX(-100%);
    width: 280px !important;
    min-width: 280px !important;
  }

  #console-toggle-btn {
    display: none !important;
  }

  #mobile-console-btn {
    display: flex !important;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }

  #mobile-console-btn:hover {
    background: #9b6aff;
  }

  #top-bar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  #content-title {
    font-size: 15px;
    flex: 1;
    min-width: 80px;
  }

  #content-sub {
    font-size: 10px;
    display: none;
  }

  .top-btn {
    padding: 5px 12px;
    font-size: 12px;
  }

  #lesson {
    padding: 16px;
  }

  #tg-badge {
    font-size: 12px;
    padding: 8px 16px;
    bottom: 12px;
    right: 12px;
  }

  #tg-badge svg {
    width: 16px;
    height: 16px;
  }

  #sidebar-overlay,
  #console-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  #sidebar-overlay.active,
  #console-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (min-width: 769px) {
  #mobile-sidebar-btn,
  #mobile-console-btn,
  #sidebar-overlay,
  #console-overlay {
    display: none !important;
  }
}

#mobile-sidebar-btn,
#mobile-console-btn {
  display: none;
}
