:root {
  --paper: #F3E6C3;
  --paper-deep: #E8D6A6;
  --card: #FCF8EE;
  --ink: #2B2118;
  --muted: #6A5841;
  --blue: #26399A;
  --green: #1E7B34;
  --red: #C9221A;
  --rule: #9FB9D166;
  --margin: #D9787088;
  --tape: #EFE3AEC8;
  --sticker: #F6D44A;
  --line: 32px;
  --display: 'Baloo Da 2', 'Hind Siliguri', system-ui, sans-serif;
  --body: 'Hind Siliguri', system-ui, sans-serif;
  --hand: 'Atma', 'Hind Siliguri', system-ui, sans-serif;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--paper-deep);
  color: var(--ink);
  font: 16px/1.6 var(--body);
  -webkit-tap-highlight-color: transparent;
}

.page, .topbar { max-width: 480px; margin-inline: auto; }

.page {
  position: relative;
  overflow-x: clip;
  padding: 24px 20px 48px 40px;
  background:
    linear-gradient(90deg, transparent 27px, var(--margin) 27px, var(--margin) 29px, transparent 29px),
    repeating-linear-gradient(transparent 0 calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px) var(--line)),
    var(--paper);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 20px 10px;
  background: var(--paper-deep);
  border-bottom: 1px solid #2B21181F;
}

.brand { font: 800 19px/1 var(--display); color: var(--ink); text-decoration: none; }

.meter { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 6px; justify-items: end; }
.meter-label { font: 400 12px var(--body); color: var(--muted); }
.meter-value { font: 800 20px/1 var(--display); color: var(--green); font-variant-numeric: tabular-nums; }
.meter-bar { grid-column: 1 / -1; width: 112px; height: 6px; margin-top: 4px; border-radius: 3px; background: #2B21181F; overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--green); transform: scaleX(calc(var(--p, 0) / 100)); transform-origin: left; transition: transform .28s ease-out; }

h1, h2, h3 { font-family: var(--display); font-weight: 800; line-height: 1.25; margin: 0; }
h1 { font-size: clamp(28px, 8vw, 34px); margin-top: 28px; text-wrap: balance; }

.label-card {
  position: relative;
  max-width: 300px;
  padding: 10px 16px;
  background: var(--card);
  border: 2px solid var(--blue);
  border-radius: 6px;
  transform: rotate(-1.5deg);
  box-shadow: 0 2px 0 #2B21181F;
}
.label-card p { margin: 0; padding: 2px 0; border-bottom: 1px solid #9FB9D1; font-size: 13px; color: var(--muted); }
.label-card p:last-of-type { border: 0; }
.label-card span { font-weight: 600; }
.label-card b { font: 400 17px var(--hand); color: var(--blue); margin-left: 4px; }

.sticker {
  position: absolute;
  right: -14px;
  top: 18px;
  width: 78px;
  height: 78px;
  display: grid;
  place-content: center;
  text-align: center;
  font: 400 11px/1.2 var(--hand);
  background: var(--sticker);
  border-radius: 50%;
  transform: rotate(12deg);
  box-shadow: 0 2px 4px #2B211833;
}
.sticker strong { display: block; font: 800 15px/1.1 var(--display); color: #8E1710; }

.lede { color: var(--muted); margin: 12px 0 8px; }
.margin-note { font: 400 15px var(--hand); color: var(--blue); margin: 0 0 20px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  width: 100%;
  padding: 12px 20px;
  border: 0;
  border-radius: 8px;
  font: 700 17px var(--body);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .09s ease-out, box-shadow .09s ease-out;
}
.btn-blue { background: var(--blue); color: #fff; box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.kicker { font: 400 16px var(--hand); color: var(--red); margin: 32px 0 8px; }

.toc ul { display: flex; gap: 8px; margin: 0 -20px 0 0; padding: 0 20px 4px 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
.toc a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1.5px solid #2B21181F;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: 600 14px var(--body);
  white-space: nowrap;
  text-decoration: none;
  transition: background-color .2s, color .2s;
}
.toc a small { font-size: 12px; font-weight: 400; color: var(--muted); }
.toc a.done { background: var(--green); border-color: var(--green); color: #fff; }
.toc a.done small { color: #fff; }

.chapter { padding-top: 40px; }
.chapter-kicker { font: 400 15px var(--hand); color: var(--red); margin: 0; }
.chapter-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chapter-head h2 { font-size: 24px; }
.aside { font: 400 14px var(--hand); color: var(--blue); margin: 2px 0 0; }
.chapter-count {
  flex: none;
  padding: 2px 12px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  font: 400 18px var(--hand);
  color: var(--blue);
  transform: rotate(-4deg);
}
.chapter.done .chapter-count { border-color: var(--green); color: #fff; background: var(--green); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 14px; margin-top: 20px; }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 8px 8px 10px;
  border: 0;
  border-radius: 2px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 1px 1px #2B21181F, 0 6px 14px -6px #2B211859;
  transform: rotate(var(--tilt, -1.5deg));
  transition: transform .09s ease-out, box-shadow .09s ease-out;
}
.card:nth-child(4n + 2) { --tilt: 1.8deg; }
.card:nth-child(4n + 3) { --tilt: 1deg; }
.card:nth-child(4n) { --tilt: -2deg; }
.card::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  width: 64px;
  height: 20px;
  background: var(--tape);
  transform: translateX(-50%) rotate(calc(var(--tilt, 0deg) * -2));
}
.card:active { transform: rotate(var(--tilt)) scale(.96); box-shadow: 0 1px 1px #2B21181F; }

.photo { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--paper-deep); }
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }

.tick {
  position: absolute;
  right: -6px;
  bottom: -10px;
  width: 58%;
  height: auto;
  color: var(--green);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 1px 0 #fff);
}

.caption { display: block; margin-top: 8px; font: 400 15px/1.35 var(--hand); }
.remembered { display: block; margin-top: 4px; font: 400 14px var(--hand); color: var(--green); opacity: 0; }

.card[aria-pressed="true"] .tick,
.card[aria-pressed="true"] .remembered { opacity: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font: 600 14px var(--body);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.submit-bar {
  position: fixed;
  inset: auto 0 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  margin-inline: auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--paper-deep);
  border-top: 1px solid #2B21181F;
  box-shadow: 0 -6px 16px -10px #2B211866;
  animation: fade-up .2s ease-out;
}
.submit-count { flex: none; font: 800 20px/1 var(--display); color: var(--green); font-variant-numeric: tabular-nums; }
.submit-bar .btn { min-height: 48px; }

.result {
  width: calc(100% - 24px);
  max-width: 456px;
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background:
    repeating-linear-gradient(transparent 0 calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px) var(--line)),
    var(--paper);
  box-shadow: 0 24px 48px -12px #2B2118AA;
  overscroll-behavior: contain;
}
.result::backdrop { background: #2B2118B3; }
.result[open] { animation: pop-in .26s var(--spring); }
.sheet { position: relative; padding: 20px 20px 28px; }
.result h2 { font-size: 24px; padding-right: 48px; }
.close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 1;
  width: 44px;
  height: 44px;
  margin: -8px -8px 0 0;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font: 700 18px var(--body);
  cursor: pointer;
  box-shadow: 0 1px 3px #2B211840;
}
.scheme-fold { margin-top: 16px; }
.scheme-fold summary { min-height: 44px; display: flex; align-items: center; gap: 8px; font: 700 14px var(--body); color: var(--muted); cursor: pointer; list-style: none; }
.scheme-fold summary::-webkit-details-marker { display: none; }
.scheme-fold summary::before { content: '▸'; color: var(--blue); transition: transform .15s ease-out; }
.scheme-fold[open] summary::before { transform: rotate(90deg); }
.result-card {
  margin-top: 16px;
  padding: 20px;
  background: var(--card);
  border-radius: 4px;
  box-shadow: 0 1px 1px #2B21181F, 0 8px 18px -8px #2B211859;
}
.result-top { display: flex; align-items: center; gap: 16px; }
.score-ring { position: relative; flex: none; width: 116px; aspect-ratio: 1; display: grid; place-items: center; }
.score-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke: var(--red); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 0; }
.score-ring span { font: 800 34px/1 var(--display); color: var(--red); font-variant-numeric: tabular-nums; }
.result-count { margin: 0; font-size: 14px; color: var(--muted); }
.rank { margin: 2px 0 0; font: 800 22px/1.25 var(--display); }
.grade { display: inline-block; margin-right: 4px; padding: 0 8px; border: 2px solid var(--red); border-radius: 999px; font: 400 18px/1.4 var(--hand); color: var(--red); transform: rotate(-4deg); vertical-align: 2px; }
.remark { margin: 16px 0 0; padding-top: 14px; border-top: 1.5px solid #9FB9D1; font: 400 15px/1.5 var(--hand); color: var(--red); min-height: 3em; }
.scheme { width: 100%; border-collapse: collapse; }
.scheme td { padding: 8px; font: 400 15px var(--hand); border-top: 1px dashed #2B21181F; }
.scheme td:first-child { font: 800 14px var(--display); color: var(--muted); white-space: nowrap; }
.scheme tr.you td { color: var(--green); background: #1E7B3414; border: 1.5px solid var(--green); border-width: 1.5px 0; }
.scheme tr.you td:first-child { border-left-width: 1.5px; color: var(--green); }
.scheme tr.you td:last-child { border-right-width: 1.5px; }
.scheme .you-mark { margin-left: 6px; font-size: 13px; white-space: nowrap; }
.result.reveal .score-ring svg { animation: draw .9s ease-out both; }

.share { margin-top: 32px; }
.share-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding-right: 48px; }
.share-head h3 { font: 700 15px var(--body); }
.share-head p { margin: 0; font: 400 13px var(--hand); color: var(--blue); }
.share-preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  margin: 10px 0 20px;
  background: var(--paper-deep);
  border-radius: 4px;
  box-shadow: 0 1px 1px #2B21181F, 0 8px 18px -8px #2B211859;
}
.btn:disabled { opacity: .6; cursor: progress; }

.challenge-banner {
  margin: 0 0 20px;
  padding: 12px 14px;
  background: var(--sticker);
  border-radius: 6px;
  font: 600 15px/1.45 var(--body);
  transform: rotate(-.8deg);
  box-shadow: 2px 2px 0 var(--ink);
  overflow-wrap: anywhere;
}
.versus {
  margin-top: 16px;
  padding: 14px;
  border: 2px dashed var(--blue);
  border-radius: 6px;
  font: 400 15px/1.5 var(--hand);
  overflow-wrap: anywhere;
}
.versus strong { display: block; font: 800 20px/1.3 var(--display); }
.versus p { margin: 6px 0 0; }

.name-label { display: block; margin-top: 12px; font: 400 13px var(--body); color: var(--muted); }
#sender {
  display: block;
  width: 100%;
  margin-top: 6px;
  min-height: 52px;
  padding: 12px 14px;
  border: 1.5px solid #2B211840;
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: 400 16px var(--body);
}
#sender::placeholder { color: var(--muted); }
.socials-title { margin: 4px 0 12px; font: 700 15px var(--body); }
.socials { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 0; padding: 0; list-style: none; }
.socials button {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: 500 12px var(--body);
  cursor: pointer;
  touch-action: manipulation;
}
.socials .ico {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform .09s ease-out, box-shadow .09s ease-out;
}
.socials .ico svg { width: 24px; height: 24px; }
.socials button:active .ico { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.socials button:disabled { cursor: progress; opacity: .5; }
.ico.fb { background: #1877F2; }
.ico.ig { background: radial-gradient(circle at 30% 107%, #FDCB52 0%, #FD5949 45%, #D6249F 60%, #285AEB 90%); }
.ico.xx { background: #000; }
.ico.wa { background: #1DA851; }
.ico.more { background: var(--blue); }
.ico.save { background: var(--card); color: var(--ink); border: 2px solid var(--ink); }
.privacy-note { margin: 14px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.btn-restart { margin-top: 24px; background: var(--card); color: var(--ink); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }

.footer { max-width: 480px; margin-inline: auto; padding: 20px 20px calc(96px + env(safe-area-inset-bottom, 0px)); background: var(--paper-deep); font-size: 13px; color: var(--muted); }
.footer p { margin: 0; }
.footer a { color: var(--blue); overflow-wrap: anywhere; }
.footer .credit { margin-top: 10px; font-size: 11px; color: var(--muted); }

.card[aria-pressed="true"] .tick { animation: tick-in .32s var(--spring) both; }
.card[aria-pressed="true"] .remembered { animation: fade-up .16s .16s ease-out both; }
.card .tick.erasing { opacity: 1; animation: erase .2s ease-in both; }
.meter-value.bump { animation: roll-up .24s ease-out; }
.meter-bar.glow { animation: glow .28s ease-out; }
.chapter.stamped .chapter-count { animation: stamp .38s var(--spring); }

@keyframes tick-in { from { opacity: 0; transform: scale(1.3) rotate(-10deg); } to { opacity: 1; transform: none; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes erase {
  0% { opacity: 1; transform: none; }
  25% { transform: translateX(-4px) rotate(-3deg); }
  50% { transform: translateX(4px) rotate(3deg); }
  75% { transform: translateX(-3px); opacity: .5; }
  100% { opacity: 0; transform: none; }
}
@keyframes roll-up { from { opacity: 0; transform: translateY(60%); } to { opacity: 1; transform: none; } }
@keyframes glow { 50% { box-shadow: 0 0 0 3px #1E7B3440; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(24px) scale(.98); } }
@keyframes draw { from { stroke-dashoffset: 100; } }
@keyframes stamp { from { transform: scale(1.6) rotate(-14deg); } to { transform: rotate(-4deg); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, ::before, ::after { animation: none !important; transition-duration: 0s !important; }
}
