/* ---------- Rusty: dark, warm, crab-approved ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #16130f;
  --bg-panel: #1e1a15;
  --bg-raised: #262019;
  --bg-hover: #2e2720;
  --border: #383026;
  --text: #ece4d8;
  --text-dim: #a2937f;
  --text-faint: #6e6250;
  --accent: #f74c00;        /* rust orange */
  --accent-soft: #ff8a50;
  --green: #7fbf5f;
  --red: #e05252;
  --yellow: #e0b152;
  --blue: #6fa8dc;
  --purple: #b58fd6;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html, body { height: 100%; }
#mobile-menu { display: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 290px;
  min-width: 290px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.side-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.logo-crab { font-size: 30px; }
.logo-name { font-weight: 800; font-size: 19px; letter-spacing: .5px; }
.logo-sub { font-size: 11.5px; color: var(--text-dim); }

.side-stats {
  display: flex; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.chip {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.chip span { color: var(--accent-soft); }

#chapter-nav { flex: 1; overflow-y: auto; padding: 8px 0 20px; }

.ch-group { margin-top: 2px; }
.ch-head {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.ch-head:hover { color: var(--text); background: rgba(255,255,255,.03); }
.ch-head .ch-icon { width: 20px; text-align: center; }
.ch-head .ch-title { flex: 1; }
.ch-head .ch-count { font-size: 11px; color: var(--text-faint); font-weight: 500; }
.ch-head.done .ch-count { color: var(--green); }
.ch-head .caret { font-size: 10px; color: var(--text-faint); transition: transform .15s; }
.ch-group.open .caret { transform: rotate(90deg); }
.ch-group.project .ch-title { color: var(--yellow); }

.ch-lessons { display: none; }
.ch-group.open .ch-lessons { display: block; }
.lesson-link {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 14px 6px 24px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.lesson-link:hover { background: rgba(255,255,255,.04); color: var(--text); }
.lesson-link.active {
  background: rgba(247, 76, 0, .12);
  border-left-color: var(--accent);
  color: var(--text);
}
.lesson-dot {
  width: 15px; height: 15px; min-width: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}
.lesson-link.done .lesson-dot {
  background: var(--green); border-color: var(--green); color: #16130f;
}
.lesson-link.done .lesson-dot::after { content: "✓"; font-weight: 800; }

.side-footer {
  padding: 10px 16px;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
}

.account {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.account img { width: 26px; height: 26px; border-radius: 50%; }
.account-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .btn.small { padding: 4px 6px; }

/* ---------- sign in ---------- */
.signed-out #sidebar, .signed-out #mobile-menu { display: none !important; }
.signed-out #app { height: 100dvh; }
.signin {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.signin-card {
  width: 100%; max-width: 420px; text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 28px;
}
.signin-card .crab { font-size: 52px; line-height: 1; margin-bottom: 12px; }
.signin-card h1 { font-size: 26px; margin-bottom: 8px; }
.signin-card p { color: var(--text-dim); margin-bottom: 24px; }
.btn.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 20px;
  background: #fff; color: #1f1f1f;
}
.btn.google-btn:hover { background: #f1ede8; }
.google-btn svg { width: 20px; height: 20px; }
.signin-error { color: var(--red); font-size: 13px; min-height: 1.4em; margin-top: 12px; }

.signin-legal { margin-top: 18px; font-size: 12px; color: var(--text-faint); }
.signin-legal a { color: var(--text-dim); }
.legal-page { height: auto; overflow: auto; }
.legal { max-width: 720px; margin: 0 auto; padding: 40px 24px 60px; }
.legal h1 { font-size: 30px; margin: 18px 0 4px; }
.legal h2 { font-size: 19px; margin: 26px 0 8px; }
.legal p, .legal li { color: var(--text-dim); margin-bottom: 10px; }
.legal ul { padding-left: 22px; }
.legal a { color: var(--accent-soft); }
.legal .dim { color: var(--text-faint); font-size: 13px; }

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

/* ---------- dashboard ---------- */
.dashboard { overflow-y: auto; padding: 40px 48px; width: 100%; }
.dash-hero { max-width: 900px; }
.dash-hero h1 { font-size: 30px; margin-bottom: 6px; }
.dash-hero .sub { color: var(--text-dim); font-size: 15.5px; max-width: 640px; }

.dash-progress {
  max-width: 900px;
  margin: 26px 0 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
}
.dash-progress .row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.dash-progress .big { font-size: 22px; font-weight: 700; }
.dash-progress .pct { color: var(--accent-soft); font-weight: 700; }
.bar { height: 10px; background: var(--bg-raised); border-radius: 6px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-soft)); border-radius: 6px; transition: width .4s; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 9px 20px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
}
.btn:hover { background: #ff5d10; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--bg-hover); border-color: var(--text-faint); }
.btn.ghost { background: transparent; color: var(--text-dim); border: none; }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 6px 13px; font-size: 13px; }

.continue-box { margin-top: 14px; }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  max-width: 900px;
  margin-top: 26px;
}
.ch-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
}
.ch-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.ch-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.ch-card .icon { font-size: 22px; }
.ch-card h3 { font-size: 15.5px; }
.ch-card.project h3 { color: var(--yellow); }
.ch-card p { font-size: 12.8px; color: var(--text-dim); margin-bottom: 12px; min-height: 38px; }
.ch-card .meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-faint); margin-top: 7px; }
.ch-card .badge-done { color: var(--green); font-weight: 700; }

/* ---------- lesson view ---------- */
.lesson-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.lesson-topbar .crumb { font-size: 12.5px; color: var(--text-faint); }
.lesson-topbar .crumb b { color: var(--text-dim); font-weight: 600; }
.lesson-topbar .spacer { flex: 1; }
.lesson-topbar .done-tag { color: var(--green); font-size: 12.5px; font-weight: 700; }

.lesson-body { flex: 1; display: flex; overflow: hidden; }

.pane-content {
  width: 47%;
  min-width: 360px;
  overflow-y: auto;
  padding: 26px 30px 60px;
  border-right: 1px solid var(--border);
}
.pane-work { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #14110d; }

/* markdown */
.md h1, .md h2 { font-size: 19px; margin: 22px 0 10px; color: var(--accent-soft); }
.md h2:first-child, .md h1:first-child { margin-top: 0; }
.md h3 { font-size: 16px; margin: 18px 0 8px; }
.md p { margin: 10px 0; color: var(--text); }
.md ul, .md ol { margin: 10px 0 10px 22px; }
.md li { margin: 5px 0; }
.md blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 14px;
  margin: 12px 0;
  background: rgba(247,76,0,.07);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
  font-style: italic;
}
.md code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--accent-soft);
}
.md pre {
  background: #100e0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
  margin: 12px 0;
  overflow-x: auto;
}
.md pre code {
  background: none; border: none; padding: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}
.lesson-title-md { font-size: 24px; margin-bottom: 4px; }
.lesson-chapter-md { font-size: 12.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 18px; }

.hint-box, .solution-box {
  margin-top: 18px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 15px;
  font-size: 13.5px;
}
.hint-box { border-color: var(--yellow); background: rgba(224,177,82,.06); }
.solution-box { border-color: var(--purple); background: rgba(181,143,214,.06); }
.hint-box .label, .solution-box .label { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.hint-box .label { color: var(--yellow); }
.solution-box .label { color: var(--purple); }
.solution-box pre { margin: 6px 0 0; background: #100e0a; border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.solution-box pre code { font-family: var(--mono); font-size: 12.5px; }

.reveal-row { margin-top: 18px; display: flex; gap: 10px; }

/* editor */
.editor-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.editor-toolbar .file-tag {
  font-family: var(--mono); font-size: 12px; color: var(--text-faint);
  flex: 1;
}
.editor-shell { flex: 1; position: relative; overflow: hidden; display: flex; min-height: 120px; }
.gutter {
  width: 44px; min-width: 44px;
  background: #14110d;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  text-align: right;
  padding: 12px 10px 12px 0;
  overflow: hidden;
  user-select: none;
  border-right: 1px solid var(--border);
}
.editor-wrap { position: relative; flex: 1; overflow: hidden; }
.editor-wrap pre, .editor-wrap textarea {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 12px 14px;
  margin: 0;
  border: none;
  white-space: pre;
  overflow-wrap: normal;
  tab-size: 4;
}
.editor-wrap pre {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none;
  color: var(--text);
}
.editor-wrap textarea {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--accent-soft);
  resize: none;
  outline: none;
  overflow: auto;
}
.editor-wrap textarea::selection { background: rgba(111,168,220,.30); }

/* syntax colors */
.tok-kw { color: #ff7b47; }
.tok-ty { color: #6fc3df; }
.tok-str { color: #a8cc7c; }
.tok-num { color: #d6a35c; }
.tok-mac { color: #e0b152; }
.tok-com { color: #756a58; font-style: italic; }
.tok-life { color: #b58fd6; }
.tok-fn { color: #dcd0bd; }

/* console */
.console {
  height: 34%;
  min-height: 150px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #100e0a;
}
.console-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}
.console-bar .title { font-size: 11.5px; font-weight: 700; letter-spacing: 1px; color: var(--text-faint); text-transform: uppercase; flex: 1; }
.console-out {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.console-out .err { color: var(--red); }
.console-out .ok { color: var(--green); }
.console-out .dim { color: var(--text-faint); }
.console-out .warn { color: var(--yellow); }

.result-banner {
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 700;
  display: none;
  align-items: center;
  gap: 10px;
}
.result-banner.pass { display: flex; background: rgba(127,191,95,.14); color: var(--green); border-top: 1px solid rgba(127,191,95,.3); }
.result-banner.fail { display: flex; background: rgba(224,82,82,.12); color: var(--red); border-top: 1px solid rgba(224,82,82,.3); }
.result-banner .btn { margin-left: auto; }

/* capstone verify pane */
.capstone-pane {
  flex: 1;
  overflow-y: auto;
  padding: 26px 28px;
}
.capstone-pane h3 { font-size: 18px; margin-bottom: 8px; }
.capstone-pane > p { color: var(--text-dim); font-size: 13.5px; max-width: 560px; }
.capstone-pane label {
  display: block;
  margin: 18px 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
}
.path-row { display: flex; gap: 8px; max-width: 640px; }
.path-row input {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
.path-row input:focus { border-color: var(--accent); }
.verify-note { margin-top: 8px; font-size: 12px; color: var(--text-faint); }
#verify-results { margin-top: 18px; max-width: 640px; }
.verify-item {
  display: flex;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 7px;
  font-size: 13.5px;
  align-items: flex-start;
}
.verify-item .mark { font-weight: 800; }
.verify-item.pass { border-color: rgba(127,191,95,.4); background: rgba(127,191,95,.07); }
.verify-item.pass .mark { color: var(--green); }
.verify-item.fail { border-color: rgba(224,82,82,.4); background: rgba(224,82,82,.06); }
.verify-item.fail .mark { color: var(--red); }
.verify-item .vlabel { font-weight: 600; }
.verify-item .vdetail {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}
.verify-item.summary { align-items: center; }
.md a { color: var(--blue); }

/* nav footer */
.lesson-nav {
  display: flex; align-items: center;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  gap: 10px;
}
.lesson-nav .spacer { flex: 1; }

/* spinner */
.spin {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -2px;
  animation: rot .7s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* confetti-ish */
@keyframes floatup {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(-130px) rotate(340deg); opacity: 0; }
}
.party {
  position: fixed;
  font-size: 22px;
  pointer-events: none;
  animation: floatup 1.2s ease-out forwards;
  z-index: 99;
}

/* celebration / all-done */
.finished-card {
  max-width: 660px;
  margin: 60px auto;
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 44px 40px;
}
.finished-card .crab { font-size: 64px; }
.finished-card h1 { margin: 12px 0 8px; }
.finished-card p { color: var(--text-dim); margin-bottom: 8px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-raised); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .lesson-body { flex-direction: column; }
  .pane-content { width: 100%; min-width: 0; max-height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
}

@media (max-width: 700px) {
  #mobile-menu {
    display: block; width: 100%; height: 44px; padding: 0 14px;
    border: 0; border-bottom: 1px solid var(--border);
    background: var(--bg-panel); color: var(--text); text-align: left;
    font: 600 14px var(--sans);
  }
  #app { height: calc(100dvh - 44px); }
  #sidebar {
    display: none; position: fixed; z-index: 50; top: 44px; bottom: 0;
    width: min(88vw, 340px); min-width: 0; box-shadow: 8px 0 30px #0008;
  }
  .menu-open #sidebar { display: flex; }
  #main { min-width: 0; width: 100%; }
  .lesson-topbar { padding: 8px 10px; gap: 7px; }
  .lesson-topbar .crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lesson-body { flex-direction: column; }
  .pane-content {
    width: 100%; min-width: 0; height: 39%; max-height: none;
    flex: none; padding: 16px 18px 26px;
  }
  .pane-work { min-height: 0; }
  .editor-toolbar { gap: 5px; padding: 7px; }
  .editor-toolbar .btn { padding: 6px 8px; }
  .gutter { width: 34px; min-width: 34px; }
  .editor-wrap pre, .editor-wrap textarea { font-size: 13px; }
  .console { min-height: 105px; height: 30%; }
  .lesson-nav { padding: 6px 8px; }
  .dashboard { padding: 18px; }
  .chapter-grid { grid-template-columns: 1fr; }
}
