.hub-code-block {
  --hub-border: var(--border, 214 32% 91%);
  --hub-card: var(--card, 0 0% 100%);
  --hub-background: var(--background, 0 0% 100%);
  --hub-foreground: var(--foreground, 222.2 84% 4.9%);
  --hub-muted: var(--muted, 210 40% 96.1%);
  --hub-muted-foreground: var(--muted-foreground, 215.4 16.3% 46.9%);
  --hub-accent: var(--accent, 210 40% 96.1%);
  --hub-accent-foreground: var(--accent-foreground, 222.2 47.4% 11.2%);
  --hub-primary: var(--primary, 221.2 83.2% 53.3%);

  border: 1px solid hsl(var(--hub-border));
  border-radius: 1rem;
  background: hsl(var(--hub-card));
  box-shadow: none;
  overflow: hidden;
  margin: 1.5rem 0;
}

.hub-code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: hsl(var(--hub-card));
  border-bottom: 1px solid hsl(var(--hub-border));
}

.hub-code-block__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: hsl(var(--hub-foreground));
}

.hub-code-block__meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.hub-code-block__lang {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: hsl(var(--hub-muted-foreground));
}

.hub-code-block__copy {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.7rem;
  border: 1px solid hsl(var(--hub-border));
  background: hsl(var(--hub-background));
  color: hsl(var(--hub-foreground));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.hub-code-block__copy:hover {
  transform: translateY(-1px);
  border-color: hsl(var(--hub-accent));
  box-shadow: none;
}

.hub-code-block__copy.is-copied {
  background: hsl(var(--hub-accent));
  color: hsl(var(--hub-accent-foreground));
  border-color: hsl(var(--hub-accent));
}

.hub-code-block__toggle {
  border: 1px solid hsl(var(--hub-border));
  background: hsl(var(--hub-background));
  color: hsl(var(--hub-foreground));
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hub-code-block__toggle:hover {
  border-color: hsl(var(--hub-accent));
}

.hub-code-block__toggle-icon {
  display: inline-flex;
  align-items: center;
}

.hub-code-block__toggle-icon--collapse {
  display: none;
}

.hub-code-block__toggle[aria-expanded="true"] .hub-code-block__toggle-icon--expand {
  display: none;
}

.hub-code-block__toggle[aria-expanded="true"] .hub-code-block__toggle-icon--collapse {
  display: inline-flex;
}

.hub-code-block .hub-code-block__pre {
  margin: 0;
  position: relative;
  display: grid;
  grid-template-columns: minmax(4ch, max-content) minmax(0, 1fr);
  column-gap: 1.2rem;
  padding: 0;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.65;
  background: hsl(var(--hub-background));
}

.hub-code-block.is-collapsible .hub-code-block__pre {
  --hub-code-line-height: 1.65em;
}

.hub-code-block.is-collapsed .hub-code-block__pre {
  max-height: calc(var(--hub-code-line-height) * var(--hub-code-lines, 10));
  overflow-y: auto;
}

.hub-code-block.is-collapsed .hub-code-block__pre::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2.25rem;
  background: linear-gradient(to bottom, hsl(var(--hub-background) / 0), hsl(var(--hub-background) / 1));
  pointer-events: none;
}

.dark .hub-code-block.is-collapsed .hub-code-block__pre::after {
  background: linear-gradient(to bottom, hsl(var(--hub-muted) / 0), hsl(var(--hub-muted) / 0.2));
}

.hub-code-block .hub-code-block__code {
  display: block;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
  color: hsl(var(--hub-foreground));
  background: transparent;
  padding: 0;
  border-radius: 0;
  white-space: pre;
}

.hub-code-block__lines {
  position: static;
  width: auto;
  text-align: right;
  color: hsl(var(--hub-muted-foreground));
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
  pointer-events: none;
  user-select: none;
  padding-right: 0.7rem;
  border-right: 1px solid hsl(var(--hub-border));
  background: hsl(var(--hub-muted) / 0.4);
  box-sizing: border-box;
  white-space: normal;
  font-size: inherit;
  line-height: inherit;
  opacity: 0.65;
}

.hub-code-block__lines span {
  display: block;
}

.hub-code-block--editor .hub-code-block__pre {
  align-items: stretch;
}

.hub-code-block--editor:not(.is-collapsed) .hub-code-block__pre {
  max-height: none;
  overflow-y: visible;
}

.hub-code-block--editor .hub-code-block__lines,
.hub-code-block--editor .hub-code-block__input,
.hub-code-block--editor .hub-code-block__preview {
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}

.hub-code-block__editor-pane {
  position: relative;
  width: 100%;
}

.hub-code-block__preview {
  position: absolute;
  inset: 0;
  margin: 0;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  scrollbar-width: none;
  opacity: 1;
  z-index: 1;
}

.hub-code-block__preview .hub-code-block__code {
  display: block;
}

.hub-code-block__input {
  border: 0;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: hsl(var(--hub-primary));
  width: 100%;
  min-height: 180px;
  resize: vertical;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  padding: 0;
  margin: 0;
  white-space: pre;
  overflow-wrap: normal;
  position: relative;
  z-index: 2;
}

.hub-code-block__input::selection {
  background: hsl(var(--hub-accent) / 0.4);
}

.hub-code-block__editor-pane:focus-within {
  box-shadow: 0 0 0 2px hsl(var(--hub-primary) / 0.25);
  border-radius: 0.5rem;
}

.hub-code-block__input:focus {
  box-shadow: none;
}

.block-editor-writing-flow .hub-code-block--editor {
  max-width: var(--wp--style--global--content-size, 760px);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.hub-code-block__editor {
  padding: 1rem;
}

.hub-code-block__editor textarea,
.hub-code-block__editor .block-editor-plain-text {
  width: 100%;
  min-height: 180px;
  border-radius: 0.75rem;
  border: 1px dashed hsl(var(--hub-border));
  padding: 0.8rem 0.9rem;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  background: hsl(var(--hub-background) / 0.5);
  color: hsl(var(--hub-foreground));
}

.hub-code-block__code.hljs {
  background: transparent;
}

.hub-code-block__code .hljs-comment,
.hub-code-block__code .hljs-quote {
  color: #6b7280 !important;
  font-style: italic;
}

.hub-code-block__code .hljs-keyword,
.hub-code-block__code .hljs-selector-tag,
.hub-code-block__code .hljs-type {
  color: #7aa2f7 !important;
  font-weight: 600;
}

.hub-code-block__code .hljs-title,
.hub-code-block__code .hljs-function,
.hub-code-block__code .hljs-section,
.hub-code-block__code .hljs-name {
  color: #bb9af7 !important;
}

.hub-code-block__code .hljs-string,
.hub-code-block__code .hljs-attr,
.hub-code-block__code .hljs-attribute,
.hub-code-block__code .hljs-template-variable {
  color: #9ece6a !important;
}

.hub-code-block__code .hljs-number,
.hub-code-block__code .hljs-literal,
.hub-code-block__code .hljs-symbol {
  color: #ff9e64 !important;
}

.hub-code-block__code .hljs-built_in,
.hub-code-block__code .hljs-builtin-name,
.hub-code-block__code .hljs-params {
  color: #f7768e !important;
}

.hub-code-block__code .hljs-meta,
.hub-code-block__code .hljs-doctag {
  color: #7dcfff !important;
}

.hub-code-block__code .hljs-emphasis {
  font-style: italic;
}

.hub-code-block__code .hljs-strong {
  font-weight: 700;
}

@media (max-width: 640px) {
  .hub-code-block__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .hub-code-block__meta {
    width: 100%;
    justify-content: space-between;
  }
}

.dark .hub-code-block__pre {
  background: hsl(var(--hub-muted) / 0.1);
}
