/* Enhanced Code Block Styling with Copy Button */

/* Remove double lines and fix code block appearance */
.book-page .highlight,
.book-page pre {
  position: relative;
  background: #2d3748 !important;
  color: #e2e8f0 !important;
  border-radius: 8px;
  border: 1px solid #4a5568 !important;
  margin: 1rem 0;
  overflow: hidden;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* Remove nested pre styling that causes double lines */
.book-page .highlight pre {
  background: transparent !important;
  border: none !important;
  margin: 0 !important;
  padding: 1rem !important;
  border-radius: 0;
  overflow-x: auto;
}

/* Code content styling */
.book-page pre code {
  background: transparent !important;
  color: inherit !important;
  padding: 0 !important;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Copy button container */
.code-block-container {
  position: relative;
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 0.375rem 0.75rem;
  color: #e2e8f0;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  z-index: 10;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.copy-button:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.copy-button:active {
  transform: translateY(0);
}

/* Copy button states */
.copy-button .copy-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
}

.copy-button .success-icon {
  width: 14px;
  height: 14px;
  display: none;
  color: #10b981;
}

.copy-button.copied .copy-icon {
  display: none;
}

.copy-button.copied .success-icon {
  display: inline-block;
}

.copy-button.copied {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #10b981;
}

/* Line numbers styling */
.book-page .chroma .lnt {
  color: #718096 !important;
  background: transparent !important;
  padding-right: 0.75rem;
  user-select: none;
}

.book-page .chroma .lntd {
  background: transparent !important;
  border: none !important;
}

/* Syntax highlighting tokens */
.book-page .chroma .k { color: #81c784; } /* Keywords */
.book-page .chroma .s,
.book-page .chroma .s1,
.book-page .chroma .s2 { color: #ffcc02; } /* Strings */
.book-page .chroma .c,
.book-page .chroma .c1,
.book-page .chroma .cm { color: #9e9e9e; } /* Comments */
.book-page .chroma .n { color: #e2e8f0; } /* Names */
.book-page .chroma .o { color: #ff5722; } /* Operators */
.book-page .chroma .p { color: #e2e8f0; } /* Punctuation */
.book-page .chroma .nf { color: #42a5f5; } /* Function names */
.book-page .chroma .nb { color: #ab47bc; } /* Built-ins */

/* Inline code styling */
.book-page p code,
.book-page li code,
.book-page td code,
.book-page th code {
  background: rgba(45, 55, 72, 0.8) !important;
  color: #fbb6ce !important;
  padding: 0.125rem 0.375rem !important;
  border-radius: 4px !important;
  font-size: 0.875em !important;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Language label styling */
.code-language-label {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.3);
  color: #9ca3af;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-bottom-right-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .copy-button {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
  }
  
  .book-page .highlight pre,
  .book-page pre {
    padding: 0.75rem !important;
  }
}

/* Dark theme inline code for light backgrounds */
@media (prefers-color-scheme: light) {
  .book-page p code,
  .book-page li code,
  .book-page td code,
  .book-page th code {
    background: #f7fafc !important;
    color: #d63384 !important;
    border: 1px solid #e2e8f0;
  }
}