/* Book Layout - GitBook Style */

.book-layout {
  background: var(--ink);
}

.book-container {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - var(--header-height));
}

/* Inner layout: article + TOC side by side, centered as a unit */
.book-content-inner {
  display: flex;
  justify-content: center;
  gap: 2rem;
  align-items: flex-start;
}

/* Sidebar */
.book-sidebar {
  background: var(--ink-light);
  border-right: 1px solid var(--ink-border);
  padding: 1.5rem 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.book-title {
  padding: 0 1.5rem 1rem;
  border-bottom: 1px solid var(--ink-border);
  margin-bottom: 1rem;
}

.book-title a {
  color: var(--ivory);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
}

.book-title a:hover {
  color: var(--primary);
}

.book-nav {
  display: flex;
  flex-direction: column;
}

.book-nav-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 1.5rem;
  color: var(--ivory-dim);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

.book-nav-item:hover {
  background: var(--teal-glow);
  color: var(--ivory);
}

.book-nav-item.active {
  background: rgba(105, 152, 165, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
}

.book-nav-number {
  color: var(--ivory-muted);
  font-size: 0.75rem;
  min-width: 1.25rem;
  padding-top: 0.1rem;
}

.book-nav-item.active .book-nav-number {
  color: var(--primary);
}

.book-nav-title {
  flex: 1;
}

/* Sidebar search */
.sidebar-search {
  padding: 0 1rem 0.75rem;
}

.sidebar-search-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  border: 1px solid var(--ink-border);
  border-radius: var(--radius-md);
  color: var(--ivory-muted);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  text-align: left;
}

.sidebar-search-btn:hover {
  border-color: var(--ivory-muted);
  color: var(--ivory);
}

.sidebar-search-shortcut {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--ivory-dim);
}

/* Module toggle */
.book-module {
  margin-bottom: 0.25rem;
}

.book-module-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 1.5rem;
  background: none;
  border: none;
  color: var(--ivory);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color 0.15s ease;
}

.book-module-toggle:hover {
  color: var(--primary);
}

.book-module-arrow {
  font-size: 0.625rem;
  color: var(--ivory-muted);
  transition: transform 0.2s ease;
}

.book-module.open .book-module-arrow {
  transform: rotate(90deg);
}

.book-module-lessons {
  display: none;
}

.book-module-lessons.visible {
  display: flex;
  flex-direction: column;
}

/* Checkmarks */
.book-nav-check {
  min-width: 1rem;
  font-size: 0.75rem;
  padding-top: 0.1rem;
  color: var(--ivory-muted);
}

.book-nav-check.completed::before {
  content: "\2713";
  color: var(--emerald);
}

/* Subsections within active chapter */
.book-nav-sections {
  display: flex;
  flex-direction: column;
  padding-left: 2.5rem;
  margin-bottom: 0.5rem;
}

.book-nav-section {
  padding: 0.375rem 1rem 0.375rem 0;
  color: var(--ivory-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  line-height: 1.4;
  border-left: 1px solid var(--ink-border);
  padding-left: 0.75rem;
  margin-left: -1px;
  transition: all 0.15s ease;
}

.book-nav-section:hover {
  color: var(--ivory-dim);
  border-left-color: var(--ivory-muted);
}

.book-nav-section.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

.book-nav-divider {
  height: 1px;
  background: var(--ink-border);
  margin: 1rem 1.5rem;
}

.book-nav-extra {
  color: var(--ivory-muted);
}

.book-nav-icon {
  font-size: 0.875rem;
  min-width: 1.25rem;
}

/* Main Content */
.book-content {
  padding: 2.5rem 4rem;
  min-width: 0;
  overflow-x: clip;
}

.book-article {
  color: var(--ivory);
  font-size: 1rem;
  line-height: 1.7;
  max-width: 65ch;
  flex: 1;
  min-width: 0;
  overflow-x: clip;
}

.book-article h1 {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--ivory);
  line-height: 1.3;
}

.book-article h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 3rem;
  margin-bottom: 0.75rem;
  color: var(--ivory);
  padding-left: 0.875rem;
  border-left: 3px solid var(--teal);
}

.book-article h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--ivory);
}

.book-article p {
  margin-bottom: 1.25rem;
  color: var(--ivory-dim);
}

.book-article a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: rgba(105, 152, 165, 0.3);
  text-underline-offset: 0.15em;
  transition: text-decoration-color 0.2s ease;
}

.book-article a:hover {
  text-decoration-color: var(--primary);
}

/* Roadmap */
.roadmap {
  position: relative;
  padding-left: 3rem;
  margin: 2rem 0;
}

.roadmap::before {
  content: "";
  position: absolute;
  left: 1.125rem;
  top: 1.5rem;
  bottom: 1.5rem;
  width: 0.125rem;
  background: var(--ink-border);
}

.roadmap-step {
  position: relative;
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.roadmap-step:last-child {
  margin-bottom: 0;
}

.roadmap-node {
  position: absolute;
  left: -3rem;
  top: 0.25rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--surface);
  border: 0.125rem solid var(--ink-border);
  color: var(--ivory-muted);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.roadmap-content {
  flex: 1;
  padding-bottom: 0.5rem;
}

.roadmap-content h3 {
  font-family: var(--font-body);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ivory);
  margin-bottom: 0.25rem;
}

.roadmap-content h3 a {
  color: var(--ivory);
}

.roadmap-content h3 a:hover {
  color: var(--primary);
}

.roadmap-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ivory-muted);
  margin-bottom: 0.75rem;
}

.roadmap-content > p:last-child {
  color: var(--ivory-dim);
  font-size: 0.9375rem;
  line-height: 1.7;
  margin-bottom: 0;
}

.book-article strong {
  color: var(--ivory);
  font-weight: 600;
}

.book-article em {
  font-style: italic;
}

.book-article ul,
.book-article ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
  color: var(--ivory-dim);
}

.book-article li {
  margin-bottom: 0.5rem;
}

.book-article li::marker {
  color: var(--primary);
}

.book-article code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--ink-light);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--coral);
}

/* Multi-file code explorer */
.code-files {
  display: flex;
  border: 1px solid var(--ink-border);
  border-radius: 0.5rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
  background: var(--code-bg);
}

.code-files-sidebar {
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  background: var(--ink-light);
  border-right: 1px solid var(--ink-border);
  padding: 0.5rem 0;
}

.code-files-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 1rem;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--ivory-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.1s ease;
}

.code-files-item:hover {
  color: var(--ivory);
  background: rgba(255, 255, 255, 0.02);
}

.code-files-item.active {
  color: var(--ivory);
  background: var(--code-bg);
  border-left-color: var(--primary);
}

.code-files-panel {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.code-files-panel pre {
  margin: 0;
  border: none;
  border-radius: 0;
  min-height: 100%;
}

.code-files-content {
  margin: 0;
}

@media (max-width: 768px) {
  .code-files {
    flex-direction: column;
  }

  .code-files-sidebar {
    flex-direction: row;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--ink-border);
    padding: 0;
    overflow-x: auto;
  }

  .code-files-item {
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }

  .code-files-item.active {
    border-bottom-color: var(--primary);
    border-left-color: transparent;
  }
}

/* Content tabs (OS selector, etc.) */
.content-tabs {
  margin-bottom: 1.5rem;
  border: 1px solid var(--ink-border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.tabs-bar {
  display: flex;
  background: var(--ink-light);
  border-bottom: 1px solid var(--ink-border);
}

.tabs-btn {
  padding: 0.5rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ivory-muted);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tabs-btn:hover {
  color: var(--ivory);
  background: rgba(255, 255, 255, 0.02);
}

.tabs-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tabs-panel {
  padding: 1rem 1.25rem;
}

.tabs-panel p {
  margin-bottom: 0.75rem;
  color: var(--ivory-dim);
}

.tabs-panel p:last-child {
  margin-bottom: 0;
}

.tabs-panel pre {
  margin: 0.75rem 0;
  border: none;
  border-radius: 0.375rem;
}

.tabs-panel .code-terminal {
  margin: 0.75rem 0;
  border: none;
}

/* Terminal blocks */
.code-terminal {
  margin-bottom: 1.5rem;
  border: 1px solid var(--ink-border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.code-terminal-header {
  display: flex;
  align-items: center;
  padding: 0.375rem 1rem;
  background: var(--ink);
  border-bottom: 1px solid var(--ink-border);
}

.code-terminal-header span {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--emerald);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.code-terminal pre {
  margin: 0;
  border: none;
  border-radius: 0 0 0.5rem 0.5rem;
  background: var(--code-bg);
  padding: 0.5rem 1rem;
}

.code-terminal pre code {
  padding: 0;
  line-height: 1.5;
}

.code-terminal pre code {
  color: var(--emerald);
}

.book-article pre {
  background: var(--code-bg);
  border: 1px solid var(--ink-border);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.book-article .code-terminal pre {
  margin-bottom: 0;
  border: none;
}

.book-article pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  color: var(--ivory);
  line-height: 1.6;
}

.book-article blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--ivory-dim);
  font-style: italic;
}

.book-article hr {
  border: none;
  border-top: 1px solid var(--ink-border);
  margin: 2.5rem 0;
}

.book-article table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9375rem;
}

.book-article th,
.book-article td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--ink-border);
  text-align: left;
}

.book-article th {
  background: var(--ink-light);
  font-weight: 600;
  color: var(--ivory);
}

.book-article td {
  color: var(--ivory-dim);
}

/* Right-side Table of Contents */
.book-toc {
  position: sticky;
  top: calc(var(--header-height) + 2rem);
  height: fit-content;
  width: var(--toc-width);
  flex-shrink: 0;
  padding: 0 1rem;
  border-left: 1px solid var(--ink-border);
  align-self: start;
}

.book-toc-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ivory-muted);
  margin-bottom: 0.75rem;
}

.book-toc-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.book-toc-link {
  font-size: 0.75rem;
  color: var(--ivory-dim);
  text-decoration: none;
  padding: 0.15rem 0;
  line-height: 1.4;
  transition: color 0.15s;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
}

.book-toc-link:hover {
  color: var(--ivory);
}

.book-toc-link.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

/* Navigation Footer */
.book-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--ink-border);
}

/* Complete checkbox */
.book-complete-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--ivory-muted);
  transition: color 0.2s ease;
  order: 0;
}

.book-complete-check:hover {
  color: var(--ivory);
}

.book-complete-check input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  accent-color: var(--emerald);
  cursor: pointer;
}

.book-complete-check.done {
  color: var(--emerald);
}

.book-nav-prev,
.book-nav-next {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  background: var(--ink-light);
  border-radius: 0.5rem;
  text-decoration: none;
  max-width: 45%;
  transition: background 0.15s ease;
}

.book-nav-prev:hover,
.book-nav-next:hover {
  background: var(--ink-border);
}

.book-nav-next {
  text-align: right;
  align-items: flex-end;
}

.book-nav-label {
  font-size: 0.75rem;
  color: var(--ivory-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.book-nav-text {
  color: var(--ivory);
  font-weight: 500;
}

.book-nav-arrow {
  color: var(--primary);
  font-size: 1.25rem;
}

.book-nav-prev .book-nav-arrow {
  margin-bottom: 0.25rem;
}

.book-nav-next .book-nav-arrow {
  margin-bottom: 0.25rem;
}

/* Try It Exercises */
.try-it {
  background: var(--teal-glow);
  border-left: 4px solid var(--teal);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin: 2rem 0;
}

.try-it h3 {
  color: var(--ivory);
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.try-it p {
  margin-bottom: 1rem;
}

.try-it p:last-of-type {
  margin-bottom: 0;
}

.try-it pre {
  background: var(--code-bg);
  border-color: var(--teal-glow);
}

.try-it details {
  margin-top: 1rem;
}

.try-it summary {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
}

.try-it summary:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 1024px) {
  .book-container {
    grid-template-columns: 1fr;
  }

  .book-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), 85vw);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
  }

  .book-sidebar.open {
    transform: translateX(0);
  }

  .book-toc {
    display: none;
  }

  .book-content {
    padding: 2rem 2.5rem;
  }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
}

.sidebar-overlay.visible {
  display: block;
}

/* Sidebar tab — visible on mobile when sidebar is closed */
.sidebar-tab {
  display: none;
}

@media (max-width: 1024px) {
  .sidebar-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 198;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    rotate: 180deg;
    background: var(--ink-light);
    border: 1px solid var(--ink-border);
    border-left: none;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--ivory-muted);
    font-family: var(--font-body);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.75rem 0.4rem;
    cursor: pointer;
    transition:
      color var(--transition-fast),
      background var(--transition-fast);
    gap: 0.5rem;
  }

  .sidebar-tab:hover {
    color: var(--ivory);
    background: var(--ink);
  }

  .sidebar-tab.hidden {
    display: none;
  }
}

/* Signup CTA for unauthenticated lesson readers */
.lesson-signup-cta {
  margin: 2rem 0 1rem;
  padding: 1.25rem 1.5rem;
  background: var(--ink-light);
  border: 1px solid var(--ink-border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.lesson-signup-cta p {
  margin: 0;
  color: var(--ivory-muted);
  font-size: 0.9375rem;
  flex: 1;
}

.lesson-signup-btn {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  background: var(--primary);
  color: var(--ivory);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--transition-fast);
}

.lesson-signup-btn:hover {
  background: var(--primary-dark);
  color: var(--ivory);
}

/* PlantUML diagrams */
figure.diagram {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

figure.diagram svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

figure.diagram figcaption {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

pre.diagram-error {
  background: var(--code-bg);
  color: var(--coral);
  padding: 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
