:root {
  --bg: #faf9f7;
  --paper: #ffffff;
  --ink: #1a1d22;
  --ink-2: #5a6270;
  --line: #e3e6eb;
  --accent: #c14b27;       /* Java orange */
  --accent-soft: #f7e2d8;
  --code-bg: #1e1f26;
  --code-ink: #e6e7ec;
  --kw: #f78da7;
  --type: #7fd1ff;
  --str: #c8e07b;
  --com: #6b7080;
  --num: #ffd479;
  --max: 1200px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15.5px/1.6 "Inter", "Segoe UI", system-ui, sans-serif;
}
h1, h2, h3, h4 { font-family: "Source Serif Pro", "Georgia", serif; letter-spacing: -.005em; line-height: 1.25; }
h1 { font-size: 1.95rem; margin: .2em 0 .6em; }
h2 { font-size: 1.35rem; margin: 1.8em 0 .5em; }
h3 { font-size: 1.05rem; margin: 1.5em 0 .4em; color: var(--accent); }
p  { margin: .35em 0 .7em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { padding-left: 1.4rem; }
li { margin: .2em 0; }
button { font: inherit; cursor: pointer; padding: .45rem 1rem; border-radius: 6px; border: 1px solid var(--line); background: var(--paper); }
button:hover { background: var(--accent-soft); border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #9d3a1d; }

/* ========================  TOP BAR  ===================================== */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .85rem 1.5rem;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.logo {
  font-family: "JetBrains Mono", Consolas, monospace; font-size: 1.2rem;
  background: var(--ink); color: var(--accent-soft);
  width: 32px; height: 32px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
.search { flex: 1; max-width: 380px; margin-left: 1rem; }
.search input {
  width: 100%; font: inherit; padding: .45rem .8rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg);
}
#topbar nav { display: flex; gap: 1.2rem; margin-left: auto; }
#topbar nav a {
  color: var(--ink-2); padding: .2rem 0;
  border-bottom: 2px solid transparent;
}
#topbar nav a.active { color: var(--ink); border-color: var(--accent); }
#topbar nav a:hover { color: var(--ink); text-decoration: none; }

/* ========================  LAYOUT  ====================================== */
#layout {
  display: grid; grid-template-columns: 280px 1fr;
  max-width: var(--max); margin: 0 auto; gap: 0;
  min-height: calc(100vh - 110px);
}

/* ========================  SIDEBAR  ===================================== */
#sidebar {
  background: var(--paper); border-right: 1px solid var(--line);
  padding: 1.4rem 1rem; position: sticky; top: 56px; align-self: start;
  max-height: calc(100vh - 56px); overflow: auto;
}
#sidebar h2 { font-size: .85rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .08em; margin: 0 0 .8rem; }
#lesson-list { list-style: none; padding: 0; margin: 0; counter-reset: lesson; }
#lesson-list li {
  counter-increment: lesson;
  padding: .35rem .6rem;
  border-radius: 6px; cursor: pointer; font-size: .92rem; color: var(--ink-2);
  display: flex; align-items: center; gap: .5rem;
  position: relative;
}
#lesson-list li:hover { background: var(--accent-soft); color: var(--ink); }
#lesson-list li.active { background: var(--ink); color: #fff; }
#lesson-list li.active .check { color: #6cd07e; }
#lesson-list li::before {
  content: counter(lesson, decimal-leading-zero);
  font-family: "JetBrains Mono", Consolas, monospace; font-size: .78rem; opacity: .65;
}
#lesson-list .check { color: #6cd07e; font-weight: bold; margin-left: auto; }
#lesson-list .check:empty { display: none; }

#progress-box { margin-top: 1.5rem; padding: 1rem; background: var(--bg); border-radius: 6px; }
.bar { background: var(--line); height: 6px; border-radius: 999px; overflow: hidden; }
#progress-fill { background: var(--accent); height: 100%; width: 0; transition: width .2s ease; }
#progress-label { font-size: .82rem; color: var(--ink-2); margin: .5rem 0; }
#reset-progress { font-size: .8rem; padding: .3rem .6rem; }

/* ========================  MAIN / LESSON  =============================== */
#main { padding: 2rem 2.5rem 3rem; max-width: 820px; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: .75rem; padding: .15rem .55rem; border-radius: 999px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .8rem; }
.objectives, .takeaways, .pitfalls {
  background: var(--paper); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: .8rem 1.2rem; border-radius: 4px; margin: 1.2rem 0;
}
.objectives { border-left-color: #4caf94; }
.pitfalls { border-left-color: #d65a5a; }
.takeaways { border-left-color: var(--accent); }
.objectives h4, .pitfalls h4, .takeaways h4 { margin: .1em 0 .4em; font-family: "Inter", sans-serif; font-size: .85rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); }

code { font-family: "JetBrains Mono", Consolas, monospace; font-size: .92em; background: var(--accent-soft); padding: .05em .35em; border-radius: 4px; }
pre {
  background: var(--code-bg); color: var(--code-ink);
  padding: 1rem 1.2rem; border-radius: 8px;
  overflow: auto; line-height: 1.45; font-size: .88rem;
  font-family: "JetBrains Mono", Consolas, monospace;
  margin: 1rem 0;
}
pre code { background: transparent; padding: 0; color: inherit; }
.kw { color: var(--kw); } .type { color: var(--type); } .str { color: var(--str); } .com { color: var(--com); font-style: italic; } .num { color: var(--num); }
.annot { color: #ffb6c1; }

table.matrix { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .92rem; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: .5rem .7rem; text-align: left; }
table.matrix th { background: var(--bg); }

.lesson-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); gap: 1rem;
}
.mini-quiz { background: var(--paper); border: 1px solid var(--line); padding: 1.2rem 1.4rem; border-radius: 8px; margin: 1.5rem 0; }
.mini-quiz h3 { margin-top: 0; color: var(--ink); }
.mini-quiz .q { margin-bottom: 1rem; }
.mini-quiz .q p { margin: 0 0 .5rem; font-weight: 500; }
.mini-quiz label { display: block; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 6px; margin: .25rem 0; cursor: pointer; font-size: .92rem; }
.mini-quiz label:hover { background: var(--accent-soft); }
.mini-quiz label.correct { background: #e1f4e2; border-color: #6cd07e; }
.mini-quiz label.wrong { background: #fde0e0; border-color: #d65a5a; }
.mini-quiz .explain { font-size: .85rem; color: var(--ink-2); margin-top: .4rem; padding-left: .5rem; border-left: 2px solid var(--accent); }

/* ========================  QUIZ MODE  =================================== */
#view-quiz h1 { margin-bottom: .2rem; }
#view-quiz .lede { color: var(--ink-2); margin-bottom: 1.5rem; }
.quiz-card { background: var(--paper); border: 1px solid var(--line); padding: 1.8rem 2rem; border-radius: 10px; }
.quiz-header { display: flex; justify-content: space-between; color: var(--ink-2); font-size: .85rem; margin-bottom: 1rem; }
.quiz-q { font-size: 1.1rem; margin-bottom: 1rem; font-family: "Source Serif Pro", serif; }
.quiz-options { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.quiz-options button {
  text-align: left; padding: .65rem .9rem; background: var(--bg); border: 1px solid var(--line);
}
.quiz-options button.correct { background: #e1f4e2; border-color: #6cd07e; color: #226633; }
.quiz-options button.wrong { background: #fde0e0; border-color: #d65a5a; color: #993939; }
.quiz-options button[disabled] { cursor: default; }
.quiz-feedback { font-size: .9rem; color: var(--ink-2); margin-bottom: 1rem; min-height: 1.5em; }
.quiz-summary { text-align: center; padding: 2rem; }
.quiz-summary .score { font-size: 3rem; font-family: "Source Serif Pro", serif; color: var(--accent); }
.quiz-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* ========================  REFERENCE  =================================== */
#reference-root { display: grid; gap: 1.2rem; grid-template-columns: 1fr 1fr; }
.ref-card { background: var(--paper); border: 1px solid var(--line); padding: 1.2rem 1.4rem; border-radius: 8px; }
.ref-card h3 { margin-top: 0; }
.ref-card pre { font-size: .82rem; padding: .7rem .9rem; }

/* ========================  FOOTER  ====================================== */
footer { text-align: center; padding: 2rem 2rem 3rem; color: var(--ink-2); font-size: .85rem; border-top: 1px solid var(--line); margin-top: 2rem; }

/* ========================  TOAST  ======================================= */
#toast-root { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: .65rem .9rem; border-radius: 6px; font-size: .9rem; max-width: 320px; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.toast.success { background: #226633; }
.toast.error { background: #993939; }

/* ========================  RESPONSIVE  ================================== */
@media (max-width: 900px) {
  #layout { grid-template-columns: 1fr; }
  #sidebar { position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  #main { padding: 1.5rem 1.2rem; }
  .search { display: none; }
  #reference-root { grid-template-columns: 1fr; }
}
