/* Animation */
/* Critical shell geometry. Keep the first paint aligned with the hydrated layout. */
body {
  margin: 0;
  display: block;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
}

#highlight-gradient {
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  z-index: 0;
  width: 100%;
  height: 100vh;
  pointer-events: none;
}

astro-island {
  display: contents;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 70;
  display: block;
  width: 100%;
  height: 72px;
}

.site-header__bar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(1200px, calc(100% - 64px));
  height: 100%;
  margin: 0 auto;
}

.site-header__desktop {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 100%;
}

.site-header__actions,
.site-header__desktop-actions {
  display: flex;
  align-items: center;
}

.site-header__actions {
  justify-self: end;
  gap: 0.75rem;
}

.site-header__menu-button,
.site-header__mobile-layer {
  display: none;
}

#main-content > a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid transparent;
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

#main-content > a p {
  margin: 0;
}

#site-shell,
#site-shell *,
#site-shell *::before,
#site-shell *::after {
  box-sizing: border-box;
}

#site-shell {
  width: 100%;
  max-width: 70rem;
  margin-inline: auto;
  padding-inline: 1rem;
}

#main-content > main:not(.home-page) {
  margin-top: 1.5rem;
  align-items: flex-start;
}

#main-content > main:not(.home-page) > article {
  min-width: 0;
}

#content {
  min-width: 0;
  margin-top: 2rem;
  overflow-x: hidden;
}

@media (min-width: 640px) {
  #site-shell {
    padding-inline: 1.75rem;
  }
}

@media (min-width: 768px) {
  #main-content > main:not(.home-page) {
    display: flex;
    column-gap: 2.5rem;
  }

  #main-content > main:not(.home-page) > article {
    flex-grow: 1;
  }

  #main-content > main:not(.home-page) > #sidebar {
    position: sticky;
    top: 5rem;
    min-width: 12rem;
    flex-basis: 15rem;
    order: 2;
  }
}

@media (min-width: 1024px) {
  #site-shell {
    padding-inline: 2.5rem;
  }

  #main-content > main:not(.home-page) > #sidebar {
    flex-shrink: 0;
  }
}

@media (max-width: 767px) {
  .site-header {
    height: 64px;
  }

  .site-header__bar {
    grid-template-columns: 1fr auto;
    width: calc(100% - 40px);
  }

  .site-header__desktop,
  .site-header__desktop-actions {
    display: none;
  }

  .site-header__menu-button {
    display: grid;
  }

  .site-header__mobile-layer {
    display: block;
  }

  #main-content > main:not(.home-page) > #sidebar {
    display: none;
  }
}

@keyframes fade-in-up {
  0% {
    transform: translateY(2rem);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}
.animate {
  opacity: 0;
  animation: 300ms fade-in-up;
  animation-fill-mode: forwards;
}
@media (prefers-reduced-motion) {
  .animate {
    opacity: 0;
    animation: 100ms fade-in-up;
    animation-fill-mode: forwards;
  }
}
#content-header {
  animation-delay: 50ms;
}
#content {
  animation-delay: 100ms;
}
#sidebar {
  animation-delay: 150ms;
}

/* Katex */
span.katex-display {
  overflow-y: scroll;
  padding: 0.5rem;
}
.katex-html {
  overflow: auto hidden;
  padding: 3px;
}
.katex-html .base {
  margin-block: 0;
  margin-inline: auto;
}
.katex-html .tag {
  position: relative !important;
  display: inline-block;
  padding-inline-start: 0.5rem;
}

/* Shiki */
.astro-code {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--border));
  background-color: hsl(var(--code-bg) / var(--un-bg-opacity, 1)) !important;
  color: hsl(var(--code-fg));

  /* Code container */
  & pre {
    margin: 0;
    padding-inline: 0;
    background: none;
    overflow-x: scroll;
    color: inherit;

    & code {
      display: block;
      width: fit-content;
      min-width: 100%;
      min-height: 1.5rem;
      counter-reset: step;
      counter-increment: step 0;
      &::before {
        position: absolute;
        inset-inline-start: 0;
        width: 2.75rem;
        top: 0.8571429em;
        bottom: 0;
        content: '';
        display: block;
        background-color: hsl(var(--code-bg) / var(--un-bg-opacity, 1));
        z-index: 1;
      }
      & .line {
        padding-inline-end: 3rem;
        &::before {
          position: sticky;
          content: counter(step);
          counter-increment: step;
          color: hsl(var(--muted-foreground) / 0.7);
          background-color: hsl(var(--code-bg) / var(--un-bg-opacity, 1));
          inset-inline-start: 0;
          justify-content: end;
          display: inline-flex;
          width: 2rem;
          padding-inline-end: 0.75rem;
          box-sizing: content-box;
          z-index: 2;
        }
        &:last-child:empty,
        &:last-child:has(> span:empty:only-child) {
          display: none;
        }
      }
    }
  }

  /* Shiki transformer */
  &:has(code) {
    position: relative;
  }
  &:has(div.title) {
    padding-top: 2rem;
    & code::before {
      top: calc(2rem + 0.8571429em);
    }
  }
  & .language {
    transition: opacity 0.3s;
    position: absolute;
    top: 0.75rem;
    right: 0;
  }
  & button.copy {
    transition: opacity 0.3s;
    opacity: 0;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    user-select: none;

    & .success::before {
      content: 'Copied!';
      position: absolute;
      right: 100%;
      top: 0;
      bottom: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 0.75rem;
      padding: 0.5rem;
      margin-right: 0.5rem;
      border-radius: 0.25rem;
      color: hsl(var(--muted-foreground) / var(--un-text-opacity, 1));
      background-color: hsl(var(--primary-foreground) / var(--un-bg-opacity, 1));
      border: 1px solid hsl(var(--border) / var(--un-border-opacity, 1));
    }
    &.copied {
      & .success {
        display: block;
      }

      & .ready {
        display: none;
      }
    }
  }
  &:hover {
    button.copy {
      opacity: 1;
    }
    .language {
      opacity: 0;
    }
  }

  & .highlighted,
  & .diff {
    min-width: 100%;
    display: inline-block;
  }
  & .highlighted,
  & .highlighted::before {
    background-color: rgba(149, 166, 183, 0.32) !important;
  }

  & .diff {
    &.remove {
      background-color: rgba(244, 63, 94, 0.16);
      &::before {
        background-color: rgba(244, 63, 94, 0.16);
        content: '-';
      }
    }
    &.add {
      background-color: rgba(16, 185, 129, 0.16);
      &::before {
        background-color: rgba(16, 185, 129, 0.16);
        content: '+';
      }
    }
  }
}
.dark {
  .astro-code pre span {
    color: var(--shiki-dark) !important;
  }
  :not(pre) > code {
    color: hsl(var(--foreground));
  }
  :not(.astro-code) > code span {
    color: var(--shiki-dark, hsl(var(--foreground))) !important;
  }
}

/* Scroll bar */
:root {
  --scrollbar-width: 6px;
  --scrollbar-bg: #e0e0e0;
  --scrollbar-thumb-bg: #c0c0c0;
}
html.dark {
  --scrollbar-bg: #2e2e2e;
  --scrollbar-thumb-bg: #4e4e4e;
}
body::-webkit-scrollbar {
  height: 0;
}
::-webkit-scrollbar {
  width: 6px !important;
  height: 6px !important;
  background: #0000;
}
::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb-bg);
  border-radius: 999px;
  border: 2px solid var(--scrollbar-thumb-bg);
  opacity: 0.5;
}
::-webkit-scrollbar-corner {
  background: transparent;
}
::-webkit-scrollbar-track {
  background: transparent;
}
