/* ==========================================================================
   Flavor Theme - Syntax Highlighting
   Warm dark theme matching the site design
   ========================================================================== */

/* Code block container */
.highlight,
.wp-block-code,
pre[class*="language-"] {
  background: #1c1917;
  color: #e7e5e4;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  tab-size: 2;
  -moz-tab-size: 2;
  position: relative;
  margin: 1.5rem 0;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling */
.highlight::-webkit-scrollbar,
pre[class*="language-"]::-webkit-scrollbar {
  height: 6px;
}

.highlight::-webkit-scrollbar-track,
pre[class*="language-"]::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.highlight::-webkit-scrollbar-thumb,
pre[class*="language-"]::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.highlight::-webkit-scrollbar-thumb:hover,
pre[class*="language-"]::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Language label in top-right corner */
.highlight[data-lang]::before,
pre[data-lang]::before {
  content: attr(data-lang);
}
pre[data-language]::before {
  content: attr(data-language);
}
.highlight[data-lang]::before,
pre[data-lang]::before,
pre[data-language]::before {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.2em 0.75em;
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #78716c;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0 8px 0 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  user-select: none;
  pointer-events: none;
}

/* Code element reset inside pre */
.highlight code,
pre[class*="language-"] code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
  font-family: inherit;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
}

/* ==========================================================================
   LINE NUMBERS
   ========================================================================== */

.highlight .line-numbers,
.line-numbers-rows {
  position: absolute;
  top: 1.25rem;
  left: 0;
  width: 3.5em;
  padding-right: 0.75em;
  text-align: right;
  user-select: none;
  pointer-events: none;
  font-size: 0.875rem;
  line-height: 1.7;
  color: #57534e;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.highlight .line-numbers span,
.line-numbers-rows > span {
  display: block;
  counter-increment: line;
}

.highlight .line-numbers span::before,
.line-numbers-rows > span::before {
  content: counter(line);
  display: block;
}

.highlight.has-line-numbers,
pre.line-numbers {
  padding-left: 4.5em;
  counter-reset: line;
}

/* Line highlight */
.highlight .line-highlight,
.line-highlight {
  background: rgba(194, 114, 78, 0.12);
  display: block;
  margin-left: -1.5rem;
  margin-right: -1.5rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  border-left: 3px solid #c2724e;
}

/* ==========================================================================
   TOKEN COLORS
   ========================================================================== */

/* Comments */
.hl-comment,
.hljs-comment,
.hljs-quote,
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #78716c;
  font-style: italic;
}

/* Keywords */
.hl-keyword,
.hljs-keyword,
.hljs-selector-tag,
.hljs-type,
.token.keyword,
.token.property,
.token.tag {
  color: #d6a88a;
  font-weight: 500;
}

/* Strings */
.hl-string,
.hljs-string,
.hljs-attr,
.hljs-template-tag,
.hljs-template-variable,
.token.string,
.token.attr-value {
  color: #87ceab;
}

/* Functions */
.hl-function,
.hljs-title,
.hljs-section,
.token.function,
.token.class-name {
  color: #c2724e;
  font-weight: 500;
}

/* Numbers */
.hl-number,
.hljs-number,
.hljs-literal,
.token.number,
.token.boolean,
.token.constant {
  color: #e5a755;
}

/* Variables & Parameters */
.hljs-variable,
.hljs-params,
.token.variable,
.token.parameter {
  color: #e78a8a;
}

/* Built-in / Types */
.hljs-built_in,
.hljs-builtin-name,
.token.builtin {
  color: #8bb8d0;
}

/* Operators */
.hljs-symbol,
.hljs-bullet,
.token.operator,
.token.punctuation {
  color: #a8a29e;
}

/* Regex */
.hljs-regexp,
.token.regex {
  color: #e5a755;
}

/* HTML/XML Tags */
.hljs-tag,
.token.tag .token.tag {
  color: #e78a8a;
}

/* HTML Attributes */
.hljs-name,
.token.attr-name {
  color: #e5a755;
}

/* CSS Selectors */
.hljs-selector-class,
.hljs-selector-id,
.token.selector {
  color: #b8a4d6;
}

/* CSS Properties */
.hljs-attribute,
.token.property {
  color: #8bb8d0;
}

/* CSS Values */
.hljs-selector-pseudo,
.token.value {
  color: #87ceab;
}

/* Meta / Preprocessor */
.hljs-meta,
.hljs-meta-keyword,
.token.atrule,
.token.important {
  color: #e5a755;
  font-weight: 500;
}

/* Additions (diff) */
.hljs-addition,
.token.inserted {
  color: #87ceab;
  background: rgba(135, 206, 171, 0.1);
}

/* Deletions (diff) */
.hljs-deletion,
.token.deleted {
  color: #e78a8a;
  background: rgba(231, 138, 138, 0.1);
}

/* Emphasis & Strong */
.hljs-emphasis,
.token.italic {
  font-style: italic;
}

.hljs-strong,
.token.bold {
  font-weight: 700;
}

/* Namespaces */
.token.namespace {
  opacity: 0.8;
}

/* Links in code */
.hljs-link,
.token.url {
  color: #8bb8d0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* Decorators / Annotations */
.hljs-meta .hljs-string,
.token.annotation {
  color: #87ceab;
}

/* Placeholder / Template literals */
.hljs-subst,
.token.template-string .token.interpolation {
  color: #e7e5e4;
}

.token.template-string .token.interpolation .token.interpolation-punctuation {
  color: #e78a8a;
}

/* Selection */
.highlight ::selection,
pre[class*="language-"] ::selection {
  background: rgba(194, 114, 78, 0.3);
  color: #fff;
}

/* ==========================================================================
   LANGUAGE-SPECIFIC OVERRIDES
   ========================================================================== */

/* JSON keys */
.language-json .hljs-attr,
.language-json .token.property {
  color: #c2724e;
}

/* Shell prompt */
.language-bash .hljs-variable,
.language-shell .hljs-variable {
  color: #e7e5e4;
}

/* Markdown */
.language-markdown .hljs-section {
  color: #c2724e;
  font-weight: 700;
}

.language-markdown .hljs-bullet {
  color: #e5a755;
}

/* YAML keys */
.language-yaml .hljs-attr {
  color: #c2724e;
}

/* CSS */
.language-css .hljs-selector-tag {
  color: #e78a8a;
}

.language-css .hljs-attribute {
  color: #8bb8d0;
}

/* SQL */
.language-sql .hljs-keyword {
  color: #d6a88a;
  text-transform: uppercase;
}

/* ==========================================================================
   COPY BUTTON
   ========================================================================== */

.code-block-wrapper {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: #78716c;
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease, color 150ms ease;
  user-select: none;
}

.code-block-wrapper:hover .code-copy-btn,
.highlight:hover .code-copy-btn,
pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #a8a29e;
}

.code-copy-btn--copied {
  color: #87ceab !important;
  background: rgba(135, 206, 171, 0.12) !important;
  border-color: rgba(135, 206, 171, 0.2) !important;
}

.code-copy-btn svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   INLINE CODE (overrides for when used outside article content)
   ========================================================================== */

:not(pre) > code[class*="language-"] {
  background: rgba(28, 25, 23, 0.08);
  color: #1c1917;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
  font-weight: 500;
  white-space: normal;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
  .highlight,
  .wp-block-code,
  pre[class*="language-"] {
    border-radius: 0;
    margin-left: -1rem;
    margin-right: -1rem;
    padding: 1rem;
    font-size: 0.8125rem;
  }

  .highlight[data-lang]::before,
  pre[data-lang]::before,
pre[data-language]::before {
    border-radius: 0 0 0 6px;
    font-size: 0.65rem;
  }

  .highlight.has-line-numbers,
  pre.line-numbers {
    padding-left: 3.5em;
  }

  .highlight .line-numbers,
  .line-numbers-rows {
    width: 2.8em;
    font-size: 0.8125rem;
  }

  .code-copy-btn {
    opacity: 1;
    font-size: 0.65rem;
  }
}

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  .highlight,
  .wp-block-code,
  pre[class*="language-"] {
    background: #f8f8f8 !important;
    color: #333 !important;
    border: 1px solid #ddd;
    page-break-inside: avoid;
  }

  .highlight code *,
  pre[class*="language-"] code * {
    color: #333 !important;
  }

  .code-copy-btn {
    display: none !important;
  }

  .highlight[data-lang]::before,
  pre[data-lang]::before,
pre[data-language]::before {
    color: #999 !important;
    background: #eee !important;
    border-color: #ddd !important;
  }
}
