/* ============================================================
   sph.moe
   Paper and router lights. Set in Instrument Serif / Sans.
   ============================================================ */

/* ------------------------------------------------------------ fonts */

@font-face {
  font-family: "Fraunces";
  src: url("/assets/fonts/fraunces-var.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/assets/fonts/fraunces-var-italic.woff2") format("woff2");
  font-weight: 300 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/assets/fonts/instrument-sans-var.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/assets/fonts/instrument-sans-var-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/fonts/jetbrains-mono-var.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

/* ----------------------------------------------------------- tokens */

:root {
  color-scheme: light dark;

  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #faf4e9;
  --bg: light-dark(#faf4e9, #14100e);
  --ink: #1f1613;
  --ink: light-dark(#1f1613, #f3e9de);
  --ink-soft: #57493f;
  --ink-soft: light-dark(#57493f, #b8a99b);
  --muted: #6a5a50;
  --muted: light-dark(#6a5a50, #93847a);
  --rule: #e8dccb;
  --rule: light-dark(#e8dccb, #2a221d);
  --rule-soft: #f1e8da;
  --rule-soft: light-dark(#f1e8da, #201a16);
  --rule-strong: #d7c6ae;
  --rule-strong: light-dark(#d7c6ae, #3e332b);

  --accent: #a31f1f;
  --accent: light-dark(#a31f1f, #ff9a86);
  --accent-fill: #a31f1f;
  --accent-fill: light-dark(#a31f1f, #ff9a86);
  --accent-ink: #fdf6ec;
  --accent-ink: light-dark(#fdf6ec, #1a1110);
  --accent-glow: rgba(163, 31, 31, 0.25);

  --code-bg: #f2e8d8;
  --code-bg: light-dark(#f2e8d8, #1b1512);

  --shell: 42rem;
  --head-height: 64px;

  --ease: cubic-bezier(0.22, 0.68, 0.22, 1);
}

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

/* ------------------------------------------------------------ reset */

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Paper grain, behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

img, svg { display: block; max-width: 100%; }
h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
a { color: inherit; }

::selection {
  background: var(--accent-fill);
  color: var(--accent-ink);
}

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: 0.6rem 0.9rem;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  text-decoration: none;
  border-radius: 4px;
}
.skip:focus { top: 1rem; }

.shell {
  width: min(100% - 2.5rem, var(--shell));
  margin-inline: auto;
}
@media (max-width: 480px) {
  .shell { width: calc(100% - 2rem); }
}

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

.site-head {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}
@supports (background: color-mix(in oklab, black, white)) {
  .site-head {
    background: color-mix(in oklab, var(--bg) 86%, transparent);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
  }
}
.site-head.is-stuck { border-bottom-color: var(--rule); }

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

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--ink);
}
.wordmark-tld { color: var(--muted); }
.wordmark-mark {
  display: grid;
  grid-template-columns: repeat(2, 3px);
  grid-template-rows: repeat(2, 3px);
  gap: 1.5px;
  width: 7.5px;
  height: 7.5px;
}
.wordmark-mark i { background: var(--rule-strong); border-radius: 0.5px; }
.wordmark-mark i:nth-child(2),
.wordmark-mark i:nth-child(3) { background: var(--accent); }
.wordmark:hover .wordmark-mark i { background: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
}
.site-nav a {
  font-family: var(--font-mono);
  font-size: 0.6563rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s var(--ease);
}
.site-nav a:hover { color: var(--ink); }

.theme-toggle {
  appearance: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.3s var(--ease);
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--rule-strong);
  transform: rotate(18deg);
}
.theme-toggle .icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

/* ------------------------------------------------------------- hero */

.hero {
  position: relative;
  padding: clamp(3.25rem, 8vw, 5.5rem) 0 clamp(2rem, 4vw, 3rem);
}

.kicker {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.6563rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}
.kicker-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent);
}

.hero h1 {
  margin: 1.1rem 0 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2.65rem, 7.4vw, 4.15rem);
  line-height: 0.98;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.hero h1 em { font-style: italic; }

.dek {
  margin-top: 1.3rem;
  max-width: 33rem;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  margin-top: 1.6rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.hero-links a {
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s var(--ease);
}
.hero-links a span { color: var(--accent); }
.hero-links a:hover { color: var(--ink); }

/* ------------------------------------------------------------ motif */

.motif {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.25rem;
  margin-top: clamp(2.5rem, 6vw, 3.75rem);
  padding: 0.85rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.motif-label {
  font-family: var(--font-mono);
  font-size: 0.5938rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  white-space: nowrap;
}
.motif-kawung {
  height: 44px;
  background: var(--accent);
  opacity: 0.5;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.2'%3E%3Cellipse cx='22' cy='10' rx='7' ry='10'/%3E%3Cellipse cx='34' cy='22' rx='10' ry='7'/%3E%3Cellipse cx='22' cy='34' rx='7' ry='10'/%3E%3Cellipse cx='10' cy='22' rx='10' ry='7'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-mask-repeat: repeat-x;
  -webkit-mask-position: center;
  -webkit-mask-size: 44px 44px;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.2'%3E%3Cellipse cx='22' cy='10' rx='7' ry='10'/%3E%3Cellipse cx='34' cy='22' rx='10' ry='7'/%3E%3Cellipse cx='22' cy='34' rx='7' ry='10'/%3E%3Cellipse cx='10' cy='22' rx='10' ry='7'/%3E%3C/g%3E%3C/svg%3E");
  mask-repeat: repeat-x;
  mask-position: center;
  mask-size: 44px 44px;
  animation: motif-in 1.1s var(--ease) both;
}
@keyframes motif-in {
  from { opacity: 0; transform: scaleY(0.55); }
  to { opacity: 0.5; transform: scaleY(1); }
}

/* ------------------------------------------------------------ notes */

.notes { padding-top: 0.5rem; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 0 1.15rem;
  border-bottom: 1px solid var(--rule);
}
.section-head h2 {
  font-family: var(--font-mono);
  font-size: 0.6563rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink);
}
.section-count {
  font-family: var(--font-mono);
  font-size: 0.5938rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.post {
  padding: 2.9rem 0 3.4rem;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: calc(var(--head-height) + 1rem);
}
.post:last-child { border-bottom: 0; }

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.post-meta .sep { opacity: 0.6; }
.post-number {
  margin-left: auto;
  padding: 0.1rem 0.35rem 0.15rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.post-number:hover { color: var(--ink); border-color: var(--rule-strong); }

.post h2 {
  margin: 0.55rem 0 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 4.6vw, 2.5rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.post h2 a {
  text-decoration: none;
  color: var(--ink);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 2px;
  transition: background-size 0.35s var(--ease);
}
.post h2 a:hover { background-size: 100% 2px; }

.post-head { margin-bottom: 1.9rem; }

.post-dek {
  max-width: 34rem;
  margin: 0.65rem 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.55;
  text-wrap: pretty;
}

/* ------------------------------------------------------------ prose */

.prose { font-size: 1.0625rem; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.15em; }
.prose p:last-child { margin-bottom: 0; }

.prose a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--rule-strong);
  transition: color 0.18s var(--ease), text-decoration-color 0.18s var(--ease);
}
.prose a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

.prose h2,
.prose h3,
.prose h4 {
  position: relative;
  margin: 2.4em 0 0.7em;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  text-wrap: balance;
}
.prose h2 { font-size: 1.35rem; }
.prose h3 { font-size: 1.13rem; }
.prose h4 { font-size: 1rem; color: var(--ink-soft); }

.prose .anchor {
  position: absolute;
  left: -1.15rem;
  padding-right: 0.4rem;
  color: var(--accent);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}
.prose h2:hover .anchor,
.prose h3:hover .anchor,
.prose h4:hover .anchor,
.prose .anchor:focus-visible { opacity: 1; }

.prose ul,
.prose ol {
  margin: 0 0 1.15em;
  padding-left: 1.2em;
}
.prose li { margin: 0.3em 0; padding-left: 0.15em; }
.prose li::marker { color: var(--muted); }

.prose blockquote {
  margin: 1.9em 0;
  padding: 0.15rem 0 0.15rem 1.35rem;
  border-left: 2px solid var(--accent);
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-size: 1.3rem;
  line-height: 1.4;
  font-style: italic;
}
.prose blockquote p { margin-bottom: 0.5em; }
.prose blockquote p:last-child { margin-bottom: 0; }

.prose hr {
  margin: 2.8em 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.83em;
  padding: 0.12em 0.38em;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  white-space: break-spaces;
}
.prose pre {
  margin: 1.8em 0;
  padding: 1.05rem 1.2rem;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-size: 0.8125rem;
  line-height: 1.7;
  tab-size: 2;
}
.prose pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  white-space: pre;
}
.prose pre.shiki { background: var(--code-bg) !important; }
.shiki,
.shiki span { color: var(--shiki-light); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .shiki,
  :root:not([data-theme="light"]) .shiki span { color: var(--shiki-dark); }
}
:root[data-theme="dark"] .shiki,
:root[data-theme="dark"] .shiki span { color: var(--shiki-dark); }

.prose figure { margin: 2em 0; }
.prose figure img {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.prose figcaption {
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; margin: 1.8em 0; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.45;
}
.prose th,
.prose td {
  padding: 0.6rem 0.8rem 0.6rem 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}
.prose th {
  font-family: var(--font-mono);
  font-size: 0.6563rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  border-bottom-color: var(--rule-strong);
  white-space: nowrap;
}

/* -------------------------------------------------------- post foot */

.post-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.2rem;
}

.read-link,
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.6563rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s var(--ease);
}
.read-link span,
.back-link span { color: var(--accent); transition: transform 0.25s var(--ease); }
.read-link:hover,
.back-link:hover { color: var(--ink); }
.read-link:hover span { transform: translate(2px, -2px); }
.back-link:hover span { transform: translateX(-3px); }

.back-link {
  display: inline-flex;
  margin: 2.6rem 0 0;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--rule);
  width: 100%;
}

.post-single { border-bottom: 0; padding-top: 2.1rem; }
.post-title {
  margin: 0.6rem 0 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.post-single .post-dek { font-size: 1.05rem; }

.post-foot-single {
  display: block;
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.post-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-decoration: none;
}
.post-nav-link.next { text-align: right; align-items: flex-end; }
.post-nav-label {
  font-family: var(--font-mono);
  font-size: 0.5938rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.post-nav-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 1.2;
  color: var(--ink);
  transition: color 0.2s var(--ease);
}
.post-nav-link:hover .post-nav-title { color: var(--accent); }

.post-share {
  margin-top: 1.9rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.post-share a {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 3px;
}
.post-share a:hover { color: var(--ink); }

/* ------------------------------------------------------------ 404 */

.not-found { padding: clamp(3rem, 10vw, 7rem) 0 6rem; }
.not-found h1 {
  margin: 1.1rem 0 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2.8rem, 9vw, 4.6rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
}
.not-found-links { margin-top: 2rem; }

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

.site-foot {
  margin-top: 3rem;
  padding: 1.9rem 0 3rem;
  border-top: 1px solid var(--rule);
}
.foot-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem 1.5rem;
}
.foot-line {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.foot-line a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 0.05em;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.foot-line a:hover { color: var(--ink); border-color: var(--ink); }
.colophon {
  max-width: 21rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
  text-wrap: pretty;
}

/* -------------------------------------------------------- responsive */

@media (max-width: 640px) {
  :root { --head-height: 58px; }
  .site-nav { gap: 1rem; }
  .motif { gap: 0.9rem; }
  .post { padding: 2.4rem 0 2.8rem; }
  .post-foot { margin-top: 1.9rem; }
  .post-single { padding-top: 1.7rem; }
  .post-nav { gap: 1rem; }
  .prose .anchor { display: none; }
}

@media (max-width: 420px) {
  .foot-inner { flex-direction: column; }
}

/* ------------------------------------------------------------ motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------- print */

@media print {
  .site-head,
  .site-foot,
  .motif,
  .back-link,
  .post-foot,
  .hero::before { display: none !important; }
  :root { --bg: #fff; --ink: #000; --ink-soft: #333; --muted: #555; --rule: #ccc; --rule-strong: #999; }
  html, body { background: #fff; }
  body { font-size: 11pt; }
  .post { border: 0; padding: 0; }
  a { text-decoration: underline; }
}
