@font-face {
  font-family: "LXGW WenKai TC";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/lxgw-wenkai-tc-400.woff2") format("woff2");
}

@font-face {
  font-family: "Roboto Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/roboto-mono-400.woff2") format("woff2");
}

@font-face {
  font-family: "Roboto Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/roboto-mono-400-italic.woff2") format("woff2");
}

@font-face {
  font-family: "Roboto Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/roboto-mono-700.woff2") format("woff2");
}

@font-face {
  font-family: "ZCOOL XiaoWei";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/zcool-xiaowei-400.woff2") format("woff2");
}

@layer reset, base, layout, content, utilities;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    min-height: 100%;
  }

  body {
    margin: 0;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}

@layer base {
  :root {
    color-scheme: light;
    --bg: #fff;
    --fg: #222;
    --muted: #aaa;
    --line: #e0e0e0;
    --line-strong: #d8d8d8;
    --accent: #c0392b;
    --accent-hover: #dd5353;
    --surface: #fff;
    --note-bg: #fff7d6;
    --code-bg: #1f1f1f;
    --inline-code-bg: #fafafa;
    --inline-code-fg: #666;
    --shadow: 2px 2px 10px rgb(0 0 0 / 10%);
    --measure: 780px;
    --shell: 1000px;
    font-family:
      "LXGW WenKai TC", "STKaiti", "KaiTi", "Noto Serif CJK SC",
      "Songti SC", cursive;
  }

  body {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    background: var(--bg);
    color: var(--fg);
    font-size: 1rem;
    line-height: normal;
  }

  a {
    color: var(--accent);
    text-underline-offset: 0.16em;
  }

  a:hover {
    color: var(--accent-hover);
  }

  a[href^="http"]::after {
    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M320 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l82.7 0L201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L448 109.3l0 82.7c0 17.7 14.3 32 32 32s32-14.3 32-32l0-160c0-17.7-14.3-32-32-32L320 0zM80 32C35.8 32 0 67.8 0 112L0 432c0 44.2 35.8 80 80 80l320 0c44.2 0 80-35.8 80-80l0-112c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 112c0 8.8-7.2 16-16 16L80 448c-8.8 0-16-7.2-16-16l0-320c0-8.8 7.2-16 16-16l112 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L80 32z"/></svg>');
    display: inline-block;
    width: 10px;
    margin-inline-start: 2px;
    opacity: 0.5;
    vertical-align: baseline;
  }

  :focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent), transparent 35%);
    outline-offset: 3px;
  }
}

@layer layout {
  .site-shell {
    width: min(93%, var(--shell));
    margin-inline: auto;
  }

  .site-header {
    max-width: var(--shell);
    margin-inline: auto;
  }

  .site-nav p {
    margin: 0;
  }

  .site-main {
    flex: 1;
    padding: 20px;
  }

  .content-layout {
    display: flex;
    gap: 0;
    align-items: flex-start;
  }

  .page {
    flex: 1 1 auto;
    max-width: var(--measure);
    min-width: 0;
  }

  .sidebar {
    flex: 0 0 280px;
    margin-left: 2em;
    overflow: hidden;
    padding: 20px;
    background: var(--surface);
    border: 1px dashed var(--line);
    box-shadow: var(--shadow);
  }

  .sidebar h2,
  .sidebar h3 {
    margin-block: 0 10px;
    padding-block-end: 0.35rem;
    border-bottom: 2px solid var(--accent);
    color: var(--accent);
    font-size: 18px;
  }

  .sidebar ul {
    padding: 0;
    margin: 0;
    list-style: none;
  }

  .sidebar li {
    margin-block: 8px;
  }

  .site-footer {
    width: 100%;
    margin-top: auto;
    padding-block: 10px;
    color: #aaa;
    box-shadow: 0 1px 0 rgb(0 0 0 / 10%) inset;
    font-family: "Microsoft YaHei", system-ui, sans-serif;
    font-size: smaller;
  }

  .site-footer p {
    margin: 0;
  }

  .site-footer a {
    color: #aaa;
    text-decoration: none;
  }

  .site-footer a:hover {
    text-decoration: underline;
  }

  @media (max-width: 1062px) {
    .content-layout {
      flex-direction: column;
    }

    .sidebar {
      width: 100%;
      flex-basis: auto;
      margin-left: 0;
      margin-top: 20px;
      padding: 0;
      border: 0;
      background: transparent;
      box-shadow: none;
    }
  }

}

@layer content {
  :where(h1, h2, h3, h4) {
    line-height: normal;
    margin-block: 0.67em;
  }

  h1 {
    text-align: center;
  }

  p,
  ul,
  ol,
  blockquote,
  pre,
  table {
    margin-block: 1rem;
  }

  blockquote {
    padding: 0.5em 1em;
    background: #f9f9f9;
    border-left: 5px solid var(--accent);
    word-break: break-word;
  }

  article blockquote,
  article .note {
    margin: 0 0 18px;
    padding: 1px 20px;
    background: var(--note-bg);
  }

  img {
    display: block;
    width: 100%;
    height: auto;
    margin: 1rem auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow 0.3s, transform 0.3s;
  }

  img:hover {
    box-shadow: 2px 2px 10px rgb(0 0 0 / 30%);
    transform: scale(1.03);
  }

  table {
    display: block;
    max-width: 100%;
    min-width: 50%;
    margin-inline: auto;
    overflow-x: auto;
    border-collapse: collapse;
    background: var(--surface);
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    font-size: 0.86rem;
    text-align: left;
  }

  th {
    padding: 0.6rem 0.5rem;
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    font-weight: 400;
  }

  td {
    padding: 0.55rem 0.5rem 0.1rem;
    color: var(--accent);
    word-break: break-all;
  }

  pre {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 1em 0;
    padding: 1rem;
    background: var(--code-bg);
    border-radius: 8px;
    scrollbar-width: none;
  }

  pre::-webkit-scrollbar {
    display: none;
  }

  .code-block {
    position: relative;
    margin: 1em 0;
  }

  .code-block pre {
    margin: 0;
  }

  pre,
  code {
    font-family:
      "Roboto Mono", "ZCOOL XiaoWei", ui-monospace, "SFMono-Regular",
      Consolas, "Liberation Mono", monospace;
  }

  pre code {
    color: #ddd;
  }

  :not(pre) > code {
    padding: 0 1px;
    margin-inline: 4px;
    color: var(--inline-code-fg);
    background: var(--inline-code-bg);
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.9em;
    word-break: break-all;
  }

  .source-line {
    display: block;
    min-width: max-content;
  }

  .line-number {
    display: inline-block;
    min-width: 2.25rem;
    margin-inline-end: 0.75rem;
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--code-bg);
    box-shadow:
      -1rem 0 0 var(--code-bg),
      1rem 0 0 var(--code-bg);
    color: #777;
    text-align: right;
    user-select: none;
  }

  .copy-code {
    position: absolute;
    top: 0.7em;
    right: 0.7em;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    opacity: 0.3;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1;
  }

  .copy-code::before {
    display: block;
    width: 100%;
    height: 100%;
    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="white" d="M384 336h-192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16h140.1L400 115.9V320c0 8.8-7.2 16-16 16zM192 384h192c35.3 0 64-28.7 64-64V107.9c0-12.7-5.1-24.9-14.1-33.9L374.1 14.1C365.1 5.1 352.9 0 340.1 0H192c-35.3 0-64 28.7-64 64v256c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64v256c0 35.3 28.7 64 64 64h192c35.3 0 64-28.7 64-64v-32h-48v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16h32v-48H64z"/></svg>');
  }

  .copy-code.copied::before {
    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="white" d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>');
  }

  .copy-code:hover,
  .copy-code.copied {
    opacity: 1;
    transform: scale(1.1);
  }

  .toast-stack {
    position: fixed;
    z-index: 1000;
    top: 1rem;
    right: 1rem;
    display: grid;
    gap: 0.5rem;
    pointer-events: none;
  }

  .toast {
    width: min(16rem, calc(100vw - 2rem));
    padding: 0.65rem 0.85rem;
    color: #fff;
    background: rgb(40 40 40 / 92%);
    border-left: 4px solid #6ad4af;
    box-shadow: 2px 2px 10px rgb(0 0 0 / 18%);
    font-family: "Microsoft YaHei", system-ui, sans-serif;
    font-size: 0.9rem;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.24s, transform 0.24s;
  }

  .toast-error {
    border-left-color: var(--accent);
  }

  .toast-leaving {
    opacity: 0;
    transform: translateY(-0.35rem);
  }

  body.lightbox-open {
    overflow: hidden;
  }

  .image-lightbox {
    position: fixed;
    z-index: 999;
    inset: 0;
    display: grid;
    grid-template-columns: minmax(2.75rem, 1fr) minmax(0, auto) minmax(2.75rem, 1fr);
    place-items: center;
    padding: 2rem;
    background: rgb(0 0 0 / 82%);
  }

  .image-lightbox[hidden] {
    display: none;
  }

  .image-lightbox figure {
    display: grid;
    max-width: min(92vw, 1200px);
    max-height: 92vh;
    margin: 0;
    place-items: center;
  }

  .image-lightbox img {
    width: auto;
    max-width: 100%;
    max-height: calc(92vh - 3rem);
    margin: 0;
    border: 1px solid rgb(255 255 255 / 18%);
    border-radius: 8px;
    box-shadow: 0 10px 36px rgb(0 0 0 / 40%);
    cursor: default;
    transform: none;
  }

  .image-lightbox img:hover {
    box-shadow: 0 10px 36px rgb(0 0 0 / 40%);
    transform: none;
  }

  .image-lightbox figcaption {
    max-width: 100%;
    margin-top: 0.75rem;
    color: #fff;
    font-size: 0.9rem;
    text-align: center;
  }

  .image-lightbox button {
    color: #fff;
    background: rgb(0 0 0 / 36%);
    border: 1px solid rgb(255 255 255 / 25%);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
  }

  .image-lightbox button:hover,
  .image-lightbox button:focus-visible {
    background: rgb(0 0 0 / 60%);
    transform: scale(1.05);
  }

  .image-lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    font-size: 1.65rem;
    line-height: 1;
  }

  .image-lightbox-nav {
    width: 2.5rem;
    height: 4rem;
    border-radius: 4px;
    font-size: 2.5rem;
    line-height: 1;
  }

  .image-lightbox-prev {
    justify-self: end;
    margin-right: 1rem;
  }

  .image-lightbox-next {
    justify-self: start;
    margin-left: 1rem;
  }

  @media (max-width: 640px) {
    .toast-stack {
      inset: 0.75rem 0.75rem auto;
      justify-items: end;
    }

    .image-lightbox {
      grid-template-columns: 1fr 1fr;
      grid-template-rows: 1fr auto;
      gap: 0.75rem;
      padding: 3.5rem 1rem 1rem;
    }

    .image-lightbox figure {
      grid-column: 1 / -1;
      max-width: 100%;
      max-height: calc(100vh - 7rem);
    }

    .image-lightbox img {
      max-height: calc(100vh - 9rem);
    }

    .image-lightbox-nav {
      width: 3.25rem;
      height: 2.5rem;
      font-size: 2rem;
    }

    .image-lightbox-prev,
    .image-lightbox-next {
      justify-self: center;
      margin: 0;
    }
  }

  .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .katex-display > .katex {
    display: inline-block;
    white-space: nowrap;
  }

  .katex-display::-webkit-scrollbar {
    display: none;
  }
}

@layer utilities {
  .skip-link {
    position: absolute;
    left: 1rem;
    top: 1rem;
    transform: translateY(-150%);
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--line);
  }

  .skip-link:focus {
    transform: translateY(0);
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto !important;
      transition-duration: 0.001ms !important;
      animation-duration: 0.001ms !important;
      animation-iteration-count: 1 !important;
    }
  }
}
