/* Mikhail Mansion — monospace archive
 * Grid conventions adapted from "The Monospace Web" by Oskar Wickström (MIT).
 * Everything aligns to a character cell (1ch) and a fixed line-height baseline. */

@import url("https://fonts.cdnfonts.com/css/jetbrains-mono-2");

:root {
  --font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --line-height: 1.2rem;
  --border-thickness: 2px;
  --text-color: #111;
  --text-color-alt: #777;
  --background-color: #fbfbfa;
  --background-color-alt: #eee;

  --font-weight-normal: 450;
  --font-weight-medium: 600;
  --font-weight-bold: 800;

  /* Type scale — exactly three sizes. Hierarchy beyond this comes from
   * weight, uppercase, and color, never from new sizes. */
  --text-large: 1.2rem; /* page titles + masthead */
  --text-base: 0.9rem; /* body, tables, nav, h2/h3 */
  --text-small: 0.7rem; /* captions, meta, footer, labels */

  font-family: var(--font-family);
  font-weight: var(--font-weight-normal);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

/* Vertical rhythm: one line-height between adjacent siblings. */
* + * {
  margin-top: var(--line-height);
}

html {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--background-color);
  color: var(--text-color);
}

body {
  width: 100%;
  min-width: 320px; /* stop the layout squishing thinner; scroll instead */
  max-width: calc(min(80ch, round(down, 100%, 1ch)));
  padding: calc(var(--line-height) * 2) 2ch;
  font-size: var(--text-base);
  line-height: var(--line-height);
  overflow-x: hidden;
}

@media screen and (max-width: 480px) {
  :root {
    font-size: 14px;
  }
  body {
    padding: var(--line-height) 1ch;
  }
  /* Let the masthead tagline and footer links wrap rather than clip. */
  .site-header .meta,
  .site-footer .right {
    white-space: normal;
  }
}

/* ---- Headings ---- */

h1,
h2,
h3 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height);
  margin: calc(var(--line-height) * 2) 0 var(--line-height);
}

h1 {
  font-size: var(--text-large);
  line-height: calc(var(--line-height) * 2);
  text-transform: uppercase;
}

h2 {
  font-size: var(--text-base);
  text-transform: uppercase;
}

h3 {
  font-size: var(--text-base);
}

p {
  margin-bottom: var(--line-height);
  word-break: break-word;
  hyphens: auto;
}

a {
  color: var(--text-color);
  text-decoration-thickness: var(--border-thickness);
  text-underline-offset: 2px;
}

strong {
  font-weight: var(--font-weight-bold);
}
em {
  font-style: italic;
}

.lede,
.detail-meta {
  color: var(--text-color-alt);
  font-size: var(--text-small);
}

hr {
  position: relative;
  display: block;
  height: var(--line-height);
  margin: calc(var(--line-height) * 1.5) 0;
  border: none;
}
hr::after {
  content: "";
  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;
  width: 100%;
  height: 0;
  border-top: calc(var(--border-thickness) * 3) double var(--text-color);
}

/* ---- Tables (archive index + masthead) ---- */

table {
  width: calc(round(down, 100%, 1ch));
  border-collapse: collapse;
  margin: 0;
}

th,
td {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) / 2)
    calc(1ch - var(--border-thickness) / 2)
    calc(var(--line-height) / 2 - var(--border-thickness));
  line-height: var(--line-height);
  vertical-align: top;
  text-align: left;
}

.width-auto {
  width: 100%;
}

/* ---- Masthead ---- */

.site-header {
  margin-bottom: calc(var(--line-height) * 2);
}

.site-header td {
  border: none;
  border-bottom: var(--border-thickness) solid var(--text-color);
}

.masthead-title {
  display: inline-block;
  font-size: var(--text-large);
  line-height: calc(var(--line-height) * 2);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  text-decoration: none;
}

.site-header .label {
  color: var(--text-color-alt);
  text-transform: uppercase;
  font-size: var(--text-small);
}

.site-header .meta {
  text-align: right;
  white-space: nowrap;
}

.site-nav a {
  text-decoration: none;
  color: var(--text-color-alt);
}
.site-nav a:hover {
  color: var(--text-color);
}
.site-nav a[aria-current="page"] {
  color: var(--text-color);
  font-weight: var(--font-weight-bold);
}
.site-nav .sep {
  color: var(--text-color-alt);
  margin: 0 1ch;
}

/* ---- Writing list ---- */

.feed-filter {
  text-align: right;
}

.year-select {
  font: inherit;
  font-size: var(--text-small);
  text-transform: uppercase;
  color: var(--text-color);
  background: var(--background-color);
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) / 4 - var(--border-thickness)) 1ch;
  cursor: pointer;
}
.year-select:focus {
  outline: none;
}

.post-list {
  border-top: 1px solid var(--text-color);
}

.post-item {
  display: flex;
  gap: 2ch;
  align-items: flex-start;
  margin: 0;
  padding: var(--line-height) 0;
  border-bottom: 1px solid var(--text-color);
  text-decoration: none;
  color: var(--text-color);
}

.post-feature {
  display: block;
  flex: 0 0 auto;
  width: 12ch;
  height: calc(var(--line-height) * 3);
  object-fit: cover;
  background-color: var(--background-color-alt);
}

.post-meta {
  display: flex;
  flex-direction: column;
}

.post-title {
  font-size: var(--text-base);
}
.post-item:hover .post-title {
  text-decoration: underline;
}

.post-date {
  color: var(--text-color-alt);
  font-size: var(--text-small);
}

/* ---- Works thumbnail grid ---- */

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16ch, 1fr));
  gap: var(--line-height) 2ch;
}

.works-grid .thumb {
  margin: 0;
  text-decoration: none;
  color: var(--text-color);
}

.thumb-frame {
  display: block;
  aspect-ratio: 1 / 1;
  border: var(--border-thickness) solid var(--text-color);
  background-color: var(--background-color-alt);
  background-size: cover;
  background-position: center;
}

.thumb-title {
  display: block;
  margin-top: calc(var(--line-height) / 2);
  font-size: var(--text-small);
}

.thumb:hover .thumb-title {
  text-decoration: underline;
}

/* ---- Project / post detail ---- */

/* Never upscale: render at intrinsic size, shrinking only to fit the column. */
.detail-body img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
}

/* Inline gallery slideshow — fixed, consistent frame */
.gallery-frame {
  aspect-ratio: 3 / 2;
  border: var(--border-thickness) solid var(--text-color);
  background: var(--background-color-alt);
  overflow: hidden;
}
.detail-body .gallery-frame img {
  width: 100%;
  height: 100%;
  margin-top: 0;
  /* object-fit (cover vs scale-down) is set per image in site.js */
}
/* Override .detail-body img { display:block } so hidden slides actually hide. */
.detail-body .gallery-frame img[hidden] {
  display: none;
}

.gallery-controls {
  display: flex;
  align-items: center;
  gap: 2ch;
  margin-top: calc(var(--line-height) / 2);
  font-size: var(--text-small);
  color: var(--text-color-alt);
}
/* Cancel the global "* + *" baseline margin so row items stay vertically aligned. */
.gallery-controls > * + * {
  margin-top: 0;
}

.gallery-nav {
  font: inherit;
  font-size: var(--text-small);
  line-height: var(--line-height);
  color: var(--text-color);
  background: var(--background-color);
  border: var(--border-thickness) solid var(--text-color);
  padding: 0 1ch;
  cursor: pointer;
}
.gallery-nav:hover {
  background: var(--background-color-alt);
}

.detail-body figcaption {
  font-style: italic;
  color: var(--text-color-alt);
  font-size: var(--text-small);
}

.detail-body blockquote {
  border-left: var(--border-thickness) solid var(--text-color);
  padding-left: 2ch;
}

.detail-body blockquote cite {
  display: block;
  font-style: normal;
  color: var(--text-color-alt);
}

.detail-body pre {
  overflow-x: auto;
  border: var(--border-thickness) solid var(--text-color);
  padding: var(--line-height) 1ch;
  font-size: var(--text-small);
}

.detail-body audio,
.detail-body video {
  display: block;
  width: 100%;
}

.detail-body .embed iframe {
  display: block;
  width: 100%;
  border: var(--border-thickness) solid var(--text-color);
}
/* Video embeds get a responsive aspect ratio; audio players keep their height. */
.detail-body .embed[data-ratio] iframe {
  height: auto;
  aspect-ratio: var(--embed-ratio);
}

.credits {
  color: var(--text-color-alt);
  white-space: pre-line;
  font-size: var(--text-small);
}

.back {
  display: inline-block;
  color: var(--text-color-alt);
  text-decoration: none;
  font-size: var(--text-small);
}
.back:hover {
  color: var(--text-color);
}
.back + * {
  margin-top: calc(var(--line-height) / 2);
}

.detail-nav {
  display: flex;
  gap: 2ch;
  margin-top: calc(var(--line-height) * 2);
  padding-top: var(--line-height);
  border-top: 1px solid var(--text-color);
  font-size: var(--text-small);
}

.detail-nav a,
.detail-nav span {
  flex: 1 1 0;
  min-width: 0;
  color: var(--text-color-alt);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-nav a:hover {
  color: var(--text-color);
}

.detail-nav .nav-next {
  text-align: right;
}

/* ---- CV ---- */

.cv-section ul {
  list-style-type: square;
  padding-left: 2ch;
}
.cv-section li {
  margin: 0;
}

/* On skinny screens, drop CV text to the smallest size so long entries fit. */
@media (max-width: 600px) {
  [data-page="cv"] .intro p,
  [data-page="cv"] .cv-section li {
    font-size: var(--text-small);
  }
}

/* ---- Contact form ---- */

.contact-form {
  max-width: 52ch;
}

.contact-form label {
  display: block;
  text-transform: uppercase;
  font-size: var(--text-small);
  color: var(--text-color-alt);
}

.contact-form input,
.contact-form textarea {
  display: block;
  width: calc(round(down, 100%, 1ch));
  margin-top: calc(var(--line-height) / 2);
  font: inherit;
  font-size: var(--text-base);
  color: var(--text-color);
  background: var(--background-color);
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) / 2 - var(--border-thickness))
    calc(1ch - var(--border-thickness) / 2);
}

.contact-form textarea {
  resize: vertical;
}

.contact-form button {
  font: inherit;
  font-size: var(--text-small);
  text-transform: uppercase;
  color: var(--text-color);
  background: var(--background-color);
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) / 2 - var(--border-thickness)) 2ch;
  cursor: pointer;
}

.contact-form button:hover {
  background: var(--background-color-alt);
}

.contact-form input:focus,
.contact-form textarea:focus {
  outline: none;
}

.contact-form .hp {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.contact-notice {
  font-size: var(--text-small);
  color: var(--text-color-alt);
  text-transform: uppercase;
}

/* ---- Footer ---- */

.site-footer {
  margin-top: calc(var(--line-height) * 3);
  color: var(--text-color-alt);
  font-size: var(--text-small);
}
.site-footer td {
  border: none;
  border-top: var(--border-thickness) solid var(--text-color);
}
.site-footer a {
  color: var(--text-color-alt);
  text-decoration: none;
}
.site-footer a:hover {
  color: var(--text-color);
}
.site-footer .right {
  text-align: right;
  white-space: nowrap;
}
