/* The app people use: one sheet of sketch paper. What you ask is written on it in your hand
   (Shantell Sans), and the answer is drawn onto the same sheet in the artist's hand (Caveat,
   the font the boards are written in). The developer view under /dev has its own stylesheet. */

:root {
  --paper: #f3eddf;
  --ink: #2b2a27;          /* graphite */
  --soft: #6f6a60;
  --faint: rgba(43, 42, 39, 0.2);
  --rule: rgba(43, 42, 39, 0.34);
  --blue: #3f5f94;         /* watercolour washes */
  --sky: #9db3cf;
  --ochre: #e2ab3d;
  --moss: #8aa274;
  --crimson: #a8263b;
  --hand: "Caveat", "Bradley Hand", cursive;
  --yours: "Shantell Sans", "Comic Neue", "Segoe Print", system-ui, sans-serif;
  /* An uneven outline, like a box drawn by hand. */
  --wobble: 255px 14px 225px 16px / 16px 225px 14px 255px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--yours);
  background-color: var(--paper);
  /* Paper grain over a faint drafting grid. */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .27 0 0 0 0 .18 0 0 0 .13 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(rgba(63, 95, 148, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(63, 95, 148, 0.07) 1px, transparent 1px);
  background-size: 260px 260px, 30px 30px, 30px 30px;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px dashed var(--blue); outline-offset: 4px; border-radius: 4px; }

.hand { font-family: var(--hand); font-weight: 700; line-height: 1.05; }

/* Text that appears as if it is being written, left to right. */
.write { animation: write var(--write, 0.9s) cubic-bezier(0.3, 0.1, 0.3, 1) both; }
@keyframes write {
  from { clip-path: inset(-10% 100% -10% 0); }
  to { clip-path: inset(-10% -2% -10% 0); }
}
.rise { animation: rise 0.6s ease-out both; animation-delay: var(--d, 0s); }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Pencil strokes made in paper.js: a line under things, a ring round the chosen thing. */
.pencil { position: absolute; pointer-events: none; overflow: visible; }
.pencil path { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.pencil.line { left: 0; right: 0; bottom: -6px; width: 100%; height: 10px; }
.pencil.line path { stroke-width: 1.6; opacity: 0.6; }
/* Stretched strokes cannot be dashed reliably, so the line is uncovered from the left instead. */
.pencil.line { animation: write 0.9s ease-out 0.25s both; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* A patch of watercolour behind something. */
.wash { position: absolute; pointer-events: none; overflow: visible; mix-blend-mode: multiply; }

/* ------------------------------------------------------------------ top */

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; max-width: 1040px; margin: 0 auto; padding: 22px 24px 0; }
.mark { font: 700 1.75rem/1 var(--hand); text-decoration: none; letter-spacing: 0.01em; }
.mark:hover { color: var(--blue); }
.top-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 22px; }
.link { padding: 2px 0; border: 0; background: none; font-size: 0.9375rem; color: var(--soft); text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 5px; text-decoration-thickness: 1.5px; }
.link:hover { color: var(--ink); text-decoration-color: var(--ink); }
.link:disabled { cursor: default; text-decoration: none; }
/* Sign in or sign out: always the last of the links, whatever a page adds after it. */
.who { order: 9; }
.who:empty { display: none; }

main { max-width: 1040px; margin: 0 auto; padding: 0 24px 56px; }
.foot { max-width: 1040px; margin: 0 auto; padding: 0 24px 28px; font-size: 0.8125rem; color: var(--soft); opacity: 0.7; }

/* ------------------------------------------------------------------ home */

.home { position: relative; max-width: 810px; padding-top: clamp(40px, 11vh, 120px); }
.sky { top: -10px; left: -9%; width: 112%; height: 230px; opacity: 0; animation: bleed 2.4s ease-out 0.1s forwards; }
@keyframes bleed {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 0.5; transform: none; }
}
.home h1 { position: relative; margin: 0 0 30px; font-size: clamp(2.4rem, 6.4vw, 3.9rem); white-space: nowrap; --write: 1.3s; }
@media (max-width: 520px) { .home h1 { white-space: normal; } }

.ask { position: relative; }
.ask textarea {
  display: block; width: 100%; min-height: 2.4em; max-height: 46vh; padding: 6px 2px 8px; resize: none;
  border: 0; outline: 0; background: none; font-size: 1.375rem; line-height: 1.5; font-weight: 400;
}
.ask textarea::placeholder { color: var(--soft); opacity: 0.65; font-style: italic; }
/* A single written line: an email address, or the code from an email. */
.ask input { display: block; width: 100%; padding: 6px 2px 8px; border: 0; outline: 0; background: none; font-size: 1.375rem; line-height: 1.5; font-weight: 400; }
.ask input::placeholder { color: var(--soft); opacity: 0.65; font-style: italic; }

.notes { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; margin-top: 30px; }
.pick { display: flex; align-items: baseline; gap: 4px; margin: 0; padding: 0; border: 0; min-width: 0; }
.pick legend { float: left; padding: 0; margin-right: 8px; font: 500 1.375rem/1 var(--hand); color: var(--soft); }
.pick label { position: relative; padding: 5px 9px; cursor: pointer; font-size: 0.9375rem; color: var(--soft); }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick label:hover { color: var(--ink); }
.pick label:has(input:checked) { color: var(--ink); }
.pick label:has(input:focus-visible) { outline: 2px dashed var(--blue); outline-offset: 2px; border-radius: 12px; }
.pencil.ring { inset: -3px -4px; width: calc(100% + 8px); height: calc(100% + 6px); }
.pencil.ring path { stroke-width: 1.5; }
.pencil.ring { opacity: 0; transform: scale(0.9) rotate(-3deg); transition: opacity 0.2s ease, transform 0.25s ease; }
.pick input:checked ~ .ring { opacity: 0.75; transform: none; }

.send { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 26px; margin-top: 34px; }
.go { position: relative; padding: 14px 34px 16px; border: 0; background: none; font: 700 2rem/1 var(--hand); isolation: isolate; transition: transform 0.15s ease; }
.go .wash { inset: -8px -12px; width: calc(100% + 24px); height: calc(100% + 16px); z-index: -1; transition: opacity 0.2s ease; opacity: 0.86; }
.go:hover { transform: rotate(-1.5deg) scale(1.03); }
.go:hover .wash { opacity: 1; }
.go:active { transform: scale(0.98); }
.go:disabled { cursor: default; transform: none; color: var(--soft); }
.attach { position: relative; cursor: pointer; }
.attach input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 12px; border: 1.5px solid var(--faint); border-radius: var(--wobble); font-size: 0.9375rem; }
.file button { width: 28px; height: 28px; border: 0; background: none; color: var(--soft); font-size: 1.2rem; line-height: 1; }
.file button:hover { color: var(--crimson); }

.say { margin: 18px 0 0; font-size: 1rem; }
.say.error { color: var(--crimson); }
.say.info { color: var(--blue); }

.tries { margin: 44px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; color: var(--soft); }
.tries > span { font: 500 1.375rem/1 var(--hand); }
.tries button { padding: 2px 0; border: 0; background: none; font-size: 0.9375rem; color: var(--soft); border-bottom: 1.5px dotted var(--rule); }
.tries button:hover { color: var(--ink); border-bottom-style: solid; }
.tries button:nth-of-type(odd) { transform: rotate(-0.8deg); }
.tries button:nth-of-type(even) { transform: rotate(0.7deg); }

.book { margin-top: 72px; }
.book h2 { margin: 0 0 14px; font: 700 1.75rem/1 var(--hand); }
.book ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.book a {
  display: flex; flex-direction: column; justify-content: space-between; gap: 14px; min-height: 108px; padding: 14px 16px 12px;
  text-decoration: none; background: rgba(255, 253, 246, 0.6); border: 1.5px solid var(--faint); border-radius: var(--wobble);
  box-shadow: 2px 3px 0 rgba(43, 42, 39, 0.07); transition: transform 0.18s ease, border-color 0.18s ease;
}
.book li:nth-child(3n + 1) a { transform: rotate(-0.7deg); }
.book li:nth-child(3n + 2) a { transform: rotate(0.5deg); }
.book a:hover { transform: rotate(0deg) translateY(-3px); border-color: var(--ink); }
.book .t { font: 700 1.375rem/1.1 var(--hand); }
.book .m { font-size: 0.8125rem; color: var(--soft); }
/* A drawing that is still being made: its label writes itself out, rests, and starts again. */
.book .m.writing { align-self: flex-start; animation: rewrite 2.6s cubic-bezier(0.3, 0.1, 0.3, 1) infinite; }
@keyframes rewrite {
  0% { clip-path: inset(-10% 100% -10% 0); opacity: 1; }
  50%, 88% { clip-path: inset(-10% -2% -10% 0); opacity: 1; }
  100% { clip-path: inset(-10% -2% -10% 0); opacity: 0; }
}

/* ------------------------------------------------------------------ signing in */

.signin h1 { white-space: normal; margin-bottom: 14px; font-size: clamp(2.2rem, 5.6vw, 3.4rem); }
.signin form { max-width: 520px; }
.signin .say { max-width: 56ch; }

/* ------------------------------------------------------------------ use it in another app */

.connect h1 { white-space: normal; margin-bottom: 14px; font-size: clamp(2.2rem, 5.6vw, 3.4rem); }
.lede { position: relative; margin: 0 0 34px; max-width: 56ch; font-size: 1.125rem; }
.yours h2, .way h2 { margin: 0 0 12px; font: 700 1.75rem/1 var(--hand); }
.addr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 26px; }
.addr { flex: 1; min-width: 240px; padding: 11px 16px; border: 1.5px solid var(--rule); border-radius: var(--wobble); outline-offset: 6px; background: rgba(255, 253, 246, 0.6); font-size: 0.9375rem; text-overflow: ellipsis; }
.yours .hint { max-width: 62ch; }
.yours .hint .link { font-size: inherit; }
.ways { margin-top: 48px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 34px 44px; }
.way ol { margin: 0; padding-left: 1.3em; }
.way li { margin: 0 0 7px; padding-left: 2px; }
.way li::marker { font: 700 1.25rem/1 var(--hand); color: var(--soft); }
.way p { margin: 0 0 5px; font-size: 0.875rem; color: var(--soft); }
.way.wide { grid-column: 1 / -1; }
.way code { display: block; margin: 0 0 14px; padding: 9px 11px; border: 1.5px dashed var(--faint); border-radius: 8px; font: 0.8125rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }
.way code span { white-space: nowrap; }

/* ------------------------------------------------------------------ a page with a drawing on it */

/* The column is as wide as a drawing that still leaves room for its caption and controls. */
#app[data-view="page"] { --col: calc(min(1040px, max(520px, (100vh - 300px) * 1.7778)) + 48px); }
#app[data-view="page"] :is(.top, .foot) { max-width: var(--col); }
.page { padding-top: 22px; max-width: var(--col); }
.page h1 { margin: 0; font-size: clamp(2.1rem, 5.2vw, 3.4rem); }
.asked { margin: 8px 0 0; max-width: 70ch; color: var(--soft); font-size: 0.9375rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.asked.whole { display: block; font-size: 1.25rem; color: var(--ink); white-space: pre-wrap; max-height: 9.5em; overflow: auto; }
.asked b { font: 500 1.25rem/1 var(--hand); margin-right: 8px; color: var(--soft); }
/* The length, surface and shape that were picked, under the prompt while the video is being made. */
.asked.picked { display: block; margin-top: 6px; font-size: 1.0625rem; color: var(--ink); }

/* The video is its own clean sheet laid on the paper, cut a little unevenly and outlined in
   pencil. It keeps the background it was made with (white, or the blackboard), so the drawing
   reads clearly against the grid behind it. While a video is being made the outline is empty. */
.frame { position: relative; margin: 26px 0 0; }
.frame.making::before, .pl-stage::before { content: ""; position: absolute; inset: -9px; border: 1.5px solid var(--faint); border-radius: var(--wobble); pointer-events: none; }
.pl { display: flex; flex-direction: column; outline: 0; }
.pl-stage { position: relative; isolation: isolate; order: 1; cursor: pointer; aspect-ratio: 16 / 9; margin-bottom: 12px; }
.pl-stage::before { z-index: -1; border-color: rgba(43, 42, 39, 0.5); background: #fdfdfb; box-shadow: 4px 6px 0 rgba(43, 42, 39, 0.13); }
.pl[data-skin="math"] .pl-stage::before { background: #0a0c11; }
.pl-stage svg { display: block; width: 100%; height: auto; }
/* A tall video (made for a phone held upright) sits in the middle of the column, as wide as
   lets the whole of it fit on the screen together with its caption and controls. On a phone
   that is most of the width; on a computer it is a tall sheet with space either side. */
.pl[data-shape="portrait"], .frame.making[data-shape="portrait"] {
  width: min(100%, max(240px, (100vh - 150px) * 0.5625));
  width: min(100%, max(240px, (100svh - 150px) * 0.5625));
  margin-inline: auto;
}
.pl[data-shape="portrait"] .pl-stage, .making[data-shape="portrait"] { aspect-ratio: 9 / 16; }

.pl-big {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; display: flex; align-items: center; gap: 14px;
  padding: 12px 26px 14px 18px; border: 2px solid var(--ink); border-radius: var(--wobble); background: rgba(243, 237, 223, 0.9);
  color: var(--ink); font: 700 1.75rem/1 var(--hand); transition: transform 0.15s ease;
}
.pl-big svg { width: 30px; height: 30px; }
.pl-big::after { content: "play"; white-space: nowrap; }
.pl-big:hover { transform: rotate(-1.5deg) scale(1.04); }

/* The caption runs up to four fifths of the video's width, and each line is filled before the
   next is begun: evened-out lines stopped well short of that. Under a tall video, which is
   narrow, it may use all of the width. */
.pl-cap { order: 2; min-height: 2.2em; margin: 16px auto 0; max-width: 80%; text-align: center; font: 500 1.625rem/1.1 var(--hand); text-wrap: pretty; }
.pl[data-shape="portrait"] .pl-cap { max-width: none; }
.pl-bar { order: 3; display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.pl-pp, .pl-cc { flex: none; display: grid; place-items: center; min-width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--ink); }
.pl-pp:hover, .pl-cc:hover { background: rgba(43, 42, 39, 0.07); }
.pl-pp svg { width: 22px; height: 22px; }
.pl-cc { font: 700 1.25rem/1 var(--hand); color: var(--soft); opacity: 0.6; }
.pl-cc[aria-pressed="true"] { color: var(--ink); opacity: 1; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.pl-time { flex: none; font-size: 0.875rem; color: var(--soft); font-variant-numeric: tabular-nums; }
/* The time line is a pencil line: darker where the drawing has got to. */
.pl-seek { flex: 1; min-width: 0; height: 28px; margin: 0; background: none; cursor: pointer; -webkit-appearance: none; appearance: none; }
.pl-seek::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--ink) var(--p, 0%), var(--faint) var(--p, 0%)); }
.pl-seek::-moz-range-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--ink) var(--p, 0%), var(--faint) var(--p, 0%)); }
.pl-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -6px; border: 0; border-radius: 50% 46% 52% 48%; background: var(--ink); }
.pl-seek::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: var(--ink); }

.takeaway { position: relative; display: inline-block; margin: 30px 0 0; max-width: 60ch; font-size: 1.125rem; }
.takeaway .wash { inset: -6px -14px; width: calc(100% + 28px); height: calc(100% + 12px); opacity: 0.5; z-index: -1; }

.parts { margin-top: 34px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 34px 56px; align-items: start; }
.parts h2 { margin: 0 0 10px; font: 700 1.75rem/1 var(--hand); }
.chapters ol { list-style: none; margin: 0; padding: 0; counter-reset: c; }
.chapters li { counter-increment: c; }
.chapters button { position: relative; display: flex; align-items: baseline; gap: 10px; width: 100%; padding: 6px 8px 6px 0; border: 0; background: none; text-align: left; color: var(--soft); }
.chapters button::before { content: counter(c) "."; flex: none; width: 1.3em; font: 700 1.375rem/1 var(--hand); }
.chapters button:hover { color: var(--ink); }
.chapters button[aria-current="true"] { color: var(--ink); }
.chapters button[aria-current="true"] .name { text-decoration: underline wavy var(--rule); text-decoration-thickness: 1.2px; text-underline-offset: 5px; }
.chapters .when { flex: none; margin-left: auto; font-size: 0.8125rem; font-variant-numeric: tabular-nums; opacity: 0.8; }
.chapters .only { flex: none; font: 500 1.125rem/1 var(--hand); color: var(--blue); }
.chapters button[aria-pressed="false"] .only { display: none; }
.hint { margin: 10px 0 0; font-size: 0.8125rem; color: var(--soft); }

.change .ask textarea { font-size: 1.125rem; }
.change-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; margin-top: 18px; }
.scope { margin: 0; font-size: 0.875rem; color: var(--soft); }
.scope button { padding: 0; border: 0; background: none; color: var(--blue); text-decoration: underline; text-underline-offset: 3px; }
.go.small { padding: 9px 24px 11px; font-size: 1.625rem; }
.drafts { margin: 26px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; font-size: 0.875rem; color: var(--soft); }
.drafts > span { font: 500 1.25rem/1 var(--hand); }
.drafts button { padding: 2px 4px; border: 0; background: none; color: var(--soft); text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 4px; }
.drafts button[aria-current="true"] { color: var(--ink); font-weight: 700; text-decoration-color: var(--ink); }

/* ------------------------------------------------------------------ while it is being made */

.making { aspect-ratio: 16 / 9; display: grid; place-items: center; }
.making svg.doodles { position: absolute; inset: 0; width: 100%; height: 100%; }
.doodles path { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.3; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.1s ease-out forwards; transition: opacity 1.2s ease; }
.doodles path.old { opacity: 0; }
.status { position: relative; margin: 0; padding: 0 20px; text-align: center; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.status small { display: block; margin-top: 10px; font: 400 0.9375rem/1.4 var(--yours); color: var(--soft); }
.tally { display: flex; justify-content: center; gap: 9px; height: 34px; margin-top: 14px; }
.tally i { width: 3px; height: 100%; border-radius: 3px; background: var(--faint); transform: rotate(6deg); transition: background 0.5s ease; }
.tally i:nth-child(even) { transform: rotate(-4deg); }
.tally i.done { background: var(--ink); }
.retry { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; margin-top: 26px; }

@media (max-width: 760px) {
  .parts { grid-template-columns: 1fr; }
  .top { padding: 16px 18px 0; }
  main { padding: 0 18px 44px; }
  .pl-cap { font-size: 1.375rem; }
  .pl-big { font-size: 1.375rem; padding: 9px 18px 10px 12px; }
  .notes { gap: 8px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .write, .rise, .sky, .pencil.line, .doodles path, .book .m.writing { animation: none; }
  .doodles path { stroke-dashoffset: 0; }
  .sky { opacity: 0.5; }
  .go:hover, .pl-big:hover, .book a:hover { transform: none; }
}
