:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --line: #dddddd;
  --margin-line: var(--line);
    --margin-gutter: clamp(1.25rem, 3.5vw, 2.5rem);
  --link: #0645ad;
  --visited: #5a3696;
  --code-bg: #f6f6f6;
  --highlight-bg: rgba(0, 0, 0, 0.05);
  --highlight-border: #bebebe;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    --bg: #151515;
    --text: #dfdfdf;
    --muted: #8c8c8c;
    --line: #2a2a2a;
    --margin-line: var(--line);
      --margin-gutter: clamp(1.25rem, 3.5vw, 2.5rem);
    --link: #6ca4ff;
    --visited: #b99bf2;
    --code-bg: #1f1f1f;
    --highlight-bg: rgba(255, 255, 255, 0.09);
    --highlight-border: #bbbbbb;
  }

  :root:not([data-theme="light"]) img {
    opacity: 0.9;
  }
}

:root[data-theme="light"] {
  color-scheme: light !important;
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --line: #dddddd;
  --margin-line: var(--line);
    --margin-gutter: clamp(1.25rem, 3.5vw, 2.5rem);
  --link: #0645ad;
  --visited: #5a3696;
  --code-bg: #f6f6f6;
  --highlight-bg: rgba(0, 0, 0, 0.05);
  --highlight-border: #bebebe;
}

:root[data-theme="dark"] {
  color-scheme: dark !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  --bg: #151515;
  --text: #dfdfdf;
  --muted: #8c8c8c;
  --line: #2a2a2a;
  --margin-line: var(--line);
    --margin-gutter: clamp(1.25rem, 3.5vw, 2.5rem);
  --link: #6ca4ff;
  --visited: #b99bf2;
  --code-bg: #1f1f1f;
  --highlight-bg: rgba(255, 255, 255, 0.09);
  --highlight-border: #bbbbbb;
}

:root[data-theme="light"] pre,
:root[data-theme="light"] code {
  color-scheme: light !important;
}

:root[data-theme="dark"] pre,
:root[data-theme="dark"] code {
  color-scheme: dark !important;
}

:root[data-theme="dark"] img {
  opacity: 0.9;
}

* {
  box-sizing: border-box;
}

html {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  font-size: 18px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  position: relative;
    min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
  background: var(--bg);
  color: var(--text);
}

body::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin-gutter);
  width: 1px;
  background: var(--line);
  pointer-events: none;
  z-index: 5;
}
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.site-header {
  width: 100%;
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: var(--margin-gutter) 0 1.25rem;
}

.site-header-inner {
  max-width: min(48rem, calc(100vw - var(--margin-gutter) - 1.25rem));
  margin: 0 1.25rem 0 var(--margin-gutter);
  padding: 0 1.5rem 0 1.5rem;
  box-sizing: border-box;
}

.page {
  max-width: min(48rem, calc(100vw - var(--margin-gutter) - 1.25rem));
  margin: 0 1.25rem 0 var(--margin-gutter);
  padding: 1.5rem 1.5rem 3.5rem 1.5rem;
  min-height: calc(100vh - 6rem);
  min-width: 0;
  box-sizing: border-box;
}

.site-header-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.site-title,
.site-title:visited {
  display: inline-block;
  font-size: 1.05rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.site-title:hover,
.site-title:visited:hover {
  color: var(--text);
  text-decoration: none;
}

.header-theme-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  padding: 0.15rem 0.45rem;
  font-size: 0.9rem;
  line-height: 1.2;
}

.header-theme-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
}

.corner-tools {
  position: fixed;
  bottom: clamp(1.25rem, 3.5vw, 2.25rem);
  right: clamp(1.25rem, 3.5vw, 2.25rem);
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}

.corner-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  pointer-events: auto;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, opacity 0.2s ease, transform 0.2s ease;
  user-select: none;
}

.corner-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.corner-btn.scroll-to-top {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.35s ease, transform 0.35s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.corner-btn.scroll-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.85rem;
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

.site-header nav a,
.site-header nav a:visited {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.site-header nav a[aria-current="page"],
.site-header nav a[aria-current="page"]:visited {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

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

a[aria-current="page"] {
  color: var(--text);
  text-decoration: none;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.28;
  letter-spacing: -0.015em;
  position: relative;
  scroll-margin-top: 2rem;
}

h1 {
  font-size: 1.65rem;
  margin: 1.8rem 0 0.5rem;
}

h2 {
  font-size: 1.35rem;
  margin: 1.7rem 0 0.45rem;
}

h3 {
  font-size: 1.15rem;
  margin: 1.35rem 0 0.4rem;
}

h4 {
  font-size: 1.02rem;
  margin: 1.15rem 0 0.35rem;
}

h5,
h6 {
  font-size: 0.95rem;
  margin: 1rem 0 0.3rem;
}

.page-heading h1 {
  margin-top: 0;
}

p,
ul,
ol,
pre,
blockquote,
figure,
table {
  margin: 1.05rem 0;
}

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

li {
  margin: 0.25rem 0;
}

.item-list,
.article-list,
.project-list {
  list-style: none;
  padding-left: 0;
}

.item-list li {
  margin: 0 0 0.55rem;
}

.item-list time,
.meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.item-list time {
  margin-left: 0.35rem;
  white-space: nowrap;
}

.item-list p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Article List */
.article-list {
  margin: 1.25rem 0 2rem;
}

.article-item {
  margin: 0 0 1.25rem;
}

.article-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.article-title {
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.12em;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.article-date {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.article-desc {
  margin: 0.2rem 0 0;
  color: var(--text);
  opacity: 0.85;
  font-size: 0.92rem;
  line-height: 1.45;
}

.article-meta {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.article-source {
  color: var(--muted);
  font-size: 0.85rem;
}

.meta-sep {
  color: var(--line);
}

.external-arrow {
  display: inline-block;
  font-size: 0.82em;
  opacity: 0.6;
  text-decoration: none;
  vertical-align: 0.05em;
  margin-left: 0.1em;
}

.external-articles {
  margin-top: 2.5rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

/* Projects List */
.project-list {
  margin: 1.25rem 0 2rem;
}

.project-item {
  margin: 0 0 1.45rem;
}

.project-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.project-title a {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.project-desc {
  margin: 0.25rem 0 0;
  color: var(--text);
  opacity: 0.88;
  font-size: 0.95rem;
  line-height: 1.5;
}

.project-desc strong,
.project-desc b {
  font-weight: normal;
}

.tldr {
  border-left: 2px solid var(--line);
  padding-left: 0.85rem;
  font-style: italic;
  color: var(--text);
  opacity: 0.9;
}

img {
  max-width: 100%;
  height: auto;
}

figure {
  margin-left: 0;
  margin-right: 0;
}

figcaption {
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
  margin-top: 0.45rem;
  text-align: left;
}

.anchor-link,
.anchor-link:visited {
  color: var(--muted);
  opacity: 0;
  position: absolute;
  text-decoration: none;
  transform: translateX(-1.2rem);
  font-weight: normal;
}

.anchor-link::before {
  content: "#";
}

.anchor-link:hover,
.anchor-link:visited:hover,
.anchor-link:focus,
.anchor-link:visited:focus {
  color: var(--text);
  text-decoration: none;
}

h2:hover .anchor-link,
h3:hover .anchor-link,
h4:hover .anchor-link,
h5:hover .anchor-link,
h6:hover .anchor-link,
.anchor-link:focus {
  opacity: 1;
}

pre,
code {
  color-scheme: inherit !important;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

:not(pre) > code {
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.32em;
  border-radius: 3px;
  vertical-align: baseline;
}

pre {
  font-size: 1rem;
  background: transparent !important;
  overflow-x: auto;
  padding: 0.5rem 0;
  line-height: 1.4;
}

pre code {
  display: grid;
  width: max-content;
  min-width: 100%;
  padding: 0;
  background: transparent;
}

.giallo-l {
  min-height: 1.4em;
  padding: 0 0.6rem;
  border-left: 3px solid transparent;
  box-sizing: border-box;
}

.giallo-l[style*="background-color"] {
  background-color: var(--highlight-bg) !important;
  border-left-color: var(--highlight-border) !important;
}

.giallo-ln {
  display: inline-block;
  margin-right: 0.4em;
  min-width: 3ch;
  opacity: 0.75;
  padding-right: 0.4em;
  text-align: right;
  user-select: none;
}

/* Footnotes */
.footnote-reference {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.45em;
}

.footnote-reference a,
.footnote-reference a:visited {
  color: var(--link);
  text-decoration: none;
  font-weight: 600;
  padding: 0 0.1em;
}

.footnote-reference a:hover,
.footnote-reference a:visited:hover {
  color: var(--link);
  text-decoration: underline;
}

h6#footnotes {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 2.5rem 0 0.8rem;
}

.footnote-definition {
  position: relative;
  padding-left: 1.6rem;
  margin: 0.5rem 0;
  font-size: 0.92rem;
  line-height: 1.5;
}

.footnote-definition .footnote-definition-label {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  width: 1.2rem;
  text-align: right;
  line-height: 1.5;
}

.footnote-definition p {
  margin: 0 0 0.4rem;
}

.footnote-definition p:last-child {
  margin-bottom: 0;
}

.footnote-definition ul,
.footnote-definition ol {
  margin: 0.3rem 0;
  padding-left: 1.2rem;
}

.footnote-backlink,
.footnote-backlink:visited {
  text-decoration: none;
  font-family: system-ui, -apple-system, sans-serif;
  margin-left: 0.3em;
  opacity: 0.65;
  color: var(--link);
}

.footnote-backlink:hover,
.footnote-backlink:visited:hover {
  opacity: 1;
  color: var(--link);
  text-decoration: underline;
}

blockquote {
  border-left: 2px solid var(--line);
  color: var(--text);
  opacity: 0.9;
  font-style: italic;
  margin: 1.25rem 0;
  padding-left: 1rem;
}

table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  width: 100%;
}

th,
td {
  border: 1px solid var(--line);
  padding: 0.25rem 0.4rem;
  text-align: left;
  vertical-align: top;
}

hr {
  border: 0;
  height: auto;
    text-align: center;
    margin: 2.25rem 0;
  }
  
  hr::before {
    content: "§";
    display: inline-block;
    color: var(--muted);
    font-size: 1.15rem;
    opacity: 0.7;
  }
  
  .site-footer {
    margin-top: 3.5rem;
    padding: 1.5rem 0 0.5rem;
    text-align: center;
  }
  
  .site-footer-mark {
    color: var(--muted);
    font-size: 0.95rem;
    letter-spacing: 0.65em;
    opacity: 0.6;
    user-select: none;
}

.horizontal-center {
  text-align: left;
}

.pagination {
  border-top: 1px solid var(--line);
  margin-top: 1.5rem;
  padding-top: 0.75rem;
}

/* Table of Contents */
.toc-sidebar {
  display: none;
}

@media (min-width: 1180px) {
  .toc-sidebar {
    display: block;
    position: fixed;
    top: 9.75rem;
    left: calc(var(--margin-gutter) + 48rem + 2rem);
    width: clamp(12rem, 15vw, 14.5rem);
    max-height: calc(100vh - 12rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
    z-index: 10;
  }

  .toc-sidebar::-webkit-scrollbar {
    display: none;
  }
}

.toc-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.65rem;
  user-select: none;
}

.toc-list,
.toc-sublist,
.toc-subsublist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list {
  border-left: 1px solid var(--line);
  padding-left: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.toc-sublist {
  padding-left: 0.75rem;
  margin-top: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.toc-subsublist {
  padding-left: 0.65rem;
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.toc-item,
.toc-subitem,
.toc-subsubitem {
  position: relative;
}

.toc-link,
.toc-link:visited {
  display: block;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease, font-weight 0.15s ease;
  overflow-wrap: break-word;
  word-break: normal;
}

.toc-link:hover,
.toc-link:visited:hover {
  color: var(--text);
  text-decoration: none;
}

.toc-item.has-active > .toc-link,
.toc-item.has-active > .toc-link:visited {
  color: var(--text);
  font-weight: 600;
}

.toc-item.active > .toc-link,
.toc-item.active > .toc-link:visited,
.toc-subitem.active > .toc-link,
.toc-subitem.active > .toc-link:visited,
.toc-subsubitem.active > .toc-link,
.toc-subsubitem.active > .toc-link:visited {
  color: var(--text);
  font-weight: 600;
}

.toc-item.active > .toc-link::before,
.toc-item.has-active > .toc-link::before {
  content: "";
  position: absolute;
  left: calc(-0.75rem - 1px);
  top: 0.15em;
  bottom: 0.15em;
  width: 2px;
  background: var(--text);
  border-radius: 1px;
}

/* Image Zoom */
article img,
figure img,
.horizontal-center img {
  cursor: zoom-in;
}

.image-zoom-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
  outline: none;
  box-sizing: border-box;
}

.image-zoom-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.image-zoom-dialog:not([open]) {
  display: none;
}

.image-zoom-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: zoomFadeIn 0.18s ease-out;
}

@keyframes zoomFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.image-zoom-toolbar {
  position: absolute;
  top: clamp(0.75rem, 2.5vw, 1.25rem);
  right: clamp(0.75rem, 2.5vw, 1.25rem);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 10002;
}

.image-zoom-btn,
.image-zoom-btn:visited {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(30, 30, 30, 0.9);
  color: #f0f0f0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.image-zoom-btn:hover,
.image-zoom-btn:visited:hover {
  background: #000000;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
}

@media (max-width: 520px) {
  .image-zoom-external span {
    display: none;
  }
}

.image-zoom-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 3.5rem 1rem 1.5rem;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  cursor: zoom-out;
}

.image-zoom-content img {
  max-width: min(92vw, 1200px);
  max-height: calc(100% - 2.5rem);
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.75);
  cursor: zoom-out;
  animation: zoomScaleUp 0.18s ease-out;
}

@keyframes zoomScaleUp {
  from {
    transform: scale(0.96);
    opacity: 0.85;
  }
  to {
    transform: scale(1);
  }
}

.image-zoom-caption {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  text-align: center;
  max-width: min(90vw, 48rem);
  font-style: italic;
  cursor: default;
}

@media (max-width: 640px) {
  body::before {
    display: none;
  }

  .site-header {
    border-bottom: 1px solid var(--line);
    padding: 1.25rem 0 0.85rem;
  }

  .site-header-inner,
  .page {
    margin: 0;
    max-width: 100%;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .page {
    padding-top: 1.25rem;
    padding-bottom: 2.5rem;
    min-height: auto;
  }

  .article-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .header-theme-toggle {
    display: inline-block;
  }

  .corner-theme-toggle {
    display: none !important;
  }

  .corner-tools {
    bottom: 1.25rem;
    right: 1.25rem;
  }
}

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

  h1 {
    font-size: 1.45rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  h3 {
    font-size: 1.05rem;
  }

  .site-header-inner,
  .page {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

@page {
  size: auto;
  margin: 20mm;
}

@media print {
  body::before,
  .corner-tools,
  .theme-toggle,
  .site-header nav,
  .pagination,
  .anchor-link,
  .toc-sidebar,
  .image-zoom-dialog {
    display: none !important;
  }

  body,
  html {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
    line-height: 1.5;
  }

  .site-header {
    border-bottom: none !important;
    padding: 0 !important;
    margin: 0 0 1.5rem 0 !important;
  }

  .site-header-inner {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .site-title {
    font-size: 13pt !important;
    text-decoration: none !important;
    color: #000000 !important;
    font-weight: 600;
  }

  .page {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  a {
    color: #000000 !important;
    text-decoration: underline;
  }

  h1, h2, h3 {
    page-break-after: avoid;
    break-after: avoid;
  }

  table, pre, blockquote, img, figure {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  thead {
    page-break-after: avoid;
    break-after: avoid;
  }
}
