/*
  The meme dictionary's styles (cloudflare/memes.html and cloudflare/meme.html): the landing page's
  colours, fonts, header, buttons and stickers (cloudflare/landing.html keeps its own inline), with
  the dictionary's own layout. One file for every page of the dictionary, so it's fetched once.
*/

:root {
  color-scheme: light dark;
  --paper: #ffffff;
  --wash: #f1f5ff;
  --ink: #18234f;
  --ink-soft: #4a5378;
  --line: rgba(24, 35, 79, 0.12);
  --link: #2a5bd7;
  --action: #2f64e8;
  --action-ink: #ffffff;
  --beak: #ff9d45;
  /* System fonts only, as on the landing page: nothing to download, nothing blocking. */
  --display: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0c1230;
    --wash: #131b42;
    --ink: #eef2ff;
    --ink-soft: #a9b3d6;
    --line: rgba(238, 242, 255, 0.14);
    --link: #9bbcff;
    --action: #8fb4ff;
    --action-ink: #0c1230;
  }
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.6 var(--text);
  -webkit-font-smoothing: antialiased;
}

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

p {
  margin: 0;
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
}

:focus-visible {
  outline: 3px solid var(--beak);
  outline-offset: 3px;
}

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.25rem, 6vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.375rem, 3vw, 1.75rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.wrap {
  width: min(100% - 48px, 1040px);
  margin-inline: auto;
}

/* The header, as on the landing page. */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font: 800 1.25rem/1 var(--display);
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand img {
  width: 36px;
  height: 36px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding-inline: 26px;
  border-radius: 999px;
  background: var(--action);
  color: var(--action-ink);
  font: 700 1.0625rem/1 var(--text);
  text-decoration: none;
}

.button:hover {
  filter: brightness(1.08);
}

.button-line {
  min-height: 44px;
  padding-inline: 20px;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
  font-size: 0.9375rem;
}

.lang {
  position: relative;
}

.lang summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding-inline: 16px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px var(--line);
  font-size: 0.9375rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

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

.lang svg {
  flex: none;
  width: 18px;
  height: 18px;
}

.lang ul {
  position: absolute;
  inset-inline-end: 0;
  z-index: 10;
  min-width: 12em;
  margin: 8px 0 0;
  padding: 8px;
  border-radius: 18px;
  background: var(--paper);
  box-shadow:
    0 0 0 2px var(--line),
    0 18px 36px -12px rgba(24, 35, 79, 0.35);
  list-style: none;
}

.lang a {
  display: block;
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
}

.lang a:hover {
  background: var(--wash);
}

.lang a[aria-current] {
  font-weight: 800;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Where the page is: Home › Meme dictionary › the meme. */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-block: 8px 32px;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.crumbs a {
  color: inherit;
}

/* A meme's page: its name, the gist and its picture first, then the four parts. */

.entry {
  max-width: 44em;
}

.entry-head {
  display: grid;
  gap: 28px;
  align-items: center;
  margin-bottom: 16px;
}

.summary {
  margin-top: 18px;
  font-size: 1.1875rem;
}

.known {
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 600;
}

.local {
  color: var(--ink-soft);
  font-weight: 600;
}

.entry h2 {
  margin-top: 44px;
}

.entry h2 + p,
.entry p + p {
  margin-top: 14px;
}

/* The pictures are stickers, as on the landing page: a white border, a shadow, a tilt. */

.sticker {
  border: 5px solid #ffffff;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 12px 18px -8px rgba(13, 30, 110, 0.45);
  transform: rotate(var(--tilt, -2deg));
}

.picture .sticker {
  max-width: min(100%, 360px);
}

/* A meme of words (67) shows them as its sticker. */
.words {
  display: grid;
  place-items: center;
  width: 200px;
  aspect-ratio: 1;
  max-width: 100%;
  box-sizing: border-box;
  color: #18234f;
  font: 800 4.5rem/1 var(--display);
  letter-spacing: -0.02em;
}

/* The call to open the app, and the memes to read next. */

.cta {
  max-width: 44em;
  margin-top: 56px;
  padding: 32px;
  border-radius: 28px;
  background: var(--wash);
}

.cta p {
  margin-top: 12px;
}

.cta .actions {
  margin-top: 22px;
}

.note {
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.more {
  max-width: 44em;
  margin-top: 48px;
}

.related {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0;
  padding: 0;
  list-style: none;
}

.related a {
  display: inline-flex;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px var(--line);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.related a:hover {
  background: var(--wash);
}

/* The dictionary: an entry for each meme, its picture and name leading to its page. */

.intro {
  max-width: 44em;
}

.sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 44px 36px;
  margin: 44px 0 0;
  padding: 0;
  list-style: none;
}

.meme {
  display: flex;
  flex-direction: column;
}

.meme-link {
  display: flex;
  flex-direction: column;
  gap: 18px;
  color: var(--ink);
  text-decoration: none;
}

.meme-link .sticker {
  align-self: flex-start;
  max-height: 200px;
  width: auto;
}

.meme-link .words {
  width: 160px;
  font-size: 3.5rem;
}

.meme:nth-child(3n + 2) .sticker {
  --tilt: 1.5deg;
}

.meme:nth-child(3n) .sticker {
  --tilt: -1deg;
}

.meme h2 {
  font-size: 1.25rem;
  line-height: 1.25;
}

.meme-link:hover h2 {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.detail {
  margin-top: 8px;
  color: var(--ink-soft);
}

/* The footer, as on the landing page. */

.foot {
  margin-top: 72px;
  padding-block: 28px 40px;
  border-top: 2px solid var(--line);
}

.foot .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.legal-note {
  flex-basis: 100%;
  font-size: 0.8125rem;
}

@media (min-width: 760px) {
  .entry-head {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .picture .sticker {
    max-width: 320px;
  }
}

@media (max-width: 520px) {
  .wrap {
    width: calc(100% - 32px);
  }

  /* Brand, language menu and the app's button share a row down to about 360 px; narrower, the
     menu and the button drop to a row of their own, at the right. */
  .top {
    flex-wrap: wrap;
    gap: 12px 8px;
  }

  .top-actions {
    gap: 8px;
    margin-inline-start: auto;
  }

  .lang summary {
    padding-inline: 12px;
  }

  .button-line {
    padding-inline: 16px;
  }

  /* The menu button keeps its globe and drops the language's name. */
  .lang-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .cta {
    padding: 24px 20px;
  }
}

/* Chinese, Japanese and Korean: their own system fonts, and room between the lines. */

:lang(zh-Hans) {
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

:lang(zh-Hant) {
  font-family: "PingFang TC", "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

:lang(ja) {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

:lang(ko) {
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

:root .brand,
:root .words {
  font-family: var(--display);
}

:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko)) body {
  line-height: 1.8;
}

:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko)) :is(h1, h2) {
  letter-spacing: 0;
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: keep-all;
}

:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko)) :is(.summary, .detail, p) {
  text-wrap: pretty;
}

:root:lang(ja) body {
  line-break: strict;
}

:root:lang(ko) body {
  overflow-wrap: break-word;
  word-break: keep-all;
}
