/* fig4.css: owned by the fig4 agent. Sheet 04, "Pebbon in your pocket": a pen-drawn phone and a live chat.
   Base rules are the no-JS fallback (a plain, readable sample chat in a CSS phone); .live switches to the
   drawn version, where js/figures/chat.js places the screen parts over the ink. */

/* ---------- layout ---------- */
.pocket { display: grid; grid-template-columns: minmax(0, 4.1fr) minmax(0, 7.9fr); gap: 36px; align-items: start; }
.pocket-text { padding-top: 6px; }
.pocket-intro { margin-top: 22px; max-width: 26em; }
@media (max-width: 1079px) {
  .pocket { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .pocket-intro { max-width: 34em; }
  .fig4 { max-width: 760px; width: 100%; margin-inline: auto; }
}
@media (max-width: 819px) {
  .pocket { display: flex; flex-direction: column; gap: 0; }
  .pocket-text { display: contents; }
  .pocket h2 { order: 1; }
  .pocket-intro { order: 2; margin-top: 16px; }
  .fig4 { order: 3; max-width: 520px; }
  .pocket .ask { order: 4; }
}

/* ---------- the chips (live only) ---------- */
.pocket .ask { display: none; margin-top: 30px; }
.chat-live .pocket .ask { display: block; }
.pocket .ask-label { font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--soft); margin: 0 0 8px; }
.pocket .chips { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.pocket .chip {
  position: relative; appearance: none; -webkit-appearance: none; background: transparent; border: 0; margin: 0;
  padding: 13px 20px 14px; min-height: 50px; font: inherit; font-size: 1.04rem; line-height: 1.3; color: var(--ink);
  cursor: pointer; text-align: left; border-radius: 3px; -webkit-tap-highlight-color: transparent;
}
.pocket .chip[hidden] { display: none; }
.pocket .chip:nth-child(4n+1) { transform: rotate(-.5deg); }
.pocket .chip:nth-child(4n+2) { transform: rotate(.4deg); }
.pocket .chip:nth-child(4n+3) { transform: rotate(-.25deg); }
.pocket .chip:nth-child(4n) { transform: rotate(.6deg); }
.pocket .chip .t { position: relative; transition: color .2s, opacity .3s; }
.pocket .chip-ink { position: absolute; inset: 0; pointer-events: none; }
.pocket .chip-ink canvas { position: absolute; left: 0; top: 0; display: block; }
.pocket .chip-ink canvas.loop { left: -12px; top: -12px; }
.pocket .chip-ink canvas.check { left: auto; right: -16px; top: -12px; }
.pocket .chip-ink canvas.shade { opacity: 0; transition: opacity .25s; }
.pocket .chip:hover .chip-ink canvas.shade, .pocket .chip:focus-visible .chip-ink canvas.shade { opacity: 1; }
.pocket .chip:hover .t { color: var(--red); }
.pocket .chip:focus-visible { outline: 2px dashed var(--red); outline-offset: 5px; }
.pocket .chip.asked .t { color: var(--soft); }
.pocket .chip.extra .t { font-family: var(--mono); font-size: .86rem; letter-spacing: .16em; }
.pocket .chip.confirm .t { color: var(--red); }
.pocket .chip.hello .t { font-family: var(--serif); font-size: 1.04rem; letter-spacing: 0; }
.chat-busy .pocket .chip { cursor: progress; }
.chat-busy .pocket .chip:not(.pressed) .t { opacity: .5; }
.chat-busy .pocket .chip:hover .t { color: inherit; }
.chat-busy .pocket .chip:hover .chip-ink canvas.shade { opacity: 0; }
.pocket .replay {
  appearance: none; -webkit-appearance: none; background: transparent; border: 0; margin: 16px 0 0 4px; padding: 6px 10px 6px 2px;
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--red); cursor: pointer; border-radius: 3px;
}
.pocket .replay canvas { display: block; width: 28px; height: 28px; transition: transform .5s cubic-bezier(.3, 1.6, .5, 1); }
.pocket .replay:hover canvas { transform: rotate(-200deg); }
.pocket .replay:hover { color: var(--ink); }
@media (max-width: 1079px) {
  .pocket .chips { flex-direction: row; flex-wrap: wrap; gap: 4px 10px; }
}
@media (max-width: 819px) {
  .pocket .ask { margin-top: 18px; }
  .pocket .chip { font-size: 1rem; padding: 12px 17px 13px; }
}

/* ---------- the phone: no-JS fallback ---------- */
.fig4 .stage { position: relative; }
.fig4 .device { max-width: 340px; margin: 6px auto 0; border: 2px solid var(--ink); border-radius: 40px; padding: 14px 11px; background: rgba(var(--paper-hi-rgb), .6); }
.fig4 .screen { border: 1px solid rgba(var(--ink-rgb), .4); border-radius: 28px; overflow: hidden; display: flex; flex-direction: column; font-size: 15px; }
.fig4 .wa-head { display: flex; flex-direction: column; justify-content: center; padding: 12px 16px 8px; border-bottom: 1px solid rgba(var(--ink-rgb), .35); line-height: 1.15; }
.fig4 .wa-head b { font-weight: 500; color: var(--ink); font-size: 1.04em; }
.fig4 .wa-head .st { font-family: var(--mono); font-size: .62em; letter-spacing: .08em; color: var(--soft); }
.fig4 .log { display: flex; flex-direction: column; gap: .5em; padding: .8em .75em; }
.fig4 .composer { margin: 0 12px 12px; padding: .5em 1em; border: 1px solid rgba(var(--ink-rgb), .5); border-radius: 2em; color: var(--soft); font-size: .92em; }
.fig4 .send { display: none; }
.fig4 .msg { position: relative; max-width: 86%; padding: .44em .64em .3em; border-radius: .62em; background: rgb(var(--bubble-in-rgb)); line-height: 1.32; color: var(--text); border: 1.3px solid var(--ink); align-self: flex-start; }
.fig4 .msg.out { align-self: flex-end; background: rgb(var(--bubble-out-rgb)); }
.fig4 .msg p, .fig4 .msg ul, .fig4 .msg blockquote { margin: 0; }
.fig4 .msg .lead { color: var(--ink); font-weight: 500; }
.fig4 .msg .body { color: var(--ink); }
.fig4 .msg .why { list-style: none; padding: 0; margin: .3em 0 .1em; font-size: .9em; line-height: 1.32; }
.fig4 .msg .why li { position: relative; padding-left: .95em; margin-bottom: .2em; }
.fig4 .msg .why li::before { content: ""; position: absolute; left: .1em; top: .66em; width: .5em; height: 1.3px; background: var(--ink); transform: rotate(-4deg); }
.fig4 .msg .tail { margin-top: .3em; font-size: .92em; font-style: italic; color: var(--soft); }
.fig4 .msg .quote { margin: .4em 0 .2em; padding: .1em 0 .1em .65em; border-left: 1.5px solid var(--ink); font-style: italic; font-size: .92em; line-height: 1.32; }
.fig4 .msg .foot { margin-top: .4em; font-family: var(--mono); font-size: .56em; letter-spacing: .1em; text-transform: uppercase; color: var(--soft); line-height: 1.3; }
.fig4 .msg .mtag { display: block; font-family: var(--mono); font-size: .58em; letter-spacing: .14em; text-transform: uppercase; color: var(--red); margin-bottom: .2em; }
.fig4 .msg .meta { display: flex; justify-content: flex-end; align-items: center; gap: .3em; margin: .12em -.1em 0 1em; font-family: var(--mono); font-size: .58em; letter-spacing: .04em; color: var(--soft); line-height: 1.2; }
.fig4 .msg .ticks { display: inline-block; width: 15px; height: 11px; }
.fig4 .msg .ticks canvas, .fig4 .msg .ink canvas { display: block; }
.fig4 .msg .ink { display: none; }
.fig4 .day { align-self: center; margin: .5em 0 .1em; font-family: var(--mono); font-size: .6em; letter-spacing: .14em; text-transform: uppercase; color: var(--soft); }
.fig4 .day span { display: inline-block; padding: .3em .8em; border: 1px solid rgba(var(--ink-rgb), .4); border-radius: 1em; background: rgba(var(--paper-hi-rgb), .9); }
.fig4 .sr, .fig4.live .fig4-notes { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.fig4-notes { list-style: none; margin: 18px auto 0; padding: 0; max-width: 520px; font-size: 1rem; line-height: 1.4; }
.fig4-notes li { position: relative; padding: 0 0 8px 26px; }
.fig4-notes li::before { content: ""; position: absolute; left: 2px; top: .72em; width: 14px; height: 1.5px; background: var(--pencil); transform: rotate(-3deg); }
.fig4-notes b { font-weight: 500; color: var(--ink); }
.fig4 figcaption { margin-inline: auto; text-align: center; }
.fig4.live figcaption { margin-top: 4px; }

/* ---------- the phone: drawn (live) ---------- */
.fig4.live .stage { overflow: hidden; container-type: inline-size; }
.fig4.live .device {
  position: absolute; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: none;
  container-type: inline-size; transform-origin: 40% 55%;
}
.fig4.live .dev-ink, .fig4.live .notes-ink { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.fig4.live .live-ink { position: absolute; left: 0; top: 0; display: block; pointer-events: none; z-index: 3; }
.fig4.live .notes-ink { z-index: 2; }
.fig4.live .device { z-index: 1; }
.fig4.live .screen {
  position: absolute; z-index: 1; display: block; border: 0; border-radius: 0; overflow: visible;
  font-size: calc(14.5 / 420 * 100cqw); opacity: 0; transition: opacity .6s ease;
}
.fig4.live .screen.on { opacity: 1; }
.fig4.live .wa-head { position: absolute; padding: 0; border: 0; }
.fig4.live .wa-head b { font-size: 1.06em; }
.fig4.live .log {
  position: absolute; padding: .75em .8em .6em 1.05em; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none; background: rgba(var(--paper-hi-rgb), .42); scroll-padding-bottom: .6em;
}
.fig4.live .log::-webkit-scrollbar { display: none; }
.fig4.live .log:focus-visible { outline: 2px dashed var(--red); outline-offset: -4px; }
.fig4.live .composer {
  position: absolute; margin: 0; padding: 0; border: 0; border-radius: 0; display: flex; align-items: center;
  font-size: .94em; white-space: nowrap; overflow: hidden; color: var(--soft);
}
.fig4.live .composer .typed { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.fig4.live .composer.typing .ph { display: none; }
.fig4.live .composer.typing::after { content: ""; flex: none; width: 1.5px; height: 1.05em; margin-left: 1px; background: var(--ink); animation: fig4-caret .9s steps(1) infinite; }
@keyframes fig4-caret { 50% { opacity: 0; } }
.fig4.live .send { display: block; position: absolute; border-radius: 50%; pointer-events: none; }
.fig4.live .send.press::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--ink); animation: fig4-ring .55s ease-out forwards; }
@keyframes fig4-ring { from { transform: scale(1); opacity: .8; } to { transform: scale(1.9); opacity: 0; } }

.fig4.live .msg { border: 0; background: rgba(var(--bubble-in-rgb), .96); max-width: 84%; }
.fig4.live .msg.out { background: rgba(var(--bubble-out-rgb), .97); }
.fig4.live .msg .ink { display: block; position: absolute; left: -10px; top: -10px; pointer-events: none; }
.fig4.live .msg.pop { animation: fig4-pop .62s linear both; transform-origin: 0 0; }
.fig4.live .msg.out.pop { transform-origin: 100% 0; }
/* a little spring: overshoot, settle */
@keyframes fig4-pop {
  0% { transform: scale(.55) translateY(6px); opacity: 0; }
  18% { opacity: 1; }
  34% { transform: scale(1.045) translateY(-1px); }
  56% { transform: scale(.985); }
  76% { transform: scale(1.006); }
  100% { transform: scale(1); }
}
.fig4.live .msg.in .why li { animation: fig4-line .5s ease-out both; }
.fig4.live .msg.in .why li:nth-child(1) { animation-delay: .25s; }
.fig4.live .msg.in .why li:nth-child(2) { animation-delay: .37s; }
.fig4.live .msg.in .why li:nth-child(3) { animation-delay: .49s; }
.fig4.live .msg.in .why li:nth-child(4) { animation-delay: .61s; }
.fig4.live .msg.in .tail, .fig4.live .msg.in .quote, .fig4.live .msg.in .foot { animation: fig4-line .5s ease-out .5s both; }
@keyframes fig4-line { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
.fig4.live .msg.typing { padding: .62em .8em .5em; }
.fig4 .dots { display: flex; gap: .32em; align-items: center; height: .7em; }
.fig4 .dots i {
  display: block; width: .44em; height: .4em; background: var(--ink); border-radius: 52% 48% 55% 45% / 50% 58% 42% 50%;
  animation: fig4-dot 1.1s ease-in-out infinite;
}
.fig4 .dots i:nth-child(2) { animation-delay: .16s; border-radius: 45% 55% 48% 52% / 58% 46% 54% 42%; }
.fig4 .dots i:nth-child(3) { animation-delay: .32s; border-radius: 55% 45% 52% 48% / 44% 52% 48% 56%; }
@keyframes fig4-dot { 0%, 60%, 100% { transform: translateY(0) scale(1); opacity: .45; } 30% { transform: translateY(-.28em) scale(1.08); opacity: 1; } }
.fig4.live .msg.wipe, .fig4.live .day.wipe { animation: fig4-wipe .6s ease-in both; }
@keyframes fig4-wipe {
  0% { opacity: 1; filter: none; transform: none; }
  40% { opacity: .35; filter: blur(.6px); transform: translate(1px, 1px) rotate(-.4deg); }
  100% { opacity: 0; filter: blur(2px); transform: translate(3px, 2px) rotate(-.8deg); }
}

@media (prefers-reduced-motion: reduce) {
  .fig4.live .msg.pop, .fig4.live .msg.in .why li, .fig4.live .msg.in .tail, .fig4.live .msg.in .quote, .fig4.live .msg.in .foot,
  .fig4.live .msg.wipe, .fig4 .dots i, .fig4.live .send.press::after { animation: none; }
  .fig4.live .screen { transition: none; }
  .pocket .replay canvas { transition: none; }
}
