/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --fg: #1a1a1a;
  --bg: #fff;
  --muted: #6b6b6b;
  --border: #e0e0e0;
  --link: #1a6fb5;
  --link-visited: #5b4a9e;
  --code-bg: #f6f8fa;
  --max-width: 56rem;
}

html { font-size: 17px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.7;
  padding: 0 1.5rem;
}

/* Layout */
header, main, footer {
  max-width: var(--max-width);
  margin: 0 auto;
}

header {
  padding: 2rem 0 1.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

header nav {
  display: flex;
  gap: 2.5rem;
}

header nav a {
  text-decoration: none;
  font-size: 1.05rem;
  color: var(--muted);
  transition: color 0.15s;
}

header nav a:visited { color: var(--muted); }
header nav a:hover { color: var(--fg); }
header nav a.active { color: var(--fg); font-weight: 600; }
header nav a.nav-right { margin-left: auto; }

main { padding-bottom: 3rem; min-height: 50vh; }

footer {
  padding: 1.5rem 0 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

/* Typography */
h1 { font-size: 1.8rem; margin: 0 0 1.2rem; line-height: 1.3; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; margin: 2.5rem 0 0.75rem; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; margin: 2rem 0 0.5rem; }
h4 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }

p { margin: 0 0 1rem; }

/* Post date */
p.post-date { color: var(--muted); font-size: 0.92rem; margin: -0.8rem 0 1.2rem; }

/* Citations and references */
sup.cite { font-size: 0.72em; line-height: 0; }
sup.cite a { text-decoration: none; }
ol.references { font-size: 0.92rem; margin-left: 1.8rem; }
ol.references li { margin-bottom: 0.4rem; padding-left: 0.2rem; }
ol.references li:target { background: #fff8e1; }

/* Notice box */
.notice {
  background: #fff8e1;
  border-left: 4px solid #f9a825;
  padding: 0.8rem 1.2rem;
  margin-bottom: 1.5rem;
  border-radius: 0 4px 4px 0;
  font-size: 0.95rem;
  line-height: 1.6;
}
.notice p:last-child { margin-bottom: 0; }

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

ul, ol { margin: 0 0 1rem 1.5rem; }
li { margin-bottom: 0.2rem; line-height: 1.5; }
li > ul, li > ol { margin-top: 0.15rem; margin-bottom: 0; }
li > p { margin-bottom: 0.2rem; }

blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

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

/* Code */
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 0 0 1.2rem;
  border-radius: 5px;
  line-height: 1.5;
  border: 1px solid var(--border);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.85em;
}

/* Pygments / codehilite */
.codehilite { margin: 0 0 1.2rem; }
.codehilite pre { margin: 0; }

/* Codehilite table (used for line-numbered source views) */
.codehilitetable {
  display: table;
  max-width: 100%;
  font-size: 1rem;
  border: none;
  margin: 0;
}
.codehilitetable td {
  text-align: left;
  border: none;
  padding: 0;
  vertical-align: top;
}
.codehilitetable .linenos {
  width: 1%;
  padding-right: 0.8rem;
  user-select: none;
}
.codehilitetable .linenos pre {
  background: none;
  border: none;
  color: var(--muted);
  text-align: right;
}
.codehilitetable .code { width: 99%; }
.codehilitetable .code pre { overflow-x: auto; }

/* Source code page (minimal chrome) */
.source-page {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.source-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--code-bg);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.source-breadcrumb { color: var(--muted); }
.source-breadcrumb a { color: var(--link); text-decoration: none; }
.source-breadcrumb a:hover { text-decoration: underline; }
.source-breadcrumb .sep { margin: 0 0.3rem; color: var(--border); }

.source-raw {
  color: var(--link);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  margin-left: 1.5rem;
}
.source-raw:hover { text-decoration: underline; }

.source-code {
  flex: 1;
  padding: 0;
  max-width: none;
}

.source-code .codehilite {
  margin: 0;
  border-radius: 0;
}

.source-code .codehilitetable {
  width: 100%;
}

.source-code .codehilitetable .linenos {
  padding-left: 1rem;
}

.source-code .codehilitetable .code pre {
  padding-right: 1.5rem;
}

/* Tables */
table {
  border-collapse: collapse;
  margin: 0 0 1.2rem;
  font-size: 0.92em;
  overflow-x: auto;
  display: block;
  max-width: fit-content;
}

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

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

td { text-align: center; }

/* Nested Cayley tables */
.cayley-tables {
  display: table;
  border: none;
}
.cayley-tables > tbody > tr > th,
.cayley-tables > tbody > tr > td {
  border: none;
  padding: 0 1rem 0 0;
  vertical-align: top;
}
.cayley-tables > tbody > tr > td:last-child { padding-right: 0; }
.cayley-tables table {
  display: table;
  margin: 0;
  font-size: 1em;
}

/* Table of contents */
.toc {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.8rem 1.2rem;
  margin-bottom: 2rem;
  font-size: 0.92rem;
  line-height: 1.5;
}

.toc > ul { margin: 0; padding-left: 1.2rem; }
.toc ul { margin-bottom: 0; }
.toc li { margin-bottom: 0.15rem; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* Post list */
.post-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.post-list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.post-list li:last-child { border-bottom: none; }

.post-list a {
  text-decoration: none;
  font-size: 1.1rem;
  color: var(--fg);
}

.post-list a:visited { color: var(--fg); }
.post-list a:hover { color: var(--link); }

.post-list .post-date {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

/* MathJax overrides */
mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

/* Post files box */
.post-files {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.8rem 1.2rem;
  margin-top: 2.5rem;
  font-size: 0.92rem;
}

.post-files h3 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.post-files ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-files li { margin-bottom: 0.2rem; }
.post-files li:last-child { margin-bottom: 0; }

.post-files a { text-decoration: none; }
.post-files a:hover { text-decoration: underline; }

.raw-link {
  color: var(--muted);
  font-size: 0.82em;
  margin-left: 0.3rem;
}
.raw-link:hover { color: var(--link); }

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

/* Lightbox */
main img.lightbox-enabled { cursor: zoom-in; }

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
  padding: 1.5rem;
}

.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.profile-photo {
  float: right;
  width: 10rem;
  height: 10rem;
  object-fit: cover;
  border-radius: 50%;
  margin: 0 0 1rem 1.5rem;
}

/* Contact links */
.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin: 1.5rem 0;
  clear: both;
}

.contact-links a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  transition: color 0.15s;
}

.contact-links a:visited { color: var(--muted); }
.contact-links a:hover { color: var(--link); }

.contact-links svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 600px) {
  html { font-size: 15px; }
  h1 { font-size: 1.5rem; }
  header {
    flex-direction: column;
    gap: 0.5rem;
  }
}
