.code-title {
  font-size: 0.75em;
  font-style: italic;
}

code span {
  font-style: var(--shiki-light-font-style);
  font-weight: var(--shiki-light-font-weight);
}

span.tab {
  display: inline-block;
  tab-size: 2;
}

:is([data-theme="tokyo_night"]) code span {
  font-style: var(--shiki-tokyo-font-style) !important;
  font-weight: var(--shiki-tokyo-font-weight) !important;
  color: var(--shiki-tokyo) !important;
}

:is([data-theme="nord"]) code span {
  font-style: var(--shiki-song-font-style) !important;
  font-weight: var(--shiki-song-font-weight) !important;
  color: var(--shiki-song) !important;
}

:is([data-theme="song_ci"]) code span {
  font-style: var(--shiki-song-font-style) !important;
  font-weight: var(--shiki-song-font-weight) !important;
  color: var(--shiki-song) !important;
}

:is([data-theme="nord_night"]) code span {
  font-style: var(--shiki-nord-font-style) !important;
  font-weight: var(--shiki-nord-font-weight) !important;
  color: var(--shiki-nord) !important;
}

:is([data-theme="mocha"]) code span {
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  color: var(--shiki-dark) !important;
}

:is([data-theme="rose_pine"]) code span {
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  color: var(--shiki-rose) !important;
}

figure.shiki {
  margin: 0.5em 0;
  border-radius: 8px;
  border: 0.5px solid var(--surface0);
  overflow: auto;
  background: var(--mantle);
  color: var(--text);
  svg {
    width: 1em;
    color: transparent;
    cursor: pointer;
    transition:
      color 0.3s,
      transform 0.3s ease;
  }

  &:hover {
    svg {
      color: var(--text);
      &:hover {
        color: var(--blue);
        transform: scale(1.2);
      }
    }
  }
}

.shiki-tools {
  display: flex;
  min-height: 1.5em;
  justify-content: space-between;
  font-family: var(--font-mono);
  padding: 0.3em 1em;
  user-select: none;
  overflow: hidden;
  position: relative;
  > .left {
    gap: 5px;
    display: flex;
    align-items: center;
  }

  > .center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    overflow: hidden;
    min-width: 0;
  }

  > .right {
    gap: 10px;
    display: flex;
    align-items: center;
  }
}

.shiki-tools > .right > .copy-notice {
  position: absolute;
  white-space: nowrap;
  visibility: hidden;
  z-index: 1000;
  padding: 0 5px 0 0;
  transform: translate(-110%);
  transition: visibility 0.2s ease;
  &.show {
    visibility: visible;
  }
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  &:has(input:checked) > svg {
    color: var(--blue);
  }
}

figure.shiki:has(.toggle-wrap input:checked) > pre.shiki > code {
  white-space: pre-wrap;
  word-break: break-all;
}

.traffic-lights {
  display: flex;
  align-items: center;
  margin-left: -0.5em;
}

.traffic-light {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  margin-left: 0.5em;
  position: relative;
  &.red {
    background-color: var(--red);
  }

  &.yellow {
    background-color: var(--yellow);
  }

  &.green {
    background-color: var(--green);
  }
}

@keyframes code-expand-pulse {
  0%,
  to {
    opacity: 0.6;
  }

  50% {
    opacity: 0.1;
  }
}

.code-expand-btn {
  position: absolute;
  bottom: 1rem;
  width: 100%;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1em;
  cursor: pointer;
  > .collapse-icon {
    display: none;
  }
  &.expand-done > .expand-icon {
    display: none;
  }
  &.expand-done > .collapse-icon {
    display: block;
  }
  > svg {
    padding: 6px 0;
    animation: code-expand-pulse 1.2s infinite;
  }
}

pre.shiki {
  background: var(--mantle);
  padding: 0.6em;
  > code {
    text-align: left;
    counter-reset: step;
    counter-increment: step 0;
    padding: 0 !important;
    background: none !important;
    border: none !important;
    width: 100%;
    margin: 0;
    font-family: var(--font-mono);
  }
}

figure.shiki[data-collapsible="true"] {
  position: relative;
}

figure.shiki[data-collapsible="true"] > pre.shiki {
  position: relative;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

figure.shiki[data-collapsible="true"]:not(.expanded) > pre.shiki:after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(transparent 0%, hsl(from var(--mantle) h s l / 0.8), 30%, var(--mantle) 100%);
  opacity: 1;
}

figure.shiki[data-collapsible="true"].expanded > .code-expand-btn {
  transform: translateY(0);
}

span.line {
  display: block;
  width: fit-content;
  min-width: 100%;
  &:before {
    content: counter(step);
    counter-increment: step;
    width: 1.2rem;
    margin-right: 1.2rem;
    display: inline-block;
    text-align: right;
    color: var(--subtext0);
  }
}

span.line.diff {
  &.remove {
    background-color: hsl(from var(--red) h s l / 0.2);
    &:before {
      content: "-";
      color: var(--red);
    }
  }

  &.add {
    background-color: hsl(from var(--green) h s l / 0.2);
    &:before {
      content: "+";
      color: var(--green);
    }
  }
}

span.line.highlighted {
  background-color: hsl(from var(--blue) h s l / 0.2);
  &.error {
    background-color: hsl(from var(--red) h s l / 0.2);
  }

  &.warning {
    background-color: hsl(from var(--yellow) h s l / 0.2);
  }
}

span.highlighted-word {
  background-color: hsl(from var(--yellow) h s l / 0.3);
  border-radius: 4px;
  margin: -1px -2px;
  padding: 1px 2px;
}

pre.shiki.has-focused > code {
  > .line {
    filter: blur(3px);
    opacity: 0.7;
    transition:
      filter 0.35s,
      opacity 0.35s;
  }

  > .line.focused,
  &:hover .line {
    filter: blur(0);
    opacity: 1;
  }
}
