@font-face {
  font-family: "Patrick Hand";
  src: url("fonts/patrick-hand-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  color: #1c1b19;
  background: #d8d5ce;
  font-family: "Segoe UI", Candara, Optima, Arial, sans-serif;
  font-synthesis: none;
  --ink: #1c1b19;
  --paper: #f3eee2;
  --red: #c23b2a;
  --glow: #f0a531;
  --narrow: "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  --hand: "Patrick Hand", cursive;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-width: 320px;
  background-color: #d8d5ce;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='92' height='92' viewBox='0 0 92 92'%3E%3Cg fill='%237a7771' fill-opacity='.16'%3E%3Ccircle cx='8' cy='13' r='.7'/%3E%3Ccircle cx='38' cy='7' r='.5'/%3E%3Ccircle cx='73' cy='21' r='.8'/%3E%3Ccircle cx='18' cy='47' r='.5'/%3E%3Ccircle cx='59' cy='55' r='.7'/%3E%3Ccircle cx='85' cy='76' r='.5'/%3E%3Ccircle cx='33' cy='83' r='.8'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; user-select: none; -webkit-user-select: none; }
svg, [data-socket], [data-placed] { user-select: none; -webkit-user-select: none; }
button:focus-visible, a:focus-visible, [role="button"]:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
[hidden] { display: none !important; }

#app { position: relative; width: 100%; max-width: 680px; min-height: 100vh; min-height: 100svh; margin: 0 auto; padding: 0 12px 28px; display: flex; flex-direction: column; }
#app > .stage { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: flex-end; }

/* top bar: back on the left, Levels / language / How to play on the right, nothing else */
.topbar {
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(28, 27, 25, .45);
}
.pl-right { display: flex; gap: 8px; align-items: center; }
.chair-brand, .top-action {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1px solid var(--ink);
  background: rgba(244, 241, 233, .38);
  color: var(--ink);
  font-family: var(--narrow);
  font-size: 14px;
  line-height: 1.05;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.chair-brand { border: 0; background: transparent; padding: 0; justify-content: flex-start; gap: 6px; text-align: left; font-family: var(--hand); font-size: 15px; font-weight: 700; line-height: .85; cursor: pointer; }
.brand-mark { display: inline-grid; place-items: center; width: 31px; height: 31px; border: 2px solid var(--ink); background: var(--red); color: #fff8ec; font-family: var(--narrow); transform: rotate(-5deg); }
.top-action[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.howto-button .short { display: none; }
.howto-button .long { max-width: 52px; white-space: normal; }

.level-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding-top: 8px; }
.goal-line { margin-top: 7px; font-family: var(--hand); font-size: 17px; font-weight: 700; color: #42362d; }
.level-name { margin: 0; font-family: var(--narrow); font-size: 18px; font-weight: 600; letter-spacing: .02em; line-height: 1.15; }
.tries { display: flex; align-items: center; gap: 6px; font-family: var(--narrow); font-size: 14px; white-space: nowrap; }
.tries .marks { display: inline-flex; gap: 3px; }
.tries .marks i { width: 10px; height: 16px; border: 2px solid var(--ink); background: var(--ink); transform: skewX(-12deg); }
.tries .marks i.used { background: transparent; border-color: var(--red); }

.prompt { min-height: 30px; margin: 6px 0 6px; font-size: 17px; line-height: 1.25; }
.prompt.fail { color: var(--red); font-weight: 650; }

.stage {
  position: relative;
  border-top: 1px solid rgba(28, 27, 25, .28);
  border-bottom: 1px solid rgba(28, 27, 25, .4);
  background-color: rgba(243, 240, 232, .2);
  /* a faint brick wall behind the chair, so a tall screen shows more street, not blank page */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='36' viewBox='0 0 64 36'%3E%3Cpath d='M0 .5H64M0 18.5H64M16 1V18M48 19V36' stroke='%237a7771' stroke-opacity='.07' fill='none'/%3E%3C/svg%3E");
  background-position: center bottom;
}
.chair-scene { display: block; width: 100%; height: auto; max-height: 360px; overflow: visible; }
.chair-scene .piece-fill, .chair-scene .chair-body, .chair-scene .chair-back { filter: url(#torn); }
.tape-strip { fill: #d4bd78; opacity: .76; stroke: #8d7744; stroke-width: .5; filter: url(#torn); }
.floor-line { stroke: #45423d; stroke-width: 3; }
.puddle { fill: #b9c0be; opacity: .55; }
.wall-mark { stroke: #77736d; stroke-width: 1; opacity: .24; }
.pipe { stroke: #77736d; stroke-width: 9; opacity: .55; }
.pipe-bracket { fill: #5f5c56; }
.chair-ink { fill: none; stroke: var(--ink); stroke-width: 7; stroke-linecap: square; }
.chair-seat { fill: #373531; stroke: var(--ink); stroke-width: 2; }
.chair-back { fill: #373531; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.chair-slat { stroke: #8d877c; stroke-width: 2; }
.break-edge { fill: none; stroke: var(--red); stroke-width: 3; stroke-linejoin: miter; }
.piece-fill { stroke: var(--ink); stroke-width: 1.5; }
.piece-line { stroke-width: 1.2; }
.person-label { font-family: var(--narrow); font-size: 12px; letter-spacing: .08em; fill: var(--ink); }
.badge-text { font-family: var(--narrow); font-size: 10px; font-weight: 700; fill: #fff8ec; }
.person-body, .person-head { fill: #2c2b29; }

/* glowing sockets */
.socket { cursor: pointer; }
.socket .hit { fill: transparent; pointer-events: all; }
.socket .hit-line { fill: none; stroke: transparent; stroke-width: 30; pointer-events: stroke; }
.socket .glow { fill: rgba(240, 165, 49, .32); stroke: var(--glow); stroke-width: 2.5; stroke-dasharray: 5 3; pointer-events: none; animation: glow-pulse 1.4s ease-in-out infinite; }
.socket .glow-line { fill: none; stroke: var(--glow); stroke-width: 3; stroke-dasharray: 5 4; pointer-events: none; }
.socket.full .glow, .socket.full .glow-line { opacity: 0; animation: none; }
.socket.full { cursor: default; }
.gap-label { font-family: var(--hand); font-size: 10px; font-weight: 700; fill: #6e4508; pointer-events: none; }
.gap-tick { stroke: var(--glow); stroke-width: 1.5; stroke-dasharray: 3 3; pointer-events: none; }
.socket.full .gap-tick { opacity: 0; }
.load-number { font-family: var(--narrow); font-size: 15px; font-weight: 700; }
.socket.nofit .glow { fill: rgba(194, 59, 42, .3); stroke: var(--red); stroke-dasharray: none; animation: nofit-shake .35s ease-in-out 2; transform-box: fill-box; }
.piece-card.bounce { animation: bounce-back .45s ease-out; }
.choosing .socket.fits .glow, .socket.over .glow { fill: rgba(240, 165, 49, .62); stroke-width: 3.5; stroke-dasharray: none; }
.choosing .socket:not(.fits):not(.full) .glow { opacity: .45; animation: none; }
.load-arrow { pointer-events: none; }
.placed-piece { cursor: pointer; }
.placed-piece .hit { fill: transparent; }
.placed-piece .hit-line { stroke: transparent; stroke-width: 26; fill: none; }
.placed-piece.carrying .piece-fill { filter: brightness(.82); }
.placed-piece.snapped .piece-fill { animation: snap-flash .5s ease-out both; }
.testing .placed-piece { cursor: default; }
.placed-piece.crush { transform-box: fill-box; transform-origin: 50% 100%; animation: squash .45s .3s ease-in both; }
.placed-piece.crush .piece-fill { fill: var(--red); }
.placed-piece.slacked .tie-line { stroke: var(--red); }
.chair-body.sinking { transform-box: view-box; transform-origin: 206px 242px; animation: chair-sink .5s .3s ease-in both; }
.chair-body.dropping { transform-box: view-box; transform-origin: 206px 242px; animation: seat-drop .45s .3s ease-in both; }
.person.lowered { animation: lower .4s .2s ease-in both; }
.person.seated { animation: sit-down .4s ease-out both; }

/* pile */
.piece-shelf { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; overflow: visible; padding: 10px 1px 8px; border-bottom: 1px solid rgba(28, 27, 25, .32); }
.piece-card {
  position: relative;
  flex: 1 1 62px;
  min-width: 60px;
  max-width: none;
  min-height: 132px;
  padding: 3px 2px 4px;
  border: 1px solid var(--ink);
  background: #f2eddf;
  cursor: grab;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.piece-card svg { width: 100%; max-width: 70px; height: 56px; display: block; }
.piece-card:nth-child(odd) { transform: rotate(-1.2deg); }
.piece-card:nth-child(even) { transform: rotate(.8deg); }
.piece-card.selected { outline: 3px solid var(--glow); outline-offset: -4px; background: rgba(240, 165, 49, .18); }
.piece-card.lifted { opacity: .35; }
.piece-card.squashed { cursor: not-allowed; border-style: dashed; border-color: var(--red); background: rgba(194, 59, 42, .08); }
.piece-card.squashed .piece-fill { fill: var(--red); }
.piece-card.squashed .dots { opacity: .35; }
.piece-holds { font-family: var(--narrow); font-size: 14px; font-weight: 700; line-height: 1; white-space: nowrap; }
.piece-holds.gone { color: var(--red); font-size: 13px; }
.piece-card.squashed { opacity: .75; }
.piece-card.squashed .piece-name { text-decoration: line-through; }
.piece-tall { font-family: var(--narrow); font-size: 12px; line-height: 1; color: #6e4508; }
.piece-name { font-family: var(--narrow); font-size: 13px; white-space: nowrap; max-width: 74px; overflow: hidden; text-overflow: ellipsis; }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 56px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.drag-ghost { position: fixed; left: 0; top: 0; width: 60px; height: 48px; pointer-events: none; z-index: 40; opacity: .9; }
.drag-ghost svg { width: 60px; height: 48px; }

.controls { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding-top: 10px; }
.controls.gave-up { grid-template-columns: 1fr; }
.gave-up-line { margin: 0; font-size: 15px; }
.sit-button {
  min-height: 52px;
  padding: 10px 15px;
  border: 2px solid var(--ink);
  background: rgba(244, 241, 233, .38);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--narrow);
  font-size: 18px;
  letter-spacing: .035em;
}
.sit-button.ready { background: var(--red); color: #fff8ec; box-shadow: 3px 3px 0 var(--ink); }
.sit-button.quiet { border-color: #a8a49c; color: #6c6861; background: #c9c5bd; cursor: default; }
.sit-button.ready:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.tool-button { min-height: 44px; padding: 0 10px; border: 1px solid var(--ink); background: rgba(244, 241, 233, .38); font-family: var(--narrow); font-size: 15px; cursor: pointer; }

/* levels */
.levels-screen { padding-top: 12px; }
.levels-screen .level-name { font-size: 26px; margin-bottom: 10px; }
.map-arc { margin: 0 0 14px; }
.map-arc h2 { margin: 0 0 6px; font-family: var(--narrow); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.map-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.map-level { min-height: 56px; padding: 6px 4px; border: 1px solid var(--ink); background: rgba(244, 241, 233, .38); font-family: var(--narrow); cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.map-number { font-size: 15px; }
.map-title { font-size: 12px; color: #4b4842; }
.map-level.current { background: var(--ink); color: var(--paper); }
.map-level.current .map-title { color: #d9d3c4; }
.map-level.done .map-number::after { content: " ●"; color: var(--red); }

/* result */
.result { padding-top: 6px; }
.polaroid { position: relative; max-width: 390px; margin: 10px auto 16px; padding: 12px 12px 32px; background: #f7f3e8; box-shadow: 3px 4px 0 rgba(28,27,25,.46); transform: rotate(-.7deg); }
.polaroid-tape { position: absolute; width: 92px; height: 22px; top: -9px; left: calc(50% - 46px); background: rgba(215,193,120,.72); transform: rotate(2deg); }
.polaroid p { margin: 9px 0 0; font-family: var(--hand); font-size: 16px; text-align: center; }
.result-picture-wrap { border-bottom: 2px solid var(--ink); background: #d8d5ce; }
.result h1 { margin: 12px 0 0; font-family: var(--narrow); font-size: clamp(36px, 11vw, 60px); line-height: .9; letter-spacing: -.03em; text-transform: uppercase; }
.result-subhead { margin: 8px 0 2px; font-size: 18px; }
.result-level { margin: 0 0 14px; font-family: var(--narrow); font-size: 15px; color: #4b4842; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.result-button { min-height: 48px; padding: 8px 4px; border: 1px solid var(--ink); background: rgba(244, 241, 233, .38); font-family: var(--narrow); font-size: 15px; cursor: pointer; }
.result-button.main { background: var(--red); color: #fff8ec; border: 2px solid var(--ink); }
.share-line { min-height: 20px; margin: 10px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.collection-wall { margin-top: 20px; padding: 12px; background: rgba(243,238,226,.6); border: 1px dashed rgba(28,27,25,.65); }
.collection-wall h2 { margin: 0 0 8px; font-family: var(--hand); font-size: 18px; }
.collection-wall > div { display: flex; gap: 8px; flex-wrap: wrap; }
.collection-card { display: inline-grid; place-items: center; width: 66px; height: 52px; padding-top: 12px; background: #f7f3e8; box-shadow: 1px 2px 0 rgba(28,27,25,.48); font-family: var(--hand); font-size: 12px; transform: rotate(-2deg); }

.why { margin-top: 18px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.why summary { list-style: none; display: block; min-height: 44px; padding: 12px 0; font-family: var(--narrow); font-size: 17px; cursor: pointer; }
.why summary::-webkit-details-marker { display: none; }
.why summary::after { content: "+"; float: right; font-size: 23px; line-height: .6; }
.why[open] summary::after { content: "−"; }
.why p { max-width: 58ch; margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.why .credit { font-style: italic; }

/* how to play card */
#overlay { position: fixed; inset: 0; z-index: 50; }
.howto-backdrop { position: absolute; inset: 0; background: rgba(28, 27, 25, .9); display: flex; align-items: safe center; justify-content: center; overflow-y: auto; padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 16px; touch-action: none; }
.howto-card { width: 100%; max-width: 460px; background: #ece8de; border: 2px solid var(--ink); box-shadow: 5px 5px 0 var(--ink); padding: 12px 14px 14px; }
.howto-card h2 { margin: 0 0 8px; font-family: var(--narrow); font-size: 22px; letter-spacing: .02em; }
.howto-pictures { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.howto-picture { margin: 0; border: 1px solid rgba(28, 27, 25, .5); background: #dcd8cf; }
.howto-picture svg, .howto-picture img { width: 100%; height: auto; display: block; }
.card-arrow { fill: none; stroke: var(--glow); stroke-width: 4; stroke-dasharray: 7 5; }
.howto-lines { margin: 12px 0 14px; padding-left: 0; list-style: none; font-size: 17px; line-height: 1.3; }
.howto-lines li { margin: 0 0 6px; }
.howto-footer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.howto-footer .sit-button { flex: 1 1 140px; }
.howto-footer .sit-button:focus-visible { outline: 2px solid #fff8ec; outline-offset: -7px; }

/* hand demo */
.hand { position: absolute; left: 0; top: 0; z-index: 30; pointer-events: none; animation: hand-drag 2.4s ease-in-out infinite; filter: drop-shadow(2px 3px 0 rgba(28, 27, 25, .35)); }

@keyframes glow-pulse { 50% { opacity: .5; } }
@keyframes nofit-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes bounce-back { 0% { transform: translateY(-14px); } 60% { transform: translateY(3px); } 100% { transform: none; } }
@keyframes snap-flash { 0% { stroke: var(--glow); stroke-width: 5; } 100% { stroke: var(--ink); stroke-width: 1.5; } }
@keyframes squash { to { transform: scale(1.25, .35); } }
@keyframes chair-sink { 60% { transform: rotate(-17deg); } 80% { transform: rotate(-14deg); } to { transform: rotate(-16deg); } }
@keyframes seat-drop { to { transform: rotate(-6deg); } }
@keyframes lower { to { transform: translateY(6px); } }
@keyframes sit-down { from { opacity: .4; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes hand-drag {
  0% { transform: translate(var(--x0), var(--y0)); opacity: 0; }
  10% { transform: translate(var(--x0), var(--y0)); opacity: 1; }
  22% { transform: translate(var(--x0), var(--y0)) scale(.9); }
  72% { transform: translate(var(--x1), var(--y1)) scale(.9); opacity: 1; }
  86% { transform: translate(var(--x1), var(--y1)); opacity: 1; }
  100% { transform: translate(var(--x1), var(--y1)); opacity: 0; }
}

/* motion off: every frame that carries information stays, as a still */
body.still *, body.still *::before, body.still *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
body.still .socket .glow { animation: none; }
body.still .hand { animation: none; transform: translate(var(--x0), var(--y0)); }

@media (max-width: 380px) {
  #app { padding-left: 8px; padding-right: 8px; }
  .level-name { font-size: 16px; }
}
@media (max-width: 359px) {
  .top-action { font-size: 13px; padding: 0 2px; }
  .topbar { margin-right: -5px; }
  .chair-brand { font-size: 12px; gap: 3px; }
  .brand-mark { width: 27px; height: 27px; }
  .howto-button .long { display: none; }
  .howto-button .short { display: inline; font-size: 20px; font-weight: 700; }
  .piece-shelf { gap: 4px; }
  .piece-card { min-width: 0; }
  .piece-holds { font-size: 12px; letter-spacing: -.02em; }
  .piece-card { padding-left: 0; padding-right: 0; }
}

/* street levels (10-12): the free grid */
.grid-slot { fill: transparent; stroke: transparent; cursor: pointer; }
.grid-slot.active { fill: rgba(240, 165, 49, .28); stroke: var(--glow); stroke-width: 2; }
.grid-slot.guide { fill: rgba(240, 165, 49, .34); stroke: var(--glow); stroke-width: 3; animation: glow-pulse 1.4s ease-in-out infinite; }
.placed-piece.failed .piece-fill { fill: var(--red); }
.result-picture .person.seated, .card-scene .person.seated { animation: none; }
