/* Controls: image sizes and horizontal position, followed by layout, type, and fade.
   Image sizing does not change the content gutter. */
:root {
  --ink: #1f2535;
  /* Preserve the original placement; change this offset or the width independently. */
  --content-offset: max(0rem, calc((100% - 62rem) / 2));
  --content-width: 62rem;
  --header-width: 38rem;
  --menu-bottom: 18rem; /* Measured below after layout. */
  --corn-height: max(0px, calc(120vh - var(--menu-bottom)));
  --side-logo-height: var(--corn-height); /* Or a size such as 30rem. */
  --side-logo-x: 0rem; /* Negative moves left; positive moves right. */
  --banner-width: 75%;
  --menu-font: "EB Garamond", Georgia, serif;
  --menu-size: 1rem;
  --menu-border-overhang: 3rem;
  --menu-border-fade: var(--menu-border-overhang);
  --fade-duration: 4s;
  --fade-width: 350%;
}

/* Base elements */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: white;
  font: 1rem/1.65 Georgia, serif;
}

.script {
   font-family: "Courier New", Courier, monospace;
}

a {
  color: inherit;
  text-underline-offset: .2em;
}

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

/* Header logo */
.site-header {
  padding: 2rem 1rem 1rem;
}

.site-header img {
  display: block;
  width: var(--header-width);
  margin: auto;
}

/* Fit the borders to the menu, with a little breathing room at each end. */
.menu {
  position: relative;
  width: max-content;
  max-width: calc(100% - 1rem);
  margin: 0 auto 2.5rem;
  padding: .5rem var(--menu-border-overhang);
  font: var(--menu-size) var(--menu-font);
  /* One broad opacity gradient keeps the text and both borders exactly in sync. */
  mask-image: linear-gradient(to right, black 30%, transparent 70%);
  mask-size: var(--fade-width) 100%;
  mask-repeat: no-repeat;
  mask-position: 100% 0;
  animation: menu-fade var(--fade-duration) ease-in-out both;
}

/* Borders share the menu's fade rather than running separate animations. */
.menu::before,
.menu::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent,
    var(--ink) var(--menu-border-fade),
    var(--ink) calc(100% - var(--menu-border-fade)), transparent);
}

.menu::before { top: 0; }
.menu::after { bottom: 0; }

@keyframes menu-fade {
  to { mask-position: 0 0; }
}

.menu ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.menu li + li::before {
  content: "|";
  margin-inline: .65rem;
  opacity: .5;
}

.menu a {
  text-decoration: none;
}

.menu a:hover,
.menu [aria-current="page"] {
  text-decoration: underline;
}

/* Main content, demos, and gallery */
.side {
  display: none;
}

main {
  /* Stack demo media based on available content space, including beside the corn. */
  container: page-content / inline-size;
  max-width: var(--content-width);
  margin: 0 auto 3rem;
  padding-inline: 1rem;
}

h1, h2 {
  line-height: 1.25;
  font-weight: normal;
}

h1 { font-size: 2.5rem; }
h2 { margin-top: 2rem; }

.sort-toggle {
  float: right;
  padding: .4rem .75rem;
  font: inherit;
  cursor: pointer;
}

.demo-catalogue {
  display: flow-root; /* Contain the right-aligned sort button. */
}

.demo-list {
  clear: both; /* Entries start below the sort button. */
}

.demo {
  display: flow-root; /* Contain the right-floated screenshots. */
  padding-block: 2rem calc(2rem - 10px);
  border-bottom: 1px solid #ddd;
}

.demo img {
  float: right;
  clear: right;
  margin: 0 0 10px 28px;
}

.demo h2 {
  display: flow-root; /* Keep the heading beside the floated images. */
  margin-top: 0;
  margin-bottom: 0;

  a {
    text-decoration: none;
  }
}

.demo .date {
  padding: 0;
  margin: 0;
}

/* Arriving from the About card: keep the entry clear of the top edge and mark it briefly. */
.demo:target {
  scroll-margin-top: 1rem;
  animation: demo-target 2.5s ease-out;
}

@keyframes demo-target {
  from { background: #f3efe2; }
}

/* Latest demo card (About page): title + date | abridged text | screenshots, in one line. */
.latest-demo {
  --shot-height: 5rem;
  --text-lines: 3;
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-block: 1.5rem 2.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid #ddd;
  /* The whole card is one link. */
  text-decoration: none;
  transition: border-color .2s, background-color .2s;
}

.latest-demo:hover,
.latest-demo:focus-visible {
  border-color: var(--ink);
  background: #faf8f2;
}

.latest-demo:hover .latest-demo-title { text-decoration: underline; }

/* The label sits on the top border, like a legend. */
.latest-demo-label {
  position: absolute;
  top: 0;
  left: 1rem;
  margin: 0;
  padding-inline: .4rem;
  transform: translateY(-50%);
  background: white;
  font: .75rem/1 var(--menu-font);
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .75;
}

.latest-demo p { margin: 0; }

.latest-demo-head { flex: 0 0 auto; max-width: 14rem; }

.latest-demo-title {
  font-size: 1.2rem;
  line-height: 1.25;
}

.latest-demo .date { font-size: .85rem; opacity: .75; }

.latest-demo-text {
  flex: 1 1 0;
  min-width: 0;
  font-size: .9rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--text-lines);
  line-clamp: var(--text-lines);
  overflow: hidden;
}

.latest-demo-shots {
  flex: 0 0 auto;
  display: flex;
  gap: .5rem;
}

.latest-demo-shots img {
  display: block;
  height: var(--shot-height);
  width: auto;
}

/* Tune this threshold to choose when demo images move between date and copy. */
@container page-content (max-width: 40rem) {
  .demo {
    display: flex;
    flex-direction: column;
  }

  /* Images come first in the HTML for desktop floats; move the header above them. */
  .demo h2 { order: -2; }
  .demo .date { order: -1; margin-bottom: 1rem; }
  .demo > a { align-self: flex-start; max-width: 100%; }
  .demo img { float: none; display: block; margin: 0 0 10px; }

  .latest-demo { flex-wrap: wrap; }
  .latest-demo-head, .latest-demo-text { flex-basis: 100%; max-width: none; }
  /* Keep the title/date first, screenshots second, and abridged copy last. */
  .latest-demo-text { order: 1; }
  .latest-demo-shots { flex-wrap: wrap; max-width: 100%; }
  .latest-demo-shots img { object-fit: contain; }
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 2rem;
}

.gallery figure { margin: 0; }
.gallery img { display: block; width: 100%; }
.gallery video { display: block; width: 100%; } /* Use native playback controls. */

/* Music: one row per track, title then native player. */
.music { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.music li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; }
.music .track-title { min-width: 10rem; }
.music .wip { cursor: help; }
/* Work-in-progress mark before the title; the second form gives screen readers words instead of the symbol. */
.music .wip::before { content: "\26A0\FE0E\00A0"; content: "\26A0\FE0E\00A0" / "work in progress, "; }
.music audio { flex: 1 1 18rem; max-width: 100%; }
/* Gallery label: adjust its position and appearance here. */
.gallery-label {
  display: block;
  position: relative;
  top: 0;
  left: 0;
  margin-top: 0rem;
  padding: 0;
  font: 0.8rem/1.55 serif;
  color: var(--ink);
  opacity: 0.75;
  text-align: center;
  text-decoration: none;
}

/* Contact portraits: change the size or crop position here when photos are added. */
.contact-profile {
  --photo-size: 8rem;
  --photo-position: center;
  display: grid;
  grid-template-columns: var(--photo-size) minmax(0, 1fr);
  align-items: center;
  gap: 1.5rem;
  margin-block: 2rem;
}
.profile-photo {
  width: var(--photo-size);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #eee;
}
.profile-photo img { width: 100%; height: 100%; object-fit: cover; object-position: var(--photo-position); }
.contact-profile h2 { margin: 0; }
.profile-role, .profile-links { margin: .25rem 0; }

/* Full illustration and company footer */
.corn-banner {
  display: block;
  width: var(--banner-width);
  height: auto;
  margin-left: auto;
}

.site-footer {
  padding: 2rem 1rem;
  color: white;
  background: black;
  text-align: center;
}

.site-footer p { margin: .25rem 0; }

.skip-link {
  position: absolute;
  top: -5rem;
  left: 1rem;
}

.skip-link:focus {
  top: 1rem;
  padding: .5rem;
  background: white;
  z-index: 1;
}

/* Wide layout: sticky corn in its own gutter, above the footer */
@media (min-width: 40rem) {
  .scroll-region {
    display: grid;
    grid-template-columns: 14rem minmax(0, 1fr);
    column-gap: 2rem;
  }

  .site-header, .menu {
    grid-column: 1 / -1;
  }

  .site-header { grid-row: 1; }
  .menu { grid-row: 2; }
  .page-body { grid-column: 2; grid-row: 3; }

  /* The default offset matches the former auto margins, independent of the width setting. */
  main {
    width: var(--content-width);
    max-width: calc(100% - var(--content-offset));
    margin-left: var(--content-offset);
    margin-right: 0;
  }

  /* A viewport-height sticky column anchors the corn to the bottom until the footer. */
  .side {
    grid-column: 1;
    grid-row: 1 / 4;
    position: sticky;
    top: 0;
    align-self: start;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    /* Occupy the existing left gutter without changing the content's layout. */
    width: var(--corn-area-width, 16rem);
    height: 100vh;
  }

  .side img {
    /* Fit both the gutter and requested height, preserving proportions and bottom alignment. */
    width: calc(100% - 2rem);
    height: min(var(--side-logo-height), 100%);
    object-fit: contain;
    object-position: center bottom;
    /* Position can be adjusted without affecting the centered slot or the content. */
    position: relative;
    left: var(--side-logo-x);
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu {
    animation: none;
    mask-image: none;
  }
}
