:root {
  --ink: #23315e;
  --pen: #c8302c;
  --pencil: #6d6a66;
  --rule: #9cc0e6;
  --margin: #e88f8f;
  --paper: #fbf8ef;
  --desk: #3a2f25;
}
* { box-sizing: border-box; }
/* No double-tap zoom on mobile; pinch on the canvas is handled by the app. */
html, body, .paper, .paper * { touch-action: manipulation; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--desk); }
body { font-family: "Caveat", "Comic Sans MS", cursive; color: var(--ink); -webkit-tap-highlight-color: transparent; }

#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }

#loading {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: #f3e6cf; font-size: 28px; opacity: .8; pointer-events: none; transition: opacity .6s;
}
#loading.gone { opacity: 0; }

/* ---------------------------------------------------------------- paper */
.paper {
  position: fixed; left: 28px; bottom: 26px; width: 330px; margin: 0;
  padding: 40px 26px 30px 58px;
  transform: rotate(-2.6deg); transform-origin: 20% 100%;
  background:
    linear-gradient(90deg, transparent 46px, var(--margin) 46px, var(--margin) 47.5px, transparent 47.5px),
    repeating-linear-gradient(180deg, transparent 0 29px, var(--rule) 29px 30px),
    linear-gradient(170deg, #fffdf6, var(--paper) 55%, #f1ebdb);
  background-position: 0 0, 0 14px, 0 0;
  box-shadow:
    0 1px 1px rgba(0,0,0,.15),
    0 10px 18px -4px rgba(30,15,0,.45),
    0 30px 50px -10px rgba(30,15,0,.45),
    inset 0 0 40px rgba(170,140,90,.12);
  border-radius: 2px 3px 2px 2px;
  user-select: none;
}
.paper::after { /* paper grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 .55 0 0 0 0 .5 0 0 0 0 .42 0 0 0 .5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
.clip { position: absolute; top: -30px; left: 50%; width: 120px; transform: translateX(-50%); filter: drop-shadow(0 4px 3px rgba(0,0,0,.45)); z-index: 2; }
.holes { position: absolute; left: 14px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: space-around; padding: 40px 0; }
.holes i { width: 16px; height: 16px; border-radius: 50%; background: var(--desk); box-shadow: inset 1px 2px 3px rgba(0,0,0,.6); opacity: .9; }

h1 { font-family: "Permanent Marker", cursive; font-weight: 400; font-size: 25px; line-height: 30px; margin: 0; color: #1d1d22; transform: rotate(-1deg); }
.note { margin: 0 0 4px; font-size: 19px; line-height: 30px; color: var(--pencil); }

fieldset { border: 0; margin: 0; padding: 0; }
legend { padding: 0; font-size: 21px; line-height: 30px; color: var(--pencil); float: left; width: 100%; }
.kinds label { position: relative; display: inline-block; font-size: 23px; line-height: 30px; margin: 0 10px 0 0; cursor: pointer; white-space: nowrap; }
.kinds input { position: absolute; opacity: 0; pointer-events: none; }
.kinds span { position: relative; padding: 0 4px; }
.kinds input:focus-visible + span { outline: 2px dashed var(--pen); outline-offset: 2px; }
.kinds span svg { position: absolute; left: -9px; top: -6px; width: calc(100% + 18px); height: calc(100% + 12px); overflow: visible; pointer-events: none; }
.kinds span svg path { fill: none; stroke: var(--pen); stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 400; stroke-dashoffset: 400; animation: draw .45s ease-out forwards; vector-effect: non-scaling-stroke; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.row { display: flex; align-items: baseline; gap: 6px; height: 30px; font-size: 23px; line-height: 30px; }
.row .lbl { width: 46px; color: var(--pencil); }
.row output { min-width: 34px; text-align: center; font-size: 32px; font-weight: 700; line-height: 30px; transform: rotate(-3deg); display: inline-block; }
.row output.bump { animation: bump .25s ease-out; }
@keyframes bump { 40% { transform: rotate(-3deg) scale(1.3); } }
.row .unit { color: var(--pencil); font-size: 19px; }
.row button {
  font: inherit; font-size: 24px; line-height: 1; width: 30px; height: 26px; padding: 0; align-self: center;
  color: var(--ink); background: none; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 48% 52% 45% 55% / 55% 45% 55% 45%;
  transition: transform .1s, background .15s;
}
.row button:hover { background: rgba(35,49,94,.08); transform: rotate(-6deg); }
.row button:active { transform: scale(.9); }
.row button[aria-disabled="true"] { opacity: .3; cursor: default; }
.row button[aria-disabled="true"]:hover, .row button[aria-disabled="true"]:active { background: none; transform: none; }
.row.na output, .row.na .unit { text-decoration: line-through 2px var(--pen); opacity: .55; }
.row.na::after { content: "n/a"; color: var(--pen); font-size: 20px; transform: rotate(-8deg); margin-left: -4px; }

.sum { margin: 0; font-size: 20px; line-height: 30px; color: var(--pencil); }
.hint { margin: 0; font-size: 17px; line-height: 30px; color: #a19b92; }

.sticky {
  position: absolute; right: -54px; bottom: 34px; width: 112px; height: 104px; padding: 14px 10px 0;
  font: inherit; color: #3b2d07; text-align: left; cursor: pointer; border: 0;
  background: linear-gradient(160deg, #fff59a, #fde867 60%, #f4d84a);
  transform: rotate(6deg); transform-origin: 50% 0;
  box-shadow: 0 1px 1px rgba(0,0,0,.12), 4px 10px 14px -6px rgba(40,25,0,.5);
  border-bottom-right-radius: 26px 8px;
  transition: transform .2s cubic-bezier(.3,1.6,.6,1), box-shadow .2s;
}
.sticky::before { /* tape */
  content: ""; position: absolute; top: -10px; left: 30px; width: 54px; height: 20px;
  background: rgba(255,255,255,.55); box-shadow: 0 0 1px rgba(0,0,0,.2); transform: rotate(-4deg);
}
.sticky span { display: block; font-size: 22px; line-height: 22px; }
.sticky b { display: block; font-family: "Permanent Marker", cursive; font-weight: 400; font-size: 28px; line-height: 34px; color: var(--pen); }
.sticky em { position: absolute; right: 12px; bottom: 6px; font-style: normal; font-size: 28px; }
.sticky:hover { transform: rotate(2deg) translateY(-3px); box-shadow: 0 1px 1px rgba(0,0,0,.12), 8px 18px 20px -8px rgba(40,25,0,.55); }
.sticky:active { transform: rotate(4deg) scale(.97); }
.sticky.busy { animation: wiggle .4s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(9deg); } }

.pencil { position: fixed; left: 250px; bottom: 6px; width: 260px; transform: rotate(-14deg); filter: drop-shadow(3px 7px 4px rgba(20,10,0,.45)); pointer-events: none; }

.fallback { color: var(--pen); font-size: 20px; line-height: 30px; margin: 0; }

@media (max-width: 640px), (max-height: 560px) {
  .paper { transform: rotate(-2deg) scale(.78); transform-origin: 0 100%; left: 10px; bottom: 10px; }
  .pencil { display: none; }
}
@media (max-width: 380px) {
  .paper { transform: rotate(-2deg) scale(.68); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .kinds span svg path { stroke-dashoffset: 0; }
}
