/* Borrowed Thunder: flat ink on paper, after Šašek. Palette and type reasons in docs/DESIGN.md. */
:root {
  --ink: #1d1a1f; --red: #c2401f; --blue: #2f4d9e; --mustard: #e0a826; --grass: #6a9a3a;
  --stone: #cbbba0; --paper: #fbf8f0; --sky: #a9d3e3;
  --ui: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  --news: Georgia, "Times New Roman", serif;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink); font: 16px/1.35 var(--ui); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
/* keyboard focus: an ultramarine rule printed just outside the control, the colour of things you press */
button:focus-visible, [role="button"]:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
#ribbon button:focus-visible, #help:focus-visible { outline-color: var(--paper); }
/* the town itself takes focus for the keyboard drag; render.js rings the chosen bubble, this frames the town */
#town:focus { outline: none; }
#town:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { position: fixed; inset: 0; height: 100%; height: 100dvh; overflow: hidden; background: var(--sky); transition: background-color 6s; }
/* the town gets whatever the dares and the ribbon leave; ui.js sets the three strips */
#town {
  position: absolute; left: var(--town-left, 0px); top: var(--town-top, 0px);
  width: calc(100% - var(--town-left, 0px)); height: calc(100% - var(--town-top, 0px) - var(--town-bottom, 58px));
  display: block; touch-action: none;
}

/* paper slips: a flat sheet with a mustard block printed a little off from it */
.slip, .slip-btn, #dares {
  background: var(--paper); border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--mustard);
}

/* ---- top bar ---- */
#bar {
  position: absolute; top: 0; left: 0; right: 0; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(8px + var(--sat)) calc(8px + var(--sar)) 0 calc(8px + var(--sal));
}
#bar { z-index: 2; }
#bar > *, #bar .right > * { pointer-events: auto; }
#bar .right { display: flex; gap: 10px; margin-left: auto; }
.slip-btn {
  min-height: 46px; padding: 6px 14px; display: inline-flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: bold; border-radius: 0;
}
.slip-btn svg, .icon-btn svg { width: 24px; height: 24px; flex: none; }
.slip-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--mustard); }
#press { background: var(--blue); color: var(--paper); box-shadow: 4px 4px 0 var(--ink); }
#press.armed { background: var(--red); }
.icon-btn {
  width: 46px; height: 46px; display: grid; place-items: center; padding: 0;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 50%;
}

/* ---- the goal line ---- */
/* sits on the road at the bottom left of the town, clear of the sky and the net */
#goal {
  position: absolute; left: calc(var(--town-left, 0px) + 12px + var(--sal)); bottom: calc(var(--town-bottom, 58px) + 12px);
  transform: rotate(-1deg); margin: 0; padding: 8px 16px;
  max-width: min(560px, calc(100% - var(--town-left, 0px) - 230px));
  font-size: 18px; font-weight: bold; pointer-events: none;
  transition: opacity .8s, transform .8s;
}
#goal.gone { opacity: 0; transform: translateY(30px) rotate(-1deg); }

/* ---- the dares: a stack of envelopes ---- */
#dares {
  position: absolute; display: flex; flex-direction: column; overflow: hidden;
  left: calc(8px + var(--sal)); top: calc(8px + var(--sat)); width: 310px;
  transform: rotate(-0.6deg);
}
#dares[hidden] { display: none; }
.dares-head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; justify-content: space-between; padding: 4px 4px 4px 12px; border-bottom: 2px solid var(--ink); flex: none; }
.dares-head h2 { margin: 0; font-size: 18px; letter-spacing: .02em; white-space: nowrap; }
/* the hide control: large, loud and always in the card's header */
.tab-btn {
  min-height: 48px; min-width: 96px; padding: 0 14px 0 10px; font-size: 16px; font-weight: bold;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--mustard); border: 2px solid var(--ink); white-space: nowrap;
}
.tab-btn svg { width: 20px; height: 20px; flex: none; }
#dares-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; -webkit-user-select: text; user-select: text; }
.dare { position: relative; flex: none; padding: 8px 10px 8px 46px; border: 2px solid var(--ink); background: var(--paper); font-size: 15px; min-height: 48px; }
.dare b { display: block; font-size: 15px; }
.dare.sealed { background: #e9dfca; color: #4a4450; min-height: 34px; padding: 5px 10px 5px 40px; font-size: 14px; }
.dare.sealed .seal { width: 22px; height: 22px; top: 5px; }
.dare.sealed .seal::after { inset: 5px; }
.dare .secret { font-style: italic; }
.dare.none { padding-left: 12px; min-height: 0; font-style: italic; }
.dare .seal, .dare .flap, .dare .stamp { position: absolute; left: 8px; top: 9px; width: 28px; height: 28px; }
.dare .seal { border-radius: 50%; background: var(--red); border: 2px solid var(--ink); }
.dare .seal::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; border: 2px solid rgba(29,26,31,.55); }
.dare .flap { border: 2px solid var(--ink); background: var(--paper); height: 20px; top: 13px; }
.dare .flap::after { content: ""; position: absolute; left: 3px; top: -10px; width: 16px; height: 16px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); background: var(--paper); }
.dare .bar { display: block; height: 6px; margin-top: 6px; border: 1.5px solid var(--ink); }
.dare .bar i { display: block; height: 100%; background: var(--mustard); transition: width .4s; }
.dare.done { background: #f3e7c4; }
.dare .stamp { border-radius: 50%; border: 3px double var(--blue); transform: rotate(-14deg); }
.dare .stamp::after { content: ""; position: absolute; left: 7px; top: 3px; width: 7px; height: 13px; border-right: 3px solid var(--blue); border-bottom: 3px solid var(--blue); transform: rotate(40deg); }
.dare .doneline { display: block; font-size: 14px; margin-top: 2px; }

/* docked beside the town (wide phones held sideways) */
#app[data-dares="left"] #dares { top: 0; left: 0; bottom: auto; height: auto; transform: none; box-shadow: none; border-width: 0 2px 0 0; padding-top: var(--sat); padding-left: var(--sal); }
/* the panel column also carries mute and Send to press, so the town's sky stays clear */
#app[data-dares="left"] #bar .right { position: fixed; left: calc(8px + var(--sal)); bottom: calc(var(--town-bottom) + 8px); width: 234px; justify-content: space-between; }
#app[data-dares="left"] #dares { padding-bottom: 62px; }
/* docked under the town (portrait) */
#app[data-dares="bottom"] #dares { left: 0; right: 0; top: auto; width: auto; transform: none; box-shadow: none; border-width: 2px 0 0 0; padding-left: var(--sal); padding-right: var(--sar); }
#app[data-dares="bottom"] #dares-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; align-items: stretch; }
#app[data-dares="bottom"] .dare { flex: 0 0 min(250px, 72vw); }

/* ---- the rewind ribbon ---- */
/* --red is the vermilion printed heavier (#c2401f, not the roofs' #d94f2b): paper text on it reaches 4.89:1, ink parts 3.32:1 */
#ribbon {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(58px + var(--sab));
  padding: 6px calc(64px + var(--sar)) calc(6px + var(--sab)) calc(8px + var(--sal));
  display: flex; align-items: center; gap: 8px;
  background: var(--red); color: var(--paper); border-top: 2px solid var(--ink);
}
#ribbon::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: rgba(29,26,31,.35); pointer-events: none; }
#ribbon-label { position: relative; font-weight: bold; font-size: 15px; letter-spacing: .04em; flex: none; }
.back-btn {
  position: relative; flex: none; width: 46px; height: 46px; display: grid; place-items: center;
  background: var(--ink); border: 2px solid var(--paper); border-radius: 50%; padding: 0;
}
.back-btn svg { width: 24px; height: 24px; }
.back-btn:disabled { opacity: .45; cursor: default; }
#knots { position: relative; flex: 1; min-width: 0; display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; height: 100%; }
#knots::-webkit-scrollbar { display: none; }
#knots .empty { font-size: 15px; font-style: italic; white-space: nowrap; }
.knot {
  flex: none; min-height: 44px; max-width: 190px; display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px 0 6px; background: transparent; color: var(--paper); border: 0; font-size: 14px;
}
.knot .tie { width: 18px; height: 18px; flex: none; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
.knot .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.knot.now { background: var(--paper); color: var(--ink); border: 2px solid var(--ink); }
.knot.now .tie { background: var(--mustard); }
/* help sits at the ribbon's right end: on every screen, never over the town */
#help { position: absolute; z-index: 2; right: calc(8px + var(--sar)); bottom: calc(6px + var(--sab)); }
#help[aria-pressed="true"] { background: var(--mustard); }

/* ---- the title card: a poster pinned over the waiting town ---- */
#title {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; overflow-y: auto;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  background: rgba(251, 248, 240, 0.42);
}
.poster {
  width: min(560px, 100%); padding: 26px 30px 30px; background: var(--paper);
  border: 2px solid var(--ink); box-shadow: 8px 8px 0 var(--mustard); transform: rotate(-0.8deg);
  animation: settle .5s ease-out;
}
@keyframes settle { from { opacity: 0; transform: translateY(-14px) rotate(-2deg); } }
.poster h1 { margin: 0 0 12px; font-size: clamp(40px, 10vw, 74px); line-height: .95; letter-spacing: -0.01em; }
/* the second word printed in vermilion over a mustard block that missed its mark */
.poster h1 span { display: inline-block; color: var(--red); text-shadow: 3px 3px 0 var(--mustard); }
#title-about { margin: 0 0 22px; font-size: 18px; line-height: 1.4; max-width: 34ch; }
.begin-btn {
  width: 100%; min-height: 64px; padding: 10px 20px; font-size: 22px; font-weight: bold;
  background: var(--blue); color: var(--paper); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
}
.begin-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
@media (max-height: 440px) {
  .poster { padding: 16px 22px 20px; }
  .poster h1 { font-size: 40px; margin-bottom: 8px; }
  #title-about { margin-bottom: 14px; font-size: 16px; }
  .begin-btn { min-height: 56px; }
}

/* ---- toast ---- */
#toast {
  position: absolute; left: calc(var(--town-left, 0px) + (100% - var(--town-left, 0px)) / 2); top: calc(var(--town-top, 0px) + 12px + var(--sat)); max-width: min(460px, calc(100% - 32px));
  padding: 10px 16px; font-size: 17px; font-weight: bold; text-align: center;
  transform: translate(-50%, -16px) rotate(1deg); opacity: 0; pointer-events: none; transition: opacity .35s, transform .35s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0) rotate(1deg); }
#toast.low { top: auto; bottom: calc(var(--town-bottom, 58px) + 12px); }

/* ---- a dare done: a paper ticket slides onto the town and the stamp comes down on its mustard stub ---- */
/* main.js places it (left/top) on the road or in the sky, wherever no bubble is */
#ticket {
  position: absolute; z-index: 3; left: 0; top: 0; display: flex; align-items: stretch;
  width: max-content; max-width: min(380px, calc(100% - var(--town-left, 0px) - 28px));
  background: var(--paper); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--mustard);
  pointer-events: none; opacity: 0; transform: translateX(-60px) rotate(-4deg);
  transition: opacity .25s, transform .4s cubic-bezier(.2, .9, .3, 1.25), left .3s, top .3s;
}
#ticket.in { opacity: 1; transform: rotate(-1.5deg); }
.t-stub { position: relative; flex: none; width: 62px; background: var(--mustard); border-right: 2px dashed var(--ink); }
.t-stamp {
  position: absolute; left: 9px; top: 50%; width: 42px; height: 42px; margin-top: -21px;
  border-radius: 50%; border: 4px double var(--blue);
  opacity: 0; transform: scale(2.4) rotate(-50deg); transition: opacity .1s, transform .16s cubic-bezier(.6, 0, .9, .5);
}
.t-stamp::after { content: ""; position: absolute; left: 11px; top: 4px; width: 10px; height: 19px; border-right: 4px solid var(--blue); border-bottom: 4px solid var(--blue); transform: rotate(40deg); }
#ticket.stamped .t-stamp { opacity: 1; transform: scale(1) rotate(-14deg); }
#ticket.stamped { animation: thump .22s ease-out; }
@keyframes thump { 40% { margin-top: 3px; } }
.t-body { padding: 8px 16px 10px 14px; }
.t-title { display: block; font-size: 17px; line-height: 1.2; }
.t-line { display: block; margin-top: 3px; font-size: 15px; line-height: 1.3; }

/* ---- the newspaper ---- */
#news {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(29,26,31,.55); padding: calc(16px + var(--sat)) calc(12px + var(--sar)) calc(24px + var(--sab)) calc(12px + var(--sal));
  -webkit-user-select: text; user-select: text;
}
#news[hidden] { display: none; }
.paper {
  max-width: 980px; margin: 0 auto; padding: 22px 30px 26px; background: #f4f1e8; color: #221f22;
  font: 17px/1.5 var(--news); box-shadow: 6px 6px 0 var(--ink); transform: rotate(-0.4deg);
  animation: drop .6s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes drop { from { transform: translateY(-60px) rotate(-4deg); opacity: 0; } to { transform: rotate(-0.4deg); opacity: 1; } }
.mast { text-align: center; }
.mast .ear { font-size: 14px; letter-spacing: .12em; text-transform: uppercase; border-bottom: 1px solid #221f22; padding-bottom: 4px; }
.mast h1 { margin: 6px 0 4px; font-size: clamp(38px, 8vw, 78px); line-height: 1; font-weight: bold; letter-spacing: -0.02em; }
.mast .rule { height: 6px; border-top: 3px solid #221f22; border-bottom: 1px solid #221f22; margin-bottom: 14px; }
.lead h2 { margin: 4px 0 6px; font-size: clamp(28px, 4.6vw, 46px); line-height: 1.05; }
.standfirst { margin: 0 0 12px; font-size: 20px; font-style: italic; }
.cols { column-count: 2; column-gap: 26px; column-rule: 1px solid #b9b3a6; text-align: justify; hyphens: auto; }
.cols p, .item p { margin: 0 0 .7em; }
.cols p:first-child::first-letter { float: left; font-size: 3.1em; line-height: .85; padding: 4px 6px 0 0; font-weight: bold; }
.items { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 26px; border-top: 3px double #221f22; margin-top: 16px; padding-top: 12px; }
.item { border-bottom: 1px solid #b9b3a6; padding-bottom: 10px; margin-bottom: 12px; }
.item h3 { margin: 0 0 6px; font-size: 22px; line-height: 1.15; }
.small { border: 1px solid #221f22; padding: 6px 14px; margin-top: 8px; font-size: 15px; }
.small ul { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 24px; }
.small li { padding: 4px 0; border-bottom: 1px dotted #9a9488; break-inside: avoid; }
.photo { margin: 0 0 12px; cursor: pointer; }
.photo .plate { position: relative; border: 1px solid #221f22; background: #ddd8cc; aspect-ratio: 3 / 2; overflow: hidden; }
.photo.big .plate { aspect-ratio: 16 / 7; }
.photo canvas { display: block; width: 100%; height: 100%; filter: grayscale(1) contrast(1.25) brightness(1.05) sepia(.15); }
.photo .plate::after { /* halftone screen */
  content: ""; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: multiply; opacity: .35;
  background: radial-gradient(circle, rgba(34,31,34,.55) 0.9px, transparent 1.3px) 0 0 / 4px 4px;
}
.photo figcaption { font-size: 14px; font-style: italic; padding-top: 4px; border-bottom: 1px solid #b9b3a6; }
.photo.blank .plate { display: none; }
.paper-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: flex-end; border-top: 3px solid #221f22; margin-top: 14px; padding-top: 14px; font-family: var(--ui); }
.paper-foot .share { flex: 1 1 100%; order: -1; margin: 0; font: italic 15px var(--news); text-align: center; }
.btn { min-height: 48px; padding: 8px 18px; font-size: 17px; font-weight: bold; background: var(--paper); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--mustard); }
.btn.primary { background: var(--blue); color: var(--paper); box-shadow: 3px 3px 0 var(--ink); }
body.reading #bar, body.reading #ribbon, body.reading #dares, body.reading #goal, body.reading #ticket { visibility: hidden; }

@media (max-width: 700px) {
  .paper { padding: 16px 16px 20px; transform: none; }
  .cols { column-count: 1; }
  .small ul { columns: 1; }
  .photo.big .plate { aspect-ratio: 3 / 2; }
  #goal { font-size: 16px; max-width: calc(100% - 210px); }
  .slip-btn { font-size: 15px; padding: 6px 10px; }
}
@media (max-height: 440px) {
  #goal { font-size: 16px; padding: 6px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .paper, .poster, #ticket.stamped { animation: none; }
  #goal, #toast, #app, .dare .bar i, #ticket, .t-stamp { transition: none; }
  #ticket { transform: rotate(-1.5deg); }
  .t-stamp { transform: rotate(-14deg); }
}
