/* Tally, the helper (tally.js): the rendered calculator (art/tally.webp) at the size tally.js picks (--w, --h), alive in
   small ways (a turn toward the pointer, a sway and a breath, its moods, a tilt when carried and a bounce when dropped), its panel with
   the answers printed on a strip of calculator tape, the greeting, and the tab that brings it back. The app's tokens,
   so dark mode follows; the tape keeps its paper colour in both. */
.tally { position: fixed; right: 12px; bottom: 16px; z-index: 44; width: var(--w, 112px); height: var(--h, 140px); transition: opacity .2s, visibility .2s; }
.tally.ready { transition: right .32s cubic-bezier(.2, .7, .1, 1), bottom .32s cubic-bezier(.2, .7, .1, 1), opacity .2s, visibility .2s; }
.tally.ready.dragging { transition: opacity .2s, visibility .2s; }
/* A phone: peeking in from the right edge, its face showing; the shadow falls inward. */
.tally.peek .tally-bot { filter: drop-shadow(-6px 8px 10px rgba(13, 13, 15, .2)); }
.tally.peek .tally-bot:hover { transform: translateX(-4px); }
.tally[hidden] { display: none; }
.tally.aside { opacity: 0; visibility: hidden; pointer-events: none; }
.tally-bot { display: block; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 18px; background: none; cursor: grab; touch-action: none; -webkit-tap-highlight-color: transparent; transition: transform .2s cubic-bezier(.2, .7, .1, 1); }
.tally-bot:hover { transform: translateY(-3px); }
.tally.dragging .tally-bot { cursor: grabbing; }
.tally-bot:focus-visible { outline: 2px solid var(--act); outline-offset: 4px; }
.tally-sprite { display: block; width: 100%; height: 100%; transform: rotate(var(--tilt, 0deg)); transform-origin: 50% 92%; transition: transform .3s cubic-bezier(.2, .7, .1, 1); }
.tally.dragging .tally-sprite { transition: transform .08s linear; }

/* The render (its idle loop, or the poster): it turns toward the pointer (--ry, --rx), sways a little at rest (the loop
   breathes, blinks and looks around on its own), and moves with its mood. */
.tl-wrap { display: block; width: 100%; height: 100%; transform-origin: 50% 96%; animation: tl-idle 6s ease-in-out infinite; }
@keyframes tl-idle { 0%, 100% { transform: rotate(-.7deg); } 50% { transform: rotate(.7deg); } }
.tl-img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; transform: perspective(700px) rotateY(var(--ry, 0deg)) rotateX(var(--rx, 0deg)); transform-origin: 50% 70%; transition: transform .35s cubic-bezier(.2, .7, .1, 1); filter: drop-shadow(0 14px 16px rgba(13, 13, 15, .18)); -webkit-user-drag: none; user-select: none; pointer-events: none; }
.tally[data-mood="hello"] .tl-wrap { animation: tl-hop .8s cubic-bezier(.3, 1.4, .5, 1) 2, tl-idle 6s ease-in-out 1.6s infinite; }
@keyframes tl-hop { 0%, 100% { transform: none; } 30% { transform: translateY(-14%) scale(.97, 1.04); } 55% { transform: translateY(0) scale(1.05, .94); } 75% { transform: scale(.99, 1.02); } }
.tally[data-mood="think"] .tl-wrap { animation: none; transform: rotate(-6deg) translateY(-2%); transition: transform .3s cubic-bezier(.2, .7, .1, 1); }
.tally[data-mood="work"] .tl-wrap { animation: tl-work .18s ease-in-out infinite alternate; }
@keyframes tl-work { from { transform: rotate(-2deg) translateY(0); } to { transform: rotate(2deg) translateY(-1.5%); } }
.tally[data-mood="done"] .tl-wrap { animation: tl-nod .7s cubic-bezier(.3, 1.3, .5, 1), tl-idle 6s ease-in-out .7s infinite; }
@keyframes tl-nod { 0%, 100% { transform: none; } 35% { transform: translateY(3%) scale(1.03, .95); } 70% { transform: translateY(-2%) scale(.99, 1.02); } }
.tally.drop .tl-wrap { animation: tl-drop .55s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes tl-drop { 0% { transform: translateY(-8%) scale(1.02, .97); } 40% { transform: translateY(0) scale(1.06, .92); } 70% { transform: scale(.98, 1.03); } 100% { transform: none; } }

/* The panel: who it is, the tape, the question field, a few suggestions. */
.tally-panel { position: absolute; z-index: 1; display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 70px -28px rgba(13, 13, 15, .45), 0 2px 6px rgba(13, 13, 15, .06); overflow: hidden; transform-origin: bottom right; animation: tp-in .22s cubic-bezier(.2, .7, .1, 1); }
.tally-panel[hidden], .tally-bubble[hidden] { display: none; }
.tally-panel.below { transform-origin: top right; }
@keyframes tp-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.tp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 10px 10px 16px; }
.tp-head h2 { font: 650 17px/1.2 var(--display); letter-spacing: -.01em; }
.tp-head p { margin-top: 2px; font-size: 13px; color: var(--text-3); }
.tp-x, .tb-x { display: grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 999px; background: var(--sunk); color: var(--ink); cursor: pointer; }
.tp-x svg, .tb-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.tp-x:hover { background: var(--line); }

/* The tape: paper out of a slot, each answer a slip torn along a dotted line. */
.tp-tape { --paper: #F7F1E3; --paper-ink: #1D1712; --paper-dim: #7A7064; position: relative; flex: 1 1 auto; min-height: 64px; margin: 0 12px; padding: 2px 14px 12px; border-radius: 3px 3px 10px 10px; background: var(--paper); color: var(--paper-ink); box-shadow: inset 0 4px 0 -1px rgba(29, 23, 18, .12), 0 1px 0 rgba(29, 23, 18, .06); overflow: auto; overscroll-behavior: contain; font-variant-numeric: tabular-nums; }
.tp-slip { padding: 10px 0 12px; }
.tp-slip + .tp-slip { border-top: 1.5px dashed color-mix(in srgb, var(--paper-dim) 55%, transparent); }
.tp-slip.printing { animation: tp-feed .26s steps(6, end); }
@keyframes tp-feed { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
.tp-q { font-size: 12.5px; font-weight: 600; color: var(--paper-dim); }
.tp-q::before { content: "› "; }
.tp-a { margin-top: 4px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; }
.tp-q + .tp-a { margin-top: 3px; }
.tp-there { display: inline-flex; align-items: center; height: 32px; margin-top: 10px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--act); color: #fff; font: 650 13px var(--ui); cursor: pointer; transition: filter .15s; }
.tp-there:hover { filter: brightness(.95); }
.tp-there::after { content: "→"; margin-left: 8px; }
.tp-there[hidden] { display: none; }
/* Under an answer: its figures (two columns, a dotted rule between rows), anything to copy as it is (an address, a
   command), and its buttons (the first the way there, the rest quieter). Three dots while the answer is worked out. */
.tp-stats { display: grid; margin-top: 10px; font-size: 13px; line-height: 1.35; }
.tp-stats div { display: flex; align-items: baseline; gap: 12px; padding: 4px 0; border-bottom: 1px dotted color-mix(in srgb, var(--paper-dim) 50%, transparent); }
.tp-stats div:last-child { border-bottom: 0; }
.tp-stats dt { flex: 1 1 auto; min-width: 0; color: var(--paper-dim); }
.tp-stats dd { flex: none; max-width: 60%; font-weight: 650; text-align: right; }
.tp-code { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: rgba(29, 23, 18, .07); font: 500 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: all; user-select: all; }
.tp-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tp-acts .tp-there { margin-top: 0; }
.tp-act { display: inline-flex; align-items: center; height: 32px; padding: 0 13px; border: 1px solid color-mix(in srgb, var(--paper-ink) 24%, transparent); border-radius: 999px; background: none; color: var(--paper-ink); font: 650 13px var(--ui); cursor: pointer; transition: border-color .15s, background-color .15s; }
.tp-act:hover { border-color: var(--paper-ink); background: rgba(29, 23, 18, .05); }
.tp-stats[hidden], .tp-code[hidden], .tp-acts[hidden] { display: none; }
.tp-dots { display: flex; align-items: center; gap: 5px; height: 22px; }
.tp-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--paper-dim); animation: tp-dot 1s ease-in-out infinite; }
.tp-dots i:nth-child(2) { animation-delay: .15s; }
.tp-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tp-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-2px); } }

.tp-ask { display: flex; gap: 8px; padding: 12px 12px 8px; }
.tp-ask input { flex: 1 1 auto; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink); font: 500 15px var(--ui); outline: 0; transition: border-color .15s, box-shadow .15s; }
.tp-ask input:focus { border-color: var(--act); box-shadow: 0 0 0 3px color-mix(in srgb, var(--act) 18%, transparent); }
.tp-go { display: grid; place-items: center; flex: none; width: 44px; height: 40px; padding: 0; border: 0; border-radius: 10px; background: var(--ink); color: var(--canvas); cursor: pointer; }
.tp-go svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tp-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.tp-chip { padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 999px; background: none; font: 600 12.5px var(--ui); color: var(--text-2); cursor: pointer; transition: border-color .15s, color .15s; }
.tp-chip:hover { border-color: var(--ink); color: var(--ink); }
.tp-hide { align-self: flex-start; margin: 0 12px 12px; padding: 4px 4px; border: 0; background: none; font: 600 12px var(--ui); color: var(--text-3); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.tp-hide:hover { color: var(--ink); }

/* The greeting: one bubble, ink on paper reversed. */
.tally-bubble { position: absolute; z-index: 1; padding: 14px 16px 14px; border-radius: 16px; background: var(--ink); color: var(--canvas); box-shadow: 0 24px 50px -22px rgba(13, 13, 15, .55); animation: tp-in .26s cubic-bezier(.2, .7, .1, 1); }
.tally-bubble p { padding-right: 28px; font-size: 14px; line-height: 1.5; }
.tally-bubble .tb-x { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; background: color-mix(in srgb, var(--canvas) 14%, transparent); color: var(--canvas); }
.tb-ask { margin-top: 10px; padding: 7px 12px; border: 0; border-radius: 14px; line-height: 1.35; background: var(--act); color: #fff; font: 650 13px var(--ui); text-align: left; cursor: pointer; }
.tb-ask:hover { filter: brightness(.96); }

/* Put away: a sliver of the calculator at the right edge, its stripes showing. */
.tally-tab { position: fixed; right: 0; bottom: 140px; z-index: 44; width: 14px; height: 52px; padding: 0; border: 0; border-radius: 9px 0 0 9px; background: #EFE6D0; box-shadow: -2px 4px 14px rgba(13, 13, 15, .18), inset 1px 0 0 rgba(29, 23, 18, .12); cursor: pointer; transition: width .16s cubic-bezier(.2, .7, .1, 1), opacity .2s, visibility .2s; }
.tally-tab[hidden] { display: none; }
.tally-tab.aside { opacity: 0; visibility: hidden; pointer-events: none; }
.tally-tab span { position: absolute; left: 4px; right: 0; top: 50%; height: 9px; margin-top: -4.5px; background: linear-gradient(#F2B33D 0 33.3%, #E8742C 33.3% 66.6%, #C8402E 66.6%); }
.tally-tab:hover, .tally-tab:focus-visible { width: 20px; }
.tally-tab:focus-visible { outline: 2px solid var(--act); outline-offset: 2px; }

/* A control Tally points at in the top bar: a ring for a moment. */
.tally-here { animation: tally-ring 1.2s ease-out 2; }
@keyframes tally-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--act) 60%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }

:root[data-theme="dark"] .tl-img { filter: drop-shadow(0 14px 20px rgba(0, 0, 0, .55)); }
:root[data-theme="dark"] .tally-panel { box-shadow: 0 30px 70px -24px rgba(0, 0, 0, .85), 0 0 0 1px var(--line-2); }
:root[data-theme="dark"] .tp-tape { --paper: #EDE5D2; }
:root[data-theme="dark"] .tally-bubble { box-shadow: 0 24px 50px -18px rgba(0, 0, 0, .8); }

@media (prefers-reduced-motion: reduce) {
  .tally-panel, .tally-bubble, .tp-slip.printing, .tally-here, .tp-dots i { animation: none; }
  .tally-bot, .tally.ready, .tally-sprite, .tl-img { transition: none; }
  .tl-wrap, .tally[data-mood] .tl-wrap, .tally.drop .tl-wrap { animation: none; transform: none; }
}
@media (max-width: 640px) {
  .tally-tab { bottom: 160px; }
  .tally-tab::before { content: ""; position: absolute; inset: -10px -2px -10px -22px; }
}
@media (max-width: 980px), (pointer: coarse) {
  .tp-ask input { font-size: 16px; height: 44px; }
  .tp-go { height: 44px; }
  .tp-x { width: var(--tap, 44px); height: var(--tap, 44px); }
  .tp-chip { padding: 9px 12px; }
  .tp-there, .tp-act { height: 40px; }
}
