/*
 * Freek in Shanghai: the one stylesheet for the whole site.
 *
 * The page is the city at night (the hero photo's dark blue); the posts are lit white panels on it. Post text sits
 * in a narrow reading column, photos and slideshows break out wider. One typeface: SOLIX.
 *
 * Sections: tokens, fonts, base, layout, header, hero, cards, articles, post content, slideshow, photo roll, lightbox,
 * comments, footer, utilities. Breakpoints (max-width): 1199px and 991px (card columns), 1024px (mobile header,
 * matches site.js), 760px (phones).
 */

/* --- Tokens ------------------------------------------------------------------------------------------------- */

:root {
  /* Night: the page, header and footer. Paper: the panels the text sits on. */
  --night: #060f35;
  --night-deep: #030726;
  --night-raised: #0f1c48;
  --on-night: #fff;
  --on-night-muted: #a9afc2;
  --line-night: rgb(255 255 255 / 0.1);
  /* Black behind photos (slideshows and the viewer), apart from the night of the page; the bar a shade lighter. */
  --photo-frame: #000;
  --photo-bar: #0e0e10;

  --paper: #fff;
  --ink: #1d2130;
  --ink-body: #2b3040;
  --muted: #5a6072;
  --line: #e4e6ec;

  /* Red for text on paper (5.5:1); the brighter red only on night (5.5:1). */
  --red: #c8282b;
  --red-bright: #fc4949;

  --font: 'SOLIX', 'SOLIX Fallback', sans-serif;

  /* Type scale: 1.25 steps from an 18px body. */
  --text-sm: 0.875rem;
  --text-base: 1.125rem;
  --text-md: 1.375rem;
  --text-lg: 1.75rem;
  --text-xl: clamp(2.125rem, 1.6rem + 2vw, 3.25rem);
  --text-hero: clamp(2.75rem, 1.5rem + 6vw, 6.5rem);

  --measure: 42rem;
  --wide: 60rem;
  --container: 1170px;
  --card-width: 350px;
  --panel-padding: 4rem;
  --gap: 1.5rem;
  --radius: 3px;
  --header-height: 4rem;
  /* Photo roll under slideshows and in the viewer: thumbnail size (the build makes them 160 px wide) and row height. */
  --thumb: 3.5rem;
  --roll: calc(var(--thumb) + 1.5rem);
}

@media (max-width: 1199px) {
  :root {
    --container: 970px;
    --card-width: 290px;
  }
}

@media (max-width: 991px) {
  :root {
    --container: 750px;
    --card-width: 330px;
    --panel-padding: 2.5rem;
  }
}

@media (max-width: 760px) {
  :root {
    --container: 100%;
    --card-width: 100%;
    --panel-padding: 1.25rem;
    --text-base: 1.0625rem;
  }
}

/* --- Fonts -------------------------------------------------------------------------------------------------- */

@font-face {
  font-family: 'SOLIX';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/solix-variable.woff2') format('woff2');
}

/* Arial sized to SOLIX, so the text doesn't move when SOLIX arrives (numbers from the SOLIX README). */
@font-face {
  font-family: 'SOLIX Fallback';
  src: local('Arial'), local('ArialMT');
  size-adjust: 99.82%;
  ascent-override: 87.16%;
  descent-override: 16.73%;
  line-gap-override: 0%;
}

/* --- Base --------------------------------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  background-color: var(--night);
}

body {
  margin: 0;
  background-color: var(--night);
  color: var(--ink-body);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.65;
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 2.5rem 0 0.75rem;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.2;
}

h2 {
  font-size: var(--text-lg);
}

h3 {
  font-size: var(--text-md);
}

h4 {
  font-size: var(--text-base);
}

p {
  margin: 0 0 1.25rem;
}

b,
strong {
  font-weight: 700;
}

a {
  color: var(--red);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

figure {
  margin: 0 0 1.25rem;
}

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.125em;
}

.button {
  display: inline-block;
  padding: 0.6em 1.2em;
  border-radius: var(--radius);
  background-color: var(--red);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
}

.button:hover {
  background-color: var(--ink);
}

/* --- Layout ------------------------------------------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: 15px;
}

.site-content {
  padding-block: 3rem 5rem;
}

/* Posts, the About page and the 404 page: one paper panel holding the article, post navigation and comments. */
.content-area {
  border-radius: var(--radius);
  background-color: var(--paper);
}

/* --- Header ------------------------------------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--line-night);
  background-color: var(--night-deep);
  transition: background-color 0.4s;
}

/* On the home page the header lies over the photo until the page scrolls. */
.site-header.over-hero {
  position: fixed;
  width: 100%;
  border-bottom-color: transparent;
  background-color: transparent;
}

.site-header.over-hero.is-scrolled {
  border-bottom-color: var(--line-night);
  background-color: var(--night-deep);
}

.site-header-inner {
  display: flex;
  align-items: center;
  gap: var(--gap);
  min-height: var(--header-height);
}

.site-branding {
  flex: 1;
}

.site-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1.2;
}

.site-title a {
  color: var(--on-night);
  text-decoration: none;
}

.menu-toggle {
  display: none;
  padding: 0.5rem;
  border: 0;
  background: none;
  color: var(--on-night);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.main-nav ul {
  display: flex;
  gap: 2rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.main-nav a {
  color: var(--on-night);
  text-decoration: none;
}

.main-nav a:hover,
.main-nav a[aria-current='page'] {
  text-decoration: underline;
  text-decoration-color: var(--red-bright);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.4em;
}

/* The language switch stands apart from the menu, after a thin line. */
.main-nav .lang-switch {
  padding-left: 2rem;
  border-left: 1px solid var(--line-night);
}

.site-header :focus-visible {
  outline-color: var(--red-bright);
}

@media (max-width: 1024px) {
  .menu-toggle {
    display: block;
  }

  .main-nav {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    border-bottom: 1px solid var(--line-night);
    background-color: var(--night-deep);
  }

  .js .main-nav:not(.is-open) {
    display: none;
  }

  .main-nav ul {
    display: block;
  }

  .main-nav a {
    display: block;
    padding: 0.75rem 15px;
    border-top: 1px solid var(--line-night);
  }

  .main-nav .lang-switch {
    padding-left: 0;
    border-left: 0;
  }

  .site-header.over-hero {
    background-color: var(--night-deep);
  }
}

/* --- Hero (home page) --------------------------------------------------------------------------------------- */

.hero {
  position: relative;
}

.hero-image {
  display: block;
  width: 100%;
  height: min(90vh, 56.25vw);
  object-fit: cover;
}

/* The photo fades into the night of the page, where the cards start. */
.hero::after {
  content: '';
  position: absolute;
  inset: 40% 0 0;
  background: linear-gradient(to top, var(--night), transparent);
  pointer-events: none;
}

.hero-text {
  position: absolute;
  bottom: 12%;
  left: 50%;
  z-index: 1;
  display: flex;
  flex-direction: column-reverse;
  width: 100%;
  max-width: var(--container);
  padding-inline: 15px;
  transform: translateX(-50%);
  color: var(--on-night);
}

.hero-title {
  margin: 0;
  font-size: var(--text-hero);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  margin: 1rem 0 0;
  color: var(--on-night-muted);
  font-size: var(--text-md);
}

@media (max-width: 1024px) {
  .hero-text {
    bottom: 8%;
  }
}

@media (max-width: 760px) {
  .hero-image {
    height: 70vw;
  }

  .hero-subtitle {
    margin-top: 0.5rem;
    font-size: var(--text-base);
  }
}

/* --- Post cards (home and tag pages) ------------------------------------------------------------------------ */

/* Without JS: a centred grid. site.js positions the cards as masonry (.is-masonry), each in the shortest column,
   and reads the 15px margin around each card. */
.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, calc(var(--card-width) + 30px));
  justify-content: center;
  align-items: start;
}

.posts-grid.is-masonry {
  position: relative;
  display: block;
}

.posts-grid.is-masonry > .card {
  position: absolute;
}

/* Lit windows on the night: photo on top, then title, date and excerpt. */
.card {
  display: flex;
  flex-direction: column;
  width: var(--card-width);
  margin: 15px;
  overflow: hidden;
  border-radius: var(--radius);
  background-color: var(--paper);
  font-size: 1rem;
}

.card > * {
  margin-inline: 1.5rem;
}

.card-image {
  order: -1;
  margin: 0 0 1.25rem;
}

.card-image img {
  display: block;
  width: 100%;
}

.card-title {
  margin: 0 0 0.25rem;
  font-size: var(--text-md);
  font-weight: 600;
}

.card-title a {
  color: var(--ink);
  text-decoration: none;
}

.card-title a:hover {
  color: var(--red);
}

.card .entry-meta {
  margin-bottom: 0.75rem;
}

.card-excerpt {
  margin-bottom: 0.75rem;
}

.card-more {
  align-self: flex-start;
  margin-bottom: 1.5rem;
}

@media (max-width: 760px) {
  .posts-grid {
    grid-template-columns: minmax(0, 30rem);
  }

  .card {
    margin: 0 0 var(--gap);
  }
}

/* Tag pages: the tag name above its cards, on the night. */
.page-header {
  padding: 0 15px 1rem;
}

.page-title {
  margin: 0;
  color: var(--on-night);
  font-size: var(--text-xl);
  font-weight: 300;
}

.page-title .icon {
  margin-right: 0.75rem;
  color: var(--red-bright);
  font-size: 0.6em;
  vertical-align: 0.1em;
}

/* --- Articles (posts, About, 404) --------------------------------------------------------------------------- */

.entry {
  padding: var(--panel-padding) var(--panel-padding) 3rem;
}

/* Text keeps to the reading column; photos and slideshows get the wider column. */
.entry-header,
.entry-content > *,
.entry-footer {
  max-width: var(--measure);
  margin-inline: auto;
}

.entry-content > .slideshow,
.entry-content > .aligncenter,
.entry-content > .wp-caption,
.entry-image {
  /* min(): WordPress captions carry an inline width. */
  max-width: min(var(--wide), 100%);
}

.entry-title {
  margin: 0 0 0.75rem;
  font-size: var(--text-xl);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 2.5rem;
  color: var(--muted);
  font-size: var(--text-sm);
}

.entry-meta a {
  color: inherit;
  text-decoration: none;
}

.entry-image {
  margin: 0 auto 2.5rem;
}

/* Featured images are 700 px at most, narrower than the column. */
.entry-image img {
  display: block;
  margin-inline: auto;
}

.entry-footer {
  margin-top: 2.5rem;
}

.tag-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tag-links a {
  display: block;
  padding: 0.2rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: var(--text-sm);
  text-decoration: none;
}

.tag-links a:hover {
  border-color: var(--red);
  color: var(--red);
}

/* Older post on the left, newer on the right, each with its label. */
.post-nav {
  display: flex;
  gap: var(--gap);
  /* Lines up with the reading column above it. */
  padding: 2rem max(var(--panel-padding), (100% - var(--measure)) / 2);
  border-top: 1px solid var(--line);
}

.post-nav a {
  flex: 1;
  color: var(--ink);
  font-weight: 500;
  line-height: 1.4;
  text-decoration: none;
}

.post-nav a:hover {
  color: var(--red);
}

.post-nav-label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 400;
}

.post-nav-newer {
  text-align: right;
}

.post-nav-newer:only-child {
  margin-left: 50%;
}

/* --- Post content (HTML from WordPress) --------------------------------------------------------------------- */

.alignleft {
  float: left;
  margin-right: 1.5em;
}

.alignright {
  float: right;
  margin-left: 1.5em;
}

.aligncenter {
  display: block;
  clear: both;
  margin-inline: auto;
}

.wp-caption img {
  display: block;
  margin-inline: auto;
}

.wp-caption-text {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

@media (max-width: 600px) {
  .alignleft,
  .alignright {
    display: block;
    float: none;
    margin: 0 auto 1.25rem;
  }
}

/* --- Slideshow ---------------------------------------------------------------------------------------------- */

/* Without JS: the photos one below the other. */
.slide {
  margin: 0 0 1.25rem;
  text-align: center;
}

.slide figcaption {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* With JS: one photo at a time in a night frame, and a bar below it with the photo roll and the controls. The frame
   is 4:3, the shape of most photos, but no taller than the screen leaves room for. */
.js .slideshow {
  --frame: min(75cqi, 100svh - var(--header-height) - var(--roll) - 2rem);
  container-type: inline-size;
  margin-block: 2rem;
  overflow: hidden;
  border-radius: var(--radius);
  background-color: var(--photo-frame);
}

.js .slide {
  display: none;
  margin: 0;
}

.js .slide.is-active {
  position: relative;
  display: block;
  animation: fade-in 0.3s;
}

.js .slide > a {
  display: flex;
  align-items: center;
  justify-content: center;
  height: max(var(--frame), 12rem);
  cursor: zoom-in;
}

/* Fills the frame's height: width: auto alone would stop at the 824 px of the photos' sizes attribute. */
.js .slide img {
  width: auto;
  height: 100%;
  object-fit: contain;
}

/* Few photos have a caption (63 of 934), so it goes over the bottom of the photo instead of taking a row. */
.js .slide figcaption {
  position: absolute;
  inset: auto 0 0;
  margin: 0;
  padding: 0.25rem 1rem;
  background-color: rgb(0 0 0 / 0.7);
  color: var(--on-night);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.slideshow-bar {
  display: flex;
  border-top: 1px solid var(--line-night);
  background-color: var(--photo-bar);
}

.slideshow-bar .photo-roll {
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
}

.slideshow-controls {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.25rem;
  padding-inline: 0.5rem 0.75rem;
  border-left: 1px solid var(--line-night);
}

.control-button {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: rgb(255 255 255 / 0.08);
  color: var(--on-night);
  font-size: 1rem;
  cursor: pointer;
}

.control-button:hover {
  background-color: rgb(255 255 255 / 0.2);
}

.control-button:focus-visible {
  outline-color: var(--red-bright);
}

.slideshow-counter {
  min-width: 4.5rem;
  margin: 0;
  color: var(--on-night-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@media (max-width: 760px) {
  /* Edge to edge, and square, so portrait photos get as much room as landscape ones. */
  .js .slideshow {
    --frame: min(100cqi, 100svh - var(--header-height) - var(--roll) - 3.5rem - 2rem);
    max-width: none;
    margin-inline: calc(-1 * var(--panel-padding));
    border-radius: 0;
  }

  .js .slide figcaption {
    text-align: center;
  }

  /* Too narrow for the roll and the controls side by side: the controls get a row above the roll. */
  .slideshow-bar {
    flex-direction: column-reverse;
  }

  .slideshow-bar .photo-roll {
    flex: none;
  }

  .slideshow-controls {
    justify-content: center;
    height: 3.5rem;
    border-left: 0;
    border-bottom: 1px solid var(--line-night);
  }
}

@media (prefers-reduced-motion: reduce) {
  .js .slide.is-active {
    animation: none;
  }
}

/* --- Photo roll ---------------------------------------------------------------------------------------------- */

/* A row of thumbnails along the bottom of a slideshow or the viewer; it scrolls sideways and keeps the current photo
   in the middle (site.js). */
.photo-roll {
  display: flex;
  justify-content: safe center;
  align-items: center;
  gap: 0.375rem;
  height: var(--roll);
  padding-inline: 0.75rem;
  overflow: auto hidden;
  overscroll-behavior-x: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--on-night-muted) transparent;
}

.photo-roll-thumb {
  flex: none;
  width: var(--thumb);
  height: var(--thumb);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background-color: var(--night-raised);
  opacity: 0.5;
  cursor: pointer;
}

.photo-roll-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-roll-thumb:hover {
  opacity: 0.85;
}

.photo-roll-thumb[aria-current] {
  outline: 2px solid var(--red-bright);
  outline-offset: 2px;
  opacity: 1;
}

.photo-roll-thumb:focus-visible {
  outline: 2px solid var(--on-night);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .photo-roll {
    scroll-behavior: auto;
  }
}

/* --- Lightbox (full-size photo) ----------------------------------------------------------------------------- */

.lightbox {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background-color: var(--photo-frame);
  color: var(--on-night);
}

.lightbox::backdrop {
  background-color: var(--photo-frame);
}

.lightbox-figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  padding: 4rem 5rem 3rem;
}

.lightbox-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-caption {
  min-height: 1.7em;
  margin-top: 0.75rem;
  color: var(--on-night-muted);
  text-align: center;
}

.lightbox .control-button {
  position: absolute;
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.25rem;
}

.lightbox-close {
  top: 0.75rem;
  right: 0.75rem;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: 0.75rem;
}

.lightbox-next {
  right: 0.75rem;
}

.lightbox .slideshow-counter {
  position: absolute;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
}

.lightbox .photo-roll {
  position: absolute;
  inset: auto 0 0;
}

.lightbox.has-roll .lightbox-figure {
  padding-bottom: calc(var(--roll) + 1rem);
}

@media (max-width: 760px) {
  .lightbox-figure {
    padding: 4rem 0.5rem 4.5rem;
  }

  .lightbox.has-roll .lightbox-figure {
    padding-bottom: calc(var(--roll) + 4.5rem);
  }

  .lightbox-prev,
  .lightbox-next {
    top: auto;
    bottom: 0.75rem;
    transform: none;
  }

  .lightbox.has-roll :is(.lightbox-prev, .lightbox-next) {
    bottom: calc(var(--roll) + 0.75rem);
  }
}

/* --- Comments ----------------------------------------------------------------------------------------------- */

.comments {
  padding: 3rem var(--panel-padding);
  border-top: 1px solid var(--line);
}

.comments > * {
  max-width: var(--measure);
  margin-inline: auto;
}

.comments-title {
  margin-top: 0;
  margin-bottom: 1.5rem;
  font-size: var(--text-md);
}

.comment-list,
.comment-replies {
  margin-block: 0;
  padding: 0;
  list-style: none;
}

/* Replies hang off a line under the comment they answer. */
.comment-replies {
  margin-left: 0.5rem;
  padding-left: 1.25rem;
  border-left: 2px solid var(--line);
}

.comment-body {
  padding-block: 1rem;
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  margin-bottom: 0.25rem;
}

.comment-author {
  color: var(--ink);
}

.comment-date {
  color: var(--muted);
  font-size: var(--text-sm);
  text-decoration: none;
}

.comment-date:hover {
  text-decoration: underline;
}

.comment-content p:last-child {
  margin-bottom: 0;
}

/* --- Footer ------------------------------------------------------------------------------------------------- */

.site-footer {
  padding-block: 2rem;
  border-top: 1px solid var(--line-night);
  background-color: var(--night-deep);
  color: var(--on-night-muted);
  font-size: var(--text-sm);
}

.site-footer a {
  color: var(--on-night-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--on-night);
  text-decoration: underline;
}

.site-footer :focus-visible {
  outline-color: var(--red-bright);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.footer-menu {
  display: flex;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-name {
  margin: 0;
}

/* --- Utilities ---------------------------------------------------------------------------------------------- */

.visually-hidden,
.skip-link:not(:focus) {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 1000;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  background-color: var(--paper);
  color: var(--ink);
  font-weight: 600;
}

.icon-sprite {
  display: none;
}
