/* ==========================================================================
   Palette — "washi & sumi"
   Light: warm unbleached paper, soot-black ink, vermilion (shu) seal red,
          indigo (ai) for links.
   Dark:  indigo-black night, paper-coloured ink, lifted vermilion & indigo.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg:          #f7f3ea;
  --bg-sunk:     #efe8da;
  --text:        #24211c;
  --text-soft:   #4a453c;
  --muted:       #6e6759;
  --rule:        #ddd4c2;
  --accent:      #b5432a;
  --accent-soft: #b5432a1f;
  --accent-ink:  #9b3b26;
  --link:        #2b4b7c;
  --link-line:   #2b4b7c59;
  --mark:        #f1d9a3;
  --selection:   #e9c3b6;

  --syn-keyword: #9b3b26;
  --syn-string:  #4e6b2e;
  --syn-comment: #6e6759;
  --syn-func:    #2b4b7c;
  --syn-number:  #8a5a12;

  --font-serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino,
                "Noto Serif JP", "Hiragino Mincho ProN", "Source Han Serif", Georgia, serif;
  --font-sans:  "IBM Plex Sans", system-ui, -apple-system, "Segoe UI",
                "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-mono:  "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --measure: 38rem;
  --wide:    48rem;
  --gutter:  clamp(1.25rem, 5vw, 2.5rem);
  --radius:  6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:          #14161b;
    --bg-sunk:     #1c1f26;
    --text:        #e8e2d6;
    --text-soft:   #cfc8ba;
    --muted:       #968f81;
    --rule:        #2c3039;
    --accent:      #e7795a;
    --accent-soft: #e7795a24;
    --accent-ink:  #ef9a7f;
    --link:        #9cbbe6;
    --link-line:   #9cbbe666;
    --mark:        #5a4a22;
    --selection:   #5b3328;

    --syn-keyword: #ef9a7f;
    --syn-string:  #b5cc8e;
    --syn-comment: #8f897a;
    --syn-func:    #9cbbe6;
    --syn-number:  #e3b86a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #14161b;
  --bg-sunk:     #1c1f26;
  --text:        #e8e2d6;
  --text-soft:   #cfc8ba;
  --muted:       #968f81;
  --rule:        #2c3039;
  --accent:      #e7795a;
  --accent-soft: #e7795a24;
  --accent-ink:  #ef9a7f;
  --link:        #9cbbe6;
  --link-line:   #9cbbe666;
  --mark:        #5a4a22;
  --selection:   #5b3328;

  --syn-keyword: #ef9a7f;
  --syn-string:  #b5cc8e;
  --syn-comment: #8f897a;
  --syn-func:    #9cbbe6;
  --syn-number:  #e3b86a;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 2rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: clamp(1.0625rem, 0.98rem + 0.35vw, 1.1875rem);
  line-height: 1.65;
  font-optical-sizing: auto;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::selection { background: var(--selection); color: var(--text); }

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

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

a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.18em;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}
a:hover { text-decoration-color: currentColor; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  padding: 0.5rem 0.9rem;
  background: var(--text);
  color: var(--bg);
  font: 500 0.85rem/1 var(--font-sans);
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus { left: 0.5rem; }

.wrap {
  width: 100%;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

main { flex: 1; }

/* ==========================================================================
   Header & footer
   ========================================================================== */

.site-header {
  padding: clamp(1.5rem, 4vw, 2.5rem) 0 0;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text);
  text-decoration: none;
}
.brand-seal {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 5px;
  background: var(--accent);
  color: var(--bg);
  font: italic 600 1.15rem/1 var(--font-serif);
  font-variation-settings: "opsz" 72;
  transform: rotate(-4deg);
  transition: transform 0.25s ease;
}
.brand:hover .brand-seal { transform: rotate(0deg); }
.brand-name {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 560;
  letter-spacing: -0.01em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.9rem, 3vw, 1.6rem);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 1.5px solid transparent;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle svg { width: 1rem; height: 1rem; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.site-footer {
  margin-top: clamp(4rem, 10vw, 7rem);
  padding: 2rem 0 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--muted);
}
.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.site-footer a { color: inherit; text-decoration-color: var(--rule); }
.site-footer a:hover { color: var(--text); text-decoration-color: currentColor; }

/* ==========================================================================
   Home
   ========================================================================== */

.intro {
  max-width: var(--measure);
  padding: clamp(3.5rem, 10vw, 6.5rem) 0 clamp(2.5rem, 6vw, 4rem);
}
.intro h1 {
  margin: 0 0 1.1rem;
  font-size: clamp(2.25rem, 1.5rem + 3.2vw, 3.6rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.022em;
  text-wrap: balance;
}
.intro h1 em {
  font-style: italic;
  color: var(--accent);
}
.intro p {
  margin: 0;
  font-size: 1.125em;
  color: var(--text-soft);
  text-wrap: pretty;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.post-list li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.25rem 1.5rem;
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-list time {
  padding-top: 0.42rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.post-list h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.post-list h2 a {
  color: var(--text);
  text-decoration: none;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0 1.5px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s ease;
}
.post-list h2 a:hover { background-size: 100% 1.5px; }
.post-list p {
  grid-column: 2;
  margin: 0.35rem 0 0;
  color: var(--text-soft);
  font-size: 0.98em;
  text-wrap: pretty;
}

@media (max-width: 34rem) {
  .post-list li { grid-template-columns: 1fr; }
  .post-list time { padding-top: 0; }
  .post-list p { grid-column: 1; }
}

/* ==========================================================================
   Article
   ========================================================================== */

.post-header {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3rem, 9vw, 5.5rem) 0 clamp(1.75rem, 4vw, 2.5rem);
}
.post-kicker {
  margin: 0 0 1rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.post-kicker a { color: inherit; text-decoration: none; }
.post-header h1 {
  margin: 0;
  font-size: clamp(2.1rem, 1.4rem + 3vw, 3.25rem);
  font-weight: 450;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.post-dek {
  margin: 1rem 0 0;
  font-size: 1.2em;
  font-style: italic;
  line-height: 1.5;
  color: var(--text-soft);
  text-wrap: pretty;
}
.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  margin: 1.6rem 0 0;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--muted);
}
.post-meta .dot { opacity: 0.6; }
.tag {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
}

/* Prose ------------------------------------------------------------------ */

.prose {
  max-width: var(--measure);
  margin: 0 auto;
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.prose > * { margin-top: 0; margin-bottom: 0; }
.prose > * + * { margin-top: 1.25em; }

.prose p { text-wrap: pretty; }

.prose > p:first-child {
  font-size: 1.12em;
  line-height: 1.6;
}
.prose > p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.1em 0 0;
  font-size: 3.6em;
  line-height: 0.82;
  font-weight: 500;
  font-variation-settings: "opsz" 72;
  color: var(--accent);
}

.prose h2,
.prose h3,
.prose h4 {
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
  hyphens: manual;
}
.prose h2 {
  margin-top: 2.4em;
  font-size: 1.6em;
  font-weight: 500;
}
.prose h3 {
  margin-top: 2em;
  font-size: 1.25em;
  font-weight: 600;
}
.prose h4 {
  margin-top: 1.8em;
  font-family: var(--font-sans);
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: 0.7em; }

.prose .anchor {
  margin-left: 0.35em;
  color: var(--rule);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.prose h2:hover .anchor,
.prose h3:hover .anchor,
.prose .anchor:focus { opacity: 1; }
.prose .anchor:hover { color: var(--accent); }

.prose strong { font-weight: 650; }
.prose small { font-size: 0.85em; }
.prose abbr[title] { text-decoration: underline dotted var(--muted); cursor: help; }
.prose .smcp {
  font-family: var(--font-sans);
  font-size: 0.8em;
  letter-spacing: 0.05em;
}

.prose mark {
  background: var(--mark);
  color: inherit;
  padding: 0 0.15em;
  border-radius: 2px;
}

.prose kbd {
  display: inline-block;
  padding: 0.05em 0.4em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78em;
  line-height: 1.4;
  background: var(--bg-sunk);
}

.prose ul,
.prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.4em; }
.prose li > ul,
.prose li > ol { margin-top: 0.4em; }
.prose ul > li::marker { color: var(--accent); }
.prose ol > li::marker {
  font-family: var(--font-sans);
  font-size: 0.85em;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.prose blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 0.1em 0 0.1em 1.4em;
  border-left: 2px solid var(--accent);
  font-style: italic;
  color: var(--text-soft);
}
.prose blockquote p + p { margin-top: 0.8em; }
.prose blockquote footer {
  margin-top: 0.6em;
  font-family: var(--font-sans);
  font-style: normal;
  font-size: 0.8em;
  color: var(--muted);
}

.prose .pullquote {
  margin: 2.2em 0;
  padding: 0;
  border: 0;
  font-size: 1.45em;
  line-height: 1.35;
  font-weight: 400;
  font-style: italic;
  text-align: center;
  color: var(--text);
  text-wrap: balance;
}
.prose .pullquote::before,
.prose .pullquote::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 1px;
  margin: 0 auto 0.9em;
  background: var(--accent);
}
.prose .pullquote::after { margin: 0.9em auto 0; }

.prose hr {
  margin: 2.6em auto;
  border: 0;
  height: auto;
  text-align: center;
}
.prose hr::before {
  content: "\2042";
  font-size: 1.1em;
  color: var(--accent);
}

/* Code */
.prose code,
.prose pre {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}
.prose :not(pre) > code {
  padding: 0.1em 0.32em;
  border-radius: 4px;
  background: var(--bg-sunk);
  font-size: 0.84em;
  overflow-wrap: anywhere;
}
.prose pre {
  margin-left: calc(-1 * min(1.25rem, var(--gutter) / 2));
  margin-right: calc(-1 * min(1.25rem, var(--gutter) / 2));
  padding: 1.1em 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-sunk);
  font-size: 0.8em;
  line-height: 1.65;
  hyphens: none;
  tab-size: 2;
}
.prose pre[data-lang] { position: relative; padding-top: 2.1em; }
.prose pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.7em;
  right: 1rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.prose pre code { font-size: inherit; }

.tok-k { color: var(--syn-keyword); }
.tok-s { color: var(--syn-string); }
.tok-c { color: var(--syn-comment); font-style: italic; }
.tok-f { color: var(--syn-func); }
.tok-n { color: var(--syn-number); }

/* Figures, tables */
.prose figure { margin-left: 0; margin-right: 0; }
.prose figure.wide {
  margin-left: calc(-1 * min((var(--wide) - var(--measure)) / 2, var(--gutter)));
  margin-right: calc(-1 * min((var(--wide) - var(--measure)) / 2, var(--gutter)));
}
.prose figure img,
.prose figure svg {
  display: block;
  width: 100%;
  border-radius: var(--radius);
}
.prose figcaption {
  margin-top: 0.75em;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.82em;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}
.prose th,
.prose td {
  padding: 0.6em 0.9em 0.6em 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.prose th {
  font-weight: 600;
  font-size: 0.85em;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--text-soft);
}
.prose td.num, .prose th.num { text-align: right; }

/* Swatches (used in the colophon) */
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.75rem;
  margin-top: 1.25em;
  padding: 0;
  list-style: none;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  line-height: 1.4;
}
.swatches li { margin: 0; }
.swatches .chip {
  display: block;
  height: 3.25rem;
  margin-bottom: 0.45rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.swatches b { display: block; font-weight: 600; color: var(--text); }
.swatches code { background: none !important; padding: 0 !important; color: var(--muted); }

/* Type specimen (colophon) */
.specimen {
  padding: 1.1em 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.specimen + .specimen { margin-top: 0; border-top: 0; }
.specimen .label {
  display: block;
  margin-bottom: 0.3em;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.specimen .sample { font-size: 1.9em; line-height: 1.2; letter-spacing: -0.01em; }
.specimen .sample.sans { font-family: var(--font-sans); font-size: 1.5em; }
.specimen .sample.mono { font-family: var(--font-mono); font-size: 1.25em; }

/* Footnotes */
.prose sup { line-height: 0; }
.prose .fn-ref a {
  padding: 0 0.1em;
  font-family: var(--font-sans);
  font-size: 0.72em;
  font-weight: 600;
  text-decoration: none;
  color: var(--accent);
}
.prose .footnotes {
  margin-top: 3em;
  padding-top: 1.2em;
  border-top: 1px solid var(--rule);
  font-size: 0.85em;
  color: var(--text-soft);
}
.prose .footnotes ol { padding-left: 1.2em; }
.prose .footnotes a.back { text-decoration: none; margin-left: 0.25em; }
.prose :target { scroll-margin-top: 2rem; }
.prose li:target { background: var(--accent-soft); border-radius: 3px; }

/* Asides */
.prose .note {
  padding: 1em 1.2em;
  border-radius: var(--radius);
  background: var(--bg-sunk);
  font-size: 0.92em;
}
.prose .note > :first-child { margin-top: 0; }
.prose .note-title {
  display: block;
  margin-bottom: 0.25em;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Post footer navigation ------------------------------------------------- */

.post-end {
  max-width: var(--measure);
  margin: clamp(3rem, 8vw, 4.5rem) auto 0;
}
.post-end .fin {
  display: block;
  width: 0.7rem;
  height: 0.7rem;
  margin: 0 0 2.5rem;
  background: var(--accent);
  border-radius: 2px;
  transform: rotate(45deg);
}
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.post-nav a {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.post-nav a:hover { border-color: var(--accent); background: var(--bg-sunk); }
.post-nav .dir {
  display: block;
  margin-bottom: 0.2rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.post-nav .title { font-size: 1.02rem; line-height: 1.3; }
.post-nav .next { grid-column: 2; text-align: right; }
@media (max-width: 34rem) {
  .post-nav { grid-template-columns: 1fr; }
  .post-nav .next { grid-column: 1; }
}

/* ==========================================================================
   Simple pages (about, 404)
   ========================================================================== */

.page-hero {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3.5rem, 10vw, 6rem) 0 clamp(1.5rem, 4vw, 2.25rem);
}
.page-hero h1 {
  margin: 0;
  font-size: clamp(2.25rem, 1.5rem + 3vw, 3.4rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.022em;
}
.page-hero .big {
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--accent);
}

/* ==========================================================================
   Motion & print
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .brand-seal { transform: none; }
}

@media print {
  :root {
    --bg: #fff; --bg-sunk: #f4f4f4; --text: #000; --text-soft: #222;
    --muted: #555; --rule: #ccc; --link: #000;
  }
  .site-header nav, .theme-toggle, .site-footer, .post-nav, .skip-link { display: none; }
  body { font-size: 11pt; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: var(--muted); }
  .prose pre { white-space: pre-wrap; }
}
