:root {
  --book-panel-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --book-panel-border: 1px solid rgba(15, 23, 42, 0.08);
}

.book-page {
  max-width: min(1100px, 100%);
  margin: 0 auto;
  padding: 40px var(--page-pad-x, 20px) 96px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.book-page__breadcrumb {
  font-size: 0.9375rem;
  color: var(--muted);
}

.book-page__breadcrumb a {
  color: inherit;
}

.book-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.book-hero__cover {
  width: var(--book-hero-cover-width, clamp(120px, 16vw, 160px));
  height: var(--book-hero-cover-height, auto);
  aspect-ratio: 7 / 10;
  border-radius: 16px;
  border: var(--book-panel-border);
  background: var(--white-3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: var(--book-panel-shadow);
  align-self: start;
}

.book-hero__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.book-hero__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  font-weight: 600;
  text-transform: uppercase;
  color: #334155;
  background: rgba(148, 163, 184, 0.2);
}

.book-hero__meta {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.book-hero__title {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.1;
  color: var(--banner);
}

.book-hero__byline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
}

.book-hero__authors,
.book-hero__published {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.book-hero__summary {
  margin: 0;
  font-size: 1rem;
  line-height: 1.6;
  color: #1f2937;
}

.book-hero__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.book-hero__tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-fg);
  border: 1px solid var(--pill-bd);
  font-size: 0.8125rem;
}

.book-hero__panel {
  width: 100%;
  padding: 18px 20px;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(148, 163, 184, 0.15));
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.book-hero__panel .book-inline-nav {
  justify-content: center;
}

.book-hero__panel .book-inline-nav select {
  min-width: 88px;
}

.book-panel {
  background: var(--white-1);
  border-radius: 18px;
  border: var(--book-panel-border);
  box-shadow: var(--book-panel-shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.book-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.book-panel__title {
  margin: 0;
  font-size: 1.1rem;
  color: #0f172a;
}

.book-inline-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.book-inline-nav select,
.book-inline-nav a,
.book-inline-nav span {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--pill-bd);
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-size: 0.875rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.book-inline-nav span.disabled {
  opacity: 0.55;
  background: var(--white-3);
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.4);
  cursor: default;
}

.book-nav a.disabled {
  pointer-events: none;
  color: #94a3b8;
  opacity: 0.6;
}

.book-inline-nav select {
  appearance: none;
  cursor: pointer;
  padding-right: 32px;
  background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="%23134e4a" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"%3E%3Cpath d="M4 6l4 4 4-4"/%3E%3C/svg%3E');
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.book-sentence {
  font-size: 1.25rem;
  line-height: 1.6;
  margin: 0;
  color: #0f172a;
}

.book-panel--code {
  background: #0b1220;
  color: #e5e7eb;
  border-color: rgba(30, 41, 59, 0.6);
}

.book-panel--code .book-panel__title {
  color: inherit;
}

.book-panel--code pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, SFMono, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9375rem;
  line-height: 1.5;
  background: rgba(15, 23, 42, 0.75);
  color: inherit;
  padding: 16px;
  border-radius: 12px;
  overflow-x: auto;
}

.book-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.book-panel__actions .icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: inherit;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.875rem;
}

.book-panel__actions .icon-btn:hover,
.book-panel__actions .icon-btn:focus-visible {
  background: rgba(148, 163, 184, 0.15);
  outline: none;
}

.book-panel__actions .copy-label {
  font-size: 0.875rem;
}


#diagram-stage {
  --canvas-stage-gap: 16px;
}

.book-diagram__actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.7);
  padding: 8px 10px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.25);
}

.book-diagram__actions .icon-btn {
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.35);
}

.book-diagram__actions .icon-btn:hover,
.book-diagram__actions .icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.15);
}

.book-diagram__canvas-settings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: clamp(12px, 2.5vw, 20px);
  pointer-events: none;
}

.book-diagram__controls {
  margin: 0;
  max-width: min(320px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(248, 250, 252, 0.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 22px 40px rgba(15, 23, 42, 0.2);
  padding: clamp(14px, 3vw, 18px);
  pointer-events: auto;
}

.book-diagram__toggles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.book-diagram__controls .toggle {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.book-diagram__controls .toggle__label {
  font-weight: 600;
  color: #0f172a;
}

.book-diagram__controls .toggle.locked {
  opacity: 0.55;
}

.book-diagram__controls .toggle.locked .toggle__label {
  color: #94a3b8;
}

.book-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.book-nav .book-inline-nav {
  margin-left: auto;
  margin-right: auto;
  justify-content: center;
}

.book-nav a {
  color: var(--pill-fg);
  text-decoration: none;
}

.book-nav a:hover,
.book-nav a:focus-visible {
  text-decoration: underline;
}

.book-panel__empty {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.copy-btn.copied .copy-label {
  font-weight: 600;
}

@media (max-width: 780px) {
  .book-hero {
    grid-template-columns: 1fr;
  }

  .book-hero__cover {
    margin: 0 auto;
    align-self: center;
  }

  .book-inline-nav {
    width: 100%;
  }

  .book-nav {
    flex-wrap: wrap;
    justify-content: center;
  }

  .book-nav .book-inline-nav {
    margin-left: 0;
    margin-right: 0;
  }

  .book-inline-nav select,
  .book-inline-nav a,
  .book-inline-nav span {
    flex: 1 1 auto;
    justify-content: center;
  }

  .book-diagram__toggles {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

@media (max-width: 540px) {
  .book-page {
    padding-left: 16px;
    padding-right: 16px;
  }

  .book-panel__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .book-inline-nav {
    justify-content: center;
  }

  .book-nav {
    flex-direction: column;
    align-items: center;
  }
}
