@font-face {
  font-family: "Nanum Pen Script";
  src: url("/fonts/nanum-pen-script-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #f2f5f9;
  --grid: #dde4ee;
  --ink: #1f2130;
  --faded-ink: color-mix(in srgb, var(--ink) 55%, transparent);
  --red-pen: #c8372b;
  --pen: "Nanum Pen Script", "Bradley Hand", "Segoe Print", cursive;
}

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

html {
  color: var(--ink);
  background: var(--paper);
  font: 1.5rem/1.2 var(--pen);
  cursor: url("/cursors/arrow.svg") 8 8, auto;
}

/* Selecting text blacks it out with marker, like a redacted file; the letters show through in
   paper so it stays readable. The halo behind the headings is dropped while selected. */
::selection {
  background: color-mix(in srgb, var(--ink) 88%, transparent);
  color: var(--paper);
  text-shadow: none;
}

/* Browsers give labels the system arrow; keep the drawn one. */
label {
  cursor: inherit;
}

a,
button {
  cursor: url("/cursors/arrow-click.svg") 8 8, pointer;
}

textarea,
input {
  cursor: url("/cursors/pencil.svg") 3 29, text;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(1.5rem, 5vh, 3.5rem) 1.25rem;
}

/* Background: graph paper, a price line, and margin doodles, all in the same ballpoint. */

.doodles {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 1.5rem 1.5rem,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 1.5rem 1.5rem;
}

.doodles svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.defs {
  position: absolute;
}

.trend {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  stroke-width: 3;
  opacity: .3;
}

.d {
  --u: clamp(3.5rem, 8vw, 8rem);
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: calc(var(--u) * var(--s));
  rotate: var(--r);
  stroke-width: calc(2.6 / var(--s));
  opacity: .6;
}

/* On phones the text column covers most of the page, so the doodles step back. */
@media (max-width: 40rem) {
  .d {
    opacity: .38;
  }
}

/* Foreground */

main {
  position: relative;
  width: min(100%, 36rem);
}

.reached {
  margin: 0 0 .5rem;
  font-size: 1.6rem;
  line-height: 1.1;
  rotate: 1.2deg;
}

/* Its own line, sized to stay on one line down to phone widths. */
.address {
  display: block;
  width: fit-content;
  font-size: min(1em, 4.9vw);
  overflow-wrap: anywhere;
  color: inherit;
  text-decoration: underline 1px var(--faded-ink);
  text-underline-offset: .15em;
}

.address:hover {
  text-decoration-color: currentColor;
}

h1 {
  margin: 0 0 1.25rem -.2rem;
  font-size: clamp(3.2rem, 1.6rem + 5.5vw, 5.5rem);
  font-weight: 400;
  line-height: .85;
  rotate: -2.5deg;
}

.reached,
h1,
.sent-title {
  /* Paper-coloured halo keeps doodles behind the letters from cutting through them. */
  text-shadow: 0 0 .08em var(--paper), 0 0 .2em var(--paper), 0 0 .4em var(--paper);
}

form {
  rotate: -.6deg;
}

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

/* A box drawn twice by hand around whatever it wraps. */
.scrawl {
  position: relative;
  background: rgb(242 245 249 / .85);
}

.scrawl::before,
.scrawl::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--ink);
}

.scrawl::before {
  inset: 0;
  filter: url(#scrawl);
}

.scrawl::after {
  inset: -3px 2px 1px -2px;
  border-width: 1.5px;
  opacity: .45;
  filter: url(#scrawl-again);
}

textarea,
input {
  display: block;
  width: 100%;
  margin: 0;
  padding: .5rem .75rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 1.6rem/1.25 var(--pen);
}

textarea {
  min-height: 8rem;
  max-height: 24rem;
  resize: none;
  field-sizing: content;
}

textarea::placeholder,
input::placeholder {
  color: var(--faded-ink);
}

textarea:focus-visible,
input:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.count {
  min-height: 1.4rem;
  margin: .25rem 0 0;
  font-size: 1.2rem;
  color: var(--faded-ink);
  text-align: right;
}

.reply-label {
  display: block;
  margin: 0 0 .35rem;
  rotate: .8deg;
}

.reply-label span {
  color: var(--faded-ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1rem;
  margin-top: 1.25rem;
}

.status {
  flex: 1 1 12rem;
  margin: 0;
  color: var(--red-pen);
}

.status:empty {
  display: none;
}

.send {
  margin-left: auto;
  padding: .3rem 1.4rem .4rem;
  border: 0;
  color: var(--ink);
  font: 1.9rem/1 var(--pen);
  rotate: 2deg;
}

@media (hover: hover) {
  .send:hover {
    background: color-mix(in srgb, var(--ink) 8%, transparent);
  }
}

.send:disabled {
  cursor: progress;
  opacity: .6;
}

.send:focus-visible,
.again:focus-visible,
.address:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 5px;
}

/* Sent state */

.sent {
  padding: 1rem 0 2rem;
  outline: none;
}

.sent[hidden] {
  display: none;
}

.check {
  width: 4.5rem;
  fill: none;
  stroke: var(--ink);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.sent-title {
  margin: .25rem 0 1rem;
  font-size: 2.4rem;
  line-height: 1;
}

.again {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline wavy;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
}
