/**
 * Code Block Styling for vinceverbon.com
 * Module: vv_code_blocks (theme-update-proof)
 *
 * Works with Prism.js (Tomorrow Night theme loaded via CDN).
 * CKEditor 5 outputs: <pre><code class="language-xxx">
 *
 * AI COWRITING NOTE:
 * When writing articles with code blocks, use the CKEditor "Code Block"
 * button and select the appropriate language. The frontend will automatically:
 *   - Apply syntax highlighting (via Prism.js)
 *   - Show a language label (top-right)
 *   - Show a copy button (top-right, next to label)
 *
 * Supported languages in CKEditor:
 *   plaintext, c, cs (C#), cpp (C++), css, diff, html, java, javascript,
 *   php, python, ruby, typescript, xml, bash, yaml, json, prompt (AI Prompt)
 */

/* Container: position anchor for toolbar */
pre[class*="language-"],
pre:has(> code[class*="language-"]) {
  position: relative;
  border-radius: 6px;
  margin: 1.5em 0;
  padding: 0;
  background: #1e1e2e !important;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Code element inside pre */
pre[class*="language-"] > code,
pre > code[class*="language-"] {
  display: block;
  padding: 2.5em 1.2em 1.2em;
  overflow-x: auto;
  font-family: 'Fira Code', 'Source Code Pro', 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
  line-height: 1.6;
  tab-size: 2;
}

/* Toolbar: language label + copy button container */
.code-block-toolbar {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0;
  z-index: 2;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  line-height: 1;
}

/* Language label */
.code-block-toolbar .code-lang-label {
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
  border-bottom-left-radius: 6px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  user-select: none;
}

/* Copy button */
.code-block-toolbar .code-copy-btn {
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
  border: none;
  border-top-right-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  font-size: 12px;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
}

.code-block-toolbar .code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #e5e7eb;
}

.code-block-toolbar .code-copy-btn.copied {
  color: #34d399;
  background: rgba(52, 211, 153, 0.1);
}

/* Copy icon SVG sizing */
.code-copy-btn .copy-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
}

/* Inline code (not in pre) */
:not(pre) > code {
  background: #f1f5f9;
  color: #dc2626;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'Fira Code', 'Source Code Pro', 'Consolas', monospace;
}

/* Responsive */
@media (max-width: 768px) {
  pre[class*="language-"] > code,
  pre > code[class*="language-"] {
    padding: 2.2em 0.8em 0.8em;
    font-size: 0.82em;
  }

  .code-block-toolbar {
    font-size: 11px;
  }
}
