/* SPDX-License-Identifier: CC0-1.0 */

/* The site's own rules, linked after Forester's native style.css and the
   Seimiya design system's tokens.css by decorate.py. Forester's stylesheet is
   used as shipped, sizes and spacing included (12pt, line height 1.55, its
   margins and indents); this file gives it the design system's faces and
   colours, and adds the navigation above the page and the side view.

   The page is Forester's own: the tree, and the table of contents to its
   right; "« MIYA-LIS.NET" stands where Forester puts "« Home", with
   [Navigation] beside it, which scrolls up to the navigation above the page.
   Below 1000px, where Forester drops the table of contents, the contents and
   the backmatter stand to the right of the page, and the view scrolls
   sideways to them. */

/* Monaspace Neon (SIL OFL 1.1, theme/LICENSES/OFL-1.1.txt) is the Latin face;
   IBM Plex Sans JP comes from Google Fonts. */
@font-face { font-family: "Monaspace Neon"; src: url("/fonts/MonaspaceNeon-300.woff2") format("woff2"); font-weight: 300; font-display: swap; }
@font-face { font-family: "Monaspace Neon"; src: url("/fonts/MonaspaceNeon-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Monaspace Neon"; src: url("/fonts/MonaspaceNeon-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --tree-mark-size: 4rem;
}

/* ── Page ─────────────────────────────────────────────────────────────────── */

body.miya-native {
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  /* Monaspace's texture healing is a contextual alternate. */
  font-variant-ligatures: contextual;
  hyphens: manual;
}

/* Long URLs and titles wrap inside the column rather than widen the page. */
#grid-wrapper > article { min-width: 0; overflow-wrap: anywhere; }

/* Forester's "« Home" link carries the site name, on every page (Forester
   hides it on the home tree). */
#home-link.hidden { display: flex; }
.logo a { color: var(--ink-muted); }
.logo a:hover { color: var(--ink); background: none; }

/* ── Trees ────────────────────────────────────────────────────────────────── */

span.taxon { color: var(--ink-taxon); }
article > section > header > h1 > .taxon { color: var(--ink-muted); }
.slug, .doi, .orcid { color: var(--ink-muted); }
address { font-style: normal; }

.block:hover { background-color: var(--hover); }
/* A closed tree says there is more behind its title. */
section.block:has(> .mainmatter.collapsed) > header > h1::after { content: " …"; color: var(--ink-muted); font-weight: 400; }

.highlighted { background-color: var(--orange-soft); border-color: var(--line); }
.highlighted:hover { background-color: var(--orange-soft); border-color: var(--line-strong); }
mark { background-color: var(--orange-soft); color: inherit; }

/* No italics: Japanese has none. */
blockquote, figcaption { font-style: normal; }

pre, code { background-color: var(--surface-code); font-family: var(--font-mono); }

/* ── Links ────────────────────────────────────────────────────────────────── */

/* Text stays ink; the underline is green, dotted inside the site, solid out. */
a { color: var(--link); }
.link.local a, a.link.local, a.slug { text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--link-underline); text-underline-offset: 3px; }
.link.external a, a.link.external, a.orcid, a.doi { text-decoration: underline solid var(--link-underline); text-underline-offset: 3px; }
a.slug:hover, a.bullet:hover, .link:hover, .link a:hover, a.orcid:hover, a.doi:hover { background-color: var(--green-soft); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

.link-preview { background-color: var(--surface); border-color: var(--line); box-shadow: var(--shadow-float); color: var(--ink); }

/* ── Table of contents ────────────────────────────────────────────────────── */

nav#toc, nav#toc a { color: var(--ink-muted); }
nav#toc a.bullet, .side-part a.bullet { color: var(--orange); opacity: 1; }

/* ── Navigation ───────────────────────────────────────────────────────────── */

/* decorate.py puts the site navigation above the page (#nav-top) and
   [Navigation] beside the site name. The page opens scrolled past the
   navigation (side.js), scrolling up stops once where it is just hidden, and
   [Navigation] scrolls up to it. The scrolling glides, unless motion is
   reduced; side.js makes the stop at the site-name line. */
#home-link { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 1em; }
.side-tab { padding: 2px 4px; font-weight: 200; color: var(--ink-muted); border-radius: var(--radius-sm); text-decoration: none; }
.side-tab:hover { color: var(--ink); background: var(--green-soft); }
.bib-copy { font: inherit; font-size: .9em; padding: 2px 4px; margin-left: .3em; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink-muted); cursor: pointer; }
.bib-copy:hover, .bib-copy:focus-visible { color: var(--ink); background: var(--green-soft); }
.side-tab--nav::before { content: "«"; display: inline-block; transform: rotate(90deg); margin-right: .4em; }
.nav-top { padding: 0 .5em 1em 0; margin-bottom: 1em; border-bottom: 1px solid var(--line); }
.nav-top > .block > h1 { font-size: 16pt; margin-top: 0; }
/* [Back to top], back to the site-name line: at the foot of the window, on
   the right, once the page is scrolled (side.js sets .is-scrolled). */
.back-to-top { opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility .3s; }
.is-scrolled .back-to-top { opacity: 1; visibility: visible; }
nav#toc .back-to-top { position: fixed; right: 2em; bottom: 1.5em; background: var(--surface); }
nav#toc .back-to-top::before { content: "«"; display: inline-block; transform: rotate(90deg); margin-right: .4em; }
/* At least a screen below it, so a short page can still open scrolled past it. */
.page-view > #grid-wrapper { min-height: 100vh; }
html { scroll-behavior: smooth; }
/* The navigation reads across, as a line of links. */
.side-menu { display: flex; flex-wrap: wrap; gap: 0 1em; padding-left: 0; margin: 0; list-style: none; }
.side-menu-link { display: flex; align-items: baseline; gap: .4em; padding: .2em .3em; border-radius: var(--radius-sm); color: var(--ink-muted); text-decoration: none; }
.side-menu-link:hover { background: var(--hover); color: var(--ink); }
.side-menu-bullet { font-size: .7em; color: var(--line-strong); flex: none; }
.side-menu-link.is-current { color: var(--ink); font-weight: 700; }
.side-menu-link.is-current .side-menu-bullet { color: var(--orange); }

/* ── Side view (narrow screens) ───────────────────────────────────────────── */

/* Below 1000px decorate.py's side view, copies of the table of contents and
   of each part of the backmatter, stands to the right of the page in one view
   that scrolls sideways. Its edge, a column of bracketed vertical links, stays
   in sight beside the page; a link glides the view to its part, a whole
   screen over, and [Back to page] or a swipe brings the page back. */
.side-view { display: none; }
.side-part + .side-part { margin-top: 1.5em; }
.side-part ul { list-style: none; }
.side-part > .block > ul { padding-left: 0; }
.side-part h1 { margin-top: 0; }
/* Forester sets its table of contents heading at 16pt; the parts follow it. */
.side-part > .block > h1 { font-size: 16pt; }
.side-part { scroll-margin-top: 1em; }

@media (max-width: 1000px) {
  html, body.miya-native { height: 100%; overflow: hidden; }
  body.miya-native { margin: 0; }
  #main-wrapper { display: flex; height: 100%; overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth;
    scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none; }
  #main-wrapper::-webkit-scrollbar { display: none; }
  .page-view { flex: 0 0 calc(100% - 18px - env(safe-area-inset-right, 0px)); min-width: 0; box-sizing: border-box;
    overflow-y: auto; scroll-snap-align: start; padding: 1em 0 2em .5em; scroll-behavior: smooth; }
  .page-view > #grid-wrapper { min-height: 100%; }
  #grid-wrapper > article > footer { display: none; }
  /* Small enough to share the site name's line on a phone, at its right end. */
  .side-tab--nav { font-size: 14px; }
  #home-link { column-gap: .5em; }
  #home-link .side-tabs { margin-left: auto; }
  .side-view { flex: 0 0 auto; display: flex; height: 100%; }
  .side-strip { display: flex; flex-direction: column; gap: .5em; flex: 0 0 18px; padding-top: 3.5em; overflow: hidden; }
  .side-strip .side-tab { writing-mode: vertical-rl; padding: 4px 1px; line-height: 1; font-size: 13px; }
  /* Which way each goes: » over [Table of Contents], to the side view on
     the right; « over [Back to page], to the page on the left. Upright, so
     the marks keep pointing across while the words run down. */
  .side-strip .side-tab--toc::before, .side-back--narrow::before { text-orientation: upright; margin-bottom: .4em; }
  .side-strip .side-tab--toc::before { content: "»"; }
  .side-back--narrow::before { content: "«"; }
  /* [Back to top] closes the column of tabs; set down the line, « points up. */
  .side-strip .back-to-top { margin-top: .5em; }
  .side-strip .back-to-top::before { content: "«"; margin-bottom: .4em; }
  /* The side view's body is a whole screen wide, so going there takes the
     tabs out of sight; [Back to page] stands on its left edge instead. */
  .side-body { width: 100vw; display: flex; scroll-snap-align: start; }
  .side-back--narrow { display: block; flex: 0 0 18px; writing-mode: vertical-rl; padding: 3.5em 1px 0; line-height: 1;
    font-size: 13px; border-right: 1px solid var(--line); border-radius: 0; }
  .side-parts { flex: 1; min-width: 0; overflow-y: auto; scroll-behavior: smooth;
    padding: 1em calc(.5em + env(safe-area-inset-right, 0px)) 2em .5em; }
}

@media (prefers-reduced-motion: reduce) {
  html, #main-wrapper, .page-view, .side-parts { scroll-behavior: auto !important; }
}

@media (max-width: 839px) {
  /* Narrow columns cannot spare a 40px list indent per level. */
  article :is(ul, ol), .side-part :is(ul, ol) { padding-left: 1.3em; }
  article :is(ul, ol) :is(ul, ol) { padding-left: 1.1em; }
  .side-part > .block > ul { padding-left: 0; }
}

/* ── A tree's own picture ─────────────────────────────────────────────────── */

/* 0000 is the tree about the person this site belongs to, and the drawing is
   of him, so this is addressed to that one tree rather than to `Person` — a
   rule on the taxon would put his portrait on everyone's card. Forester gives
   the block an id made from the tree's URI, so that id is the address.

   Scoped to the article's own mainmatter, because the same tree is rendered
   again in the backmatter beneath it, as a reference rather than as itself. A
   portrait in a list of backlinks is noise.

   The block reserves a column the width of the picture plus a gutter, so the
   prose stops short of it rather than running underneath: the picture is
   taken out of flow, and out-of-flow boxes are not something block text moves
   aside for on its own. */
article>section>.mainmatter>.block:is(#id-https-3a-2f-2fmiya-lis-2enet-2f0000-2f, :has(> #id-https-3a-2f-2fmiya-lis-2enet-2f0000-2f)) {
  position: relative;
  padding-right: calc(var(--tree-mark-size) + var(--space-4));
}

article>section>.mainmatter>.block:is(#id-https-3a-2f-2fmiya-lis-2enet-2f0000-2f, :has(> #id-https-3a-2f-2fmiya-lis-2enet-2f0000-2f))::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: var(--tree-mark-size);
  height: var(--tree-mark-size);
  /* The drawing is taller than the square it is shown in; `cover` fills the
     square from the top, which is where the head is. */
  background: url("/icon.svg") no-repeat top center / cover;
}

/* ── Link cards ───────────────────────────────────────────────────────────── */

/* A `cardlink` block in the vault — what Obsidian's card plugin wrote down
   after fetching a page's Open Graph metadata — compiles to an anchor whose
   parts tree_of_md classes and leaves unstyled, because what a card looks like
   is this theme's business and not the note's. */

.card-link {
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  margin: var(--space-4) 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-decoration: none;
}

.card-link:hover {
  background-color: var(--hover);
}

/* The picture is decoration, not the point: it takes a fixed column and the
   words take whatever is left, so a tall cover cannot set the card's height. */
.card-link-image {
  flex: 0 0 auto;
  width: clamp(5rem, 25%, 10rem);
  align-self: stretch;
  object-fit: cover;
}

.card-link-body {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  padding: var(--space-2) 0;
  padding-inline-end: var(--space-2);
  min-width: 0;
}

/* Without an image the words would sit against the border. */
.card-link-image + .card-link-body {
  padding-inline-start: 0;
}

.card-link-body:first-child {
  padding-inline-start: var(--space-2);
}

.card-link-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* Two lines of the page's own words. A description is a paragraph on some
   sites and a sentence on others, and a card is neither place to read one. */
.card-link-description {
  color: var(--ink-muted);
  font-size: 14px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.card-link-host {
  display: flex;
  align-items: center;
  gap: 0.4em;
  color: var(--ink-muted);
  font-size: 14px;
  margin-top: auto;
}

.card-link-favicon {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
}

/* Side by side needs room for two columns; a phone has room for one. */
@media (max-width: 30rem) {
  .card-link {
    flex-direction: column;
  }

  .card-link-image {
    width: 100%;
    height: clamp(6rem, 40vw, 10rem);
  }

  .card-link-image + .card-link-body {
    padding-inline-start: var(--space-2);
  }
}
