/* Max's Math Tycoon — celebrations (spec §15).
   Paper and ink only: rubber stamps, torn paper, ribbons, chalk, a rolled
   diploma. Colours come from tokens.css and nothing else. Every class and
   keyframe is prefixed cel-. Motion is transforms + opacity; the few
   clip-path shapes are static. Reduced motion is decided in celebrate.js
   (which then uses the --fade variants); the .cel-reduced rules at the end
   are only a safety net for the CSS-keyframed pieces. */

/* ---------------------------------------------------------------- root */
.cel-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  pointer-events: none;
  font-family: var(--font);
  color: var(--ink);
}
.cel-root.cel-dismissable {
  pointer-events: auto;
  cursor: pointer;
}

/* --------------------------------------------------------------- stamp */
.cel-stamp-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 5;
}
.cel-stamp-wrap--corner {
  left: auto;
  top: 14px;
  right: 14px;
  transform: none;
}
.cel-stamp {
  position: relative;
  display: inline-block;
  padding: 6px 18px;
  border: 3px solid var(--brick);
  color: var(--brick);
  font: 700 40px/1 var(--font);
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
  transform: rotate(-8deg);
  mix-blend-mode: multiply;
}
.cel-stamp::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid var(--brick);
  pointer-events: none;
}
.cel-stamp--small {
  padding: 3px 8px;
  border-width: 2px;
  font-size: 12px;
  letter-spacing: .1em;
  transform: rotate(-6deg);
}
.cel-stamp--small::before { inset: 1px; }
.cel-stamp--x {
  width: 22px;
  height: 22px;
  padding: 3px;
  border-width: 2px;
  font-size: 0;
  line-height: 0;
  transform: rotate(-10deg);
}
.cel-stamp--x::before { inset: 1px; }
.cel-stamp--x svg {
  display: block;
  width: 22px;
  height: 22px;
  stroke: var(--brick);
  stroke-width: 3;
  stroke-linecap: square;
  fill: none;
}
.cel-stamp--slam { animation: cel-stamp-slam 180ms ease-in both; }
.cel-stamp--small.cel-stamp--slam { animation-name: cel-stamp-slam-small; }
.cel-stamp--fade { animation: cel-fade-in 200ms ease-out both; }
.cel-stamp--fade-slow { animation: cel-fade-in 400ms ease-out both; }
/* Exits: specific enough to beat every entrance above (the --small.--slam pair is 0,2,0). */
.cel-fade-out,
.cel-stamp.cel-stamp--out { animation: cel-fade-out 200ms ease-in both; }
/* 1 px ink bleed once the stamp has landed */
.cel-stamp--landed {
  text-shadow: 0 0 1px var(--brick);
  box-shadow: 0 0 1px var(--brick), inset 0 0 1px var(--brick);
}

@keyframes cel-stamp-slam {
  0%   { transform: scale(1.6) rotate(-8deg); opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); opacity: 1; }
}
@keyframes cel-stamp-slam-small {
  0%   { transform: scale(1.6) rotate(-6deg); opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: scale(1) rotate(-6deg); opacity: 1; }
}
@keyframes cel-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes cel-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------- torn-paper confetti */
.cel-confetti {
  position: absolute;
  left: 0;
  top: 0;
  width: 7px;
  height: 12px;
  background: var(--card);
  clip-path: polygon(8% 0, 100% 6%, 92% 100%, 0 94%);
  pointer-events: none;
  will-change: transform, opacity;
}
.cel-confetti--b {
  width: 9px;
  height: 9px;
  clip-path: polygon(0 12%, 55% 0, 100% 20%, 90% 100%, 10% 88%);
}
.cel-confetti--c {
  width: 6px;
  height: 14px;
  clip-path: polygon(15% 0, 100% 10%, 85% 55%, 100% 100%, 0 90%, 10% 40%);
}
.cel-confetti--card3 { background: var(--card-3); }
.cel-confetti--line  { background: var(--line); }
.cel-confetti--brick { background: var(--brick); }

/* ------------------------------------------------------------- chalk */
.cel-chalk {
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card-3);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.cel-chalk--b { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
.cel-chalk--c { width: 22px; height: 22px; margin: -11px 0 0 -11px; }

/* ------------------------------------------------------------ ribbon */
.cel-ribbon-track {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
}
.cel-ribbon {
  position: absolute;
  left: 50%;
  top: 50%;
  padding: 9px 30px;
  background: var(--brick);
  color: var(--rail-text);
  font: 600 14px/1.2 var(--font);
  letter-spacing: .04em;
  white-space: nowrap;
  clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 50%, 100% 100%, 0 100%, 10px 50%);
  transform: translate(var(--cel-x0, -50%), -50%);
  animation: cel-ribbon-across 1450ms both;
}
.cel-ribbon--fade {
  transform: translate(-50%, -50%);
  animation: cel-fade-in 200ms ease-out both;
}
@keyframes cel-ribbon-across {
  0%   { transform: translate(var(--cel-x0, -50%), -50%); animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
  26%  { transform: translate(-50%, -50%); animation-timing-function: linear; }
  74%  { transform: translate(-50%, -50%); animation-timing-function: cubic-bezier(.6, 0, .8, .4); }
  100% { transform: translate(var(--cel-x1, -50%), -50%); }
}

/* -------------------------------------------- parchment banner (gate 25) */
.cel-parchment {
  position: absolute;
  overflow: hidden;
  padding-bottom: 12px;
  pointer-events: none;
}
.cel-parchment-sheet {
  position: relative;
  animation: cel-unroll 500ms cubic-bezier(.2, .7, .2, 1) both;
}
.cel-parchment-sheet--fade { animation: cel-fade-in 200ms ease-out both; }
.cel-parchment--out .cel-parchment-sheet { animation: cel-roll-up 400ms ease-in both; }
.cel-parchment--out .cel-parchment-sheet--fade { animation: cel-fade-out 200ms ease-in both; }
.cel-paper {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: 0;
  color: var(--ink);
  text-align: center;
  clip-path: polygon(
    0 0, 100% 0, 100% calc(100% - 6px), 96% 100%, 92% calc(100% - 4px), 87% calc(100% - 7px),
    82% 100%, 76% calc(100% - 3px), 71% calc(100% - 8px), 65% calc(100% - 2px), 59% calc(100% - 6px),
    53% 100%, 47% calc(100% - 5px), 41% calc(100% - 1px), 35% calc(100% - 7px), 29% calc(100% - 3px),
    23% 100%, 17% calc(100% - 6px), 11% calc(100% - 2px), 6% calc(100% - 8px), 0 calc(100% - 4px)
  );
}
.cel-parchment-sheet .cel-paper {
  padding: 14px 20px 20px;
  font: 600 15px/1.3 var(--font);
}
.cel-roll {
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -6px;
  height: 12px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--card-3);
  box-shadow: var(--shadow);
  animation: cel-roll-fade 300ms ease-out 450ms both;
}
.cel-parchment-sheet--fade .cel-roll { display: none; }
@keyframes cel-unroll  { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes cel-roll-up { from { transform: translateY(0); } to { transform: translateY(-100%); } }
@keyframes cel-roll-fade { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------------- scrim + hint */
.cel-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: cel-fade-in 150ms ease-out both;
}
.cel-scrim--out { animation: cel-fade-out 150ms ease-in both; }
.cel-hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 24px;
  text-align: center;
  color: var(--rail-text);
  font: 600 12px/1 var(--font);
  letter-spacing: .1em;
  text-transform: uppercase;
  opacity: .8;
  animation: cel-fade-in 300ms ease-out 400ms both;
}

/* --------------------------------------------- diploma scroll (course) */
.cel-diploma {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(440px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  overflow: hidden;
  padding: 10px 0 16px;
  cursor: pointer;
}
.cel-diploma-sheet {
  position: relative;
  animation: cel-unroll 600ms cubic-bezier(.2, .7, .2, 1) both;
}
.cel-diploma-sheet--fade { animation: cel-fade-in 200ms ease-out both; }
.cel-diploma--out .cel-diploma-sheet { animation: cel-roll-up 200ms ease-in both; }
.cel-diploma--out .cel-diploma-sheet--fade { animation: cel-fade-out 200ms ease-in both; }
.cel-diploma-sheet .cel-paper {
  padding: 30px 28px 34px;
  border-bottom: 0;
}
.cel-diploma-sheet .cel-roll {
  animation-delay: 550ms;
}
.cel-kicker {
  margin: 0 0 18px;
  font: 600 11px/1 var(--font);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.cel-oval {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 120px;
  margin: 0 auto 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--card-2);
  overflow: hidden;
}
.cel-oval > svg,
.cel-oval > img {
  display: block;
  width: 100%;
  height: 100%;
}
.cel-oval-monogram {
  font: 700 36px/1 var(--font);
  color: var(--ink);
}
.cel-diploma-title {
  margin: 0;
  font: 700 24px/1.2 var(--font);
  font-style: italic;
  letter-spacing: .01em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.cel-diploma-sub {
  margin: 6px 0 0;
  font: 400 14px/1.3 var(--font);
  color: var(--ink-2);
}
.cel-rule {
  width: 120px;
  height: 0;
  margin: 18px auto 0;
  border-top: 1px solid var(--ink);
}
.cel-seal-slot {
  display: flex;
  justify-content: center;
  height: 60px;
  margin-top: 16px;
}
.cel-seal {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brick);
  color: var(--brick-wash);
  font: 700 22px/56px var(--font);
  text-align: center;
  box-shadow: inset 0 0 0 3px var(--brick-ink), inset 0 0 0 5px var(--brick);
  mix-blend-mode: multiply;
  opacity: 0;
}
.cel-seal--show { opacity: 1; }
.cel-seal--slam { animation: cel-seal-slam 180ms ease-in both; }
.cel-seal--landed { box-shadow: inset 0 0 0 3px var(--brick-ink), inset 0 0 0 5px var(--brick), 0 0 1px var(--brick); }
@keyframes cel-seal-slam {
  0%   { transform: scale(1.6) rotate(-8deg); opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); opacity: 1; }
}
.cel-tassel {
  position: absolute;
  top: 0;
  right: 34px;
  width: 12px;
  transform-origin: 50% 0;
}
.cel-tassel-cord {
  display: block;
  width: 2px;
  height: 62px;
  margin: 0 auto;
  background: var(--ink);
}
.cel-tassel-tuft {
  display: block;
  width: 12px;
  height: 26px;
  background: var(--brick);
  clip-path: polygon(0 0, 100% 0, 100% 62%, 85% 100%, 70% 66%, 55% 100%, 40% 66%, 25% 100%, 10% 66%, 0 100%);
}
.cel-tassel--swing { animation: cel-tassel-swing 1200ms ease-in-out both; }
@keyframes cel-tassel-swing {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(16deg); }
  45%  { transform: rotate(-12deg); }
  70%  { transform: rotate(8deg); }
  88%  { transform: rotate(-4deg); }
  100% { transform: rotate(0deg); }
}

/* ------------------------------------------- transcript (graduation) */
.cel-transcript {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(600px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  text-align: center;
}
.cel-transcript-title {
  margin: 0 0 4px;
  font: 700 22px/1.2 var(--font);
  color: var(--rail-text);
}
.cel-transcript-sub {
  margin: 0 0 18px;
  font: 400 13px/1.3 var(--font);
  color: var(--line);
}
.cel-transcript-head { opacity: 0; }
.cel-transcript-head--show { animation: cel-fade-in 300ms ease-out both; }
.cel-transcript-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.cel-transcript-card {
  width: 96px;
  padding: 10px 8px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform-origin: 50% 180%;
  will-change: transform;
}
.cel-transcript-card .cel-oval {
  width: 44px;
  height: 56px;
  margin-bottom: 8px;
  border-width: 1px;
}
.cel-transcript-card .cel-oval-monogram { font-size: 18px; }
.cel-transcript-course {
  font: 600 11px/1.25 var(--font);
  color: var(--ink);
}
.cel-transcript-biz {
  margin-top: 2px;
  font: 400 11px/1.25 var(--font);
  color: var(--ink-2);
}
.cel-transcript-card .cel-seal {
  width: 18px;
  height: 18px;
  margin: 8px auto 0;
  font: 700 9px/18px var(--font);
  box-shadow: inset 0 0 0 1px var(--brick-ink), inset 0 0 0 2px var(--brick);
  opacity: 1;
}

@media (max-width: 480px) {
  .cel-transcript-grid { gap: 8px; }
  .cel-transcript-card { width: 78px; padding: 8px 6px 6px; }
  .cel-transcript-card .cel-oval { width: 36px; height: 46px; margin-bottom: 6px; }
  .cel-transcript-course { font-size: 10px; }
  .cel-transcript-biz { display: none; }
  .cel-transcript-card .cel-seal { margin-top: 6px; }
  .cel-transcript-title { font-size: 18px; }
  .cel-transcript-sub { margin-bottom: 12px; }
}

/* ------------------------------------------------------- split flap */
.cel-flap {
  display: inline-block;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  backface-visibility: hidden;
  will-change: transform;
}

/* ------------------------------------------------ costume card flip */
.cel-flip {
  backface-visibility: hidden;
  will-change: transform;
}

/* ------------------------------------------------ semester roll bar */
.cel-roll-bar {
  position: absolute;
  height: 14px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--card-3);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
}

/* ------------------------------------------------------ streak flame */
.cel-flame-clone {
  position: absolute;
  margin: 0;
  color: var(--brick);
  pointer-events: none;
  will-change: clip-path;
}
.cel-lit { color: var(--brick); }

/* ------------------------------------------ permanent marks (course) */
/* Ink check on the rail entry: takes the entry's own text colour. */
.cel-cleared::after {
  content: '';
  display: inline-block;
  box-sizing: border-box;
  width: 7px;
  height: 13px;
  margin-left: 10px;
  vertical-align: 1px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
/* Brick "Course cleared" ribbon pinned to the faculty card's top-right. */
.cel-course-ribbon {
  position: absolute;
  top: 10px;
  right: -6px;
  z-index: 1;
  padding: 5px 10px 5px 16px;
  background: var(--brick);
  color: var(--rail-text);
  font: 600 11px/1 var(--font);
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 8px 50%);
  pointer-events: none;
}
.cel-course-ribbon::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: -5px;
  width: 6px;
  height: 5px;
  background: var(--brick-ink);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* ------------------------------------------------- reduced-motion net */
/* celebrate.js already picks the --fade variants; this only catches a
   CSS-keyframed entrance that slipped through. Exits are restated below it
   with higher specificity so a reduced run still fades out. */
.cel-root.cel-reduced .cel-stamp--slam,
.cel-root.cel-reduced .cel-seal--slam,
.cel-root.cel-reduced .cel-ribbon,
.cel-root.cel-reduced .cel-parchment-sheet,
.cel-root.cel-reduced .cel-diploma-sheet {
  animation: cel-fade-in 200ms ease-out both;
}
.cel-root.cel-reduced .cel-tassel--swing { animation: none; }
.cel-root.cel-reduced .cel-roll,
.cel-diploma-sheet--fade .cel-roll { display: none; }
.cel-ribbon.cel-fade-out,
.cel-root.cel-reduced .cel-ribbon.cel-fade-out,
.cel-root.cel-reduced .cel-parchment--out .cel-parchment-sheet,
.cel-root.cel-reduced .cel-diploma--out .cel-diploma-sheet {
  animation: cel-fade-out 200ms ease-in both;
}
