/* ============================================================
   OCP Java SE 21 — study reader
   Design system: warm cream background, forest-green accent,
   serif headings, dual-language (Latin + Bengali) typography.
   ============================================================ */

/* ---- Theme tokens ---- */
:root {
  --bg: #faf8f3;
  --bg-sidebar: #f3f1e9;
  --bg-panel: #ffffff;
  --bg-code: #f1efe7;
  --bg-active: #e7efe7;

  --text: #2b2b29;
  --text-soft: #57564f;
  --text-muted: #908e84;

  --border: #e6e2d7;
  --border-soft: #efece3;

  --accent: #4e7d5b;
  --accent-strong: #3f6b4c;
  --accent-soft: #6f9a7a;

  --radius: 8px;
  --reading-width: 680px;

  --font-serif: "Merriweather", Georgia, serif;
  --font-sans: "Inter", "Noto Sans Bengali", system-ui, -apple-system, sans-serif;
  --font-bn: "Noto Sans Bengali", "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #181815;
  --bg-sidebar: #1f1f1b;
  --bg-panel: #1c1c19;
  --bg-code: #232320;
  --bg-active: #25342a;

  --text: #e8e6dd;
  --text-soft: #c2c0b6;
  --text-muted: #8d8b80;

  --border: #33332d;
  --border-soft: #2a2a25;

  --accent: #79b08a;
  --accent-strong: #8cc29c;
  --accent-soft: #5e8e6e;
}

/* ---- Reset / base ---- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  /* App-shell: fixed header/footer, scrolling happens inside the regions. */
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

:lang(bn),
.bn {
  font-family: var(--font-bn);
}

/* ---- Header ---- */
.site-header {
  flex: 0 0 auto; /* fixed band at the top */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  /* Collapsible on scroll-down (see body.header-hidden). */
  max-height: 80px;
  overflow: hidden;
  transition: max-height 0.28s ease, padding 0.28s ease, border-color 0.28s ease;
}

body.header-hidden .site-header {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-color: transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-icon {
  display: inline-flex;
  color: var(--accent);
}

.brand-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-subtitle {
  margin: 0;
  font-family: var(--font-bn);
  font-size: 11px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.icon-btn:hover {
  border-color: var(--accent-soft);
  color: var(--accent-strong);
}

.icon-btn svg {
  display: block;
}

/* Show the moon in light mode (click → dark) and the sun in dark mode.
   Selectors are scoped to .icon-btn so they outrank `.icon-btn svg`. */
.icon-btn .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-btn .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-btn .icon-sun {
  display: block;
}

/* ---- Reading progress bar ----
   Fixed above the header (higher z-index) so it stays visible even when the
   header collapses on scroll-down. Width is driven from script.js. */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 20;
  pointer-events: none;
}

.reading-progress__fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* ---- Layout ---- */
.layout {
  flex: 1 1 auto;
  min-height: 0; /* let children own the scroll instead of overflowing the flex */
  display: grid;
  grid-template-columns: 230px 1fr;
  transition: grid-template-columns 0.18s ease;
}

/* ---- Sidebar (fixed; scrolls internally only if the list is long) ---- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px 12px;
  height: 100%;
  overflow-y: auto;
}

.sidebar-label {
  margin: 0 0 12px 12px;
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.chapter-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chapter-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: background 0.15s, color 0.15s;
}

.chapter-item:hover {
  background: var(--border-soft);
  color: var(--text);
}

.chapter-item.active {
  background: var(--bg-active);
  border-left-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 500;
}

.chapter-num {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chapter-item.active .chapter-num {
  color: var(--accent);
}

/* ---- Reading area ---- */
/* The reading column = a fixed tab bar above one scrolling region. */
.reading {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reading-head {
  flex: 0 0 auto;
  background: var(--bg);
  padding: 18px 40px 0;
}

.reading-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 40px 48px;
}

.reading-inner {
  max-width: 940px;
  margin: 0 auto;
}

/* Tab strip row: active-chapter label + view tabs + focus toggle, sharing
   one bottom divider. Spans the reading column (left-anchored, not centered). */
.reading-head-inner {
  max-width: none;
  margin: 0;
  display: flex;
  align-items: flex-end;
  gap: 28px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

/* Reading body (content + footer): centered, width capped per view. */
.reading-body-inner {
  max-width: 860px; /* prose default */
  margin: 0 auto;
}

.reading--wide .reading-body-inner {
  max-width: 1180px;
}

.reading--prose .reading-body-inner {
  max-width: 860px;
}

/* ---- Active-chapter label in the tab strip ---- */
.strip-chapter {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 1px;
  padding-bottom: 10px;
  white-space: nowrap;
}

.strip-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.strip-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.strip-dot {
  color: var(--text-muted);
}

.strip-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.strip-title-bn {
  font-size: 11.5px;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 28px;
}

/* ---- Focus toggle (far right of the tab strip) ---- */
.focus-toggle {
  margin-left: auto;
  margin-bottom: 7px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.focus-toggle:hover {
  border-color: var(--accent-soft);
  color: var(--accent-strong);
}

.focus-toggle.active {
  color: var(--accent-strong);
  border-color: var(--accent-soft);
  background: var(--bg-active);
}

.tab {
  position: relative;
  padding: 10px 2px 12px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 15px;
  cursor: pointer;
  line-height: 1.2;
}

.tab:hover:not(.disabled) {
  color: var(--text);
}

.tab.active {
  color: var(--accent-strong);
  font-weight: 500;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

.tab.disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.tab .soon {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
  margin: 0 0 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ---- Content host -------------------------------------------
   Each view is a self-contained document embedded in an iframe,
   so it brings its own styling. The host just sizes the frame;
   the base typography below only styles loading/error messages.
--------------------------------------------------------------- */
.reading-content {
  width: 100%;
}

.view-frame {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  overflow: hidden; /* page scrolls as one; frame auto-sizes to content */
}

.reading-content h1,
.reading-content h2,
.reading-content h3 {
  font-family: var(--font-serif);
  color: var(--text);
  line-height: 1.3;
}

.reading-content h1 {
  font-size: 30px;
  margin: 0 0 18px;
}

.reading-content p {
  color: var(--text-soft);
}

.reading-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  color: var(--accent-strong);
  padding: 1px 5px;
  border-radius: 4px;
}

.reading-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
}

.reading-content pre code {
  background: none;
  color: var(--text-soft);
  padding: 0;
  font-size: 13.5px;
  line-height: 1.7;
}

.reading-content .note {
  border-top: 1px solid var(--border);
  margin-top: 28px;
  padding-top: 18px;
  color: var(--text-soft);
}

.reading-content .note-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---- States ---- */
.state-msg {
  color: var(--text-muted);
  font-size: 15px;
  padding: 24px 0;
}

.state-msg.error {
  color: #b5523f;
}

/* ---- Footer ----
   Flows at the end of the reading content (inside .reading-inner), so it
   only appears once the reader scrolls past the content — and spans the
   reading column, not the sidebar. */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 40px;
  padding: 16px 0 4px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Left: source attribution. Right: developer credit (the only footer link). */
.footer-source {
  color: var(--text-muted);
}

.footer-source .bn {
  font-family: var(--font-bn);
}

.footer-source a {
  color: inherit;
  text-decoration: none;
}

.footer-source a:hover,
.footer-source a:focus {
  color: var(--accent);
}

.footer-copy {
  color: var(--text-muted);
}

.footer-copy a {
  color: var(--accent);
  text-decoration: none;
}

.footer-copy a:hover,
.footer-copy a:focus {
  color: var(--accent-strong);
}

/* ---- Focus mode ----
   <html class="focus-mode"> collapses the sidebar to a numbered rail and
   centers the reading column. Borders soften for a quieter surface. The
   sidebar width animates via the .layout grid-template-columns transition. */
html.focus-mode {
  --border: var(--border-soft);
}

html.focus-mode .layout {
  grid-template-columns: 60px 1fr;
}

html.focus-mode .sidebar {
  padding: 24px 6px;
}

html.focus-mode .sidebar-label {
  display: none;
}

html.focus-mode .chapter-item {
  justify-content: center;
  gap: 0;
  padding: 8px 0;
}

html.focus-mode .chapter-title {
  display: none;
}

/* Reading width stays consistent with normal mode (per-view max-width,
   centered) — focus mode only collapses the sidebar and softens borders. */

/* ---- Responsive ----
   On small screens, drop the app-shell and use normal page scroll. */
@media (max-width: 820px) {
  body {
    height: auto;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: auto;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .reading {
    height: auto;
    overflow: visible;
  }
  .reading-head {
    padding: 16px 20px 0;
  }
  .reading-scroll {
    overflow: visible;
    padding: 16px 20px 40px;
  }
  .site-header {
    padding-left: 20px;
    padding-right: 20px;
  }
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}
