/* Toys on the Work index (/): a split-flap board in the sidebar
   (ported from a Bencho block) and a tear-off month calendar tile on the
   wall (ported from Yaoguai High). Scripts: work/js/flapboard.js,
   work/js/almanac.js. */

.card--flap {
  display: flex; align-items: center; justify-content: center;
  padding: 22px 16px; flex: none;
}

/* ---------- flap board ---------- */

.sfb {
  --sfb-slab: #0d0c0a;
  --sfb-ink: #f7f5f0;
  display: grid;
  grid-template-columns: repeat(12, 22px);
  gap: 4px 2px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  outline: none;
}
.sfb:focus-visible { outline: 2px solid var(--ink); outline-offset: 6px; }
.sfb-tile { position: relative; display: block; width: 22px; height: 32px; perspective: 120px; }
.sfb-half {
  position: absolute; left: 0; right: 0;
  height: calc(50% - .5px);
  overflow: hidden;
  background: var(--sfb-slab);
}
.sfb-top { top: 0; border-radius: 6px 6px 0 0; }
.sfb-bot { bottom: 0; border-radius: 0 0 6px 6px; }
.sfb-ch {
  position: absolute; left: 0; right: 0; height: 32px;
  font: 500 20px/32px var(--sans);
  letter-spacing: -0.02em; text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--sfb-ink);
}
.sfb-top .sfb-ch { top: 0; }
.sfb-bot .sfb-ch { bottom: 0; }
/* the old top falls to edge-on, then the new bottom falls flat */
.sfb-fall {
  z-index: 2; transform-origin: 50% 100%; backface-visibility: hidden;
  animation: sfb-fall calc(var(--sfb-flap, 70ms) / 2) ease-in both;
}
.sfb-land {
  z-index: 2; transform-origin: 50% 0; backface-visibility: hidden;
  animation: sfb-land calc(var(--sfb-flap, 70ms) / 2) ease-out calc(var(--sfb-flap, 70ms) / 2) both;
}
@keyframes sfb-fall { from { transform: rotateX(0deg); } to { transform: rotateX(-90deg); } }
@keyframes sfb-land { from { transform: rotateX(90deg); } to { transform: rotateX(0deg); } }

/* ---------- tear-off month calendar ---------- */

/* the tile is a patch of warm plaster wall, lit from above, for the
   calendar to hang on and cast its shadow onto */
.tile--almanac {
  display: flex; justify-content: center;
  padding: 64px 32px 22px;
  background:
    radial-gradient(120% 70% at 50% 0%, #fbf8f2 0%, transparent 70%),
    linear-gradient(180deg, #f1ece3, #e8e1d5);
}

.alm {
  --alm-ink: #236049;
  --alm-rule: #39735996;
  --alm-red: #b84736;
  --alm-serif: Georgia, 'Songti SC', 'STSong', serif;
  position: relative; isolation: isolate;
  width: 100%; max-width: 340px; margin: 0 auto;
}
.alm-pad {
  position: relative; isolation: isolate;
  cursor: pointer; -webkit-user-select: none; user-select: none; touch-action: pan-y;
  /* hanging on the wall: a tight contact shadow where paper meets plaster,
     a softer one a little lower, and a wide faint one from the room light */
  filter:
    drop-shadow(0 1px 1px rgb(52 38 24 / .22))
    drop-shadow(0 5px 7px rgb(52 38 24 / .16))
    drop-shadow(0 16px 22px rgb(52 38 24 / .14))
    drop-shadow(0 34px 40px rgb(52 38 24 / .08));
}
.is-pulling .alm-pad { cursor: grabbing; }
/* on touch, a pull anywhere on the sheet tears it (Laura, 2026-11-19); almanac.js scrolls
   the page itself for a swipe up, since the sheet keeps the finger from the browser */
.alm-pad, .alm-date { touch-action: none; }

.alm-hanger {
  position: absolute; top: -24px; left: 50%; z-index: 1;
  width: 56px; height: 29px; transform: translateX(-50%);
  pointer-events: none;
}
.alm-hanger::before, .alm-hanger::after {
  content: ''; position: absolute; left: 50%; top: 5px;
  width: 2.5px; height: 35px; border-radius: 5px;
  background: linear-gradient(90deg, #913b30, #c54c3c 51%, #9f3c31);
  box-shadow: 1px 1px 1px #673f3626; transform-origin: 50% 0;
}
.alm-hanger::before { transform: translateX(-50%) rotate(45deg); }
.alm-hanger::after { transform: translateX(-50%) rotate(-45deg); }
.alm-nail {
  position: absolute; z-index: 1; top: 1px; left: 50%;
  width: 7px; height: 7px; transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(circle at 33% 28%, #c4bcb0, #80786d 46%, #49443e 78%);
  box-shadow: 1px 1px 2px #453b355e;
}
.alm-roll {
  position: relative; z-index: 2; overflow: hidden;
  height: 37px; margin: 0 -4px -3px;
  border-radius: 14px 16px 7px 7px / 50% 60% 24% 24%;
  background: linear-gradient(180deg, #e9e9dc 1%, #f9f8ee 28%, #f4f3e8 56%, #c5cabc 88%, #818f7e);
  box-shadow: 0 4px 6px #162e2338;
}
/* the ghost of the date on the sheet above, printed through the roll */
.alm-roll::before {
  content: attr(data-day); position: absolute; inset: -24px 0 auto; text-align: center;
  font: 900 5.6rem/.95 Georgia, serif; color: #a33b3238;
  transform: scaleY(.65) rotate(180deg);
}
.alm-roll::after {
  content: ''; position: absolute; right: 2px; top: 2px; bottom: 4px; width: 10px;
  border-radius: 50%;
  background: linear-gradient(90deg, #7b3226, #b44031 43%, #dfc4a9 47%, #a84937 60%);
}

.alm-sheet {
  position: relative; transform-origin: 0 0; box-sizing: border-box;
  padding: 10px 12px 9px; color: var(--alm-ink);
  background:
    linear-gradient(180deg, #dfe4d7 0, transparent 22px),
    repeating-linear-gradient(0deg, #65795d06 0 1px, transparent 1px 4px),
    #f7f6e9;
  box-shadow: 1px 2px #e1e2d3, 2px 4px #d4d9ca, 3px 6px #bcc7b7, 4px 8px #adbcac, 7px 11px #9c4b3c;
  border-right: 1px solid #b7bfad;
}
.alm-seam { position: absolute; inset: 34px 0 auto; z-index: 1; pointer-events: none; }
.alm-fibre {
  position: absolute; top: -2px; display: block;
  background: #e8ebdb; box-shadow: .65px 0 #81908045; transform: translateX(-50%);
}
.alm-fibre[hidden] { display: none; }
.alm-under { position: absolute; inset: 34px 0 auto; z-index: 0; pointer-events: none; }
.is-tearing .alm-front { box-shadow: 2px 5px 9px #27392f36; clip-path: var(--torn-edge, inset(0)); }
.is-tearing .alm-front::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 13px; pointer-events: none;
  background: linear-gradient(180deg, #99a48d58, #fffcf02b 34%, transparent);
  opacity: var(--tear-fold, 0);
}
/* the tip: the sheet's bottom corner, curled up off the page (drawn and lifted by almanac.js).
   Only the curl and the shade under it take the pointer: a click there tears the page off. */
.alm-tip {
  position: absolute; right: 0; bottom: 0; z-index: 4;
  width: 64px; height: 64px; pointer-events: none;
}
.alm-tip svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.alm-tip-under, .alm-tip-flap { pointer-events: visiblePainted; cursor: grab; }
.alm-tip-shadow, .alm-tip-crease { pointer-events: none; }
.is-tearing .alm-tip { display: none; }

.alm-fall { position: fixed; inset: 0; z-index: 50; width: auto; max-width: none; margin: 0; overflow: hidden; pointer-events: none; }
.alm-fall .alm-sheet { filter: drop-shadow(0 12px 18px rgb(52 38 24 / .22)); }

/* the printed date */
.alm-date { text-align: center; border: 1px solid var(--alm-rule); border-bottom: 0; }
.alm-month, .alm-weekday {
  display: grid; align-items: center;
  font: 700 .72rem/1.2 var(--alm-serif); letter-spacing: .08em; text-transform: uppercase;
}
.alm-month { grid-template-columns: 1fr 2.6fr 1fr; padding: 2px 5px; border-bottom: 1px solid var(--alm-rule); }
.alm-year { text-align: left; }
.alm-month-han { text-align: right; }
.alm-month-en { border-inline: 1px solid var(--alm-rule); }
.alm-print { display: grid; grid-template-columns: 26px 1fr 26px; justify-items: center; align-items: center; padding: 8px 4px 10px; }
.alm-side { writing-mode: vertical-rl; font: 700 .64rem/1.1 var(--alm-serif); letter-spacing: .15em; }
.alm-number {
  display: block; padding-top: 1px; color: var(--alm-ink);
  font: 900 5.4rem/.8 'Arial Black', 'Arial Bold', Georgia, serif; letter-spacing: -.07em;
}
.alm-weekday { grid-template-columns: 1fr 1.35fr; border-top: 1px solid var(--alm-rule); }
.alm-weekday > span { padding: 4px; }
.alm-weekday-han { border-inline-end: 1px solid var(--alm-rule); font-size: .87rem; }

/* the month's band, weekday letters and grid */
.alm-bar {
  display: grid; grid-template-columns: minmax(44px, 16%) 1fr; min-height: 34px;
  border: 1px solid var(--alm-rule); border-top: 3px double var(--alm-ink);
  background: #e5ebdb;
  font: 700 .85rem/1 var(--alm-serif); letter-spacing: .02em;
}
.alm-bar > span { display: grid; align-items: center; }
.alm-range { justify-items: center; background: var(--alm-ink); color: #fffdef; font-size: .6rem; letter-spacing: 0; }
.alm-caption { padding-inline: 10px; }
.alm-labels, .alm-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border-inline-start: 1px solid var(--alm-rule);
}
.alm-labels > span {
  padding: 3px 0; text-align: center;
  border-inline-end: 1px solid var(--alm-rule); border-bottom: 1px solid var(--alm-rule);
  font: 700 .69rem/1.2 var(--alm-serif);
}
.alm-grid { background: repeating-linear-gradient(0deg, #65795d05 0 1px, transparent 1px 5px); }
.alm-cell {
  position: relative; display: grid; place-items: center;
  width: 100%; min-width: 0; aspect-ratio: 1.3; margin: 0; padding: 0;
  border: 0; border-inline-end: 1px solid var(--alm-rule); border-bottom: 1px solid var(--alm-rule);
  border-radius: 0; background: transparent; color: var(--alm-ink);
  font: 700 .74rem/1 Georgia, serif; font-variant-numeric: tabular-nums;
}
.alm-num { position: relative; z-index: 1; }
.alm-cell.has-seal .alm-num { position: absolute; top: 3px; left: 3px; color: #294532; font-size: .56rem; font-weight: 800; }
.alm-seal {
  position: absolute; z-index: 2; inset: 50% auto auto 50%;
  width: 78%; max-width: 38px; aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(var(--seal-r, -4deg));
  background: url('/media/calendar/seals.webp') var(--seal-x, 0%) 50% / 300% 100% no-repeat;
  filter: saturate(.88) contrast(1.04);
  mix-blend-mode: multiply; opacity: .9;
  pointer-events: none;
}

/* today: a soft wash, nothing more */
.alm-cell.is-today { background: #faedbd; }
.alm-cell.is-today .alm-num { color: var(--alm-red); font-weight: 800; }

/* stamps pressed anywhere on the page; each lands big and soft, bounces,
   and the ink settles. The sheet clips them at the paper's edge. */
.alm-stamps { position: absolute; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.alm-stamp {
  /* the size of the seals on this month's days (.alm-seal), so a press matches them */
  position: absolute; width: 38px; aspect-ratio: 1;
  translate: -50% -50%; rotate: var(--seal-r, 0deg);
  background: url('/media/calendar/seals.webp') var(--seal-x, 0%) 50% / 300% 100% no-repeat;
  filter: saturate(.9) contrast(1.05);
  mix-blend-mode: multiply; opacity: .9;
}
.alm-stamp.is-fresh { animation: alm-press 420ms cubic-bezier(.15, .8, .2, 1) both; }
@keyframes alm-press {
  0% { opacity: 0; scale: 2.1; filter: saturate(.5) blur(1.5px); }
  45% { opacity: .95; scale: .9; filter: saturate(1.1) blur(0); }
  70% { scale: 1.04; }
  100% { opacity: .9; scale: 1; filter: saturate(.9) contrast(1.05); }
}

.alm-register {
  display: grid; grid-template-columns: auto 1.5fr 1fr; margin-top: 4px;
  border: 1px solid var(--alm-rule); border-top: 3px double var(--alm-ink);
  text-align: center;
  font: 700 .58rem/1.2 var(--alm-serif); letter-spacing: .04em; text-transform: uppercase;
}
.alm-register > span { padding: 4px 6px; }
.alm-register > span:first-child { background: var(--alm-ink); color: #f7f6e9; }
.alm-count { border-inline-end: 1px solid var(--alm-rule); }

/* under the pad: Reset (once something changed) and, for keyboards only,
   a tear button that shows when focused. Reset keeps its room while hidden
   so the tile never changes height. */
.alm-foot { display: flex; justify-content: center; gap: 8px; min-height: 32px; margin-top: 30px; }
.alm-reset, .alm-tear {
  min-height: 32px; padding: 0 14px; border: 0; border-radius: 999px;
  background: #fff; color: var(--muted);
  font: 500 13px/1 var(--sans); letter-spacing: -0.01em; cursor: pointer;
  box-shadow: 0 1px 2px rgb(52 38 24 / .1);
  transition: color .2s var(--ease), transform .2s var(--ease);
}
.alm-reset:hover, .alm-tear:hover { color: var(--ink); transform: translateY(-1px); }
.alm-reset[hidden] { display: inline-block; visibility: hidden; }
.alm-tear:not(:focus-visible) {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.alm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .sfb-fall { display: none; }
  .sfb-land, .alm-stamp.is-fresh { animation: none; }
}
