/* Off Your Mind. One idea: the page starts loud and gets quiet as the head empties.
   --t is the tension, from 1 (14 thoughts) to 0 (nothing). app.js sets it. */

@font-face { font-family: "Bricolage"; src: url(fonts/bricolage.woff2) format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url(fonts/newsreader.woff2) format("woff2"); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url(fonts/newsreader-italic.woff2) format("woff2"); font-weight: 200 800; font-style: italic; font-display: swap; }

:root {
  --t: 1;
  --hot: #F2401C;
  --calm: #F3EFE6;
  --ink: #14110F;
  --cream: #FFF3DC;
  --line: rgb(20 17 15 / .16);
  --bg: color-mix(in oklab, var(--hot) calc(var(--t) * 100%), var(--calm));
  --loud: "Bricolage", "Arial Narrow", Arial, sans-serif;
  --soft: "Newsreader", Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--soft);
  transition: background-color .8s ease;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
p { margin: 0; }

/* Layout: phone first. One screen until the head is empty, then the page may grow. */
.page {
  --w: min(84vw, 46svh); /* the head's width */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100svh;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  gap: 8px;
}
.done .page { --w: min(60vw, 32svh); grid-template-rows: auto auto auto; height: auto; min-height: 100svh; padding-bottom: 40px; }

.brand { font: 600 14px/1.2 var(--loud); letter-spacing: -.01em; }

h1 {
  margin: 10px 0 0;
  font-family: var(--loud);
  font-size: clamp(30px, 9.4vw, 44px);
  line-height: 1;
  letter-spacing: calc(-.035em * var(--t) - .01em);
  font-weight: calc(300 + 500 * var(--t));
  transition: font-weight .7s ease, letter-spacing .7s ease;
  text-wrap: balance;
}
#count { font-variant-numeric: tabular-nums; }

.prompt { min-height: 34px; margin-top: 8px; display: flex; align-items: center; }
#hint { font: 500 15px/1 var(--loud); }
.think { font-size: 21px; font-style: italic; line-height: 1.1; }
.all {
  font: 700 15px/1 var(--loud);
  background: var(--ink);
  color: var(--cream);
  border: 0;
  border-radius: 99px;
  padding: 10px 16px;
  cursor: pointer;
}
.all:hover { background: #000; }

/* The head */
.headwrap { grid-row: 2; grid-column: 1; display: flex; justify-content: center; align-items: flex-start; min-height: 0; clip-path: inset(-200px -200px 0 -200px); margin: 0 -16px; }
.head {
  position: relative;
  flex: none;
  width: var(--w);
  aspect-ratio: 800 / 1000;
  container-type: inline-size;
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.done .head { transition: width .9s cubic-bezier(.2, .8, .2, 1); }
.head svg { position: absolute; inset: 0; width: 100%; height: auto; overflow: visible; display: block; }
#skull { fill: var(--ink); stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; transition: fill 1.1s ease; }

.done .headwrap { height: calc(var(--w) * 1.06); }
.done .head { touch-action: auto; cursor: default; }
.done #skull { fill: rgb(255 255 255 / .55); }

.thoughts { position: absolute; inset: 0; }

#tangle {
  fill: none;
  stroke: var(--cream);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .5;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--t));
  transition: stroke-dashoffset .8s ease, opacity .6s ease;
}
.done #tangle { opacity: 0; }

/* Every thought is a slip of paper stuffed into the head */
.thought {
  position: absolute;
  left: var(--x);
  top: var(--y);
  padding: .3em .5em .34em;
  white-space: nowrap;
  border: 0;
  border-radius: 1px;
  cursor: pointer;
  background: var(--bg-slip);
  color: var(--ink);
  font-family: var(--loud);
  font-size: calc(var(--s) * 1cqw);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.02em;
  box-shadow: 0 .12em .4em rgb(0 0 0 / .4);
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: jit var(--d) linear infinite;
  animation-delay: var(--dl);
}
.thought:hover, .thought:focus-visible {
  z-index: 2;
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  scale: 1.07;
}

@keyframes jit {
  0%, 100% { translate: 0 0; }
  20% { translate: calc(var(--t) * var(--ax)) calc(var(--t) * var(--ay)); }
  50% { translate: calc(var(--t) * var(--ay) * -1) calc(var(--t) * var(--ax)); }
  80% { translate: calc(var(--t) * var(--ax) * -1) calc(var(--t) * var(--ay) * -1); }
}

/* A thought on its way out */
.flying {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10;
  margin: 0;
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--loud);
  line-height: 1;
  transform-origin: 0 0;
  letter-spacing: -.02em;
}
.flying.slip { padding: .3em .5em .34em; box-shadow: 0 .12em .4em rgb(0 0 0 / .3); }

/* A quiet idea, once there is room for one */
.idea {
  position: absolute;
  left: 18%;
  right: 16%;
  top: 30%;
  text-align: center;
  font-style: italic;
  font-size: 6.4cqw;
  line-height: 1.2;
  opacity: 0;
  transition: opacity 1.4s ease;
}
.idea.on { opacity: 1; }
.done .head { animation: breathe 7s ease-in-out infinite; }
@keyframes breathe { 50% { scale: 1.012; } }

/* The list: messy thought in, plain dated task out */
/* On a phone the list shares the head's cell. The neck runs off the screen until the first
   thought leaves, then the list wipes in over it. clip-path, so rows already sit in place. */
.side {
  grid-row: 2; grid-column: 1; align-self: end;
  height: calc(100% - var(--w) * 1.06);
  min-height: 0; display: flex; flex-direction: column; padding-top: 6px;
  margin: 0 -16px; padding-inline: 16px;
  background: var(--bg);
  transition: background-color .8s ease, clip-path .5s cubic-bezier(.2, .8, .2, 1);
  clip-path: inset(100% 0 0 0);
  position: relative;
}
.started .side { clip-path: inset(0); }
.done .side { grid-row: 3; height: auto; background: none; clip-path: none; }
.rows {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  overflow-y: auto;
  scrollbar-width: none;
  flex: 0 1 auto;
  min-height: 0;
}
.done .rows { overflow: visible; }
.rows::-webkit-scrollbar { display: none; }
.row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  column-gap: 8px;
  align-items: baseline;
  border-top: 1px solid var(--line);
  overflow: hidden;
}
.row > * { padding: 5px 0; }
.when { font: 600 12px/1.2 var(--loud); letter-spacing: -.005em; }
.what { font-size: 18px; line-height: 1.2; }
.rep { font: italic 400 14px/1 var(--soft); opacity: .68; margin-left: 6px; white-space: nowrap; }
.row.landing { opacity: 0; }
.row.landed { animation: settle .45s ease both; }
@keyframes settle { from { opacity: .2; } to { opacity: 1; } }
.row.folding { max-height: 0 !important; opacity: 0; border-color: transparent; transition: max-height .7s ease, opacity .4s ease, border-color .4s ease; }

.more { font-size: 16px; font-style: italic; padding: 2px 0 0; }

/* After the head is empty */
.after { max-width: 34em; padding-top: 18px; animation: settle 1.1s ease both; }
.say { display: flex; gap: 8px; border-bottom: 1.5px solid var(--ink); }
.say input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  padding: 10px 0;
  font-size: 18px; /* at least 16px, or iPhones zoom in on focus */
}
.say input::placeholder { color: rgb(20 17 15 / .55); font-style: italic; }
.say button {
  border: 0;
  background: none;
  font: 700 15px/1 var(--loud);
  cursor: pointer;
  padding: 8px 0 8px 8px;
}
.pitch { font-size: 21px; line-height: 1.25; margin-top: 24px; }
.pitch.quiet { margin-top: 8px; opacity: .68; }
.pun { font: 700 20px/1.15 var(--loud); letter-spacing: -.02em; margin-top: 24px; }
.pun span { font-weight: 300; }
.small { font-size: 14px; line-height: 1.35; margin-top: 14px; opacity: .75; }
.again { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; white-space: nowrap; }
.nojs { font-size: 21px; padding: 16px 0; grid-column: 1 / -1; }

/* Laptop and up: head left, running off the bottom; everything else right */
@media (min-width: 860px) {
  .page {
    --w: min(46vw, calc(100svh * .76));
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    padding: 28px 48px 0 28px;
    column-gap: 40px;
    overflow: hidden;
  }
  .headwrap { grid-column: 1; grid-row: 1 / 3; align-items: flex-end; justify-content: center; height: 100%; margin: 0; }
  .done .headwrap { height: 100svh; }
  .done .page { --w: min(40vw, calc(100svh * .72)); overflow: visible; grid-template-rows: auto auto; }
  .done .headwrap { position: sticky; top: 0; align-self: start; margin-top: -28px; }
  .top { grid-column: 2; grid-row: 1; padding-top: 2px; }
  .side { grid-column: 2; grid-row: 2; height: auto; align-self: stretch; margin: 0; padding-inline: 0; background: none; clip-path: none; transition: none; }
  .done .side { grid-row: 2; }
  .brand { font-size: 16px; }
  h1 { font-size: clamp(44px, 4.8vw, 72px); margin-top: clamp(14px, 4svh, 44px); }
  #hint { font-size: 18px; }
  .all { font-size: 17px; padding: 11px 19px; }
  .prompt { margin-top: 12px; min-height: 44px; }
  .think { font-size: 28px; }
  .what { font-size: 20px; }
  .when { font-size: 13px; }
  .row { grid-template-columns: 92px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * , *::before, *::after { animation: none !important; transition: none !important; }
  .row.landing { opacity: 1; }
}
