/* Rogarithm — static site styles */

/* Light is the default; the dark palette below is duplicated on purpose so it
   can apply either from the OS setting or from an explicit data-theme choice. */
:root {
  color-scheme: light;

  --bg: #fbfbfa;
  --bg-raised: #ffffff;
  --bg-sunken: #f2f2f0;
  --text: #1c1d1b;
  --text-muted: #63665f;
  --border: #e0e0dc;
  --border-strong: #cfcfc9;
  --accent: #0f8f68;
  --accent-text: #0b6b4e;
  --accent-contrast: #ffffff;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px -12px rgb(0 0 0 / 0.12);

  --measure: 46rem;
  --wrap: 68rem;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #131514;
    --bg-raised: #1b1e1c;
    --bg-sunken: #0e100f;
    --text: #e7e9e5;
    --text-muted: #9aa096;
    --border: #2b2f2c;
    --border-strong: #3b403c;
    --accent: #3fcfa0;
    --accent-text: #52d9ad;
    --accent-contrast: #0c1712;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px -12px rgb(0 0 0 / 0.7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #131514;
  --bg-raised: #1b1e1c;
  --bg-sunken: #0e100f;
  --text: #e7e9e5;
  --text-muted: #9aa096;
  --border: #2b2f2c;
  --border-strong: #3b403c;
  --accent: #3fcfa0;
  --accent-text: #52d9ad;
  --accent-contrast: #0c1712;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px -12px rgb(0 0 0 / 0.7);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

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

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

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2rem); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: var(--accent-contrast);
  padding: 0.5rem 1rem; border-radius: var(--radius); z-index: 10;
}
.skip:focus { left: 1rem; top: 1rem; }

:where(a, summary, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- header ---------- */

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

.site-header .wrap {
  display: flex; align-items: center; gap: 1.5rem;
  flex-wrap: wrap;
  min-height: 4rem;
  padding-block: 0.75rem;
}

.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { font-size: 0.75rem; color: var(--text-muted); line-height: 1.2; }

.nav {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0; padding: 0; list-style: none;
  font-size: 0.9375rem;
}

.site-header nav { margin-left: auto; }

.nav > li > a,
.nav summary {
  display: inline-flex; align-items: center; gap: 0.25rem;
  color: var(--text-muted);
  text-decoration: none;
  padding-block: 0.25rem;
  cursor: pointer;
}
.nav > li > a:hover,
.nav summary:hover { color: var(--text); }
.nav a[aria-current="page"],
.nav details.is-current > summary { color: var(--text); font-weight: 600; }
.nav .ext { font-size: 0.75em; opacity: 0.7; }

.lang {
  display: flex; gap: 1px;
  margin: 0;
  padding: 2px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem; font-weight: 550;
  letter-spacing: 0.03em;
}
.lang a {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
}
.lang a:hover { color: var(--text); }
.lang a[aria-current="true"] {
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

/* Shown only once the script enables it — without JS it would do nothing. */
.theme {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem;
  padding: 0;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
}
.theme:hover { color: var(--text); border-color: var(--border-strong); }
.theme svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.6; }
.theme .icon-sun { display: none; }
.theme[aria-pressed="true"] .icon-sun { display: block; }
.theme[aria-pressed="true"] .icon-moon { display: none; }

.nav .has-sub { position: relative; }
.nav summary { list-style: none; }
.nav summary::-webkit-details-marker { display: none; }
.nav summary::after {
  content: ""; width: 0.4em; height: 0.4em; margin-left: 0.1em;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-0.1em);
}
.nav details[open] summary::after { transform: rotate(-135deg) translateY(-0.1em); }

.nav .sub {
  position: absolute; right: 0; top: calc(100% + 0.5rem);
  min-width: 12rem;
  margin: 0; padding: 0.375rem;
  list-style: none;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.nav .sub a {
  display: block; padding: 0.4rem 0.65rem; border-radius: 6px;
  color: var(--text-muted); text-decoration: none;
}
.nav .sub a:hover { background: var(--bg-sunken); color: var(--text); }

@media (max-width: 46rem) {
  /* the two-row nav is too tall to keep pinned on a phone */
  .site-header { position: static; }
  .site-header .wrap { gap: 0.75rem; }
  /* keep the switch beside the brand; the nav gets its own row below */
  .lang { order: 1; margin-left: auto; }
  .theme { order: 1; }
  .site-header nav { order: 2; width: 100%; margin-left: 0; }
  .nav { gap: 0.25rem 1rem; }
  .nav .sub { position: static; box-shadow: none; min-width: 0; margin-top: 0.25rem; }
}

/* ---------- home ---------- */

.stack { padding-block: clamp(2.5rem, 8vw, 5rem); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1rem;
  margin: 0; padding: 0; list-style: none;
}

.card {
  display: block; height: 100%;
  padding: 1.375rem 1.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none; color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 0.375rem;
  font-size: 1.0625rem; font-weight: 640; letter-spacing: -0.01em;
}
.card p { margin: 0; font-size: 0.9375rem; color: var(--text-muted); line-height: 1.6; }
.card .ext { margin-left: 0.35em; font-size: 0.75em; opacity: 0.6; }
.card.is-external { background: transparent; border-style: dashed; }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}

/* ---------- article ---------- */

.prose {
  max-width: calc(var(--measure) + 4rem);
  padding-block: clamp(2.5rem, 7vw, 4.5rem);
}

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

.prose h1 {
  font-size: clamp(1.75rem, 5vw, 2.375rem);
  font-weight: 680; letter-spacing: -0.02em; line-height: 1.25;
  margin: 0 0 2rem;
}

.prose h2 {
  font-size: 1.25rem; font-weight: 640; letter-spacing: -0.01em;
  margin: 3rem 0 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.prose h2:first-of-type { border-top: 0; padding-top: 0; margin-top: 2rem; }

.prose h3 { font-size: 1.0625rem; font-weight: 640; margin: 2rem 0 0.5rem; }

.prose p { margin: 0 0 1rem; }
.prose .lead {
  font-size: 1.0625rem;
  color: var(--text-muted);
  margin-top: -1rem;
  margin-bottom: 1.5rem;
}
.prose ul, .prose ol { margin: 0 0 1.25rem; padding-left: 1.25rem; }
.prose li { margin-bottom: 0.375rem; }
.prose li::marker { color: var(--text-muted); }

.prose strong { font-weight: 640; }

/* download buttons */

.prose .file { margin: 0 0 0.625rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 0.9375rem; font-weight: 550;
  color: var(--text); text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
/* Only actual downloads get the arrow — error pages reuse .btn for navigation. */
.btn[download]::before {
  content: "↓";
  font-size: 0.875em;
  color: var(--accent-text);
}
.btn:hover { border-color: var(--accent); background: var(--bg-sunken); }
.btn-meta {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 450;
  font-variant-numeric: tabular-nums;
}

/* figures and galleries */

.prose figure { margin: 1.75rem auto; }
.prose figure img, .prose figure video {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
}
.prose figcaption {
  margin-top: 0.5rem;
  font-size: 0.875rem; color: var(--text-muted); text-align: center;
}

.gallery {
  max-width: var(--wrap);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.875rem;
  margin: 2rem auto;
}
.gallery figure { margin: 0; }

.media { margin: 1.75rem auto; }
.media figure { margin: 0; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding-block: 2rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.site-footer .wrap {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem;
  align-items: center; justify-content: space-between;
}
.site-footer p { margin: 0; }
.site-footer ul {
  display: flex; flex-wrap: wrap; gap: 1.25rem;
  margin: 0; padding: 0; list-style: none;
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); text-decoration: underline; }
