/* Far From Baghdad, the one page.

   A leaf of the book, not a web page: washed paper, the title as the
   game's scribe wrote it, one written line, the pictures, and where to
   write to. The paper, the ink and the pictures are made by tools/make.py
   after round 61 of the game. No scan is used.

   Each written line and picture is ink on white. The page multiplies it
   into the paper, so the paper goes on through the ink. For that, nothing
   between .paper and a picture may carry opacity, a transform or a filter. */

@font-face {
  font-family: "Fondamento";
  src: url("fonts/Fondamento-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --cream: #e7d4b7;
  --ink: #1d1611;
  --ink-soft: #4a3a2a;
  --rubric: #7d2513;
  --gutter: clamp(16px, 4.5vw, 56px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--cream); }

/* The paper: its grain close up, and over it what time did to the leaf.
   The two washes repeat at different lengths, so no stain comes round
   at the same place twice. */
.paper {
  isolation: isolate;
  min-height: 100vh;
  min-height: 100svh;
  background-color: var(--cream);
  background-image: url("img/paper_wash_a.jpg"), url("img/paper_wash_b.jpg"), url("img/paper_grain.jpg");
  background-size: 100% auto, 100% auto, 512px 512px;
  background-repeat: repeat-y, repeat-y, repeat;
  background-position: 50% 0, 50% 37vw, 0 0;
  background-blend-mode: multiply, multiply, normal;
  color: var(--ink);
  font-family: "Fondamento", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  font-size: clamp(1.125rem, 1rem + .45vw, 1.375rem);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; height: auto; }
.title img, .written img, .picture img { mix-blend-mode: multiply; }

a { color: var(--rubric); text-underline-offset: .18em; text-decoration-thickness: 1px; }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 4px; }

/* The leaf's text block. */
.leaf {
  max-width: 62rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 3.4vw, 2.75rem) var(--gutter) clamp(2rem, 6vw, 4.5rem);
}

/* The title: the Arabic as the scribe wrote it, its English under it in red. */
.title { margin: 0; }
.title-ar { width: min(39rem, 92%); margin: 0 auto; }
.title-en { width: min(17.5rem, 58%); margin: clamp(.1rem, .8vw, .5rem) auto 0; }

/* One or two lines of heavy writing over the picture. */
.written { margin: 0; }
.hook { margin-top: clamp(1.25rem, 3vw, 2.25rem); }
.hook img { width: 100%; }

.signup {
  position: relative;
  max-width: 38rem;
  margin: clamp(2.5rem, 6vw, 4.5rem) 0 0;
  scroll-margin-top: 2rem;
}
.signup::before {
  content: "";
  display: block;
  width: 5.5rem;
  height: .65rem;
  margin-bottom: 1rem;
  background: url("img/rule.webp") left center / 100% 100% no-repeat;
  mix-blend-mode: multiply;
}
.signup h2 {
  margin: 0 0 .45rem;
  color: var(--rubric);
  font-weight: normal;
  font-size: clamp(1.9rem, 1.4rem + 1.7vw, 2.75rem);
  line-height: 1.2;
}
.signup-intro { max-width: 34rem; margin: .4rem 0 1.15rem; line-height: 1.4; }
.signup form { max-width: 31rem; }
.signup label { display: block; margin-bottom: .2rem; font-size: 1rem; }
.signup-row { display: flex; flex-wrap: wrap; gap: .45rem; }
.signup-row input, .signup-row button {
  border: 1px solid var(--rubric);
  border-radius: 2px;
  padding: .45rem .8rem;
  min-height: 2.75rem;
  font: inherit;
  font-size: 1.125rem;
  line-height: 1.3;
}
.signup-row input {
  flex: 1 1 13rem;
  min-width: 0;
  color: var(--ink);
  background-color: rgb(255 250 235 / 52%);
}
.signup-row button {
  flex: 0 1 auto;
  background: var(--rubric);
  color: #fff5e0;
  cursor: pointer;
}
.signup-row button:hover { background-color: #632013; }
.signup-row button:disabled { cursor: progress; }
.signup-trap { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.signup-privacy, .signup-status { margin: .55rem 0 0; font-size: .95rem; line-height: 1.4; }
.signup-privacy { color: var(--ink-soft); }
.signup-status:empty { margin: 0; }
.signup-status[data-state="error"] { color: var(--rubric); }

@media (max-width: 27rem) {
  .signup-row { flex-direction: column; }
  .signup-row input { flex-basis: auto; }
}

/* A picture lies on the paper with no line round it. */
.picture { position: relative; margin: clamp(.75rem, 2vw, 1.5rem) 0 0; }
.picture img { width: 100%; }
.picture + .picture { margin-top: clamp(1.75rem, 4.5vw, 3.25rem); }
.note {
  margin: .35rem .25rem 0 0;
  text-align: right;
  color: var(--rubric);
  font-size: .9em;
  line-height: 1.3;
}

.game { margin-top: clamp(2.25rem, 6vw, 4.25rem); }
.game img { width: min(29.5rem, 92%); }
.game + .picture { margin-top: clamp(.5rem, 1.5vw, 1rem); }

/* Where to write to: who makes it, and the address on a line ruled by hand in red. */
.hand { margin: clamp(2.5rem, 5vw, 3.75rem) 0 0; }
.by { margin: 0 0 .35rem; color: var(--ink-soft); }
.by a { color: inherit; }
.write { position: relative; width: fit-content; max-width: 100%; margin: 0; padding: 0 1.5rem .5rem 0; }
.write a {
  color: var(--ink);
  text-decoration: none;
  font-size: clamp(1.45rem, 1.05rem + 2vw, 2.1rem);
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.write a:hover { color: var(--rubric); }
.write::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -.2rem;
  height: 1rem;
  background: url("img/rule.webp") 0 50% / 100% 100% no-repeat;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* The foot of the leaf: small, and shut until asked. */
.foot {
  max-width: 62rem;
  margin: 0 auto;
  padding: clamp(.5rem, 2vw, 1.5rem) var(--gutter) 2rem;
  color: var(--ink-soft);
  font-size: .85em;
  line-height: 1.5;
}
.foot summary { cursor: pointer; color: var(--rubric); width: fit-content; }
.foot details p { max-width: 44rem; margin: .7rem 0 0; }
.colophon { margin: 1rem 0 0; }

/* On a wide leaf a picture's note is written up the outer margin, as a reader's note is. */
@media (min-width: 78rem) {
  .note {
    position: absolute;
    left: -2.1rem;
    bottom: 10%;
    margin: 0;
    white-space: nowrap;
    text-align: left;
    transform-origin: 0 100%;
    transform: rotate(-83deg);
  }
}

@media (max-width: 44rem) {
  /* A phone shows the middle of the leaf, close: fewer stains, larger. */
  .paper { background-size: 190% auto, 230% auto, 512px 512px; background-position: 50% 0, 50% 60vw, 0 0; }
  /* On a phone the pictures run to the paper's edge. */
  .picture { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); }
  .note { margin-right: var(--gutter); }
}

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