/* Chuckles Chat — see docs/03-design-brief.md.
   Hand-drawn, monochrome, one accent colour. Nothing soft, nothing smoothed. */

:root {
  --ink: #111111;
  --paper: #ffffff;
  --bubble-1: #f9d835;
  --bubble-2: #f3961c;
  --shadow: #c9c9c9;
  --good: #2e7d32;
  --bad: #c62828;

  --marker: "Permanent Marker", "Comic Sans MS", cursive;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* A marker outline never closes neatly. Absolute (not %) so the asymmetry
     reads the same on a 300px button and a 550px speech bubble. */
  --wobble: 28px 9px 24px 11px / 11px 24px 9px 28px;
  --wobble-alt: 9px 26px 11px 22px / 22px 11px 26px 9px;
}

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

body {
  margin: 0;
  padding: 0 1rem 3rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
  flex: 1;
}

/* --- masthead ------------------------------------------------------------ */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.5rem 0 0.5rem;
}

.wordmark {
  font-family: var(--marker);
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 1;
  margin: 0;
  transform: rotate(-1.5deg);
}

.wordmark a {
  color: inherit;
  text-decoration: none;
}

.masthead nav a {
  font-family: var(--marker);
  color: var(--ink);
  text-decoration: none;
  border-bottom: 3px solid var(--bubble-2);
}

.masthead nav a:hover {
  background: var(--bubble-1);
}

/* --- the stage: bubble + chuckles ---------------------------------------- */

.stage {
  display: grid;
  /* Capped so a one-word quote doesn't sit alone in a metre-wide bubble. */
  grid-template-columns: minmax(0, 34rem) auto;
  justify-content: center;
  gap: 1.5rem;
  align-items: center;
  margin: 2rem 0;
}

.bubble {
  position: relative;
  min-height: 10rem;
  display: flex;
  align-items: center;
  padding: 1.5rem 1.75rem;
  background: linear-gradient(var(--bubble-1), var(--bubble-2));
  border: 4px solid var(--ink);
  border-radius: var(--wobble);
  transform: rotate(-0.8deg);
}

/* The tail, pointing at Chuckles. Two triangles so it keeps a black outline. */
.bubble::after,
.bubble::before {
  content: "";
  position: absolute;
  right: -26px;
  top: 3.25rem;
  width: 0;
  border-style: solid;
}

.bubble::before {
  border-width: 16px 0 16px 26px;
  border-color: transparent transparent transparent var(--ink);
}

.bubble::after {
  right: -18px;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent var(--bubble-2);
}

#quote-text {
  margin: 0;
  font-size: clamp(1.35rem, 3.2vw, 2rem);
  line-height: 1.3;
  font-weight: 600;
  text-wrap: balance;
  /* 49 of the quotes are poems or numbered lists whose line breaks are the
     joke. Without pre-line, HTML collapses them into one run-on sentence. */
  white-space: pre-line;
}

.chuckles {
  width: 300px;
  height: 300px;
  max-width: 40vw;
  image-rendering: auto;
  user-select: none;
}

.chuckles.pop {
  animation: pop 220ms ease-out;
}

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.06, 0.94) translateY(4px); }
  100% { transform: scale(1); }
}

/* --- controls ------------------------------------------------------------ */

.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--marker);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.85rem 1.6rem;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--wobble-alt);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 90ms, box-shadow 90ms, background 90ms;
}

.btn:hover {
  background: var(--bubble-1);
}

.btn:active {
  transform: translate(5px, 5px);
  box-shadow: 0 0 0 var(--ink);
}

.btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.btn-quiet {
  font-family: var(--body);
  font-size: 1rem;
  box-shadow: 3px 3px 0 var(--ink);
  border-width: 3px;
  padding: 0.5rem 1rem;
}

.linky {
  font-family: var(--marker);
  color: var(--ink);
  text-decoration: none;
  border-bottom: 3px solid var(--bubble-2);
  font-size: 1.15rem;
}

.linky:hover {
  background: var(--bubble-1);
}

.permalink {
  background: none;
  border: 0;
  padding: 0.25rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  opacity: 0.65;
  cursor: pointer;
  text-decoration: underline;
}

.permalink:hover {
  opacity: 1;
}

/* --- forms --------------------------------------------------------------- */

.prose {
  max-width: 40rem;
}

.prose h2 {
  font-family: var(--marker);
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.15;
  margin: 1.5rem 0 0.5rem;
}

.field {
  margin: 1.25rem 0;
  max-width: 40rem;
}

.field label {
  display: block;
  font-family: var(--marker);
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}

.field .hint {
  font-size: 0.9rem;
  opacity: 0.7;
}

textarea,
input[type="email"] {
  width: 100%;
  font-family: var(--body);
  font-size: 1.15rem;
  padding: 0.75rem;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--wobble);
}

textarea:focus,
input:focus,
.btn:focus-visible,
a:focus-visible {
  outline: 4px solid var(--bubble-2);
  outline-offset: 3px;
}

textarea {
  min-height: 8rem;
  resize: vertical;
}

.counter {
  font-size: 0.9rem;
  text-align: right;
  opacity: 0.7;
}

.counter.over {
  color: var(--bad);
  font-weight: 700;
  opacity: 1;
}

.toast {
  font-family: var(--marker);
  font-size: 1.3rem;
  color: var(--paper);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  border: 4px solid var(--ink);
  border-radius: var(--wobble-alt);
  opacity: 0;
  /* Matches the legacy 2s fade in / 4s hold / 2s fade out. */
  transition: opacity 2s ease;
}

.toast.show { opacity: 1; }
.toast.good { background: var(--good); }
.toast.bad  { background: var(--bad); }

/* Two columns rather than a float — a floated illustration leaves the form's
   first field stranded below it. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 34rem) auto;
  gap: 2.5rem;
  align-items: start;
}

.illo {
  width: 100%;
  max-width: 17rem;
  height: auto;
}

/* --- footer -------------------------------------------------------------- */

.foot {
  border-top: 4px solid var(--ink);
  margin-top: 3rem;
  padding-top: 1rem;
  font-size: 0.9rem;
  opacity: 0.75;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- small screens ------------------------------------------------------- */

@media (max-width: 46rem) {
  .stage {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .bubble {
    order: 1;
  }

  /* Tail flips to the bottom so it still points at Chuckles when stacked. */
  .bubble::before {
    right: auto;
    left: 3rem;
    top: auto;
    bottom: -26px;
    border-width: 26px 16px 0 16px;
    border-color: var(--ink) transparent transparent transparent;
  }

  .bubble::after {
    right: auto;
    left: 3.3125rem;
    top: auto;
    bottom: -17px;
    border-width: 18px 11px 0 11px;
    border-color: var(--bubble-2) transparent transparent transparent;
  }

  .chuckles {
    order: 2;
    width: 180px;
    height: 180px;
    max-width: 55vw;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .illo {
    order: -1;
    width: 60%;
    margin: 0 auto 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
