:not(dialog) {
  margin: 0;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    interpolate-size: allow-keywords;
  }
}

body {
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

img, picture, video, canvas, svg {
  max-width: 100%;
  display: block;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

p {
  text-wrap: pretty;
}

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

#root, #__next {
  isolation: isolate;
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: normal;
  font-weight: 400;
  src: url("../fonts/ibm-plex-sans-v23-latin-regular.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: italic;
  font-weight: 400;
  src: url("../fonts/ibm-plex-sans-v23-latin-italic.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: normal;
  font-weight: 600;
  src: url("../fonts/ibm-plex-sans-v23-latin-600.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: italic;
  font-weight: 600;
  src: url("../fonts/ibm-plex-sans-v23-latin-600italic.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: normal;
  font-weight: 700;
  src: url("../fonts/ibm-plex-sans-v23-latin-700.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: IBM Plex Sans;
  font-style: italic;
  font-weight: 700;
  src: url("../fonts/ibm-plex-sans-v23-latin-700italic.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: STIX Two Math;
  font-style: normal;
  font-weight: 400;
  src: url("../fonts/stix-two-math-v12-latin-regular.woff2") format("woff2");
}

@view-transition {
  navigation: auto;
}

:root {
  color-scheme: light dark;
  --fresh-sky: #60b6e2;
  --frozen-water: #cbfbf0;
  --icy-blue: #bae5fd;
  --yale-blue: #104d70;
  --sandy-brown: #ffb36b;
  --ochre: #e17f23;
  --background: light-dark(#fff, #16181c);
  --text: light-dark(#111, #e6e6e6);
  --text-muted: light-dark(#717171, #9a9a9a);
  --text-soft: light-dark(#3c3c3c, #c4c4c4);
  --surface: light-dark(#f4f4f4, #23262b);
  --border: light-dark(#ccc, #3a3e45);
  --link-color: light-dark(var(--yale-blue), var(--fresh-sky));
  --rem-8px: .5rem;
  --rem-12px: calc(12 / 16 * 1rem);
  --rem-14px: calc(14 / 16 * 1rem);
  --rem-18px: calc(18 / 16 * 1rem);
  --rem-21px: calc(21 / 16 * 1rem);
  --rem-24px: 1.5rem;
  --rem-27px: calc(27 / 16 * 1rem);
  --rem-40px: 2.5rem;
  --rem-53px: calc(53 / 16 * 1rem);
  --rem-56px: 3.5rem;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

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

html {
  background-color: var(--background);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  padding: 0 1rem;
  font-family: IBM Plex Sans, Sarasa UI TC, Sarasa Gothic TC, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Source Han Sans TW VF, Noto Sans TC VF, Source Han Sans TW, Noto Sans TC, PingFang TC, Microsoft JhengHei UI, Microsoft JhengHei, Roboto, Ubuntu, Cantarell, Noto Sans, Comic Sans MS, sans-serif;

  @media screen and (width >= 1200px) {
    font-size: 18px;
  }
}

body {
  max-width: 45rem;
  margin: auto;
}

.site-header {
  justify-content: space-between;
  align-items: center;
  padding: 2rem 0;
  display: flex;
}

.logo-link {
  width: 4rem;
  height: 4rem;
  display: block;

  & img {
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    border: 3px solid #0000;
  }

  &.is-current {
    -webkit-user-select: none;
    user-select: none;
    cursor: not-allowed;
  }

  &:not(.is-current):hover img {
    border-color: var(--border);
  }
}

.theme-toggle {
  width: 2.75rem;
  height: 2.75rem;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
  place-items: center;
  margin-right: -.625rem;
  padding: 0;
  display: grid;

  &[hidden] {
    visibility: hidden;
    display: grid;
  }

  & svg {
    width: 1.5rem;
    height: 1.5rem;
  }
}

.skip-link {
  background-color: var(--surface);
  padding: .5rem .75rem;
  position: absolute;
  top: -4rem;
  left: 1rem;

  &:focus {
    top: .5rem;
  }
}

main {
  padding-top: .4rem;
  padding-bottom: 4rem;

  & + footer {
    color: var(--text-muted);
    padding-bottom: 2rem;
  }
}

:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.3;
}

h1 {
  font-size: var(--rem-40px);
  margin: 0 0 2rem;
}

h2 {
  font-size: var(--rem-27px);
  margin: 2.5rem 0 1.5rem;
}

h3 {
  font-size: var(--rem-24px);
  margin: 2rem 0 1.5rem;
}

h4 {
  font-size: var(--rem-21px);
  margin: 1.5rem 0;
}

p, ul, ol {
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

ul, ol {
  padding-left: 1.5rem;
}

li {
  margin-bottom: .2rem;
}

a {
  color: var(--link-color);
  text-decoration: underline;
}

strong {
  font-weight: 600;
}

time {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.post-meta {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

h1:has( + .post-meta) {
  margin-bottom: .75rem;
}

blockquote {
  background-color: var(--surface);
  color: var(--text-soft);
  margin: 0 0 1.5rem;
  padding: 1rem;

  & > :last-child {
    margin-bottom: 0;
  }
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

pre, code {
  font-family: IBM Plex Mono, JetBrains Mono, ui-monospace, SFMono-Regular, SF Mono, Menlo, Cascadia Mono, Consolas, Ubuntu Mono, Roboto Mono, DejaVu Sans Mono, Liberation Mono, Sarasa Mono TC, Sarasa Fixed TC, monospace;
}

:not(pre) > code {
  word-break: break-all;
  background-color: var(--surface);
}

pre {
  background-color: var(--surface);
  font-size: var(--rem-14px);
  margin: 0 0 1.5rem;
  padding: 1rem;
  overflow: auto;

  & code {
    tab-size: 2;
    line-height: 1.5;
  }
}

table {
  text-align: left;
  border-collapse: collapse;
  white-space: nowrap;
  width: 100%;
  margin-bottom: 1.5rem;
  display: block;
  overflow: auto;
}

thead {
  background-color: var(--surface);
}

th {
  font-size: var(--rem-14px);
  padding: .5rem;
}

td {
  padding: .85rem .5rem;
}

tbody tr:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

img, picture, video, svg {
  max-width: 100%;
  display: block;
}

img {
  height: auto;
}

figure {
  margin: 0 0 1.5rem;

  & img {
    background-color: var(--surface);
  }

  & figcaption {
    font-size: var(--rem-14px);
    text-align: center;
    color: var(--text-soft);
    margin-top: .5rem;
  }
}

.icon {
  vertical-align: -.125em;
  display: inline-block;
}

.postlist {
  margin: 0;
  padding: 0 0 0 2rem;
  list-style: none;
}

.postlist-item {
  counter-increment: start-from -1;
  flex-wrap: wrap;
  align-items: baseline;
  margin-bottom: 1rem;
  display: flex;

  &:before {
    content: counter(start-from) ". ";
    font-variant-numeric: tabular-nums;
    width: 2rem;
    margin-left: -2rem;
  }

  & a {
    @media screen and (width >= 1200px) {
      text-underline-offset: .25rem;
      -webkit-text-decoration: underline wavy;
      text-decoration: underline wavy;
    }
  }
}

.postlist-date, .postlist-item:before {
  font-size: var(--rem-14px);
  color: var(--text-muted);
}

.postlist-link {
  font-size: var(--rem-21px);
  flex-basis: 100%;
  font-weight: 700;
  line-height: 1.4;
  text-decoration-thickness: 1px;
}

a:has( > .citation) {
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

.footnote-ref {
  font-size: var(--rem-12px);
  line-height: 0;

  & a {
    padding: 0 .15em;
    text-decoration: none;
  }
}

.footnotes, .bibliography {
  border-top: 1px solid var(--border);
  font-size: var(--rem-14px);
  color: var(--text-soft);
  margin-top: 3rem;
  padding-top: 1.5rem;
  line-height: 1.5;
}

.bibliography-title {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.footnotes-list {
  margin: 0;
  padding-left: 1.5rem;

  & p {
    margin: 0;
  }
}

.footnote-backref {
  font-family: system-ui;
  text-decoration: none;
}

.csl-entry {
  text-indent: -2rem;
  overflow-wrap: anywhere;
  padding-left: 2rem;
}

.footnote-item, .csl-entry {
  margin-bottom: .5rem;
  scroll-margin-top: 1rem;

  &:target {
    background-color: var(--surface);
    box-shadow: 0 0 0 .25rem var(--surface);
  }
}

.csl-entry {
  text-indent: -2rem;
  overflow-wrap: anywhere;
  margin-bottom: .75rem;
  padding-left: 2rem;
  line-height: 1.5;

  &:target {
    background-color: var(--surface);
  }
}

.footnotes-sep {
  display: none;
}

.footnotes {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;

  & p {
    margin: 0;
  }
}

math {
  font-family: STIX Two Math, math;

  &[display="block"] {
    margin-bottom: 1.5rem;
    overflow: auto hidden;
  }
}

.post-footer {
  font-size: var(--rem-14px);
  color: var(--text-muted);
  justify-content: space-between;
  margin-top: 3rem;
  display: flex;

  & a {
    border: 2px solid var(--border);
    color: var(--text-soft);
    padding: .375rem;
    text-decoration: none;

    &:hover {
      background-color: var(--surface);
    }
  }
}

.island {
  margin-bottom: 1.5rem;
}

.counter {
  background-color: var(--surface);
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  display: flex;

  & .counter-label {
    font-size: var(--rem-14px);
    color: var(--text-soft);
    margin-right: auto;
  }

  & output {
    text-align: center;
    font-variant-numeric: tabular-nums;
    min-width: 2.5ch;
    font-weight: 700;
  }

  & button {
    width: 2.75rem;
    height: 2.75rem;
    font: inherit;
    font-size: var(--rem-21px);
    color: inherit;
    background-color: var(--background);
    border: 1px solid var(--border);
    cursor: pointer;
  }
}

a[href$="/atom.xml"] svg {
  color: light-dark(var(--ochre), var(--sandy-brown));
}
