@font-face {
  font-family: 'Xiaolai';
  src: url('Xiaolai-sub.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'JessieCN';
  src: url('jessie-cn.woff') format('woff');
  font-display: swap;
}
@font-face {
  font-family: 'JessieHand';
  src: url('jessie-hand.woff') format('woff');
  font-display: swap;
}

:root {
  --ink: #111;
  --pink: #F28BC1;
  --pink-dark: #C85C95;
  --sky-bottom: #F9CFE0;
  --cn: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --hand: 'JessieHand';
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
html { height: 100%; background: var(--sky-bottom); overflow: hidden; }
body {
  position: relative;
  height: 100vh;
  height: 100dvh;      /* the visible height on phones, without the browser's toolbar */
  overflow: hidden;
  font-family: var(--hand), 'Xiaolai', var(--cn);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  max-width: 560px;
  margin: 0 auto;
}

/* the picture: drawn small, blown up with hard pixels */
#scene {
  position: absolute;
  left: 0; top: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* === bottom panel: sits on top of the sky, no box === */
.panel {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  padding: 6px 6px calc(34px + env(safe-area-inset-bottom, 0px));
}
.panel-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

/* pink 3D triangles, like the reference's ◀ ▶ */
.arrow {
  width: 46px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.arrow i { display: none; }
.arrow canvas { width: 38px; height: 38px; display: block; }
.arrow i::before, .arrow i::after {
  content: ''; position: absolute; width: 0; height: 0;
  border-top: 14px solid transparent; border-bottom: 14px solid transparent;
}
.arrow.prev i::before { border-right: 22px solid #FBF8F1; left: -11px; top: -14px; }
.arrow.prev i::after  { border-right: 22px solid rgba(90,60,70,0.18); left: -11px; top: -10px; z-index: -1; }
.arrow.next i::before { border-left: 22px solid #FBF8F1; left: -11px; top: -14px; }
.arrow.next i::after  { border-left: 22px solid rgba(90,60,70,0.18); left: -11px; top: -10px; z-index: -1; }
.arrow:active canvas { transform: translateY(2px); }
.arrow:disabled { visibility: hidden; cursor: default; }

/* === the pen: a plain white block that writes onto the paper === */
.pen {
  display: none;
  align-items: center;
  width: 84%;
  max-width: 320px;            /* about as wide as the row of stamps under it */
  margin: 0 auto 10px;
  border-bottom: 2px solid #FBF8F1;
  padding: 2px 4px 4px;
  filter: url(#wobble);
}
.pen.on { display: flex; }
.pen b {
  font-family: var(--hand), 'Xiaolai', var(--cn);
  font-weight: 400;
  font-size: 18px;
  color: var(--pink-dark);
  width: 26px;
  flex-shrink: 0;
}
.pen input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--hand), "Xiaolai", var(--cn);
  font-size: 22px;
  color: var(--ink);
  padding: 0 26px 0 0;   /* balance the label on the left so the words sit in the middle */
  text-align: center;
}
.pen input::placeholder { color: rgba(120,100,110,0.4); }

/* === stamps: one long white strip; the one in your hand is bigger and floats === */
.stamps {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 94%;
  max-width: 420px;
  margin: 0 auto 10px;
  padding: 0 8px;
  background: #fff;
  border-radius: 4px;
}
.stamp {
  flex: 1;
  height: 30px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stamps-label {
  font-family: var(--hand), 'Xiaolai', var(--cn);
  font-size: 13px;
  color: var(--pink-dark);
  padding: 0 6px 0 2px;
  margin-right: 2px;
  border-right: 1.5px dotted rgba(200,92,149,0.4);
  white-space: nowrap;
}
.stamp canvas { width: 24px; height: 24px; display: block; transition: transform 0.2s; }
.stamp.on canvas { animation: bob 1.1s ease-in-out infinite; }
@keyframes bob {
  0%, 100% { transform: scale(1.5) translateY(-2px) rotate(-6deg); }
  50% { transform: scale(1.5) translateY(-6px) rotate(6deg); }
}
.stamp:active canvas { transform: scale(0.85); }

/* === buttons: plain white blocks, no outline === */
.chips { display: flex; flex-wrap: wrap; justify-content: center; }
.chip {
  position: relative;
  min-width: 40px;
  height: 34px;
  margin: 5px;
  padding: 0 13px;
  background: transparent;
  border: none;
  font-family: var(--hand), 'Xiaolai', var(--cn);
  font-size: 14px;
  color: transparent;          /* the word is drawn in chalk on the canvas; this keeps the button's size */
  cursor: pointer;
}
.chip-bg { position: absolute; left: -7px; top: -7px; pointer-events: none; }
.chip-txt { position: relative; white-space: nowrap; }
.nav { display: flex; align-items: center; justify-content: center; width: 100%; }
.nav .chips { flex: 0 1 auto; }
.chip.cn { font-family: var(--hand), "Xiaolai", var(--cn); font-size: 14px; }
.chip:active { transform: scale(0.95); }
.big {
  height: 40px;
  padding: 0 20px;
  font-size: 16px;
}
@keyframes wiggle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

/* === the fortune card === */
.card {
  position: absolute;
  left: 50%; top: 56%;
  width: 72%;
  max-width: 340px;
  transform: translate(-50%, -50%) rotate(-2deg);
  background: #FBF6EE;
  border: 2px solid var(--ink);
  box-shadow: none;
  filter: url(#wobble);
  padding: 16px 14px 10px;
  text-align: center;
  cursor: pointer;
  z-index: 5;
  animation: cardIn 0.4s cubic-bezier(.3, 1.5, .5, 1) both;
}
@keyframes cardIn { from { transform: translate(-50%, -50%) scale(0.2) rotate(10deg); } to { transform: translate(-50%, -50%) scale(1) rotate(-2deg); } }
.card-no {
  display: inline-block;
  font-family: var(--hand), "Xiaolai", var(--cn);
  font-size: 15px;
  color: var(--pink-dark);
  margin-bottom: 8px;
}
.card-text { font-family: var(--hand), "Xiaolai", var(--cn); font-size: 30px; line-height: 1.4; word-break: break-all; }
.card-tap { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 11px; color: #999; margin-top: 10px; letter-spacing: 1px; }

/* the answer, written under the paper above the buttons */
.answer { text-align: center; margin-bottom: 10px; }
.answer .who { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 14px; color: var(--pink-dark); letter-spacing: 1px; }
.answer .what { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 26px; color: var(--ink); margin-top: 2px; }

/* === toast === */
.toast {
  position: absolute;
  left: 50%; top: 14%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-family: var(--cn);
  font-size: 12px;
  padding: 6px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 9;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* === the table button, top corner === */
.bgbtn {
  display: none !important;   /* the table is picked on the cover now */
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px 4px 4px;
  background: #fff;
  border: none;
  border-radius: 4px;
  font-family: var(--hand), 'Xiaolai', var(--cn);
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}
.bgbtn canvas { width: 22px; height: 22px; border-radius: 3px; display: block; }
.bgbtn:active { transform: scale(0.95); }

/* on the dark chalk desk the words under the paper turn to chalk white */
body.dark .pen { border-bottom-color: #F4F0E6; }
body.dark .pen input { color: #F4F0E6; }
body.dark .pen input::placeholder { color: rgba(244,240,230,0.45); }
body.dark .answer .what { color: #F4F0E6; }
body.dark .answer .who { color: #F7B5D6; }

/* === the stamps on the desk, round the paper === */
.tray { position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 4; }
.stamprow { display: flex; justify-content: center; align-items: center; margin: 0 auto 6px; }
.stampcase {
  display: flex; padding: 0; background: none; box-shadow: none;   /* the stamps sit straight on the desk */
}
.tstamp.eraser { margin-left: 6px; }
.tstamp {
  position: relative;
  width: 46px; height: 50px; margin: 0 -1px;
  padding: 0; border: none; background: transparent;
  cursor: pointer; pointer-events: auto;
  transform: rotate(var(--r));
  transition: transform 0.2s;
}
.tstamp canvas { display: block; }
.tstamp.on { transform: rotate(var(--r)) translateY(-6px) scale(1.18); filter: drop-shadow(0 6px 4px rgba(70,30,60,0.22)); }
.tstamp:active { transform: rotate(var(--r)) scale(0.92); }

/* === the little camera window while playing with your hand === */
.handcam {
  position: absolute; left: 12px; top: calc(12px + env(safe-area-inset-top, 0px));
  width: 96px; height: 72px; object-fit: cover;
  border-radius: 10px; border: 2px solid #FBF8F1;
  z-index: 6; opacity: 0.92;   /* the picture is already drawn mirrored */
}

.handvid { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.tstamp canvas { width: 44px !important; height: 44px !important; margin-left: -2px; }

.tables { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; }
.tables .chips { pointer-events: auto; }
.tables-label { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 13px; color: rgba(52,44,50,0.55); margin-bottom: 2px; }
.chip.small { height: 30px; min-width: 34px; padding: 0 10px; margin: 3px; font-size: 14px; }

/* the step arrows, up in the two top corners */
.arrow.top { position: absolute; top: 47%; margin-top: -21px; z-index: 6; }   /* halfway down, either side of the paper */
.arrow.top.prev { left: 4px; }
.arrow.top.next { right: 4px; }

.tstamp.undo { margin-right: 6px; }
.tstamp.undo.off { opacity: 0.35; }

.langbtn { position: absolute; z-index: 6; padding: 0; border: none; background: none; cursor: pointer; }
.langbtn canvas { display: block; }
.langbtn:active { transform: scale(0.92); }

/* the language star is the only thing on the cover that moves: a slow little wobble that says "tap me" */
.langbtn canvas { animation: starwob 2.4s ease-in-out infinite; transform-origin: 50% 55%; }
@keyframes starwob {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(8deg) scale(1.08); }
}

/* the writing line is not shown: you type and the words go straight onto the paper.
   The input still takes the keyboard, out of sight at the top so the phone never scrolls to it */
.pen.on { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; overflow: hidden; margin: 0; padding: 0; border: 0; }

/* the four directions (two by two) and the numbers (two rows of four): a little bigger, easy to tap */
.chip.grid { height: 40px; min-width: 56px; margin: 4px 6px; font-size: 18px; }
.orline { text-align: center; font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 15px; color: rgba(255,255,255,.85); margin: 6px 0 0; letter-spacing: 2px; }
.orline::before, .orline::after { content: ''; display: inline-block; width: 34px; height: 1.5px; background: rgba(255,255,255,.55); vertical-align: middle; margin: 0 10px; border-radius: 2px; }
body.lightbg .orline { color: rgba(52,44,50,.7); }
body.lightbg .orline::before, body.lightbg .orline::after { background: rgba(52,44,50,.35); }
.answer .who, body.dark .answer .who { color: #FBF8F1; font-size: 20px; letter-spacing: 2px; }
body.lightbg .answer .who { color: rgba(52,44,50,.8); }
/* computer screens: the table carries on either side of the page's column */
.bgfull { position: fixed; left: 0; top: 0; z-index: -1; pointer-events: none; }
.bgfull[hidden] { display: none; }

/* === the box of finished ones === */
.boxbtn { position: absolute; z-index: 5; padding: 0; border: none; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.boxbtn[hidden] { display: none; }
.boxbtn canvas { display: block; }
.boxbtn:active { transform: scale(0.92); }
.boxbtn.bump { animation: boxbump .6s ease; }
@keyframes boxbump { 0% { transform: scale(1); } 30% { transform: scale(1.22) rotate(-6deg); } 60% { transform: scale(0.94) rotate(3deg); } 100% { transform: scale(1); } }
.boxview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(48,30,40,0.62);
  overflow-y: auto; -webkit-overflow-scrolling: touch; text-align: center;
  padding: 40px 14px 30px; padding-top: calc(var(--xhs-top, 24px) + 18px); padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px)); }
.boxview[hidden] { display: none; }
.boxtitle { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 26px; color: #FBF8F1; letter-spacing: 3px; }
.boxsub { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 14px; color: rgba(251,248,241,0.75); margin: 2px 0 14px; }
.boxgrid { display: flex; flex-wrap: wrap; justify-content: center; max-width: 520px; margin: 0 auto 10px; }
.bcard { position: relative; width: 42%; max-width: 200px; margin: 8px 3%; background: #FFFDF8; padding: 7px 7px 4px; border-radius: 3px;
  box-shadow: 0 4px 12px rgba(30,10,20,0.28); cursor: pointer; }
.bcard img { display: block; width: 100%; border-radius: 2px; background: #EADBC8; }
.bcard:active { opacity: 0.8; }
.bdate { font-family: var(--hand), 'Xiaolai', var(--cn); font-size: 13px; color: #8A6F7A; padding: 4px 0 1px; }
.bdel { position: absolute; top: -9px; right: -9px; width: 26px; height: 26px; border-radius: 13px; border: none; padding: 0;
  background: #F48BC0; color: #fff; font-size: 17px; line-height: 26px; cursor: pointer; box-shadow: 0 2px 5px rgba(30,10,20,0.25); }

/* ?poster=1: the cover picture only, nothing to press */
html.poster .panel, html.poster .arrow, html.poster .tray, html.poster .boxbtn, html.poster .langbtn, html.poster .toast, html.poster .card, html.poster .bgbtn { display: none !important; }
