/*
  efbakir.com design system
  One column, system font (SF Pro on Apple devices), light and dark.
  Components use the tokens below and nothing else. Docs: DESIGN_SYSTEM.md
*/

/* Tokens ---------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Color, named by role */
  --color-bg: #ffffff;
  --color-surface: #f5f5f5;
  --color-text-primary: #171717;
  --color-text-secondary: #525252;
  --color-text-tertiary: #737373;
  --color-underline: #8c8c8c;
  --color-image-outline: #0000001a;
  --color-focus: #171717;
  --color-selection-bg: #171717;
  --color-selection-text: #ffffff;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-size-label: 1rem;      /* 16px  nav, section labels, footer */
  --font-size-body: 1.125rem;   /* 18px  prose */
  --font-size-list: 1.25rem;    /* 20px  list rows */
  --font-size-title: 1.5rem;    /* 24px  page title and lede */
  --line-height-title: 1.3334;  /* 32px at 24px */
  --line-height-text: 1.6;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;

  /* Space, 4px steps */
  --spacing-1: 0.25rem;   /* 4 */
  --spacing-2: 0.5rem;    /* 8 */
  --spacing-3: 0.75rem;   /* 12 */
  --spacing-4: 1rem;      /* 16 */
  --spacing-6: 1.5rem;    /* 24 */
  --spacing-8: 2rem;      /* 32 */
  --spacing-16: 4rem;     /* 64 */
  --spacing-32: 8rem;     /* 128 */

  /* Layout */
  --column-width: 42rem;  /* 672px including gutters */
  --gutter: var(--spacing-4);
  --header-height: 3.5rem;
  --page-padding-block: var(--spacing-16);
  --section-gap: var(--spacing-16);
  --list-gap: var(--spacing-4);
  --hit-area: 2.75rem;    /* 44px */
  --nav-link-padding: var(--spacing-1);
  --avatar-size: 3.75rem; /* 60px */
  --social-icon-size: 1.25rem; /* 20px */
  --radius-small: 0.25rem; /* 4px: focus rings, book covers */
  --radius-app-icon: 22.5%; /* iOS app icon corner */
  --media-max-height: 80svh; /* tall photos and videos in prose */
  --list-indent: 1.5em;

  /* Motion */
  --duration-fast: 150ms;

  /* Lines: chevrons and link underlines share one stroke, rounded ends */
  --stroke-link: 2px;
  --icon-size-small: 0.75rem; /* 12px chevron */
  --duration-theme: 350ms;    /* light and dark cross-fade */
  --duration-enter: 450ms;    /* page content rising in */
  --duration-reveal: 700ms;   /* first page of a visit */
  --ease-enter: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --enter-distance: 0.875rem; /* 14px */
  --enter-stagger: 60ms;
  --reveal-blur: 0.5rem;
}

@media (min-width: 40rem) {
  :root {
    --page-padding-block: var(--spacing-32);
    --list-gap: var(--spacing-2);
    --nav-link-padding: var(--spacing-2);
  }
}

@media (pointer: fine) {
  :root {
    --hit-area: 2.5rem;   /* 40px */
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #000000;
  --color-surface: #171717;
  --color-text-primary: #ffffffe6;
  --color-text-secondary: #ffffffb3;
  --color-text-tertiary: #ffffff80;
  --color-underline: #ffffff66;
  --color-image-outline: #ffffff1a;
  --color-focus: #ffffffe6;
  --color-selection-bg: #ffffffe6;
  --color-selection-text: #000000;
}

/* Base ------------------------------------------------------------------ */

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

html {
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  line-height: var(--line-height-text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Default macOS smoothing, same as the reference site. Not antialiased. */
  -webkit-font-smoothing: auto;
  -moz-osx-font-smoothing: auto;
}

body {
  margin: 0;
  font-size: var(--font-size-label);
}

h1,
h2,
p,
ul,
ol {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-small);
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

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

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

[id] {
  scroll-margin-top: calc(var(--header-height) + var(--spacing-4));
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* Motion ---------------------------------------------------------------- */

/* Page content rises in on every page, one block after another. The first
   page of a visit also comes out of a soft blur (theme.js sets data-reveal).
   Header stays still. Between pages, browsers with view transitions
   cross-fade. Nothing moves when the visitor asks for reduced motion. */
@keyframes page-enter {
  from {
    opacity: 0;
    transform: translate3d(0, var(--enter-distance), 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes page-reveal {
  from {
    opacity: 0;
    transform: translate3d(0, var(--enter-distance), 0);
    filter: blur(var(--reveal-blur));
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  .site-header {
    view-transition-name: site-header;
  }

  main > *,
  .site-footer {
    animation: page-enter var(--duration-enter) var(--ease-enter) both;
  }

  [data-reveal] main > *,
  [data-reveal] .site-footer {
    animation-name: page-reveal;
    animation-duration: var(--duration-reveal);
  }

  main > :nth-child(2) {
    animation-delay: var(--enter-stagger);
  }

  main > :nth-child(3) {
    animation-delay: calc(var(--enter-stagger) * 2);
  }

  main > :nth-child(n + 4),
  .site-footer {
    animation-delay: calc(var(--enter-stagger) * 3);
  }

  .theme-fading::view-transition-old(root),
  .theme-fading::view-transition-new(root) {
    animation-duration: var(--duration-theme);
    animation-timing-function: var(--ease-enter);
  }
}

/* Skip link ------------------------------------------------------------- */

.skip-link {
  position: absolute;
  top: var(--spacing-2);
  inset-inline-start: var(--gutter);
  z-index: 20;
  padding: var(--spacing-2) var(--spacing-3);
  background: var(--color-bg);
  color: var(--color-text-primary);
  transform: translateY(calc(-100% - var(--spacing-4)));
}

.skip-link:focus {
  transform: none;
}

/* Header and nav -------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg);
}

/* Narrow: links spread across the column. Wide: links centered, 24px apart.
   Nav padding is the gutter minus link padding, so link text lines up
   with the column edge on every row. */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  max-width: var(--column-width);
  min-height: var(--header-height);
  margin-inline: auto;
  padding-inline: calc(var(--gutter) - var(--nav-link-padding));
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit-area);
  padding-inline: var(--nav-link-padding);
  color: var(--color-text-tertiary);
  transition: color var(--duration-fast) ease-out;
}

@media (min-width: 40rem) {
  .site-nav {
    justify-content: center;
    column-gap: var(--nav-link-padding);
  }
}

.site-nav a {
  position: relative;
}

.site-nav a[aria-current] {
  color: var(--color-text-primary);
}

/* Current page: short rounded line under the text, same stroke as links */
.site-nav a[aria-current]::after {
  content: "";
  position: absolute;
  inset-inline: var(--nav-link-padding);
  top: calc(50% + 0.6875em);
  height: var(--stroke-link);
  border-radius: var(--stroke-link);
  background: currentColor;
}

/* Page ------------------------------------------------------------------ */

main,
.site-footer {
  max-width: var(--column-width);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  padding-block-start: var(--page-padding-block);
}

/* Page header: avatar, title, lede */

.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
}

.avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  margin-block-end: var(--spacing-8);
  border-radius: 50%;
  outline: 1px solid var(--color-image-outline);
  outline-offset: -1px;
  object-fit: cover;
  user-select: none;
}

.page-title,
.page-lede {
  font-size: var(--font-size-title);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-title);
}

.page-title {
  text-wrap: balance;
}

.page-meta {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-label);
  font-variant-numeric: tabular-nums;
}

.page-lede {
  color: var(--color-text-secondary);
  text-wrap: pretty;
}

/* App icon in the avatar spot (Prompter pages). Linked on subpages. */
.avatar-app {
  border-radius: var(--radius-app-icon);
}

.avatar-link {
  align-self: flex-start;
  margin-block-end: var(--spacing-8);
  border-radius: var(--radius-app-icon);
}

.avatar-link .avatar {
  margin-block-end: 0;
}

/* Social links: icon row under the lede. Glyph edge lines up with the text. */
.social-links {
  display: flex;
  flex-wrap: wrap;
  margin-inline-start: calc((var(--hit-area) - var(--social-icon-size)) / -2);
}

.social-links a {
  display: grid;
  place-items: center;
  width: var(--hit-area);
  height: var(--hit-area);
  color: var(--color-text-tertiary);
  transition: color var(--duration-fast) ease-out;
}

.social-icon {
  width: var(--social-icon-size);
  height: var(--social-icon-size);
  fill: currentColor;
}

/* Section: quiet label, then content */

.section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
}

.section-label {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-label);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-text);
}

.section-label a {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-1);
  transition: color var(--duration-fast) ease-out;
}

.icon {
  flex: none;
  width: var(--icon-size-small);
  height: var(--icon-size-small);
}

.icon path {
  stroke-width: var(--stroke-link);
  vector-effect: non-scaling-stroke;
}

/* List rows */

.list {
  display: flex;
  flex-direction: column;
  gap: var(--list-gap);
}

/* Narrow: title on its own line, then description and meta.
   Wide: title and description flow together, meta sits on the right. */
.row {
  display: block;
  font-size: var(--font-size-list);
  line-height: var(--line-height-text);
  overflow-wrap: break-word;
}

.row-title {
  display: block;
  width: fit-content;
  font-weight: var(--font-weight-medium);
}

.row-desc,
.row-meta {
  color: var(--color-text-tertiary);
}

.row-meta {
  font-size: var(--font-size-label);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@media (width < 40rem) {
  .row:has(.row-desc) .row-meta::before,
  .row:not(:has(.row-title)) .row-meta::before {
    content: "·";
    margin-inline: 0.375em;
  }
}

@media (min-width: 40rem) {
  .row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: var(--spacing-4);
  }

  .row-text {
    min-width: 0;
    text-wrap: pretty;
  }

  .row-title {
    display: inline;
    margin-inline-end: 0.125em;
  }
}

/* Book covers: grid like marcastbury.com/reading.
   Title text sits under the image and shows if the cover fails to load. */

.covers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--spacing-3);
}

@media (min-width: 40rem) {
  .covers {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--spacing-4);
  }
}

.cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: var(--radius-small);
  background: var(--color-surface);
  outline: 1px solid var(--color-image-outline);
  outline-offset: -1px;
}

.cover:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.cover-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: var(--spacing-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-label);
  line-height: var(--line-height-title);
  overflow-wrap: break-word;
}

.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--duration-fast) ease-out;
}

/* Screens: app screenshots side by side, caption under each */

.screens {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--spacing-3);
}

@media (min-width: 40rem) {
  .screens {
    gap: var(--spacing-4);
  }
}

.screens figure {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
  margin: 0;
}

.screens img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-small);
  background: var(--color-surface);
  outline: 1px solid var(--color-image-outline);
  outline-offset: -1px;
}

.screens figcaption {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-label);
  text-wrap: pretty;
}

/* Prose */

.prose {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
  font-size: var(--font-size-body);
  line-height: var(--line-height-text);
}

.prose h2 {
  margin-block-start: var(--spacing-4); /* 32px above with the flex gap */
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-text);
}

.prose strong {
  font-weight: var(--font-weight-semibold);
}

.prose ul,
.prose ol {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
  padding-inline-start: var(--list-indent);
}

.prose ul {
  list-style: disc;
}

.prose ol {
  list-style: decimal;
}

.prose li ul {
  margin-block-start: var(--spacing-2);
  list-style: circle;
}

.prose li::marker {
  color: var(--color-text-tertiary);
}

.prose figure {
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* keep photo and video proportions */
  gap: var(--spacing-2);
  margin: 0;
}

.prose figure img,
.prose figure video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: var(--media-max-height);
  border-radius: var(--radius-small);
  background: var(--color-surface);
  outline: 1px solid var(--color-image-outline);
  outline-offset: -1px;
}

.prose figcaption {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-label);
}

/* Link line: one rounded bar under the text, same stroke as the chevron.
   Links in ledes and prose are short, so they stay on one line.
   Row titles show the bar only on hover. */
.prose a,
.page-lede a,
a.row .row-title {
  position: relative;
}

.prose a,
.page-lede a {
  white-space: nowrap;
}

.prose a::after,
.page-lede a::after,
a.row .row-title::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -1px;
  height: var(--stroke-link);
  border-radius: var(--stroke-link);
  background: var(--color-underline);
  pointer-events: none;
  transition: background-color var(--duration-fast) ease-out;
}

a.row .row-title::after {
  background: transparent;
}

.note {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-label);
}

details summary {
  width: fit-content;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: color var(--duration-fast) ease-out;
}

details[open] summary {
  margin-block-end: var(--spacing-2);
}

/* Footer ---------------------------------------------------------------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--spacing-6);
  margin-block-start: var(--section-gap);
  padding-block-end: var(--page-padding-block);
  color: var(--color-text-tertiary);
}

.site-footer a,
.site-footer button {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit-area);
  transition: color var(--duration-fast) ease-out;
}

/* Hover, only where hover exists ---------------------------------------- */

@media (hover: hover) {
  .site-nav a:hover,
  .section-label a:hover,
  .social-links a:hover,
  details summary:hover,
  .site-footer a:hover,
  .site-footer button:hover {
    color: var(--color-text-primary);
  }

  a.row:hover .row-title::after,
  .prose a:hover::after,
  .page-lede a:hover::after {
    background: var(--color-text-primary);
  }

  a.cover:hover img {
    opacity: 0.8;
  }

  .prose a:hover,
  .page-lede a:hover {
    color: var(--color-text-primary);
  }
}
