/* Code syntax theme centralized
   - Uses the theme CSS variables from :root in style.css (--accent-deep, --text-dim, etc.)
   - Covers common token classes from Prism, Highlight.js, Rouge/GFM and generic classes
   - Targets many languages: java, javascript, typescript, xml, json, yaml, toml, ini, bash
*/

/* Base for code blocks */
.post-content pre {
  background-color: var(--bg-darker);
  border: 2px solid var(--accent);
  padding: 1.5rem;
  margin: 1.5rem 0;
  position: relative;
  /* Create a positioning context for the scrollable area */
  display: flex;
  flex-direction: column;
}

/* Scrollable container for code */
.post-content pre .code-container {
  overflow-x: auto;
  margin-right: -0.5rem; /* Compensate for the copy button padding */
  padding-right: 2.5rem; /* Make space for the copy button */
  padding-bottom: 0.5rem; /* Add space for the horizontal scrollbar */
  /* Scrollbar styles for Firefox */
  scrollbar-width: auto;
  scrollbar-color: #4a4a4a var(--bg-darker);
}

/* Webkit scrollbar styles for code blocks */
.post-content pre .code-container::-webkit-scrollbar {
  width: 18px;  /* Vertical scrollbar width */
  height: 18px; /* Horizontal scrollbar height */
}

.post-content pre .code-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 10px;
  margin: 4px; /* Add some space around the track */
}

.post-content pre .code-container::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border: 4px solid var(--bg-darker); /* Thicker border for larger thumb */
  border-radius: 10px;
  transition: all 0.2s ease;
  min-height: 40px; /* Minimum height for vertical scrollbar thumb */
  min-width: 40px;  /* Minimum width for horizontal scrollbar thumb */
}

.post-content pre .code-container::-webkit-scrollbar-thumb:hover {
  background: #666;
  border: 3px solid var(--bg-darker);
}

.post-content pre .code-container::-webkit-scrollbar-corner {
  background: var(--bg-darker);
  border-radius: 0;
}

.post-content pre code {
  background-color: transparent;
  padding: 0;
  border: none;
  display: inline-block;
  min-width: 100%;
}

/* Copy button styles */
.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: var(--accent);
  border: 1px solid var(--accent-deep);
  border-radius: 0.25rem;
  color: var(--bg-darker);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  /* position: fixed; Change to fixed within the pre container */
  z-index: 1; /* Ensure button stays above the code */
}

.copy-button:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.copy-button.copied {
  background: var(--success, #4CAF50);
  border-color: var(--success-deep, #43A047);
}

/* Copy button text/icon visibility */
.copy-button .text {
  display: none;
}

.copy-button .icon {
  display: block;
  width: 1rem;
  height: 1rem;
}

/* Show text on larger screens */
@media (min-width: 768px) {
  .copy-button .text {
    display: block;
  }
  .copy-button .icon {
    display: none;
  }
}

/* Text selection styles */
::selection {
  background: var(--accent);
  color: var(--bg-darker);
  text-shadow: none;
}

::-moz-selection {
  background: var(--accent);
  color: var(--bg-darker);
  text-shadow: none;
}

/* Code block selection */
.post-content pre code::selection {
  background: var(--accent-deep);
  color: var(--text);
}

.post-content pre code::-moz-selection {
  background: var(--accent-deep);
  color: var(--text);
}
/* Code text styles */
.post-content pre code {
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Generic token styles */
.post-content pre .comment,
.post-content pre .token.comment,
.post-content pre .hljs-comment,
.post-content pre .c {
  color: var(--text-dim);
  font-style: italic;
}

.post-content pre .string,
.post-content pre .token.string,
.post-content pre .hljs-string,
.post-content pre .s {
  color: #00ff88;
}

.post-content pre .function,
.post-content pre .token.function,
.post-content pre .hljs-function,
.post-content pre .nf,
.post-content pre .na {
  color: #00d4ff;
}

.post-content pre .number,
.post-content pre .token.number,
.post-content pre .hljs-number,
.post-content pre .m {
  color: #ff9500;
}

.post-content pre .punctuation,
.post-content pre .token.punctuation,
.post-content pre .hljs-punctuation {
  color: var(--text-dim);
}

/* Keywords & operators: use accent-deep for emphasis */
.post-content pre .keyword,
.post-content pre .token.keyword,
.post-content pre .hljs-keyword,
.post-content pre .k,
.post-content pre .kr,
.post-content pre .kd,
.post-content pre .kn,
.post-content pre .kt,
.post-content pre .operator,
.post-content pre .token.operator,
.post-content pre .hljs-operator,
.post-content pre .o,
.post-content pre .hljs-built_in,
.post-content pre .hljs-type,
.post-content pre .hljs-literal {
  color: var(--accent-deep);
  font-weight: 700;
}

/* Language-specific small tweaks */
/* Java / C-like */
.post-content pre[class*="language-java"] .token.keyword,
.post-content pre[class*="language-java"] .hljs-keyword,
.post-content pre[class*="language-java"] .k {
  color: var(--accent-deep);
  font-weight: 700;
}

/* JavaScript / TypeScript */
.post-content pre[class*="language-js"] .token.keyword,
.post-content pre[class*="language-js"] .hljs-keyword,
.post-content pre[class*="language-ts"] .token.keyword,
.post-content pre[class*="language-ts"] .hljs-keyword,
.post-content pre .token.class-name,
.post-content pre .hljs-class {
  color: var(--accent-deep);
  font-weight: 700;
}

/* XML / HTML */
.post-content pre[class*="language-xml"] .token.tag,
.post-content pre[class*="language-html"] .token.tag,
.post-content pre .hljs-tag {
  color: var(--accent-deep);
  font-weight: 700;
}

/* JSON - keys and punctuation */
.post-content pre[class*="language-json"] .token.property,
.post-content pre[class*="language-json"] .token.key,
.post-content pre .hljs-attr {
  color: var(--accent-deep);
}

/* YAML/TOML/INI */
.post-content pre[class*="language-yaml"] .token.key,
.post-content pre[class*="language-toml"] .token.key,
.post-content pre[class*="language-ini"] .token.key,
.post-content pre .hljs-keyword {
  color: var(--accent-deep);
}

/* Diff/patch files (added/removed) */
.post-content pre .hljs-add { background-color: rgba(0,255,136,0.03); }
.post-content pre .hljs-delete { background-color: rgba(255,80,80,0.03); }

/* Accessibility: ensure enough contrast for accent-deep on dark bg */
.post-content pre .keyword,
.post-content pre .hljs-keyword {
  text-shadow: 0 0 6px rgba(0,0,0,0.45);
}

/* Keep file small by referencing variables from main style; specific overrides can be added here as needed */

/* Line numbers styling for code blocks */
pre[class*="language-"].line-numbers {
    padding-left: 0;
    counter-reset: linenumber;
}

pre[class*="language-"].line-numbers > code {
    white-space: pre;
    padding-left: 3.8em !important;
    line-height: 1.5;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 100%;
    left: 0;
    width: 3em;
    letter-spacing: -1px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    user-select: none;
    padding: 1.5rem 0;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
    line-height: 1.5;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: rgba(255, 255, 255, 0.4);
    display: block;
    padding-right: 0.8em;
    text-align: right;
    line-height: 1.5;
}

/* Line numbers styling for code blocks */
pre[class*="language-"].line-numbers {
    padding-left: 0;
    counter-reset: linenumber;
}

pre[class*="language-"].line-numbers > code {
    white-space: pre;
    padding-left: 3.8em !important;
    line-height: 1.5;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 100%;
    left: 0;
    width: 3em;
    letter-spacing: -1px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    user-select: none;
    padding: 1.5rem 0;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
    line-height: 1.5;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: rgba(255, 255, 255, 0.4);
    display: block;
    padding-right: 0.8em;
    text-align: right;
    line-height: 1.5;
}

/* Responsive line numbers for mobile */
@media (max-width: 768px) {
    pre[class*="language-"].line-numbers > code {
        padding-left: 2.5em !important;
        font-size: 0.875rem;
    }
    
    .line-numbers .line-numbers-rows {
        width: 2em;
        font-size: 0.875rem;
    }
    
    .line-numbers-rows > span:before {
        padding-right: 0.5em;
    }
}
