/* ── Variables ── */
:root {
  --bg: #fafafa;
  --fg: #171717;
  --muted: #737373;
  --accent: #005fcc;
  --accent-hover: #004c99;
  --border: #e5e5e5;
  --surface: #f3f3f3;
  --highlight: #fffb7a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #e5e5e5;
    --muted: #a3a3a3;
    --accent: #4d9fff;
    --accent-hover: #80bbff;
    --border: #262626;
    --surface: #141414;
    --highlight: #3f3a00;
  }
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #e5e5e5;
  --muted: #a3a3a3;
  --accent: #4d9fff;
  --accent-hover: #80bbff;
  --border: #262626;
  --surface: #141414;
  --highlight: #3f3a00;
}

[data-theme="light"] {
  --bg: #fafafa;
  --fg: #171717;
  --muted: #737373;
  --accent: #005fcc;
  --accent-hover: #004c99;
  --border: #e5e5e5;
  --surface: #f3f3f3;
  --highlight: #fffb7a;
}

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

* {
  margin: 0;
}

html {
  background: var(--bg);
  color: var(--fg);
  font-family: "Times New Roman", Times, serif;
  font-size: 20px;
  line-height: 1.5;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

body {
  max-width: 68ch;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* ── Header ── */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.5rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}

header a.site-title {
  font-weight: 650;
  font-size: 1rem;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.01em;
}

header a.site-title:hover {
  color: var(--accent);
}

#theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 0;
  transition: color 0.15s, border-color 0.15s;
}

#theme-toggle:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin-block: 2rem 0.75rem;
  color: var(--fg);
}

h1 { font-size: 1.75rem; margin-top: 0; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p {
  margin-block: 0.875rem;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.15em;
  transition: color 0.15s;
}

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

img, video, iframe {
  display: block;
  max-width: 100%;
  height: auto;
  margin-block: 1.5rem;
}

iframe, video {
  width: 100%;
  border: none;
}

blockquote {
  margin-block: 1.5rem;
  padding-left: 1.25rem;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-style: italic;
}

code, kbd, samp {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9em;
  background: var(--surface);
  padding: 0.15em 0.35em;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-block: 1.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin-block: 1.5rem;
  font-size: 0.9375rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

th {
  background: var(--surface);
  font-weight: 600;
}

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

li {
  margin-block: 0.375rem;
}

li::marker {
  color: var(--muted);
}

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

::selection {
  background: var(--highlight);
  color: var(--fg);
}

/* ── Homepage ── */
.homepage-intro {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 2.5rem;
}

.homepage-intro .intro-text > *:first-child {
  margin-top: 0;
}

.canvas-container-3d {
  width: 110px;
  height: 110px;
  overflow: hidden;
  background: transparent;
}

.canvas-container-3d canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  outline: none;
}

.page-list {
  list-style: none;
  padding: 0;
}

.page-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding-block: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.page-list li:first-child {
  border-top: 1px solid var(--border);
}

.page-list a {
  text-decoration: none;
  font-weight: 500;
}

.page-list a:hover {
  text-decoration: underline;
}

.page-list .date {
  font-size: 0.875rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Article ── */
article > *:first-child {
  margin-top: 0;
}

/* ── Tags ── */
.tags {
  margin-block: 0.5rem 1.5rem;
}

.tags a {
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: none;
  margin-right: 0.75rem;
}

.tags a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.tags a::before {
  content: "#";
}

/* ── Backlinks ── */
.backlinks {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.backlinks h3 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

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

.backlinks li {
  margin-block: 0.375rem;
}

.backlinks a {
  font-size: 0.9375rem;
}

/* ── Footer ── */
footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--muted);
}

/* ── Utilities ── */
.iframe169 { aspect-ratio: 16 / 9; }
.iframe1   { aspect-ratio: 1 / 1; }
.iframe45  { aspect-ratio: 4 / 5; }

/* ── Mobile ── */
@media (max-width: 520px) {
  html { font-size: 15px; }
  body { padding: 1.5rem 1rem 3rem; }
  .homepage-intro { grid-template-columns: 80px 1fr; gap: 1rem; }
  .canvas-container-3d { width: 80px; height: 80px; }
  h1 { font-size: 1.5rem; }
}
