/* ---------- reset ---------- */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "MedievalSharp", "Book Antiqua", Georgia, serif;
  color: #d7e2e7;
  line-height: 1.5;
}

/* ---------- separate background layer ---------- */
#bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: url("background.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

/* background image credit, tucked into a corner over the background */
#bg-credit {
  position: fixed;
  right: 6px;
  bottom: 4px;
  z-index: 1;
  font-size: 11px;
  color: rgba(215, 226, 231, 0.55);
  text-decoration: none;
}

#bg-credit:hover {
  color: #ffffff;
}

/* subtle darkening veil so the boxes on top stay readable */
#bg-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 20, 0.45);
}

/* ---------- content layer, lays on top ---------- */
#page {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

/* ---------- generic old-internet box ---------- */
.box {
  background: rgba(14, 22, 33, 0.88);
  border: 3px outset #6f8aa3;
  margin-bottom: 20px;
  box-shadow: 0 0 5px rgba(18, 43, 207, 0.712);
}

.box-title {
  background: #2f4a63;
  border-bottom: 2px solid #6f8aa3;
  padding: 4px 10px;
  font-family: "UnifrakturCook", "MedievalSharp", serif;
  font-weight: 700;
  font-size: 130%;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 1px 1px 0 #000;
  flex: 0 0 auto;
}

.box-body {
  padding: 12px 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.box-body ul {
  margin: 0;
  padding-left: 18px;
}

.box a {
  color: #8fc7ec;
}

.box a:hover {
  color: #ffffff;
}

/* ---------- banner ---------- */
.banner {
  text-align: center;
  border-width: 4px;
  padding: 10px 12px 16px;
  background: rgba(14, 22, 33, 0.92);
}

.banner h1 {
  margin: 4px 0 6px;
  font-family: "UnifrakturCook", "MedievalSharp", serif;
  font-size: 380%;
  line-height: 1;
  color: #ffffff;
  text-shadow: 2px 2px 0 #000, 0 0 12px rgba(126, 179, 214, 0.5);
}

.banner .tagline {
  margin: 0;
  font-size: 105%;
  color: #b8c9d0;
}

/* ---------- two-column layout ---------- */
.layout {
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-start;   /* boxes keep their own height, nothing stretches */
  gap: 20px;
}

.sidebar {
  flex: 1 1 200px;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
}

.column {
  flex: 3 1 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
}

/* boxes inside the columns: no stacking margin, allowed to shrink */
.sidebar .box,
.column .box {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* the nav box is only as tall as its content */
.sidebar .nav {
  flex: 0 0 auto;
}

/* the portrait box stays its natural size — no stretching */
.sidebar .portrait {
  flex: 0 0 auto;
}

/* the welcome box always shows all its text (never scrolls, never shrinks) */
.column > .welcome {
  flex: 0 0 auto;
}

.column > .welcome .box-body {
  overflow-y: visible;
}

/* the latest-article box is a fixed height and scrolls its own content */
.column > #latest-article {
  flex: 0 0 auto;
  height: 70vh;
}

/* wrapper the latest article fragment is injected into */
#latest-article {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#latest-article > .box {
  flex: 1 1 auto;
  min-height: 0;
}

.latest-more {
  margin-top: 14px;
}

/* "open full article" / "back to all articles" links */
.article-open {
  margin: 16px 0 0;
  font-size: 92%;
  text-align: right;
}

#article-list .article-open {
  text-align: left;
  font-weight: 700;
}

#article-view .article-open {
  text-align: left;
}

/* ---------- nav box ---------- */
.nav ul {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.nav li {
  padding: 3px 0;
  border-bottom: 1px dotted #4a6478;
}

/* ---------- portrait box under the nav ---------- */
.portrait .box-body {
  padding: 6px;
}

.portrait a {
  display: block;
  border: 1px inset #6f8aa3;
}

.portrait img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;   /* stays square regardless of box height */
  object-fit: cover;
  object-position: center;
}

/* ---------- welcome headings ---------- */
.welcome h3 {
  margin-top: 0;
  color: #9ec4a8;
}

/* ---------- footer ---------- */
.footer ul {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
}

.footer .neocities {
  max-width: 50px;
  display: block;
}

/* ---------- recent-articles list inside the nav box ---------- */
.nav-articles {
  margin-top: 10px;
  border-top: 1px dotted #4a6478;
  padding-top: 8px;
}

.nav-articles-head {
  font-family: "UnifrakturCook", "MedievalSharp", serif;
  font-size: 105%;
  color: #9ec4a8;
  margin-bottom: 4px;
}

.nav-articles ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 90%;
}

.nav-articles li {
  padding: 3px 0;
  border-bottom: 1px dotted #33485a;
}

/* ---------- .flow: reading layout ---------- */
/* boxes grow to fit their content; columns wrap on narrow screens */
.layout.flow {
  flex-wrap: wrap;
}

.layout.flow .sidebar .box,
.layout.flow .column .box {
  flex: 0 0 auto;
}

.layout.flow .box-body {
  overflow-y: visible;
}

/* ---------- per-box source footer (article pages) ---------- */
.box-sources {
  flex: 0 0 auto;
  border-top: 2px solid #6f8aa3;
  background: rgba(0, 0, 0, 0.28);
  padding: 5px 12px;
  font-size: 80%;
  color: #8fa3ad;
}

.box-sources-label {
  margin-right: 6px;
  color: #9ec4a8;
}

.box-sources a {
  margin-right: 8px;
}

.box-sources-none {
  font-style: italic;
}

/* numbered source list in a box footer */
.box-sources-list {
  margin: 4px 0 0;
  padding-left: 22px;
}

.box-sources-list li {
  margin: 2px 0;
}

/* inline citation marker, e.g. text.<sup class="cite"><a href="...">[1]</a></sup> */
.cite {
  font-size: 72%;
  line-height: 0;
  vertical-align: super;
  margin-left: 1px;
}

.cite a {
  text-decoration: none;
}

.cite a:hover {
  text-decoration: underline;
}

/* ---------- article body bits ---------- */
.byline {
  font-size: 88%;
  color: #8fa3ad;
  margin: 0 0 14px;
}

/* ---------- article boxes on articles.html (bigger than homepage boxes) ---------- */
.article .box-title {
  font-size: 155%;
}

.article .box-body {
  padding: 18px 22px;
  font-size: 104%;
}

.article .box-body h3 {
  color: #9ec4a8;
  margin: 20px 0 6px;
  font-family: "UnifrakturCook", "MedievalSharp", serif;
}

.article .box-body h3:first-of-type {
  margin-top: 8px;
}

/* offset anchor jumps so the box title isn't hidden under the top edge */
.article {
  scroll-margin-top: 16px;
}

/* images inside an article */
.article-figure {
  margin: 14px 0;
  text-align: center;
}

.article-figure img {
  display: block;
  width: 100%;
  max-width: 380px;
  height: auto;
  margin: 0 auto;
  border: 1px inset #6f8aa3;
}

.article-figure figcaption {
  margin-top: 6px;
  font-size: 82%;
  font-style: italic;
  color: #9ec4a8;
}

/* on the standalone reading page the figure can breathe a bit more */
#article-view .article-figure img {
  max-width: 460px;
}

/* ---------- articles.html: home-page-style layout, articles tiled in a grid ---------- */
/* wider content area on the archive page so the square boxes have room */
#page.wide {
  max-width: 1180px;
}

/* the archive page keeps a fixed viewport height so the grid scrolls inside */
.articles-layout {
  height: 88vh;
  align-items: stretch;
}

/* #article-list is the (former) .column, switched from flex to a 2-up grid  */
#article-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  overflow-y: auto;
  align-content: start;
}

/* each article box is a square that scrolls its own content */
#article-list .article {
  aspect-ratio: 1 / 1;
  height: auto;
  min-height: 0;
  margin: 0;
}

/* sidebar nav sits at its natural height, like the home page */
.articles-layout .sidebar .nav {
  flex: 0 0 auto;
}

/* medium screens: one column, flow naturally instead of a fixed viewport */
@media (max-width: 880px) {
  .articles-layout {
    flex-flow: column nowrap;
    height: auto;
    min-height: 0;
  }
  .articles-layout .sidebar {
    max-width: none;
  }
  #article-list {
    grid-template-columns: 1fr;
    overflow-y: visible;
  }
  #article-list .article {
    aspect-ratio: auto;
    height: auto;
  }
  .articles-layout .box-body {
    overflow-y: visible;
  }
}

/* ---------- knight, fixed to the corner on top of everything ---------- */
#knight {
  position: fixed;
  right: 0;
  bottom: 0;
  max-width: 28%;
  z-index: 2;
  pointer-events: none;
}

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .banner h1 { font-size: 240%; }

  /* stack the columns and let boxes grow naturally again */
  .layout {
    flex-flow: column nowrap;
    height: auto;
    min-height: 0;
  }
  .sidebar { max-width: none; }
  .column .box,
  .column > #latest-article { flex: 0 0 auto; min-height: 0; height: auto; }
  .box-body { overflow-y: visible; max-height: none; }
  .portrait a { height: auto; }
  .portrait img { height: 180px; }

  #page { padding-bottom: 40px; }
}
