/* ==========================================================================
   Fall beta - shared stylesheet
   Single source of truth for typography, layout and responsive behaviour.
   Breakpoints: <=719px handheld, 720-1023px tablet, >=1024px desktop.
   ========================================================================== */

/* --------------------------------------------------------------- tokens */
:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --bg: #ffffff;
  --bg-subtle: #f4f6f8;
  --surface: #ffffff;
  --border: #dfe4ea;
  --border-strong: #c6ced8;
  --text: #1c2430;
  --text-muted: #5c6a7a;
  --accent: #2f6b4f;
  --accent-hover: #245740;
  --accent-soft: #e9f1ec;
  --code-bg: #f7f8fa;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 45, .06);
  --shadow-md: 0 2px 4px rgba(20, 30, 45, .06), 0 6px 16px rgba(20, 30, 45, .06);

  --content-max: 1120px;
  --measure: 74ch;
  --gutter: 1rem;
  --header-height: 56px;
}

@media (min-width: 720px) {
  :root {
    --gutter: 1.5rem;
    --header-height: 64px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --bg-subtle: #171c24;
    --surface: #1a2028;
    --border: #2a323d;
    --border-strong: #3a444f;
    --text: #e6eaef;
    --text-muted: #9aa7b5;
    --accent: #7fc0a0;
    --accent-hover: #a2d5bb;
    --accent-soft: #1e2a25;
    --code-bg: #161b22;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .35);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: clamp(15px, 0.95rem + 0.15vw, 17px);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover,
a:focus-visible { color: var(--accent-hover); text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

h1, h2, h3, h4 {
  margin: 0 0 .5em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(1.6rem, 1.25rem + 1.6vw, 2.25rem); }
h2 { font-size: clamp(1.3rem, 1.1rem + 0.9vw, 1.6rem); }
h3 { font-size: clamp(1.05rem, 0.98rem + 0.4vw, 1.2rem); }
h4 { font-size: 1rem; }

p { margin: 0 0 1rem; }

ul, ol { margin: 0 0 1rem; padding-left: 1.25rem; }
li { margin-bottom: .35rem; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* --------------------------------------------------------------- layout */
.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.page {
  padding-block: clamp(1.5rem, 1rem + 2vw, 3rem);
}

.page-head {
  margin-bottom: clamp(1.5rem, 1rem + 2vw, 2.5rem);
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-head p {
  max-width: var(--measure);
  margin: 0;
  color: var(--text-muted);
}

.section { margin-bottom: clamp(2rem, 1.5rem + 2vw, 3.5rem); }

.section > h2 {
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border);
}

.prose { max-width: var(--measure); }

.muted { color: var(--text-muted); }

.meta {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: .875rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: .6rem 1rem;
  z-index: 20;
}

.skip-link:focus { left: .5rem; top: .5rem; }

/* --------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .site-header { background: var(--bg); }
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-height);
}

.brand {
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: .01em;
  color: var(--text);
}

.brand:hover { text-decoration: none; color: var(--accent); }

.nav-toggle {
  display: none;
  align-items: center;
  gap: .5rem;
  min-height: 40px;
  padding: .4rem .7rem;
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav-toggle-icon {
  position: relative;
  width: 16px;
  height: 2px;
  background: currentColor;
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  background: currentColor;
}

.nav-toggle-icon::before { top: -5px; }
.nav-toggle-icon::after { top: 5px; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem;
}

.site-nav a {
  display: block;
  padding: .5rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .95rem;
}

.site-nav a:hover {
  background: var(--bg-subtle);
  color: var(--text);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

@media (max-width: 719px) {
  .nav-toggle { display: inline-flex; }

  .js .site-nav { display: none; }

  .js .site-nav.is-open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    padding: .5rem var(--gutter) .75rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
  }

  .site-nav a {
    padding: .75rem .5rem;
    font-size: 1rem;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
  }

  .site-nav a:last-child { border-bottom: 0; }
}

/* ---------------------------------------------------------------- cards */
.grid {
  display: grid;
  gap: clamp(1rem, .75rem + 1vw, 1.5rem);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}

.grid-wide {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

.card {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card h3 { margin-bottom: 0; }

/* A card whose only action is its title link is tappable as a whole. */
.card:not(:has(.card-actions)) { position: relative; }

.card:not(:has(.card-actions)) h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.card p { margin: 0; color: var(--text-muted); font-size: .925rem; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: auto;
  padding-top: .5rem;
}

/* --------------------------------------------------------------- figures */
figure {
  margin: 0 0 1rem;
}

figure img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

figcaption {
  margin-top: .4rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.figure-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  margin-bottom: 1.5rem;
}

/* ------------------------------------------------------------- document */
.doc-type {
  display: inline-block;
  padding: .1rem .45rem;
  font-size: .75rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------- button */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: .45rem .9rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  text-decoration: none;
}

.button-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.button-primary:hover { background: var(--accent-hover); color: #fff; }

@media (prefers-color-scheme: dark) {
  .button-primary { color: #10241b; }
  .button-primary:hover { color: #10241b; }
}

/* ------------------------------------------------------------ data list */
.data-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: .25rem 1.5rem;
  margin: 0;
}

.data-list dt {
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.data-list dd {
  margin: 0 0 .9rem;
}

@media (min-width: 720px) {
  .data-list {
    grid-template-columns: 10rem minmax(0, 1fr);
    align-items: baseline;
  }

  .data-list dt { padding-top: .15rem; }
}

.timeline { list-style: none; margin: 0; padding: 0; }

.timeline li {
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}

.timeline li:last-child { border-bottom: 0; }

.timeline .timeline-title { font-weight: 600; }

.post-list .timeline-title a {
  display: inline-block;
  padding: .2rem 0;
}

.timeline .timeline-meta {
  color: var(--text-muted);
  font-size: .875rem;
}

/* ----------------------------------------------------------------- post */
.post {
  padding: clamp(1rem, .75rem + 1vw, 1.75rem);
  margin-bottom: clamp(1.5rem, 1rem + 1.5vw, 2.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.post > *:last-child { margin-bottom: 0; }

.post-body { max-width: var(--measure); }

.post-list { list-style: none; margin: 0 0 2rem; padding: 0; }

.post-list li { margin-bottom: .5rem; }

/* ----------------------------------------------------------------- code */
pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: .8125rem;
  line-height: 1.6;
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
}

code { font-family: var(--font-mono); font-size: .9em; }

pre code { font-size: inherit; }

.code-block,
.disclosure {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

.code-block > summary,
.disclosure > summary {
  padding: .7rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  border-bottom: 1px solid transparent;
}

.code-block > summary::-webkit-details-marker,
.disclosure > summary::-webkit-details-marker { display: none; }

.code-block > summary::before,
.disclosure > summary::before {
  content: "+";
  display: inline-block;
  width: 1.1em;
  font-weight: 700;
  color: var(--text-muted);
}

.code-block[open] > summary,
.disclosure[open] > summary {
  border-bottom-color: var(--border);
}

.code-block[open] > summary::before,
.disclosure[open] > summary::before { content: "\2212"; }

.disclosure {
  background: var(--surface);
}

.disclosure > div {
  padding: 1rem;
}

.code-block pre {
  max-height: 26rem;
  overflow: auto;
  border: 0;
  border-radius: 0;
}

/* --------------------------------------------------------------- embeds */
.embed {
  width: 100%;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.embed-audio {
  width: 100%;
  max-width: 660px;
  height: 450px;
  border: 0;
}

/* --------------------------------------------------------------- footer */
.site-footer {
  margin-top: clamp(2rem, 1.5rem + 2vw, 4rem);
  padding-block: clamp(1.5rem, 1rem + 2vw, 2.5rem);
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  font-size: .9rem;
}

.footer-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

.footer-grid h2 {
  margin-bottom: .5rem;
  font-size: .8rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.link-list li { margin: 0; }

.link-list a {
  display: inline-block;
  padding: .25rem 0;
  color: var(--text-muted);
}

.link-list a:hover { color: var(--accent); }

.footer-note {
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .825rem;
}

/* ---------------------------------------------------------- preferences */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .site-header,
  .site-footer,
  .nav-toggle,
  .card-actions { display: none; }

  body { font-size: 11pt; color: #000; background: #fff; }

  .page { padding: 0; }

  a { color: #000; text-decoration: underline; }

  .post, .card { border: 0; box-shadow: none; padding: 0; }
}
