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

/* === BASE === */
body {
  font-family: 'Segoe UI', sans-serif;
  background: #0d1117;
  color: #e6edf3;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* === TOPBAR === */
#topbar {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 50px;
  flex-shrink: 0;
}

#topbar h1 {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, #58a6ff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

#home-link {
  color: #8b949e;
  font-size: 12px;
  text-decoration: none;
  border: 1px solid #30363d;
  padding: 3px 10px;
  border-radius: 6px;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
#home-link:hover { border-color: #58a6ff; color: #58a6ff; }

.lang-btn {
  background: transparent;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.lang-btn.active { border-color: #58a6ff; color: #58a6ff; }

#progress-bar-wrap {
  flex: 1;
  height: 6px;
  background: #30363d;
  border-radius: 99px;
  overflow: hidden;
  max-width: 300px;
}
#progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #58a6ff, #a78bfa);
  border-radius: 99px;
  transition: width .4s;
}
#progress-text { font-size: 12px; color: #8b949e; white-space: nowrap; }

/* === MAIN LAYOUT === */
#main { display: flex; flex: 1; overflow: hidden; }

/* === SIDEBAR === */
#sidebar {
  width: 210px;
  background: #0d1117;
  border-right: 1px solid #30363d;
  overflow-y: auto;
  flex-shrink: 0;
}
#sidebar h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #8b949e;
  padding: 12px 14px 6px;
}

.lesson-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 12.5px;
  color: #8b949e;
  border-left: 3px solid transparent;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lesson-item:hover  { background: #161b22; color: #e6edf3; }
.lesson-item.active { background: #161b22; border-left-color: #58a6ff; color: #58a6ff; }
.lesson-item .check { color: #3fb950; font-size: 11px; margin-left: auto; }
.lesson-item .num   { font-size: 10px; color: #484f58; min-width: 16px; }

.section-header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #484f58;
  padding: 10px 14px 4px;
  margin-top: 4px;
}

/* === CONTENT AREA === */
#content { flex: 1; display: flex; overflow: hidden; }

/* === LESSON PANEL === */
#lesson-panel {
  width: 44%;
  overflow-y: auto;
  padding: 24px 28px;
  border-right: 1px solid #30363d;
  flex-shrink: 0;
}
#lesson-panel h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.lesson-meta     { font-size: 11px; color: #8b949e; margin-bottom: 16px; }
.lesson-body     { font-size: 15px; line-height: 1.75; color: #c9d1d9; }
.lesson-body p   { margin-bottom: 12px; }
.lesson-body pre {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 14px;
  font-family: 'Courier New', monospace;
  font-size: 12.5px;
  overflow-x: auto;
  margin-bottom: 12px;
  color: #f0f6fc;
  line-height: 1.6;
}

.kw  { color: #ff7b72; }
.str { color: #a5d6ff; }
.fn  { color: #d2a8ff; }
.cm  { color: #6e7681; }
.num { color: #79c0ff; }
.bi  { color: #ffa657; }

.task-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-left: 3px solid #58a6ff;
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 20px;
}
.task-box h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #58a6ff;
  margin-bottom: 6px;
}
.task-box p { font-size: 13px; color: #e6edf3; line-height: 1.6; }

/* === EXERCISE PANEL === */
#exercise-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#ex-header {
  padding: 10px 16px;
  border-bottom: 1px solid #30363d;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
#ex-header h3 { font-size: 13px; font-weight: 600; }
#ex-nav { display: flex; gap: 6px; flex-wrap: wrap; }

.ex-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid #30363d;
  background: transparent;
  color: #8b949e;
  font-size: 11px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.ex-dot.active { border-color: #58a6ff; color: #58a6ff; background: #58a6ff18; }
.ex-dot.done   { border-color: #3fb950; background: #3fb95022; color: #3fb950; }

#editor-wrap { flex: 3; overflow: hidden; position: relative; }
.CodeMirror  { height: 100% !important; font-size: 15px; font-family: 'Courier New', monospace; }

/* === OUTPUT BAR === */
#output-bar {
  flex: 2;
  min-height: 80px;
  border-top: 1px solid #30363d;
  display: flex;
  flex-direction: column;
}

#run-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  flex-shrink: 0;
}

#run-btn {
  background: linear-gradient(135deg, #238636, #2ea043);
  border: none; color: #fff;
  padding: 6px 16px; border-radius: 6px;
  cursor: pointer; font-size: 12px; font-weight: 600;
}
#run-btn:disabled { opacity: .5; cursor: not-allowed; }

#reset-btn {
  background: transparent;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 11px;
}
#hint-btn {
  background: transparent;
  border: 1px solid #d2940022;
  color: #d29400;
  padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 11px;
}

#feedback { margin-left: auto; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.fb-pass { color: #3fb950; }
.fb-fail { color: #f85149; }
.fb-hint { color: #d29922; }

#output {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  background: #0d1117;
  line-height: 1.5;
}
.out-ok   { color: #e6edf3; }
.out-err  { color: #ff7b72; }
.out-info { color: #484f58; }

/* === PYODIDE STATUS === */
#pyodide-status {
  position: fixed;
  bottom: 10px; right: 10px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 11px;
  color: #8b949e;
  z-index: 99;
}

/* === MOBILE BOTTOM TABS (hidden on desktop) === */
#mobile-tabs {
  display: none;
  background: #161b22;
  border-top: 1px solid #30363d;
  flex-shrink: 0;
  height: 56px;
}
.mob-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: #8b949e;
  font-size: 10px;
  font-family: 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: color .15s;
  padding: 6px 0;
}
.mob-tab .tab-icon { font-size: 17px; line-height: 1; }
.mob-tab.active { color: #58a6ff; }

/* === RESPONSIVE — MOBILE === */
@media (max-width: 768px) {
  body { height: 100dvh; }

  #topbar { height: 46px; padding: 0 10px; gap: 8px; }
  #topbar h1 { font-size: 15px; }
  #home-link { padding: 2px 8px; font-size: 11px; }
  #progress-bar-wrap { max-width: 100px; }
  #progress-text { font-size: 11px; }

  /* Main: relative so sidebar overlay works */
  #main { position: relative; overflow: hidden; }

  /* Sidebar: hidden by default; mob-active makes it an overlay */
  #sidebar {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 30;
    width: 100%;
    background: #0d1117;
    overflow-y: auto;
    flex-direction: column;
  }
  #sidebar.mob-active { display: flex; }

  /* Content: relative for inner absolute panels */
  #content { position: relative; overflow: hidden; }

  /* Lesson panel fills whole content area */
  #lesson-panel {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    border-right: none;
    padding: 16px;
    overflow-y: auto;
  }
  #lesson-panel.mob-active { display: block; }

  /* Exercise panel fills whole content area */
  #exercise-panel {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
  }
  #exercise-panel.mob-active { display: flex; }

  /* Show bottom tabs */
  #mobile-tabs { display: flex; }

  /* Pyodide status above tabs */
  #pyodide-status { bottom: 64px; right: 8px; font-size: 10px; padding: 4px 10px; }

  /* Output bar slightly shorter */
  #output-bar { height: 130px; }

  /* Smaller editor font */
  .CodeMirror { font-size: 12px; }

  .lesson-body     { font-size: 13px; }
  .lesson-body pre { font-size: 11.5px; }
  .lesson-body pre { -webkit-overflow-scrolling: touch; }

  #ex-header { padding: 8px 12px; }
  #run-row   { padding: 5px 8px; gap: 6px; flex-wrap: wrap; }
  #run-btn   { padding: 5px 12px; font-size: 11px; }
  #reset-btn, #hint-btn { padding: 5px 9px; font-size: 10px; }
  #feedback  { font-size: 11px; flex-basis: 100%; margin-left: 0; margin-top: 2px; }
}

@media (max-width: 480px) {
  #topbar h1 { font-size: 13px; }
  #progress-bar-wrap { display: none; }
  .lang-btn  { padding: 2px 7px; font-size: 11px; }
  #output    { font-size: 11.5px; }
}
