/* Option 1 (Dark default) + Option 4 (Light) with 60s breathing #3E3E52 <-> #52526E */
@font-face {
  font-family: "MS PGothic";
  src: local("MS PGothic"), local("MS-PGothic"), url("/fonts/ms-pgothic.ttf") format("truetype");
  font-display: swap;
}

@keyframes breathe-bg {
  0%, 100% {
    background-color: #3E3E52;
  }
  50% {
    background-color: #52526E;
  }
}

@keyframes breathe-fg {
  0%, 100% {
    color: var(--breathe-fg-low);
  }
  50% {
    color: var(--breathe-fg-high);
  }
}

@keyframes copy-fade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

:root {
  color-scheme: dark;
  --bg: #282835;
  --surface: #3E3E52;
  --muted: #52526E;
  --text: #D2D2E6;
  --inv: #282835;
  --breathe-fg-low: #8E8EA8;
  --breathe-fg-high: #A2A2BB;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #E6E6EE;
  --surface: #D8D8E4;
  --muted: #3E3E52;
  --text: #282835;
  --inv: #E6E6EE;
  --breathe-fg-low: #3E3E52;
  --breathe-fg-high: #52526E;
}

:root[data-contrast="high"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1A1A1A;
  --text: #FFFFFF;
  --muted: var(--text);
  --inv: var(--bg);
}

:root[data-theme="light"][data-contrast="high"] {
  color-scheme: light;
  --bg: #FFFFFF;
  --surface: #F0F0F0;
  --text: #000000;
}

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

html {
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  font-family: "MS PGothic", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

::selection {
  background: var(--text);
  color: var(--inv);
}

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

a:hover,
a:focus-visible,
:root[data-contrast="high"] .prose a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

strong {
  font-weight: 600;
  color: var(--text);
}

em {
  font-style: italic;
  color: var(--text);
}

/* ---------- Hyphen bullets site-wide ---------- */

ul {
  list-style: none;
  margin: 0 0 12px;
  padding-left: 0;
}

ul li {
  position: relative;
  padding-left: 14px;
  margin: 4px 0;
}

ul li::before {
  content: "-";
  position: absolute;
  left: 0;
  color: var(--muted);
}

/* ---------- Display controls ---------- */

.display-controls {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
}

.display-controls button {
  min-height: 24px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: "MS PGothic", system-ui, sans-serif;
  font-size: 12px;
  cursor: pointer;
}

:root:not([data-contrast="high"]) .display-controls button {
  color: var(--breathe-fg-low);
  animation: breathe-fg 60s ease-in-out infinite;
}

.display-controls button:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.display-controls button:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 2px;
}

/* ---------- Homepage: centered Python http.server-style directory listing ---------- */

.dir-tree {
  width: fit-content;
  max-width: 100%;
  margin: auto 0;
}

.dir-tree h1 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
}

.dir-list {
  margin: 0;
}

.dir-list a {
  color: var(--text);
}

/* ---------- Inner pages (centered same as /) ---------- */

.page-shell {
  width: fit-content;
  max-width: min(720px, 100%);
  margin: auto 0;
  padding: 12px 0 24px;
}

.page-shell.wide {
  width: min(720px, 100%);
}

#site-header {
  margin-bottom: 18px;
}

#site-header nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
}

#site-header nav a {
  color: var(--muted);
}

#site-header nav a:hover,
#site-header nav a.active {
  color: var(--text);
}

main#content {
  width: 100%;
}

/* ---------- Byline ---------- */

.byline {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.byline time {
  color: var(--muted);
}

/* ---------- Article & prose ---------- */

.article-header {
  margin-bottom: 20px;
}

.article-header h1 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.prose h2,
.prose h3,
.prose h4 {
  margin: 20px 0 6px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.prose h2 {
  font-size: 16px;
}

.prose h3 {
  font-size: 14px;
  color: var(--text);
}

.prose p {
  margin: 0 0 12px;
}

.prose ol {
  margin: 0 0 12px;
  padding-left: 20px;
}

.prose ol li {
  margin: 3px 0;
}

.prose img,
.prose video {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.prose figure {
  margin: 16px 0;
}

.prose figcaption {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.prose blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  background-color: var(--surface);
  border-left: 3px solid var(--muted);
  border-radius: 0 8px 8px 0;
  color: var(--text);
  font-style: italic;
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 0.9em;
  background-color: var(--surface);
  color: var(--text);
  padding: 2px 4px;
  border-radius: 4px;
}

.prose pre {
  margin: 12px 0;
  padding: 10px 12px;
  background-color: var(--surface);
  color: var(--text);
  border-radius: 0;
  overflow-x: auto;
  line-height: 1.5;
}

.prose pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
  font-size: 11px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  margin: 12px 0;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--text);
}

.attachment:hover {
  text-decoration: underline;
}

.attachment:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  text-decoration: none;
}

.attachment-icon {
  flex: none;
  width: 20px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attachment-name {
  overflow-wrap: anywhere;
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
}

.demo-gifs {
  margin: 16px 0;
}

.demo-gif {
  display: block;
  width: min(480px, 100%);
  margin-bottom: 14px;
}

.demo-gif img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 0;
}

/* Keep the site's code block colors over Zola's inline defaults. */
.prose pre.giallo {
  background-color: var(--surface) !important;
  color: var(--text) !important;
}

.giallo > code {
  display: block;
}

.giallo-l {
  display: inline-block;
  min-height: 1lh;
  width: 100%;
}

:root[data-contrast="high"] .giallo > code {
  filter: brightness(1.1);
}

:root[data-theme="light"][data-contrast="high"] .giallo > code {
  filter: brightness(0.8);
}

.prose table {
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

.prose th,
.prose td {
  padding: 6px 12px;
  text-align: left;
  background-color: var(--surface);
  color: var(--text);
}

.prose th {
  background-color: var(--text);
  color: var(--inv);
  font-weight: 600;
}

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 28px;
  font-size: 13px;
}

/* ---------- 60s slow breathing #3E3E52 <-> #52526E ---------- */

:root:not([data-theme="light"]):not([data-contrast="high"]) .prose code:not(pre code),
:root:not([data-theme="light"]):not([data-contrast="high"]) .prose blockquote,
:root:not([data-theme="light"]):not([data-contrast="high"]) .prose td,
:root:not([data-theme="light"]):not([data-contrast="high"]) .gallery-item {
  animation: breathe-bg 60s ease-in-out infinite;
}

:root[data-theme="light"]:not([data-contrast="high"]) #site-header nav a:not(.active):not(:hover),
:root[data-theme="light"]:not([data-contrast="high"]) .dir-tree h1,
:root[data-theme="light"]:not([data-contrast="high"]) ul li::before,
:root[data-theme="light"]:not([data-contrast="high"]) .byline,
:root[data-theme="light"]:not([data-contrast="high"]) .byline time,
:root[data-theme="light"]:not([data-contrast="high"]) .empty-note {
  animation: breathe-fg 60s ease-in-out infinite;
}

a[data-copy] {
  position: relative;
  display: inline-block;
}

.copied-note {
  position: absolute;
  left: 100%;
  top: 0;
  font-size: inherit;
  line-height: inherit;
  font-weight: inherit;
  white-space: pre;
  color: var(--muted);
  pointer-events: none;
  animation: copy-fade 5s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  :root:not([data-theme="light"]) .prose code,
  :root:not([data-theme="light"]) .prose blockquote,
  :root:not([data-theme="light"]) .prose td,
  :root:not([data-theme="light"]) .gallery-item,
  :root[data-theme="light"] #site-header nav a,
  :root[data-theme="light"] .dir-tree h1,
  :root[data-theme="light"] ul li::before,
  :root[data-theme="light"] .byline,
  :root[data-theme="light"] .byline time,
  :root[data-theme="light"] .empty-note,
  .display-controls button {
    animation: none !important;
  }
}

/* ---------- Gallery (/gallery/) + pure-CSS lightbox ---------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.gallery-item {
  margin: 0;
  background-color: var(--surface);
  overflow: hidden;
}

.gallery-item a {
  display: block;
  text-decoration: none;
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--bg);
}

.gallery-item figcaption {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  padding: 24px;
  place-items: center;
}

.lightbox:target {
  display: grid;
}

.lightbox-backdrop {
  position: fixed;
  inset: 0;
}

.lightbox-content {
  position: relative;
  z-index: 1;
  max-width: min(92vw, 1100px);
  max-height: 90svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 82svh;
}

.lightbox-bar {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text);
}

.empty-note {
  font-size: 13px;
  color: var(--muted);
}

.footnote-definition {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0;
}

.footnote-definition p {
  display: inline;
}
