/* ============================================================
   CSE215 Java Programming — Web Reader Styles
   ============================================================ */

:root {
  --ink: #1b1b1b;
  --paper: #fbfbf7;
  --accent: #0b5394;
  --rule: #d8d2c4;
  --muted: #5a5a5a;
  --code-bg: #f3f1ec;
  --code-ink: #2b2b2b;
  --max-width: 880px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
               Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  background: #11243a;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.topbar .brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar .spacer { flex: 1; }
.topbar button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  cursor: pointer;
}
.topbar button:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 48px); }

#toc {
  position: sticky;
  top: 48px;
  align-self: flex-start;
  width: 280px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 1rem 0.75rem 2rem 1rem;
  border-right: 1px solid var(--rule);
  background: #f5f2ea;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
}
#toc h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.5rem 0 0.4rem;
}
#toc ul { list-style: none; padding-left: 0; margin: 0; }
#toc ul ul { padding-left: 0.9rem; }
#toc a {
  color: var(--ink);
  text-decoration: none;
  display: block;
  padding: 0.15rem 0.2rem;
  border-radius: 4px;
  line-height: 1.35;
}
#toc a:hover { background: #e7e1d3; }
#toc a.part { font-weight: 700; color: var(--accent); }
#toc a.chapter { font-weight: 600; }
#toc .current { background: #e0d9c8; }

main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 2rem 5rem;
}

/* ---------- Typography ---------- */
main h1 {
  font-size: 1.7rem;
  margin: 2.2rem 0 0.6rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
  scroll-margin-top: 64px;
}
main h2 {
  font-size: 1.28rem;
  margin: 1.8rem 0 0.5rem;
  color: #233;
  scroll-margin-top: 64px;
}
main h3 {
  font-size: 1.08rem;
  margin: 1.4rem 0 0.4rem;
  color: #2a2a2a;
  scroll-margin-top: 64px;
}
main p { margin: 0.6rem 0; }
main a { color: var(--accent); }
main img { max-width: 100%; height: auto; display: block; margin: 1rem auto; }
main hr { border: none; border-top: 1px solid var(--rule); margin: 2rem 0; }

/* Part dividers get a little flair */
main h1[id^="part-"] {
  text-align: center;
  font-size: 2rem;
  color: #11243a;
  border-bottom: 3px double var(--accent);
  padding-bottom: 0.6rem;
  margin: 3rem auto 1.5rem;
}

/* ---------- Code blocks ---------- */
main pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
  color: var(--code-ink);
  /* Copy deterrent on code blocks */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
main code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}
main pre code { background: transparent; padding: 0; }

/* ---------- Tables ---------- */
main table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14.5px;
}
main th, main td {
  border: 1px solid var(--rule);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
main th { background: #ece6d7; }
main tr:nth-child(even) td { background: #f6f3eb; }

/* ---------- Lists ---------- */
main ul, main ol { padding-left: 1.5rem; }
main li { margin: 0.3rem 0; }

/* ---------- Blockquote (used for the cover caption) ---------- */
main blockquote {
  border-left: 4px solid var(--accent);
  margin: 1rem 0;
  padding: 0.4rem 1rem;
  color: var(--muted);
  background: #f3f0e8;
  border-radius: 0 6px 6px 0;
}

/* ---------- Copy-deterrent watermark layer ---------- */
#watermark {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;                 /* toggled by deterrent.js */
  color: rgba(17, 36, 58, 0.045);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  overflow: hidden;
}
#watermark .wm-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(10, 1fr);
}
#watermark .wm-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-18deg);
  white-space: nowrap;
}

/* ---------- Copyright banner ---------- */
.copyright {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: #f1ece0;
  padding: 0.6rem 1rem;
  margin: 2rem 0 1.5rem;
  text-align: center;
}

/* ---------- Footer ---------- */
footer {
  text-align: center;
  font-family: system-ui, sans-serif;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding: 1.2rem 1rem 2rem;
}

/* ---------- Print: strip deterrent chrome ---------- */
@media print {
  .topbar, #toc, #watermark, .copyright { display: none !important; }
  main { max-width: 100%; padding: 0; }
}

/* ---------- Small screens: collapse TOC ---------- */
@media (max-width: 900px) {
  #toc { display: none; }
  main { padding: 1.5rem 1rem 4rem; }
}
