:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ebe6db;
  --border: #d8d1c4;
  --text: #2b2620;
  --text-dim: #7a7266;
  --accent: #e63946;
  --accent-2: #118ab2;
  --editor-bg: #1e1b16;
  --editor-text: #f0e9dc;
  --gutter-bg: #2a251e;
  --done: #06a77d;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --mono: 'JetBrains Mono', monospace;
  --display: 'Bricolage Grotesque', sans-serif;
}
[data-theme="dark"] {
  --bg: #14110d;
  --surface: #1e1a15;
  --surface-2: #262119;
  --border: #38312768;
  --text: #efe8db;
  --text-dim: #9a9082;
  --accent: #ff5a67;
  --accent-2: #48c9e8;
  --editor-bg: #0d0b08;
  --editor-text: #f0e9dc;
  --gutter-bg: #16130f;
  --done: #2edba5;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }
body {
  font-family: var(--display);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* HEADER */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px; height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.hamburger {
  display: none; background: none; border: none; color: var(--text);
  font-size: 22px; cursor: pointer;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-mark { font-size: 24px; }
.logo-text {
  font-weight: 800; font-size: 22px; letter-spacing: -.5px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.header-progress {
  margin-left: auto; font-family: var(--mono); font-size: 13px;
  color: var(--text-dim); font-weight: 500;
}
.theme-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); width: 38px; height: 38px; border-radius: 10px;
  font-size: 18px; cursor: pointer; transition: .2s;
}
.theme-btn:hover { transform: rotate(20deg) scale(1.08); border-color: var(--accent); }

/* BODY LAYOUT */
.body { display: flex; flex: 1; overflow: hidden; }

/* SIDEBAR */
.sidebar {
  width: 20%; min-width: 220px; max-width: 300px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px 10px; flex-shrink: 0;
}
.progress-block { padding: 4px 8px 18px; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim); margin-bottom: 8px; font-weight: 700;
}
.progress-count { font-family: var(--mono); color: var(--accent); }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 20px; overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 20px; transition: width .5s cubic-bezier(.34,1.56,.64,1);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.cat-group { margin-bottom: 16px; }
.cat-header {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  font-weight: 800; color: var(--text-dim); padding: 8px 10px 6px;
  display: flex; align-items: center; gap: 8px;
}
.cat-icon { color: var(--accent-2); font-size: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: none; border-left: 3px solid transparent;
  color: var(--text-dim); font-family: var(--display); font-size: 14px;
  padding: 9px 10px; text-align: left; cursor: pointer;
  border-radius: 0 8px 8px 0; transition: .18s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2); color: var(--text);
  border-left-color: var(--accent); font-weight: 700;
}
.nav-item.done .nav-check { color: var(--done); }
.nav-check { font-size: 13px; width: 14px; flex-shrink: 0; }
.nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* LESSON CONTENT */
.lesson {
  width: 30%; min-width: 260px; flex-shrink: 0;
  padding: 28px 26px; overflow-y: auto;
  border-right: 1px solid var(--border); background: var(--bg);
}
.lesson-tag {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  padding: 4px 10px; border-radius: 20px; letter-spacing: .5px;
  background: var(--surface-2); color: var(--accent-2);
  border: 1px solid var(--border); margin-bottom: 14px;
}
.lesson-title {
  font-size: 34px; font-weight: 800; letter-spacing: -1px;
  line-height: 1.05; margin-bottom: 16px;
}
.lesson-desc { color: var(--text-dim); font-size: 15px; line-height: 1.65; margin-bottom: 22px; }
.task-box {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.task-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--accent); font-weight: 800; margin-bottom: 8px;
}
.task-box p { font-size: 14px; line-height: 1.6; }
.lesson-nav { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; }
.nav-btn {
  flex: 1; min-width: 90px; padding: 11px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-family: var(--display); font-weight: 600;
  font-size: 13px; cursor: pointer; transition: .18s;
}
.nav-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.nav-btn.primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff; border: none;
}
.nav-btn.primary:hover { filter: brightness(1.1); box-shadow: var(--shadow); }
.hist-nav { display: flex; gap: 8px; margin-top: 12px; }
.hist-btn {
  flex: 1; padding: 6px; font-size: 11px; font-family: var(--mono);
  background: none; border: 1px dashed var(--border); color: var(--text-dim);
  border-radius: 6px; cursor: pointer; transition: .18s;
}
.hist-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); }
.hist-btn:disabled { opacity: .3; cursor: not-allowed; }

/* WORKSPACE */
.workspace { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pane { display: flex; flex-direction: column; overflow: hidden; }
.editor-pane { flex: 1; border-bottom: 1px solid var(--border); }
.preview-pane { flex: 1; background: var(--surface-2); }
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.pane-title { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.pane-actions { display: flex; gap: 8px; }
.mini-btn {
  padding: 6px 12px; border-radius: 7px; font-size: 12px; font-weight: 700;
  font-family: var(--mono); cursor: pointer; border: 1px solid var(--border);
  transition: .18s;
}
.mini-btn.ghost { background: none; color: var(--text-dim); }
.mini-btn.ghost:hover { color: var(--text); border-color: var(--text-dim); }
.mini-btn.run { background: var(--done); color: #fff; border: none; }
.mini-btn.run:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* EDITOR */
.editor-wrap {
  flex: 1; display: flex; overflow: hidden;
  background: var(--editor-bg); font-family: var(--mono); font-size: 13px;
}
.gutter {
  background: var(--gutter-bg); color: #5c554a; text-align: right;
  padding: 12px 8px 12px 0; user-select: none; overflow: hidden;
  line-height: 1.55; min-width: 42px;
}
.gutter-num { padding-right: 6px; }
.code-input {
  flex: 1; background: transparent; color: var(--editor-text);
  border: none; outline: none; resize: none; padding: 12px;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  white-space: pre; overflow: auto; tab-size: 2;
}

/* PREVIEW */
.preview-area { flex: 1; overflow: hidden; }
.preview-scroll {
  height: 100%; overflow: auto; padding: 14px;
  display: flex; justify-content: center; align-items: flex-start;
}
.device-frame { background: #fff; overflow: hidden; }
.device-frame.desktop { border-radius: 8px; box-shadow: var(--shadow); }
.device-frame.mobile {
  border: 10px solid #1a1a1a; border-radius: 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4); flex-shrink: 0;
}
.preview-iframe { width: 100%; height: 100%; border: none; display: block; background: #fff; }

.device-toggle { display: flex; gap: 4px; }
.dev-btn {
  padding: 5px 10px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 7px; cursor: pointer; transition: .18s;
}
.dev-btn:hover { color: var(--text); }
.dev-btn.active { background: var(--accent-2); color: #fff; border-color: transparent; }

/* FOOTER */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 18px; background: var(--surface); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); flex-shrink: 0;
}
.footer a { color: var(--accent); text-decoration: none; font-weight: 700; }
.footer a:hover { text-decoration: underline; }

/* TOAST */
.toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 20px;
  border-radius: 30px; font-size: 14px; font-weight: 600; z-index: 100;
  box-shadow: var(--shadow); animation: toastIn .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }

/* CONFETTI */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -20px; width: 10px; height: 14px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

.scrim { display: none; }

/* RESPONSIVE */
@media (max-width: 1000px) {
  .body { flex-direction: column; overflow-y: auto; }
  .hamburger { display: block; }
  .header-progress { display: none; }
  .sidebar {
    position: fixed; top: 58px; left: 0; bottom: 0; width: 260px; max-width: 80%;
    transform: translateX(-100%); transition: transform .28s; z-index: 25;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .scrim {
    display: block; position: fixed; inset: 58px 0 0 0;
    background: rgba(0,0,0,.4); z-index: 24;
  }
  .lesson { width: 100%; max-width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .workspace { min-height: 80vh; }
  .editor-wrap { min-height: 220px; }
  .preview-area { min-height: 260px; }
}
</style>