/* every ui/ux resource for fable 5.2
   plain css, no build step. tokens first, then layout, then parts. */

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

:root {
  color-scheme: light;

  --bg: #fdfdfc;
  --bg-subtle: #f9f9f8;
  --bg-hover: #f1f0ef;
  --border: #e9e9e7;
  --border-strong: #cfceca;
  --text-strong: #21201c;
  --text: #373632;
  --muted: #63635e;
  --underline: #bcbbb5;
  --selection: #e2e1de;

  --block-bg: #ffffff;
  --block-border: #3a3935;
  --block-text: #21201c;
  --md-heading: #1f5fbf;
  --md-marker: #cc4a0e;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --col: 692px;
  --pad: 24px;
  --bar-h: 97px;
}

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

  --bg: #111110;
  --bg-subtle: #191918;
  --bg-hover: #222221;
  --border: #2a2a28;
  --border-strong: #494844;
  --text-strong: #ffffff;
  --text: #d8d8d6;
  --muted: #b5b3ad;
  --underline: #62605b;
  --selection: #3b3a37;

  --block-bg: #0c0c0b;
  --block-border: #6f6d66;
  --block-text: #eeeeec;
  --md-heading: #7ab0ff;
  --md-marker: #ff9466;
}

/* no javascript: follow the system. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --bg: #111110;
    --bg-subtle: #191918;
    --bg-hover: #222221;
    --border: #2a2a28;
    --border-strong: #494844;
    --text-strong: #ffffff;
    --text: #d8d8d6;
    --muted: #b5b3ad;
    --underline: #62605b;
    --selection: #3b3a37;

    --block-bg: #0c0c0b;
    --block-border: #6f6d66;
    --block-text: #eeeeec;
    --md-heading: #7ab0ff;
    --md-marker: #ff9466;
  }
}

@media (min-width: 1240px) {
  :root {
    --bar-h: 61px;
  }
}

/* ---------- base ---------- */

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

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

/* anchors land below the sticky bar. set on the targets, not on the page,
   so typing in the search field never nudges the scroll. */
.section,
.item,
.section > .block {
  scroll-margin-top: calc(var(--bar-h) + 20px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.65;
  font-feature-settings: "cv01", "ss03";
  font-optical-sizing: auto;
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
}

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

h1,
h2,
h3,
p,
figure,
ol {
  margin: 0;
}

p {
  text-wrap: pretty;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-decoration-color: var(--underline);
  text-underline-offset: 0.18em;
  transition: text-decoration-color 150ms ease;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

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

a:focus-visible {
  border-radius: 3px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.wrap {
  max-width: var(--col);
  margin-inline: auto;
  padding-inline: var(--pad);
}

.skip {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-strong);
  font-size: 0.875rem;
  text-decoration: none;
  transform: translateY(-200%);
}

.skip:focus {
  transform: none;
}

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

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-top: 48px;
  padding-bottom: 64px;
}

.who {
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

.who a {
  position: relative;
  align-self: flex-start;
  color: var(--text-strong);
  font-weight: 500;
  text-decoration: none;
}

/* small text links keep their look and get a 44px target. */
.who a::after,
.anchor::after {
  content: "";
  position: absolute;
  inset: -11px 0;
  min-width: 44px;
}

.who span {
  color: var(--muted);
}

.theme-toggle {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -10px -12px 0 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease;
}

.theme-toggle:active {
  transform: scale(0.97);
}

.theme-toggle svg {
  grid-area: 1 / 1;
  width: 18px;
  height: 18px;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}

.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(-45deg) scale(0.9);
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 1;
  transform: none;
}

/* ---------- intro ---------- */

.intro h1 {
  color: var(--text-strong);
  font-size: 1.5rem;
  font-weight: 550;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.lede {
  margin-top: 16px;
}

.note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.contents {
  margin-top: 40px;
}

.contents ol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(6, auto);
  grid-auto-flow: column;
  column-gap: 32px;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.contents a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  text-decoration: none;
}

.count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quick {
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.9;
}

.quick a {
  margin-right: 14px;
  color: var(--text);
  white-space: nowrap;
}

/* ---------- sticky bar: search and section links ---------- */

/* search and the theme button need the script. without it they stay out of the way. */
:root:not([data-theme]) .search,
:root:not([data-theme]) .theme-toggle {
  display: none;
}

.bar-sentinel {
  height: 1px;
  margin-top: 39px;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid transparent;
}

.bar.is-stuck {
  border-bottom-color: var(--border);
}

.bar .wrap {
  padding-top: 8px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search:focus-within {
  border-color: var(--muted);
  box-shadow: 0 0 0 3px var(--bg-hover);
}

.search-icon {
  position: absolute;
  left: 13px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 8px 0 39px;
  border: 0;
  border-radius: 10px;
  outline: 0;
  background: transparent;
  color: var(--text-strong);
  font: inherit;
  appearance: none;
}

.search input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search input::-webkit-search-cancel-button,
.search input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-count {
  flex: none;
  padding-right: 12px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.search kbd {
  flex: none;
  display: none;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--muted);
  font: 500 0.6875rem/1 var(--font-mono);
}

.search-clear {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 42px;
  margin-left: -8px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), color 150ms ease;
}

.search-clear:active {
  transform: scale(0.97);
}

.search-clear svg {
  width: 14px;
  height: 14px;
}

.sections {
  display: flex;
  gap: 2px;
  margin-inline: calc(var(--pad) * -1);
  padding-inline: calc(var(--pad) - 8px);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 20px, #000 calc(100% - 20px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 20px, #000 calc(100% - 20px), transparent);
}

.sections::-webkit-scrollbar {
  display: none;
}

.sections a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding-inline: 8px;
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms ease;
}

.sections a .count {
  font-size: 0.75rem;
  color: inherit;
}

.sections a[aria-current="true"] {
  color: var(--text-strong);
}

/* wide screens: the same links become a quiet rail beside the column. */
@media (min-width: 1240px) {
  .bar .wrap {
    padding-bottom: 8px;
  }

  .sections {
    position: fixed;
    top: 84px;
    left: calc(50% - 574px);
    width: 188px;
    max-height: calc(100vh - 108px);
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding: 0;
    overflow: hidden auto;
    -webkit-mask-image: none;
    mask-image: none;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-4px);
    transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), visibility 0s linear 200ms;
  }

  .bar.is-stuck .sections {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
  }

  .sections a {
    justify-content: space-between;
    white-space: normal;
  }
}

/* ---------- sections ---------- */

.section {
  margin-top: 88px;
}

.is-searching .section {
  margin-top: 56px;
}

.section-head {
  padding-bottom: 28px;
}

.section h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--text-strong);
  font-size: 1.25rem;
  font-weight: 550;
  line-height: 1.35;
  letter-spacing: -0.015em;
}

.section h2 .count {
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0;
}

.section-lede {
  margin-top: 8px;
  color: var(--muted);
}

.anchor {
  position: relative;
  display: inline-block;
  text-decoration: none;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  margin: -12px -11px 12px;
}

.filters button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}

.filters button span {
  padding: 4px 8px;
  border-radius: 8px;
  transition: background-color 150ms ease, color 150ms ease;
}

.filters button:active {
  transform: scale(0.97);
}

.filters button[aria-pressed="true"] span {
  background: var(--bg-hover);
  color: var(--text-strong);
}

.none {
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

/* ---------- items ---------- */

.item {
  position: relative;
  padding-block: 28px;
  border-top: 1px solid var(--border);
}

.item:target::before {
  content: "";
  position: absolute;
  top: 31px;
  left: -14px;
  width: 2px;
  height: 18px;
  border-radius: 2px;
  background: var(--text-strong);
}

.item h3 {
  color: var(--text-strong);
  font-size: 1rem;
  font-weight: 550;
  line-height: 1.45;
  text-wrap: balance;
}

.meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.flag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: nowrap;
}

.when {
  margin-top: 14px;
}

.get {
  margin-top: 6px;
}

.label {
  color: var(--muted);
}

.desc,
.table-wrap {
  margin-top: 14px;
}

.credit,
.metrics {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

.credit {
  margin-top: 14px;
}

.metrics {
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.block + .credit {
  margin-top: 20px;
}

.links {
  display: flex;
  flex-wrap: wrap;
  column-gap: 24px;
  margin: 4px 0 -12px;
  font-size: 0.875rem;
}

.links a {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text-strong);
}

.links a::after {
  content: "";
  position: absolute;
  inset: 0 -11px;
}

/* the model table */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  line-height: 1.55;
}

th,
td {
  padding: 12px 20px 12px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  padding-top: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
  vertical-align: bottom;
}

@media (max-width: 600px) {
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  tr,
  td {
    display: block;
  }

  tr {
    padding: 12px 0;
    border-top: 1px solid var(--border);
  }

  td {
    padding: 4px 0;
    border: 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 0.8125rem;
  }
}

/* ---------- prompt and skill blocks ---------- */

.block {
  margin-top: 20px;
}

.section > .block {
  margin: 0 0 36px;
}

.block-box {
  position: relative;
  border: 1.5px solid var(--block-border);
  border-radius: 12px;
  background: var(--block-bg);
}

.block pre {
  margin: 0;
  padding: 15px 18px;
  overflow-x: auto;
  border-radius: 10.5px;
  color: var(--block-text);
  font-family: var(--font-mono);
  font-size: clamp(0.6875rem, 2.95vw, 0.8125rem);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.block code {
  font: inherit;
}

/* keeps the first lines clear of the copy button. */
.block-box.has-copy pre::before {
  content: "";
  float: right;
  width: 78px;
  height: 22px;
}

.md-h {
  color: var(--md-heading);
  font-weight: 600;
}

.md-b {
  font-weight: 600;
}

.md-m {
  color: var(--md-marker);
}

.md-c {
  color: var(--md-heading);
}

.md-row {
  white-space: pre;
}

.block figcaption {
  margin-top: 10px;
  padding-inline: 8px;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.55;
  text-align: center;
  text-wrap: balance;
}

.copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px 0 8px;
  border: 0;
  border-radius: 8px;
  background: var(--block-bg);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease;
}

/* 30px tall to look at, 44px to hit. */
.copy::after {
  content: "";
  position: absolute;
  inset: -7px;
}

.copy:active {
  transform: scale(0.97);
}

.copy[data-state="copied"] {
  color: var(--text-strong);
}

.swap {
  display: inline-grid;
  justify-items: start;
  align-items: center;
}

.swap > * {
  grid-area: 1 / 1;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out), filter 180ms var(--ease-out);
}

.swap svg {
  width: 14px;
  height: 14px;
}

.swap > .on,
.copy[data-state="copied"] .swap > .off {
  opacity: 0;
  transform: scale(0.9);
  filter: blur(2px);
}

.copy[data-state="copied"] .swap > .on {
  opacity: 1;
  transform: none;
  filter: none;
}

/* long blocks fold. the fold only exists once the script has measured them.
   the box changes size in place, so it uses the in-out curve. */
.block-box.is-foldable pre {
  transition: max-height 260ms var(--ease-in-out);
}

.block-box.is-folded pre {
  max-height: 318px;
  overflow: hidden;
}

.fold {
  display: flex;
  justify-content: center;
  border-radius: 0 0 10.5px 10.5px;
}

.is-folded .fold {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  align-items: flex-end;
  height: 104px;
  background: linear-gradient(to top, var(--block-bg) 28%, transparent);
  pointer-events: none;
}

.fold button {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 160ms var(--ease-out), color 150ms ease;
}

.fold button:active {
  transform: scale(0.97);
}

/* ---------- empty state and footer ---------- */

.empty {
  padding: 72px 0 24px;
}

.empty p {
  color: var(--muted);
}

.empty strong {
  color: var(--text-strong);
  font-weight: 550;
}

.empty button {
  min-height: 44px;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-strong);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-decoration-color: var(--underline);
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.site-footer {
  margin-top: 88px;
  padding-top: 32px;
  padding-bottom: 96px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

.site-footer p + p {
  margin-top: 14px;
}

.site-footer .top {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 8px;
  color: var(--text);
}

/* ---------- larger screens ---------- */

@media (min-width: 768px) {
  .site-header {
    padding-top: 64px;
    padding-bottom: 104px;
  }

  .section {
    margin-top: 104px;
  }

  .item:target::before {
    left: -20px;
  }
}

/* phones: let blocks use a little more of the screen. */
@media (max-width: 480px) {
  .contents ol {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
    column-gap: 24px;
  }

  .block-box {
    margin-inline: -14px;
  }

  .block pre {
    padding: 13px 12px;
  }
}

@media (max-width: 370px) {
  .contents ol {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-flow: row;
  }
}

/* ---------- hover, only where hover is real ---------- */

@media (hover: hover) and (pointer: fine) {
  a:hover {
    text-decoration-color: var(--muted);
  }

  .who a:hover,
  .anchor:hover {
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-decoration-color: var(--underline);
  }

  .anchor::before {
    content: "#";
    position: absolute;
    right: 100%;
    padding-right: 8px;
    color: var(--muted);
    font-weight: 400;
    opacity: 0;
    transition: opacity 150ms ease;
  }

  .anchor:hover::before,
  .anchor:focus-visible::before {
    opacity: 1;
  }

  .contents a:hover,
  .sections a:hover {
    color: var(--text-strong);
  }

  .contents a:hover .count {
    color: var(--text-strong);
  }

  .theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-strong);
  }

  .search-clear:hover,
  .fold button:hover {
    color: var(--text-strong);
  }

  .filters button:hover span {
    color: var(--text-strong);
  }

  .copy:hover {
    background: var(--bg-hover);
    color: var(--text-strong);
  }

  .search kbd {
    display: grid;
  }

  .search:focus-within kbd,
  .search.has-value kbd {
    display: none;
  }
}

/* ---------- reduced motion: gentler, not zero ---------- */

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .search-clear,
  .filters button,
  .fold button,
  .copy {
    transition-property: background-color, color;
  }

  .theme-toggle:active,
  .search-clear:active,
  .filters button:active,
  .fold button:active,
  .copy:active {
    transform: none;
  }

  .theme-toggle svg,
  .swap > * {
    transition-property: opacity;
    transform: none !important;
    filter: none !important;
  }

  .block-box.is-foldable pre {
    transition: none;
  }

  .sections {
    transform: none !important;
  }
}

/* colors should not crossfade one by one when the theme flips. */
.theme-switching,
.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
  transition: none !important;
}
