/*
 * The Estel theme.
 *
 * Colours, fonts, sizes, spacing and widths are custom properties from the styles in theme.yaml, served as /theme/styles.css.
 * Change those first. They hold the whole design in a few lines.
 * This file decides how they're used.
 *
 * The type follows Robert Bringhurst's The Elements of Typographic Style:
 * - Lines of about 66 characters (layout-text). Bringhurst's range is 45 to 75.
 * - Body text with generous leading (leading-body), headings set tighter (leading-tight).
 * - Sizes from a scale (text-*), not chosen one by one.
 * - Space between blocks is a multiple of the line height.
 * - Labels in capitals are letterspaced, and figures in dates line up.
 *
 * The layers go from general to specific. A rule in a later layer wins without a more specific selector.
 */
@layer reset, base, layout, components;

@font-face {
  font-family: Inter;
  src: url("fonts/Inter-VariableFont_slnt_wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: oblique 0deg 10deg;
  font-display: swap;
}

/* A clean slate: no default margins, and sizes that include padding and borders. */
@layer reset {
  *, ::before, ::after { box-sizing: border-box; margin: 0; padding: 0; border: 0 solid; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  :where(img, svg, video, iframe) { display: block; max-inline-size: 100%; }
  :where(img, video) { block-size: auto; }
  :where(input, button, textarea, select) { font: inherit; color: inherit; background: transparent; }
  :where(button) { cursor: pointer; }
  :where(ul, ol)[class] { list-style: none; }
  :where(table) { border-collapse: collapse; }
  [hidden] { display: none !important; }

  @media (prefers-reduced-motion: reduce) {
    *, ::before, ::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
  }
}

/* The page as a whole, and plain elements. */
@layer base {
  html {
    background: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    /* Inter's alternate 1, l and I have tails, which makes them easier to tell apart. */
    font-feature-settings: "cv05", "cv08";
    hanging-punctuation: first last;
    -webkit-font-smoothing: antialiased;
  }

  body { min-block-size: 100vh; display: flex; flex-direction: column; }

  a { color: var(--color-accent); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
  a:hover { text-decoration-thickness: 2px; }
  :focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; border-radius: 2px; }

  h1, h2, h3, h4 { line-height: var(--leading-tight); font-weight: 650; letter-spacing: -0.015em; text-wrap: balance; }
  p, li, dd { text-wrap: pretty; }

  ::selection { background: color-mix(in srgb, var(--color-accent) 22%, transparent); }
}

/*
 * Widths. Every section sits in one of two centred columns with the gutter at the sides:
 * .wrap for reading (layout-text) and .wrap-wide for images and lists (layout-wide).
 */
@layer layout {
  :root { --layout-content: var(--layout-text); }
  .wrap, .wrap-wide, .prose > * {
    inline-size: min(100% - 2 * var(--layout-gutter), var(--wrap, var(--layout-content)));
    margin-inline: auto;
  }
  .wrap-wide { --wrap: var(--layout-wide); }
  /* The wide template gives the text a quarter more room than the content width. */
  .entry[data-template="wide"] { --layout-content: calc(var(--layout-text) * 1.25); }

  .site-body { flex: 1; display: flex; flex-direction: column; }
  .site-main { flex: 1; padding-block: var(--space-xl) var(--space-xxl); }
  /* With sidebar widgets, the page and the sidebar share the wide column. On small screens the sidebar goes below. */
  .site-body.has-sidebar { inline-size: min(100% - 2 * var(--layout-gutter), var(--layout-wide)); margin-inline: auto; }
  .site-body.has-sidebar .wrap, .site-body.has-sidebar .wrap-wide, .site-body.has-sidebar .prose > * { inline-size: 100%; }
  .site-sidebar { padding-block-end: var(--space-xxl); }
  @media (width >= 64rem) {
    .site-body.has-sidebar { display: grid; grid-template-columns: minmax(0, 1fr) 18rem; gap: var(--space-xl); }
    .site-sidebar { padding-block-start: var(--space-xl); }
  }
}

@layer components {
  /* Read by screen readers, but not shown. */
  .visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  .skip-link { position: absolute; inset-inline-start: var(--space-s); inset-block-start: -10rem; padding: var(--space-xs) var(--space-s); background: var(--color-text); color: var(--color-background); }
  .skip-link:focus { inset-block-start: var(--space-s); }

  /* Header. The "Header" option centres it (see the end of this layer). */
  .site-header { padding-block: var(--space-m); border-block-end: 1px solid var(--color-border); }
  .site-header-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-s) var(--space-l); }
  .site-title { font-weight: 650; font-size: var(--text-large); letter-spacing: -0.01em; }
  .site-logo { display: inline-block; vertical-align: middle; width: auto; max-width: min(100%, 60vw); height: auto; max-height: 48px; }
  .site-title a { color: inherit; text-decoration: none; }

  .menu { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-m); font-size: var(--text-small); }
  .menu a { color: inherit; text-decoration: none; }
  .menu a:hover { color: var(--color-accent); }
  .menu-toggle { display: none; font-size: var(--text-small); font-weight: 500; padding: var(--space-xs) 0; }

  .search input {
    inline-size: 11rem; padding: 0.35em 0.75em; font-size: var(--text-small);
    border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-background);
  }
  .search input:focus { outline: none; border-color: var(--color-accent); }

  /* On small screens, the menu is hidden behind the Menu button. Without JavaScript to open it, it stays visible. */
  @media (width < 48rem) {
    .js .menu-toggle { display: block; }
    .js .menu:not([data-open]) { display: none; }
    .js .menu { flex-basis: 100%; flex-direction: column; align-items: flex-start; gap: var(--space-s); padding-block: var(--space-s); font-size: var(--text-base); }
    .site-nav { display: contents; }
  }

  /* A label in small capitals above a title: what kind of list it is, or a post's date. */
  /* A post's category above its title, like a magazine section. */
  .section-label { font-size: var(--text-small); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-accent); text-decoration: none; }
  .section-label:hover { text-decoration: underline; }

  .list-label, .meta {
    font-size: var(--text-small); color: var(--color-muted);
    font-variant-numeric: tabular-nums;
  }
  .list-label { text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
  .meta a { color: inherit; text-decoration: none; }
  .meta a:hover { color: var(--color-accent); }
  .meta-sep { margin-inline: 0.15em; }

  /* The top of a list. */
  .list-header { margin-block-end: var(--space-xl); }
  .list-title { font-size: var(--text-xx-large); margin-block-start: var(--space-xs); }
  .list-intro { max-inline-size: 20em; font-size: var(--text-xx-large); font-weight: 500; letter-spacing: -0.02em; }
  .list-bio { margin-block-start: var(--space-s); max-inline-size: var(--layout-text); font-size: var(--text-large); color: var(--color-muted); }
  .list-website { margin-block-start: var(--space-xs); font-size: var(--text-small); }
  .list-search { margin-block-start: var(--space-m); }
  .list-search .search input { inline-size: min(100%, 24rem); font-size: var(--text-base); }
  .list-empty { color: var(--color-muted); }

  /*
   * Posts in a list. data-layout="list" puts each image beside its text. data-layout="grid" puts the images in
   * columns. The number of columns depends on the width of the list, not the window, for narrower places like
   * "More posts".
   */
  .cards { display: grid; gap: var(--space-xl); container-type: inline-size; }
  .cards + .cards { margin-block-start: var(--space-xxl); }
  .card { display: grid; gap: var(--space-s); align-content: start; }
  .card-image { display: block; overflow: hidden; border-radius: 4px; background: var(--color-surface); }
  .card-image img { inline-size: 100%; aspect-ratio: 3 / 2; object-fit: cover; transition: transform 0.4s ease; }
  .card-image:hover img { transform: scale(1.02); }
  .card-text { display: grid; gap: var(--space-xs); align-content: start; }
  .card-title { font-size: var(--text-x-large); }
  .card-title a { color: inherit; text-decoration: none; }
  .card-title a:hover { color: var(--color-accent); }
  .card-summary { max-inline-size: var(--layout-text); color: var(--color-muted); }
  .card-summary:empty { display: none; }

  /* In the list, every post's text starts at the same place, with or without an image beside it. */
  @container (width >= 40rem) {
    .cards[data-layout="list"] .card { grid-template-columns: 5fr 7fr; gap: var(--space-l); align-items: center; }
    .cards[data-layout="list"] .card-text { grid-column: 2; }
  }
  .cards[data-layout="grid"] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); gap: var(--space-l); }
  .cards[data-layout="grid"] .card-title { font-size: var(--text-large); }
  .cards[data-layout="grid"] .card-summary { font-size: var(--text-small); }

  /*
   * The lead story on the first page of the blog: a wide image, then the title and summary side by side on wide
   * screens.
   */
  .lead { display: grid; gap: var(--space-m); margin-block-end: var(--space-xxl); }
  .lead-image { display: block; overflow: hidden; border-radius: 4px; background: var(--color-surface); }
  .lead-image img { inline-size: 100%; aspect-ratio: 12 / 5; object-fit: cover; }
  .lead-text { display: grid; gap: var(--space-s) var(--space-xl); }
  .lead-text > div { display: grid; gap: var(--space-xs); align-content: start; }
  .lead-title { font-size: var(--text-xx-large); }
  .lead-title a { color: inherit; text-decoration: none; }
  .lead-title a:hover { color: var(--color-accent); }
  .lead-summary { font-size: var(--text-large); line-height: 1.45; color: var(--color-muted); }
  @media (width >= 48rem) { .lead-text { grid-template-columns: 7fr 5fr; } }

  /* A single post or page. */
  .entry-header { display: grid; gap: var(--space-s); margin-block-end: var(--space-l); }
  .entry-title { font-size: var(--text-xx-large); }
  .entry-excerpt { font-size: var(--text-large); color: var(--color-muted); line-height: 1.45; }
  /*
   * A featured image runs edge to edge, straight under the site header, with the title and details on it. The dark
   * fade at the bottom keeps white text readable on any photo. A tall image is cropped.
   */
  .entry-hero { position: relative; display: grid; align-items: end; margin-block: calc(-1 * var(--space-xl)) var(--space-l); color: #FFF; }
  .entry-hero img { grid-area: 1 / 1; inline-size: 100%; block-size: min(75vh, 46rem); object-fit: cover; }
  .entry-hero::after { content: ""; grid-area: 1 / 1; align-self: stretch; background: linear-gradient(to top, rgb(0 0 0 / 0.7), rgb(0 0 0 / 0.25) 45%, transparent 70%); }
  .entry-hero-text { grid-area: 1 / 1; position: relative; z-index: 1; display: grid; gap: var(--space-s); padding-block-end: var(--space-xl); }
  .entry-hero .meta, .entry-hero .meta a { color: rgb(255 255 255 / 0.85); }
  .entry-hero .entry-title { text-shadow: 0 1px 24px rgb(0 0 0 / 0.25); }
  .entry-header:empty { display: none; }
  .entry-details { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-xs) var(--space-m); margin-block-end: var(--space-l); padding-block: var(--space-s); border-block: 1px solid var(--color-border); }
  .entry-details div { display: contents; }
  .entry-details dt { color: var(--color-muted); }
  .entry-tags { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-s); margin-block-start: var(--space-l); font-size: var(--text-small); }
  .entry-tags a { color: var(--color-muted); text-decoration: none; }
  .entry-tags a:hover { color: var(--color-accent); }

  /*
   * The text of a post, from its Markdown. One line of space between blocks. More space before a heading than after
   * it groups the heading with its text.
   */
  .prose > * + * { margin-block-start: 1.6em; }
  .prose > :where(h2, h3, h4) { margin-block-start: 2em; }
  .prose > :where(h2, h3, h4) + * { margin-block-start: 0.8em; }
  .prose h2 { font-size: var(--text-x-large); }
  .prose h3 { font-size: var(--text-large); }
  .prose h4 { font-size: var(--text-base); }
  .prose :where(ul, ol) { padding-inline-start: 1.25em; }
  .prose li + li { margin-block-start: 0.4em; }
  .prose blockquote { padding-inline-start: var(--space-m); border-inline-start: 2px solid var(--color-accent); font-style: oblique 8deg; }
  .prose hr { border-block-start: 1px solid var(--color-border); }
  /* Images and tables in the text may be wider than it, up to the wide column. */
  .prose > :where(figure, table, img, pre) { --wrap: calc(var(--layout-content) + 8rem); }
  .prose figure img { inline-size: 100%; border-radius: 4px; }
  .prose figcaption { margin-block-start: var(--space-xs); font-size: var(--text-small); color: var(--color-muted); text-align: center; }
  .prose :where(code, pre) { font-family: var(--font-mono); font-size: 0.875em; }
  .prose :not(pre) > code { padding: 0.1em 0.3em; border-radius: 3px; background: var(--color-surface); }
  .prose pre { padding: var(--space-s) var(--space-m); overflow-x: auto; border-radius: 4px; background: var(--color-surface); line-height: 1.5; }
  .prose table { font-size: var(--text-small); font-variant-numeric: tabular-nums; }
  .prose :where(th, td) { padding: 0.5em 0.75em; border-block-end: 1px solid var(--color-border); text-align: start; }

  /* Under a post: who wrote it. */
  .author-box { display: flex; gap: var(--space-m); align-items: start; margin-block-start: var(--space-xl); padding-block-start: var(--space-m); border-block-start: 1px solid var(--color-border); }
  .author-text { display: grid; gap: var(--space-xs); }
  .avatar { flex: none; inline-size: 4rem; aspect-ratio: 1; border-radius: 50%; object-fit: cover; background: var(--color-surface); }
  .avatar-large { inline-size: 6rem; margin-block-end: var(--space-m); }
  .author-name { font-size: var(--text-large); font-weight: 650; }
  .author-name a { color: inherit; text-decoration: none; }
  .author-name a:hover { color: var(--color-accent); }
  .author-bio { color: var(--color-muted); }
  .author-links { font-size: var(--text-small); }

  /* After the post: its section's pages, the previous and next posts, and more to read. */
  .entry-children { margin-block-start: var(--space-xl); }
  .entry-children ul { display: grid; gap: var(--space-xs); padding-block-start: var(--space-m); border-block-start: 1px solid var(--color-border); }
  .post-nav { display: flex; justify-content: space-between; gap: var(--space-m); margin-block-start: var(--space-xl); padding-block-start: var(--space-m); border-block-start: 1px solid var(--color-border); }
  .post-nav a { display: grid; gap: 0.2em; max-inline-size: 48%; color: inherit; text-decoration: none; font-weight: 500; }
  .post-nav a:hover { color: var(--color-accent); }
  .post-nav span { font-size: var(--text-small); color: var(--color-muted); font-weight: 400; }
  .post-nav-next { margin-inline-start: auto; text-align: end; }
  .related { margin-block-start: var(--space-xxl); }
  .section-title { margin-block-end: var(--space-m); font-size: var(--text-small); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; color: var(--color-muted); }

  .pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-m); margin-block-start: var(--space-xl); font-size: var(--text-small); }
  .pagination a { text-decoration: none; font-weight: 500; }
  .pagination-count { color: var(--color-muted); margin-inline: auto; }

  /*
   * Forms that Estel adds to a page with <div data-form="…">. The hidden field catches spam robots, and must stay
   * out of sight.
   */
  .estel-form { display: grid; gap: var(--space-m); }
  .estel-form-field { display: grid; gap: var(--space-xs); }
  .estel-form-field label { font-size: var(--text-small); font-weight: 500; }
  .estel-form-field.is-check label { display: flex; align-items: baseline; gap: 0.5em; font-weight: 400; font-size: var(--text-base); }
  .estel-form :where(input:not([type=checkbox], [type=radio]), select, textarea) {
    inline-size: 100%; padding: 0.6em 0.8em; border: 1px solid var(--color-border); border-radius: 4px; background: var(--color-background);
  }
  /* The dropdown's arrow: a thin chevron with room around it, in place of the browser's own. */
  .estel-form select {
    appearance: none; padding-inline-end: 2.75em;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239B9BA1' stroke-width='1.5'/%3E%3C/svg%3E");
    background-position: right 1em center; background-size: 0.75em; background-repeat: no-repeat;
  }
  .estel-form :where(input, select, textarea):focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }
  .estel-form button { justify-self: start; padding: 0.7em 1.6em; border-radius: 4px; background: var(--color-text); color: var(--color-background); font-weight: 500; }
  .estel-form button:hover { background: var(--color-accent); }
  .estel-form-error { color: #B32D2E; font-size: var(--text-small); }
  .estel-form-trap { position: absolute; inset-inline-start: -10000px; inline-size: 1px; block-size: 1px; overflow: hidden; }
  .estel-form.is-sent { padding: var(--space-m); border: 1px solid var(--color-border); border-radius: 4px; }

  .not-found { display: grid; gap: var(--space-s); justify-items: start; }
  .not-found .list-title { margin-block: 0 var(--space-xs); }

  /* Footer: columns that wrap onto new lines on small screens. */
  .site-footer { padding-block: var(--space-xl); border-block-start: 1px solid var(--color-border); background: var(--color-surface); font-size: var(--text-small); color: var(--color-muted); }
  .site-footer-inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: var(--space-l); }
  /* The first column is wider. Footer widgets, Pages and the newsletter take the next four, and more go on a new row. */
  @media (width >= 64rem) { .site-footer-inner { grid-template-columns: 2fr repeat(4, 1fr); } .site-footer-inner > :nth-child(4n + 6) { grid-column-start: 2; } }
  .site-footer-about { max-inline-size: 22rem; display: grid; gap: var(--space-xs); align-content: start; }
  .site-footer-title { font-size: var(--text-large); font-weight: 650; color: var(--color-text); }
  .site-footer-title a { color: inherit; text-decoration: none; }
  .site-footer-heading { margin-block-end: var(--space-s); font-size: var(--text-small); font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text); }
  .site-footer ul { display: grid; gap: var(--space-xs); list-style: none; }
  .site-footer nav a, .site-footer .widget a { color: inherit; text-decoration: none; }
  .site-footer nav a:hover, .site-footer .widget a:hover { color: var(--color-accent); }
  .site-footer .widget-title { font-size: var(--text-small); font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text); }

  /* Widgets, in the sidebar and the footer. A folded widget opens from its title. */
  .widget { display: grid; gap: var(--space-s); align-content: start; }
  .site-sidebar .widget + .widget { margin-block-start: var(--space-l); }
  .site-sidebar .widget-title { font-size: var(--text-base); font-weight: 650; }
  .widget ul { display: grid; gap: var(--space-xs); list-style: none; padding: 0; }
  .site-sidebar .widget li a { color: var(--color-text); text-decoration: none; }
  .site-sidebar .widget li a:hover { color: var(--color-accent); }
  .widget-count { color: var(--color-muted); }
  .widget summary { cursor: pointer; }
  .widget details[open] summary { margin-block-end: var(--space-s); }
  .widget-search input { inline-size: 100%; padding: var(--space-xs) var(--space-s); border: 1px solid var(--color-border); border-radius: 4px; font: inherit; }
  .site-footer-newsletter .estel-form { gap: var(--space-s); }
  .site-footer-newsletter .estel-form-field label, .site-footer-newsletter .estel-form-field.is-check label { font-weight: 400; font-size: var(--text-small); }

  /* The centred header: the title above the menu, both in the middle. */
  [data-header="centred"] .site-header-inner { flex-direction: column; justify-content: center; text-align: center; }
  [data-header="centred"] .site-title { font-size: var(--text-x-large); }
  [data-header="centred"] .menu { justify-content: center; }
  @media (width < 48rem) {
    [data-header="centred"].js .menu { align-items: center; }
  }
}
