:root {
  --bg: #f5f5f5;
  --bg-pattern: rgba(0, 0, 0, 0.05);
  --panel: #ffffff;
  --text-primary: #333333;
  --text-accent: #003399;
  --text-muted: #777777;
  --text: var(--text-primary);
  --muted: var(--text-muted);
  --line: #cccccc;
  --link: var(--text-accent);
  --link-hover: #e6f3ff;
  --shadow: rgba(0, 0, 0, 0.12);
  --toggle-bg: #f2f2f2;
  --toggle-text: var(--text-primary);
  --toggle-border: #b8b8b8;
  --info-bg: #f0f0f0;
  --table-key-bg: #e6e6e6;
  --title: #003399;
  --h2: #cc6600;
  --h3: #009900;
  --accent-tree: var(--text-muted);
}

[data-theme="dark"] {
  --bg: #161616;
  --bg-pattern: rgba(255, 255, 255, 0.04);
  --panel: #1f1f1f;
  --text-primary: #ebebeb;
  --text-accent: #9bb6ff;
  --text-muted: #bbbbbb;
  --text: var(--text-primary);
  --muted: var(--text-muted);
  --line: #565656;
  --link: var(--text-accent);
  --link-hover: #2c4258;
  --shadow: rgba(0, 0, 0, 0.55);
  --toggle-bg: #2a2a2a;
  --toggle-text: var(--text-primary);
  --toggle-border: #707070;
  --info-bg: #2a2a2a;
  --table-key-bg: #303030;
  --title: #9bb6ff;
  --h2: #ffb267;
  --h3: #8ee9a4;
  --accent-tree: var(--text-muted);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 17px;
}

body {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    repeating-linear-gradient(
      0deg,
      var(--bg-pattern) 0px,
      var(--bg-pattern) 1px,
      transparent 1px,
      transparent 4px
    );
  padding: 1rem;
}

.page {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 1.1rem 1.2rem 1.3rem;
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
  box-shadow: 0 0 20px var(--shadow);
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.theme-toggle {
  border: 1px solid var(--toggle-border);
  background: var(--toggle-bg);
  color: var(--toggle-text);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--link-hover);
  outline: none;
}

header h1 {
  margin: 0;
  color: var(--title);
  font-size: clamp(1.1rem, 4vw, 1.5rem);
}

.subtitle {
  margin: 0.3rem 0 0.7rem;
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.terminal-prompt {
  color: var(--accent-tree);
}

.ascii-inline {
  white-space: nowrap;
}

.ascii-spinner::before {
  content: "|";
  display: inline-block;
  width: 1ch;
  animation: ascii-spin 1s steps(1, end) infinite;
}

.ascii-cursor {
  display: inline-block;
  margin-left: 0.1ch;
  animation: ascii-cursor-blink 1.1s steps(1, end) infinite;
}

@keyframes ascii-spin {
  0% {
    content: "|";
  }

  25% {
    content: "/";
  }

  50% {
    content: "-";
  }

  75% {
    content: "\\";
  }

  100% {
    content: "|";
  }
}

@keyframes ascii-cursor-blink {
  0%,
  49% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0;
  }
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 0;
}

nav a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

nav a::before {
  content: "> ";
  color: var(--accent-tree);
}

main {
  margin-top: 0.25rem;
}

.section-card {
  margin-top: 0.95rem;
  padding: 0.25rem 0;
  border: 0;
  background: transparent;
}

h2 {
  margin: 0 0 0.45rem;
  color: var(--h2);
  font-size: clamp(1.05rem, 3.5vw, 1.15rem);
}

h2::after {
  content: " $";
  color: var(--accent-tree);
}

p,
ul,
ol {
  margin: 0.4rem 0;
}

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

ul li::marker {
  color: var(--accent-tree);
}

.quick-links {
  margin-top: 0.75rem;
}

.ascii-profile {
  margin: 0.55rem 0 0.1rem;
  text-align: center;
}

.ascii-profile-art {
  display: inline-block;
  margin: 0;
  padding: 0.45rem;
  background: var(--panel);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  font-size: 9.5px;
  line-height: 1;
  white-space: pre;
  text-align: left;
  max-width: 100%;
  overflow-x: auto;
}

.ascii-profile-art:empty::before {
  content: "loading pv-small.txt ...";
  color: var(--text-muted);
}

[data-theme="dark"] .ascii-profile-art {
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.35);
}

.award-badge {
  display: inline-block;
  padding: 0.02rem 0.26rem;
  border: 1px solid var(--line);
  background: var(--table-key-bg);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.award-badge::before {
  content: "[[";
  margin-right: 0.24ch;
  color: var(--accent-tree);
}

.award-badge::after {
  content: "]]";
  margin-left: 0.24ch;
  color: var(--accent-tree);
}

.award-best {
  border-color: var(--h3);
  color: var(--h3);
}

.award-hm {
  border-color: var(--h3);
  color: var(--h3);
}

.author-me {
  color: var(--link);
  font-weight: 550;
}

.pub-branch {
  color: var(--text);
  font-size: inherit;
  white-space: nowrap;
}

.related-works {
  margin: 0.35rem 0 0.9rem;
  padding: 0.55rem 0.6rem 0.65rem;
  border: 1px dashed var(--line);
  background: var(--info-bg);
}

.related-works-title {
  margin: 0;
  color: var(--text);
  font-size: 0.87rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.related-works-meta {
  display: none;
  margin-left: 0.4rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.related-works-title::-webkit-details-marker {
  display: none;
}

.related-works-title::before {
  content: "[+] ";
  color: var(--accent-tree);
}

.related-works[open] .related-works-title::before {
  content: "[-] ";
}

.related-works-body {
  margin-top: 0.45rem;
}

.rw-mobile-hint {
  display: none;
  margin: 0 0 0.45rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.related-works-graph-mount {
  display: block;
}

.related-works-graph {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.rw-mobile {
  display: none;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0.45rem;
}

.rw-mobile-topics {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.32rem;
  margin-bottom: 0.45rem;
}

.rw-mobile-topic {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.73rem;
  line-height: 1.1;
  padding: 0.2rem 0.34rem;
  cursor: pointer;
}

.rw-mobile-topic.is-active {
  border-color: var(--h3);
  color: var(--h3);
}

.rw-mobile-topic.is-dim {
  opacity: 0.35;
}

.rw-mobile-papers {
  display: grid;
  gap: 0.32rem;
}

.rw-mobile-paper {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.2;
  padding: 0.3rem 0.38rem;
  cursor: pointer;
}

.rw-mobile-paper-title {
  display: block;
  font-size: 0.77rem;
}

.rw-mobile-paper-tags {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.69rem;
  color: var(--text-muted);
}

.rw-mobile-paper.is-active {
  border-color: var(--h3);
  color: var(--h3);
  background: var(--link-hover);
}

.rw-mobile-paper.is-active .rw-mobile-paper-tags {
  color: var(--h3);
}

.rw-mobile-paper.is-dim {
  opacity: 0.35;
}

.rw-link {
  stroke: var(--line);
  stroke-width: 1.1;
  opacity: 0.72;
  transition: opacity 0.12s ease, stroke 0.12s ease, stroke-width 0.12s ease;
  vector-effect: non-scaling-stroke;
}

.rw-node {
  cursor: pointer;
  transition: opacity 0.12s ease;
}

.rw-node rect {
  fill: var(--bg);
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.rw-topic rect {
  fill: var(--table-key-bg);
}

.rw-node text {
  fill: var(--text);
  font-family: "Courier New", Courier, monospace;
  font-size: 10.2px;
  transition: fill 0.12s ease;
}

.related-works.is-active .rw-node,
.related-works.is-active .rw-link {
  opacity: 0.08;
}

.related-works .rw-node.rw-active,
.related-works .rw-link.rw-active {
  opacity: 1;
}

.rw-node.rw-active rect {
  stroke: var(--h3);
  stroke-width: 1.8;
  fill: var(--link-hover);
}

.rw-node.rw-active text {
  fill: var(--h3);
  font-weight: 600;
}

.rw-link.rw-active {
  stroke: var(--h3);
  stroke-width: 2.2;
  opacity: 1;
}

.rw-node:focus,
.rw-node:focus-visible {
  outline: none;
}

.rw-node:focus-visible rect {
  stroke: var(--h2);
  stroke-width: 1.6;
}

.publication {
  margin-bottom: 0.95rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.publication::before {
  content: "";
}

.git-timeline {
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
}

.git-entry {
  position: relative;
  margin: 0 0 1rem;
  padding-left: 1.35rem;
}

.git-entry::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  top: 0.95rem;
  bottom: -0.85rem;
  width: 1px;
  background: var(--line);
}

.git-entry:last-child::before {
  display: none;
}

.git-entry-head {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.83rem;
}

.git-entry-head::before {
  content: "*";
  position: absolute;
  left: 0;
  top: 0.01rem;
  color: var(--h3);
  font-weight: bold;
}

.git-prefix {
  color: var(--text-muted);
}

.git-hash {
  color: var(--link);
}

.git-branch {
  color: var(--h2);
}

.git-entry-role {
  margin: 0.12rem 0 0.14rem;
  color: var(--text);
  font-weight: bold;
}

.git-entry-meta {
  margin: 0;
  color: var(--text-muted);
}

.git-entry-meta em {
  font-style: normal;
}

.nerd-line {
  margin: 0.9rem 0 0;
  padding-top: 0.65rem;
  border-top: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.84rem;
}

a {
  color: var(--link);
}

a:hover,
a:focus-visible {
  background: var(--link-hover);
  outline: none;
}

@media (max-width: 680px) {
  html {
    font-size: 16px;
  }

  body {
    padding: 0.5rem;
  }

  .page {
    padding: 0.8rem 0.85rem 1rem;
    box-shadow: none;
  }

  .header-bar,
  nav {
    align-items: flex-start;
  }

  .git-entry {
    padding-left: 1.15rem;
  }

  .git-entry-head {
    font-size: 0.8rem;
  }

  .related-works {
    margin-top: 0.45rem;
    padding: 0.45rem 0.4rem 0.55rem;
  }

  .ascii-profile {
    margin-top: 0.45rem;
  }

  .ascii-profile-art {
    font-size: 8px;
  }

  .related-works:not([open]) .related-works-meta {
    display: inline;
  }

  .related-works[open] .related-works-meta {
    display: none;
  }

  .related-works-graph {
    display: none;
  }

  .rw-mobile-hint {
    display: block;
  }

  .rw-mobile {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ascii-spinner::before,
  .ascii-cursor {
    animation: none;
  }
}

@media (min-width: 1100px) {
  html {
    font-size: 18px;
  }
}
