/* The writeup pages share one stylesheet and no javascript. The tokens, the fonts and the tone come from
   src/styles/index.css so /writeups/ reads as part of tawflabs.com. Flat colours, no gradients. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --ink: #10261f;
  --muted: #4a5f57;
  --stone: #eef1ec;
  --paper: #fbfcfa;
  --glaze: #dce8e1;
  --line: #ced8d1;
  --green: #1f6b54;
  --green-deep: #175545;
  --sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  /* No bounce past the end, so the scroll never reveals the light canvas under the footer. */
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  /* Sticky footer: the content grows to fill the screen and the footer sits at its bottom. */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--green);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

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

a:hover {
  text-decoration: underline;
}

/* 80rem with 1.5rem padding, the max-w-7xl of src/components/Layout.tsx, so the header and the
   footer line up with the home page instead of sitting inside a narrower column. */
.shell {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---------- Header and footer, the shape of src/components/Layout.tsx ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
}

/* The nav is the full width bar, transparent border at the top, line + stone/80 + blur once scrolled
   (a script in the page adds .scrolled after 8px), like the nav of Layout.tsx. */
.site-nav {
  position: relative;
  border-bottom: 1px solid transparent;
  background: var(--stone);
  transition: border-color 0.2s, background-color 0.2s;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.site-nav.scrolled {
  border-bottom-color: var(--line);
  background: rgba(238, 241, 236, 0.8);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.site-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 4rem;
}

/* The logo is white on transparent: inverted to black in the header, as is in the footer. */
.brand {
  display: inline-flex;
  align-items: center;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  display: block;
  width: auto;
  height: 26px;
  filter: invert(1);
}

.brand.light img {
  height: 30px;
  filter: none;
}

.site-links,
.site-actions {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-actions {
  gap: 0.75rem;
}

.site-nav a {
  color: var(--muted);
}

.site-nav a {
  transition: color 0.15s;
}

.site-nav a:hover,
.site-nav a[aria-current='page'] {
  color: var(--green);
  text-decoration: none;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1.25rem;
  color: var(--ink) !important;
  white-space: nowrap;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

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

.button.primary {
  background: var(--green);
  /* no border, like the filled button in Layout.tsx (36px tall, 2px narrower than the outlined one) */
  border-width: 0;
  color: #fff !important;
}

.button.primary:hover {
  background: var(--green-deep);
}

/* The mobile menu, a details element so the pages stay javascript free. */
.site-menu {
  display: none;
}

.site-menu summary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  margin-right: -0.75rem;
  padding: 0.75rem;
  cursor: pointer;
  list-style: none;
  color: var(--ink);
}

.site-menu summary::-webkit-details-marker {
  display: none;
}

.site-menu .icon-close {
  display: none;
}

.site-menu[open] .icon-open {
  display: none;
}

.site-menu[open] .icon-close {
  display: block;
}

.site-menu-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  padding: 1.25rem 1.5rem;
  background: var(--stone);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.site-menu-links,
.site-menu-actions {
  display: flex;
  flex-direction: column;
}

.site-menu-links {
  gap: 1rem;
}

.site-menu-links a {
  display: block;
}

.site-menu-actions {
  gap: 0.625rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.site-menu-actions .button {
  justify-content: center;
  padding: 0.625rem 1.5rem;
  text-align: center;
}

@media (max-width: 767px) {
  .site-links,
  .site-actions {
    display: none;
  }

  .site-menu {
    display: block;
  }
}

.site-footer {
  /* Sticks to the bottom of the column when the content is shorter than the screen. */
  margin-top: auto;
  background: var(--ink);
  color: rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4rem 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
}

.site-footer h4 {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  line-height: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #fff;
}

.site-footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-footer li + li {
  margin-top: 0.75rem;
}

.site-footer a {
  color: rgba(255, 255, 255, 0.7);
  transition: color 0.15s;
}

.site-footer a:hover {
  color: #fff;
  text-decoration: none;
}

.footer-intro p {
  max-width: 24rem;
  margin: 1rem 0 0;
  line-height: 1.625;
}

.footer-legal {
  margin-top: 3rem;
}

.footer-legal p {
  margin: 0;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  line-height: 1rem;
  color: rgba(255, 255, 255, 0.7);
}

@media (min-width: 640px) {
  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-intro {
    grid-column: span 2;
  }
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 2rem;
  }
}

/* ---------- List ---------- */

main {
  /* Fills what is left of the screen so the footer lands on the bottom edge, and carries the 4rem
     that used to be the top margin of the footer so the space above it never changes. */
  flex: 1 0 auto;
  margin-bottom: 4rem;
  padding: 2.5rem 1.5rem 3.5rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(32px, 4vw, 44px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0 0 1.75rem;
  max-width: 40em;
  color: var(--muted);
  font-size: clamp(16px, 1.4vw, 18px);
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.tag-filter span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tag-filter a,
.taglist a {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 0.1rem 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.tag-filter a:hover,
.taglist a:hover {
  border-color: var(--green);
  color: var(--green);
  text-decoration: none;
}

.writeup-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.writeup-list li {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--line);
}

.writeup-list h2 {
  margin: 0 0 0.35rem;
  font-size: clamp(20px, 2.2vw, 26px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.writeup-list h2 a {
  color: var(--ink);
}

.writeup-list h2 a:hover {
  color: var(--green);
  text-decoration: none;
}

.meta {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.summary {
  margin: 0 0 0.6rem;
  max-width: 46em;
}

.taglist {
  margin: 0;
}

.taglist.compact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.empty {
  color: var(--muted);
  font-style: italic;
}

/* ---------- Article ---------- */

article,
main > h1,
main > .lede,
main > .tag-filter,
main > .writeup-list,
main > .empty {
  max-width: 46rem;
  margin-left: auto;
  margin-right: auto;
}

.crumbs {
  max-width: 46rem;
  margin: 0 auto 1rem;
  font-size: 0.85rem;
}

article h1 {
  margin-bottom: 0.5rem;
}

article .taglist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.cover {
  margin: 0 0 1.75rem;
}

.cover img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.prose {
  font-size: 1.0625rem;
  line-height: 1.75;
}

.prose p {
  margin: 0 0 1.1rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  margin: 2rem 0 0.75rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
  scroll-margin-top: 5rem;
}

.prose h1 {
  font-size: 1.75rem;
}

.prose h2 {
  font-size: 1.4rem;
}

.prose h3 {
  font-size: 1.15rem;
}

.prose ul,
.prose ol {
  margin: 0 0 1.1rem;
  padding-left: 1.4rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose blockquote {
  margin: 0 0 1.1rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border-left: 3px solid var(--green);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--glaze);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

.prose pre {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 0 0 1.1rem;
}

/* The code is a block sized to its longest line, otherwise its text overflows a box that is as wide
   as the pre and the pre has nothing to scroll, which clipped long lines on a phone. */
.prose pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  background: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.prose th {
  background: var(--glaze);
  font-weight: 600;
}

.prose img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

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

.prose strong {
  font-weight: 600;
}

/* KaTeX sits inline with the text, the display block is centred. */
.katex {
  font-size: 1.05em;
}

.katex-display {
  margin: 1.25rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* The maths block is as wide as the column with nowrap inside, so a long equation overflowed a box
   that had nothing to scroll, the same way a long code line did. Size it to the maths instead. */
.katex-display > .katex {
  display: block;
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
}

@media (max-width: 640px) {
  main {
    padding-top: 1.75rem;
  }

  .prose pre {
    padding: 0.8rem;
  }

  .prose table {
    display: block;
    overflow-x: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
