/* Mengjing Technology · the graph-paper map */

@font-face {
  font-family: "Besley";
  src: url("fonts/besley-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Kalam";
  src: url("fonts/kalam-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Kalam";
  src: url("fonts/kalam-700-latin.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Ma Shan Zheng";
  src: url("fonts/mashanzheng-mengjing.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+5883, U+68A6;
}

:root {
  --paper: #FBFDFF;
  --rule: #CDE3F2;
  --rule-2: #9FCBEA;
  --ink: #23262B;
  --graphite: #3B3F46;
  --ink-2: #4A5059;
  --pen: #C92A21;
  --pen-deep: #A8211A;
  --hi: #FFE94A;
  --on-ink: #FBFDFF;

  --slab: "Besley", Rockwell, "Roboto Slab", Georgia, serif;
  --hand: "Kalam", "Bradley Hand", "Segoe Print", cursive;
  --han: "Ma Shan Zheng", "Kaiti SC", KaiTi, serif;

  --sq: 1.5rem;
  --w: min(calc(var(--sq) * 32), calc(100vw - 1.5rem));
  --tail: 3;
  --out: cubic-bezier(.16, 1, .3, 1);
}
@supports (width: round(down, 10px, 3px)) {
  :root { --w: min(calc(var(--sq) * 32), round(down, calc(100vw - 1.5rem), var(--sq))); }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--sq) * 4);
  scrollbar-color: var(--graphite) var(--paper);
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--slab);
  overflow-x: clip;
}

::selection { background: var(--hi); color: var(--ink); }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 3px; border-radius: 2px; }

.sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.hp { position: absolute; left: -200vw; width: 1px; height: 1px; opacity: 0; }
.defs { position: absolute; }
.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 20;
  padding: .6rem 1rem; background: var(--hi); color: var(--ink); font-weight: 700;
}
.skip:focus { top: 3.5rem; }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: .2em;
  background: linear-gradient(var(--hi), var(--hi)) no-repeat 0 100% / 0 100%;
  transition: background-size .3s var(--out);
}
a:hover { background-size: 100% 100%; }

.han { font-family: var(--han); font-size: 1.3em; line-height: 1; }

/* ---------- status line ---------- */
.status {
  position: sticky; top: 0; z-index: 10;
  height: calc(var(--sq) * 2);
  background: var(--ink); color: var(--on-ink);
  font-weight: 600; font-size: 1rem; line-height: 1.2;
}
.status-in {
  width: var(--w); height: 100%; margin-inline: auto;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 1rem;
}
.status p { margin: 0; }
.brand { font-weight: 800; text-decoration: none; background: none; white-space: nowrap; }
.brand:hover { color: var(--hi); }
.status :focus-visible { outline-color: var(--hi); }
.where { justify-self: end; color: var(--hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.moves { display: none; font-variant-numeric: tabular-nums; }

/* ---------- the sheet ---------- */
.paper { overflow-x: hidden; overflow-x: clip; }
.sheet {
  position: relative; isolation: isolate;
  width: var(--w); margin-inline: auto;
  padding-block: calc(var(--sq) * 2) calc(var(--sq) * 3);
}
.sheet::before {
  content: ""; position: absolute; z-index: -1;
  inset: calc(var(--sq) * -4) calc(var(--sq) * -60) 0;
  background-image:
    linear-gradient(var(--rule-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule-2) 1px, transparent 1px),
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size:
    calc(var(--sq) * 4) calc(var(--sq) * 4), calc(var(--sq) * 4) calc(var(--sq) * 4),
    var(--sq) var(--sq), var(--sq) var(--sq);
}

.row {
  position: relative;
  display: grid; grid-template-columns: repeat(auto-fill, var(--sq)); align-items: start;
}
.row > * { grid-column: 1 / -1; }
.row + .row { margin-top: calc(var(--sq) * 3); }
.row + .r4 { margin-top: calc(var(--sq) * 8); }

/* ---------- rooms, walls, doors, halls ---------- */
.room {
  --door: 2;
  position: relative; margin: 0;
  padding: calc(var(--sq) * 1.5) var(--sq) var(--sq);
  background: rgb(255 255 255 / .62);
}
.wall, .hall, .swatch {
  fill: none; stroke: var(--graphite); stroke-width: 3.5; stroke-linecap: round;
  overflow: visible; pointer-events: none;
}
.wall { position: absolute; inset: 0; width: 100%; height: 100%; }
.wall.dash { stroke-dasharray: 11 9; }
.wall.thin { stroke-width: 2.25; }

.door { position: absolute; background: var(--paper); }
.door.s { left: calc(var(--sq) * var(--door)); bottom: -5px; width: calc(var(--sq) * 2); height: 10px; }
.door.e { display: none; right: -5px; width: 10px; height: calc(var(--sq) * 2); }

.hall { position: absolute; }
.hs {
  top: 100%; left: calc(var(--sq) * var(--door));
  width: calc(var(--sq) * 2); height: calc(var(--sq) * var(--run, 3));
}
.he { display: none; height: calc(var(--sq) * 2); }
.hs.main { display: none; }
.hs.tail { top: calc(100% + var(--sq) * 3); stroke-dasharray: 9 9; }

.here {
  position: absolute; top: -.95rem; right: var(--sq); z-index: 2; margin: 0;
  padding: 0 .7rem;
  background: rgb(255 233 74 / .92);
  font: 700 1.125rem/1.6 var(--hand);
  transform: rotate(-1.5deg);
  clip-path: inset(0 100% 0 0);
  transition: clip-path .5s var(--out);
}
.is-here .here { clip-path: inset(0); }

/* ---------- type ---------- */
h1, h2, h3, p { margin: 0; }
h1 {
  font-weight: 800; font-size: clamp(2.125rem, 9.2vw, 3.25rem); line-height: 1.06;
  letter-spacing: -.022em; text-wrap: balance;
}
h2 { font-weight: 800; font-size: 1.875rem; line-height: 1.1; letter-spacing: -.015em; text-wrap: balance; }
.lede { margin-top: 1.25rem; font-size: 1.125rem; line-height: 1.5; max-width: 40rem; text-wrap: pretty; }
.room > h2 + p, .room > p + p { margin-top: 1rem; }
.room > p { max-width: 62ch; text-wrap: pretty; }

.exits { margin-top: 1.5rem; font-size: 1rem; line-height: 1.5; color: var(--ink-2); }
.exits b { color: var(--ink); }
.exits a { color: var(--ink); }

/* ---------- the command line (email form) ---------- */
.join { margin-top: 1.75rem; }
.ask-label { display: block; margin-bottom: .125rem; font-weight: 700; font-size: 1rem; }
.cmdline { display: grid; grid-template-columns: auto 1fr; gap: .625rem .625rem; align-items: end; }
.gt { font-weight: 800; }
.cmdline .gt { font-size: 2rem; line-height: 3rem; }
.field {
  min-width: 0; height: 3rem; padding: 0 .375rem;
  border: solid var(--ink); border-width: 0 0 3px; border-radius: 0;
  background: transparent; color: var(--ink);
  font: 500 1.1875rem/1 var(--slab); caret-color: var(--pen);
}
.field::placeholder { color: var(--ink-2); opacity: 1; }
.field:focus-visible { outline: none; border-bottom-color: var(--pen); background: rgb(255 233 74 / .4); }
.field[aria-invalid="true"] { border-bottom-color: var(--pen); border-bottom-style: dashed; }
.btn {
  grid-column: 1 / -1;
  min-height: 3rem; padding: .25rem 1.5rem;
  border: 3px solid var(--ink); border-radius: 3px 7px 4px 6px;
  background: var(--ink); color: var(--paper);
  font: 800 1.0625rem/1.15 var(--slab); cursor: pointer;
  transition: background-color .2s var(--out), color .2s var(--out), transform .2s var(--out);
}
.btn:hover { background: var(--hi); color: var(--ink); }
.btn:active { transform: translateY(2px); }
.btn:disabled { cursor: progress; background: var(--paper); color: var(--ink); border-style: dashed; }
.oops { margin-top: .625rem; color: var(--pen-deep); font-weight: 700; line-height: 1.4; }
.oops:empty { display: none; }
.fine { margin-top: .625rem; font-size: .9375rem; line-height: 1.45; color: var(--ink-2); text-wrap: pretty; }
.oops:not(:empty) ~ .fine { display: none; }
.nojs { display: none; margin-top: .5rem; font-size: .9375rem; font-weight: 700; color: var(--pen-deep); }
html:not(.js) .nojs { display: block; }
.done p { font-size: 1.1875rem; line-height: 1.45; max-width: 34rem; }
.done b { font-weight: 800; background: rgb(255 233 74 / .92); padding: 0 .25rem; overflow-wrap: anywhere; }
.done-next { margin-top: .375rem; }
.again {
  margin-top: .5rem; min-height: 2.75rem; padding: 0; border: 0; background: none; color: var(--ink);
  font: 600 1rem/1.2 var(--slab); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .2em;
  cursor: pointer;
}
.again:hover { background: var(--hi); }

/* ---------- row 1: your room ---------- */
.east { margin-top: calc(var(--sq) * 3); }
.yours {
  min-height: calc(var(--sq) * 6);
  padding: var(--sq);
  display: flex; flex-direction: column;
  background: none; color: var(--ink-2);
}
.yours-name { align-self: flex-start; font: 700 1.5rem/1.25 var(--hand); padding: 0 .4rem; margin-left: -.4rem; }
.yours-state { margin-top: .125rem; font: 400 1.125rem/1.3 var(--hand); overflow-wrap: anywhere; }
.yours-note { margin-top: auto; align-self: flex-end; font: 700 1.125rem/1.2 var(--hand); color: var(--pen); transform: rotate(-2deg); }
.w-dash, .l-dash { stroke-dasharray: 11 9; opacity: .55; }
.w-ink, .l-ink { stroke-dasharray: 100; stroke-dashoffset: 100; }
.when-sketch, .when-joined { display: none; }

.is-sketching .w-dash, .is-sketching .l-dash { opacity: 1; }
.is-sketching .yours { color: var(--ink); }
.is-sketching .when-empty { display: none; }
.is-sketching .when-sketch { display: inline; }

.is-joined .yours { color: var(--ink); background: rgb(255 255 255 / .62); }
.is-joined .yours-name { background: rgb(255 233 74 / .92); }
.is-joined .w-ink, .is-joined .l-ink { stroke-dashoffset: 0; }
.is-joined .when-empty, .is-joined .when-sketch, .is-joined .when-open { display: none; }
.is-joined .when-joined { display: inline; }
.just-joined .l-ink { animation: draw .5s var(--out) both; }
.just-joined .w-ink { animation: draw 1.4s .3s var(--out) both; }
@keyframes draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }

.legend { display: none; }
.key { margin: 0; padding: 0; list-style: none; font: 400 1.125rem/1.3 var(--hand); color: var(--ink); }
.key li { display: flex; align-items: center; gap: .625rem; }
.key li + li { margin-top: .375rem; }
.rose { stroke: var(--graphite); stroke-width: 2.5; fill: none; overflow: visible; }
.rose text { fill: var(--graphite); stroke: none; font: 700 17px var(--hand); text-anchor: middle; }

/* ---------- row 2: what we're making ---------- */
.keyed { display: flex; align-items: center; gap: .75rem; margin-top: 1.75rem; font-weight: 800; font-size: 1.125rem; line-height: 1.3; }
.swatch { flex: none; width: 3.5rem; height: .75rem; }
.swatch.dash { stroke-dasharray: 9 8; }
.marks { list-style: none; margin: .5rem 0 0; padding: 0; max-width: 62ch; }
.marks li { position: relative; padding-left: 1.75rem; }
.marks li + li { margin-top: .375rem; }
.marks li::before {
  content: ""; position: absolute; left: 0; top: .45em; width: .8125rem; height: .8125rem;
  border: 2px solid var(--graphite); border-radius: 1px 3px 2px 2px;
}
.marks.undrawn li { color: var(--ink-2); }
.marks.undrawn li::before { border-style: dashed; }

.demo { margin-top: calc(var(--sq) * 3); }
.sentence { padding: var(--sq); }
.cmd { font-weight: 800; }
.rname { margin-top: .5rem; font-weight: 800; }
.sentence figcaption { margin-top: .875rem; text-align: right; font: 700 1.125rem/1.2 var(--hand); color: var(--pen); transform: rotate(-1.5deg); }
.drop { position: relative; height: calc(var(--sq) * 3); }
.arrow { left: calc(var(--sq) * 2); top: 0; width: calc(var(--sq) * 2); height: 100%; }
.drop-note {
  position: absolute; left: calc(var(--sq) * 4.25); top: 50%;
  font: 700 1.125rem/1.2 var(--hand); color: var(--pen);
  transform: translateY(-50%) rotate(-2deg);
}
.place {
  min-height: calc(var(--sq) * 7); padding: var(--sq);
  display: grid; place-content: center; justify-items: center; gap: .375rem; text-align: center;
  background: none; color: var(--ink-2);
}
.place-name { font: 700 1.5rem/1.2 var(--hand); color: var(--ink); }
.place p:last-of-type { max-width: 20rem; font-size: 1rem; line-height: 1.45; }

/* ---------- row 3: fair questions ---------- */
.qs { margin-top: 1.25rem; border-bottom: 2px solid var(--graphite); }
.q { border-top: 2px solid var(--graphite); }
.q summary {
  display: grid; grid-template-columns: auto 1fr auto; gap: .625rem; align-items: center;
  min-height: 3.5rem; padding: .5rem 0;
  list-style: none; cursor: pointer;
  font-weight: 700; font-size: 1.1875rem; line-height: 1.25;
}
.q summary::-webkit-details-marker { display: none; }
.q .t { justify-self: start; background: linear-gradient(var(--hi), var(--hi)) no-repeat 0 100% / 0 100%; transition: background-size .3s var(--out); }
.q summary:hover .t { background-size: 100% 100%; }
.pm { position: relative; width: 1.125rem; height: 1.125rem; }
.pm::before, .pm::after {
  content: ""; position: absolute; left: 0; right: 0; top: calc(50% - 1.5px); height: 3px;
  background: var(--ink); border-radius: 2px; transition: transform .3s var(--out);
}
.pm::after { transform: rotate(90deg); }
.q[open] .pm::after { transform: rotate(0); }
.q > p { padding: 0 1.75rem 1.125rem 1.5rem; max-width: 64ch; }

/* ---------- row 4: the edge ---------- */
.edge-note {
  position: absolute; z-index: 1; top: calc(var(--sq) * -4.7); left: calc(var(--sq) * (var(--tail) + 1.1));
  font: 700 1.125rem/1.2 var(--hand); color: var(--pen); transform: rotate(-2deg);
}

.block {
  position: relative; margin-top: calc(var(--sq) * 4); padding: var(--sq);
  background: rgb(255 255 255 / .62);
  font-size: .9375rem; line-height: 1.45;
}
.block dl { margin: 0; display: grid; gap: .75rem; }
.block dt { font: 700 1rem/1.2 var(--hand); color: var(--ink-2); }
.block dd { margin: 0; font-weight: 600; }
.block p { margin-top: 1rem; color: var(--ink-2); }
.block a { color: var(--ink); }

/* ---------- wider sheets ---------- */
@media (min-width: 30rem) {
  .status-in { grid-template-columns: 1fr auto 1fr; }
  .where { justify-self: center; }
  .moves { display: block; justify-self: end; }
  .cmdline { grid-template-columns: auto 1fr auto; }
  .btn { grid-column: auto; }
  .block dl { grid-template-columns: 1.6fr 1.2fr .6fr; gap: 0; }
  .block dl > div + div { padding-left: 1rem; border-left: 2px solid var(--graphite); }
  .block dl > div { padding-right: 1rem; }
}

@media (min-width: 40rem) {
  .room { padding: calc(var(--sq) * 2) calc(var(--sq) * 1.5) calc(var(--sq) * 1.5); }
  .yours, .sentence, .place, .block { padding: var(--sq); }
  h2 { font-size: 2.25rem; }
  .lede { font-size: 1.25rem; }
  .q summary { font-size: 1.25rem; }
}

/* the map proper: rooms side by side, halls running east */
@media (min-width: 63rem) {
  :root { --w: calc(var(--sq) * 40); --c1: 26; --c2: 29; --g1: 2; --c3: 22; --c4: 25; --g2: 2; --c5: 5; --c6: 28; --tail: 11; }

  .row + .row { margin-top: calc(var(--sq) * 4); }
  .row + .r4 { margin-top: calc(var(--sq) * 8); }
  .room { padding: calc(var(--sq) * 2); }
  .yours, .sentence, .place { padding: var(--sq); }
  .hs.to-side { display: none; }
  .hs.main { display: block; --run: 4; }
  .he { display: block; }
  .door.e { display: block; }

  .first { grid-column: 1 / span var(--c1); --door: 6; }
  .first .door.e { top: calc(var(--sq) * 6); }
  .r1 > .he { left: calc(var(--sq) * var(--c1)); top: calc(var(--sq) * 6); width: calc(var(--sq) * var(--g1)); }
  .east { grid-column: var(--c2) / -1; margin-top: calc(var(--sq) * 4); }
  .yours { min-height: calc(var(--sq) * 8); }
  .yours > .hs, .yours > .door { display: none; }
  .legend { display: flex; align-items: center; justify-content: space-between; gap: var(--sq); margin-top: calc(var(--sq) * 2); }
  .rose { flex: none; width: calc(var(--sq) * 6); height: calc(var(--sq) * 6); }
  h1 { font-size: 3rem; }

  .making { grid-column: 1 / span var(--c3); align-self: stretch; --door: 15; }
  .making .door.e { top: calc(var(--sq) * 3); }
  .r2 > .he { left: calc(var(--sq) * var(--c3)); top: calc(var(--sq) * 3); width: calc(var(--sq) * var(--g2)); }
  .demo { grid-column: var(--c4) / -1; margin-top: calc(var(--sq) * 2); }
  .place > .hs, .place > .door { display: none; }

  .questions { grid-column: var(--c5) / -1; --door: 6; }
  .edge { grid-column: 1 / span var(--c6); }
  .block { width: calc(var(--sq) * 32); margin-left: auto; }
}

@media (min-width: 75rem) {
  :root { --w: calc(var(--sq) * 48); --c1: 31; --c2: 35; --g1: 3; --c3: 26; --c4: 30; --g2: 3; --c5: 9; --c6: 30; --tail: 15; }
  h1 { font-size: 3.5rem; }
}

@media (min-width: 87rem) {
  :root { --w: calc(var(--sq) * 56); --c1: 36; --c2: 41; --g1: 4; --c3: 30; --c4: 35; --g2: 4; --c5: 13; --c6: 32; --tail: 19; }
  h1 { font-size: 4.25rem; }
  .lede { font-size: 1.3125rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
