/* Crayon scrapbook skin. Self-hosted fonts so the installed app works offline. */
@font-face {
  font-family: "Gochi Hand";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/gochi-hand-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Patrick Hand";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/patrick-hand-latin.woff2") format("woff2");
}

:root {
  --paper: #fdf7e6;
  --paper2: #fffdf5;
  --ink: #2b2b2b;
  --muted: #6b6b6b;
  --faint: #9a8f7a;
  --red: #e63946;
  --blue: #3a86ff;
  --yellow: #ffd23f;
  --green: #43aa8b;
  --wobble-a: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobble-b: 225px 15px 255px 15px / 15px 255px 15px 225px;
  --lift: 3px 4px 0 var(--ink);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Patrick Hand", system-ui, sans-serif;
  color: var(--ink);
  background: #e7dfcb;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }

.shell {
  position: relative;
  max-width: 460px;
  min-height: 100dvh;
  margin: 0 auto;
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.05'/%3E%3C/svg%3E"),
    repeating-linear-gradient(0deg, transparent 0 26px, rgba(58, 134, 255, .11) 26px 27px),
    repeating-linear-gradient(90deg, transparent 0 26px, rgba(58, 134, 255, .11) 26px 27px);
}
@media (min-width: 520px) {
  .shell { box-shadow: 0 24px 60px -28px rgba(43, 43, 43, .6); }
}

.screen { padding: 14px 16px calc(28px + var(--safe-bottom)) 16px; min-height: 100dvh; }

/* The bottom tab row needs clearance. On wider screens the tabs move out into
   the letterbox beside the shell, so no extra room is needed. */
.screen.with-tabs { padding-bottom: calc(112px + var(--safe-bottom)); }
@media (min-width: 600px) {
  .screen.with-tabs { padding-bottom: calc(28px + var(--safe-bottom)); }
}

/* The jar view is sized to sit inside a phone screen rather than scroll: the
   jar takes whatever height is left once the words and controls have theirs,
   capped by the window height. The log keeps its own scrolling. */
.screen.fit {
  display: flex;
  flex-direction: column;
  padding-bottom: calc(66px + var(--safe-bottom));
}
.screen.fit .jar-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}
.screen.fit .jar-actions { margin-top: 14px; }
.screen.fit .jar-actions .btn { padding: 14px; }
/* Width is set from the measured leftover space in fitJar(); this is only the
   starting point before scripts run. */
.screen.fit .jar {
  margin: 0;
  width: min(280px, 100%, max(130px, calc((100svh - 398px) * 240 / 340)));
}

/* ------------------------------ type ------------------------------ */
h1.headline {
  font-family: "Gochi Hand", cursive;
  font-size: 30px;
  line-height: 1.05;
  margin: 0;
  color: var(--red);
  text-shadow: 2px 2px 0 var(--yellow);
}
h1.headline small {
  display: block;
  font-family: "Patrick Hand", sans-serif;
  font-size: 14px;
  color: var(--ink);
  text-shadow: none;
  margin-top: 3px;
  line-height: 1.25;
}
/* The jar screen carries one of the quips rather than the app name, so it gets
   a size that keeps a 51-character line to three lines above the jar. */
h1.headline.sized { font-size: 21px; }

/* Total and the "since" line share a row, so the jar keeps the vertical space. */
.totalrow {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
  margin-top: 4px;
}
.totalrow .total { margin: 0; }
.totalrow .soft { margin: 0; font-size: 13px; }
.kicker {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0;
}
.soft { color: var(--muted); font-size: 14px; margin: 0; }
.faint { color: var(--faint); font-size: 13px; margin: 0; }

/* ----------------------------- pieces ----------------------------- */
.card {
  background: var(--paper2);
  border: 3px solid var(--ink);
  border-radius: var(--wobble-a);
  box-shadow: var(--lift);
  padding: 14px;
  position: relative;
}
.card + .card { margin-top: 16px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 17px 14px;
  background: var(--red);
  color: var(--paper2);
  font-family: "Gochi Hand", cursive;
  font-size: 26px;
  border: 3px solid var(--ink);
  border-radius: var(--wobble-b);
  box-shadow: var(--lift);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translate(3px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn.lite { background: var(--paper2); color: var(--ink); font-size: 19px; }
.btn.tiny { font-size: 16px; padding: 11px 12px; box-shadow: 2px 3px 0 var(--ink); }
.btn.danger { background: var(--paper2); color: var(--red); }
.btn[disabled] { opacity: .55; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 6px;
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: 99px;
  font-size: 15px;
  box-shadow: 2px 2px 0 rgba(43, 43, 43, .7);
}
.chip b { font-weight: 400; text-decoration: underline dotted; }
.av {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  display: grid; place-items: center;
  font-family: "Gochi Hand", cursive;
  font-size: 14px;
  color: #fff;
  flex: 0 0 auto;
}
.mini {
  font-size: 12px;
  padding: 3px 9px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: #fff;
}
.rule { height: 0; border-top: 2px dashed rgba(43, 43, 43, .28); margin: 12px 0; }

/* ------------------------------ tabs ------------------------------ */
.tabs {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 6;
  display: flex;
  gap: 8px;
}
.tab {
  flex: 1 1 0;
  background: var(--paper2);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 10px 8px;
  font-family: "Gochi Hand", cursive;
  font-size: 16px;
  text-align: center;
  box-shadow: 3px 3px 0 rgba(43, 43, 43, .75);
  transition: transform .12s;
}
.tab[aria-current="page"] { background: var(--yellow); transform: translateY(-3px); }

/* Wide enough for a letterbox beside the shell: hang the notebook tabs off the
   right edge there, in the margin, where they cost the content nothing. */
@media (min-width: 600px) {
  .tabs {
    left: auto;
    right: max(6px, calc(50vw - 300px));
    bottom: auto;
    top: 96px;
    display: grid;
    gap: 9px;
  }
  .tab {
    flex: 0 0 auto;
    border-right: 0;
    border-radius: 14px 0 0 14px;
    padding: 11px 13px 11px 15px;
    text-align: left;
    box-shadow: -2px 2px 0 rgba(43, 43, 43, .75);
    transform: translateX(4px);
  }
  .tab[aria-current="page"] { transform: translateX(-4px); }
}

/* ------------------------------ the jar ------------------------------ */
.total {
  font-family: "Gochi Hand", cursive;
  font-size: 52px;
  line-height: .95;
  color: var(--blue);
  margin: 4px 0 0;
}
.jar-wrap { text-align: center; }
.jar {
  position: relative;
  width: min(280px, 84%);
  margin: 2px auto 0;
  aspect-ratio: 240 / 340;
}
.jar canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.jar svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.jar .jarline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.jar-more {
  position: absolute;
  left: 50%;
  top: 39%;
  transform: translateX(-50%);
  font-family: "Gochi Hand", cursive;
  font-size: 17px;
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: 99px;
  padding: 2px 10px;
  box-shadow: 2px 2px 0 rgba(43, 43, 43, .6);
}

/* ------------------------------ log ------------------------------ */
.daytag { font-family: "Gochi Hand", cursive; font-size: 16px; color: var(--faint); margin: 14px 0 2px; }
.daytag:first-child { margin-top: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 2px dashed rgba(43, 43, 43, .18);
}
.row:last-child { border-bottom: 0; }
.row .who { font-family: "Gochi Hand", cursive; font-size: 18px; }
.row .what { font-size: 15px; color: var(--muted); }
.row .when { font-size: 12.5px; color: var(--faint); white-space: nowrap; }
.row .end { text-align: right; flex: 0 0 auto; }
.empty { color: var(--faint); font-size: 15px; text-align: center; padding: 18px 0; }

/* ----------------------------- setup ----------------------------- */
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 0;
  border-bottom: 2px dashed rgba(43, 43, 43, .18);
}
.field:last-child { border-bottom: 0; }
.field .lab { flex: 1 1 auto; min-width: 0; font-size: 16px; }
.field .val {
  font-family: "Gochi Hand", cursive;
  font-size: 19px;
  color: var(--blue);
  border-bottom: 2px dashed rgba(58, 134, 255, .5);
  min-width: 52px;
  text-align: right;
  padding: 2px;
}
/* Grows into whatever room is left, and drops to its own full-width line
   rather than clipping the placeholder on a narrow phone. */
.field input.val {
  flex: 1 1 150px;
  width: auto;
  min-width: 0;
  outline: none;
  border: 0;
  border-bottom: 2px solid var(--blue);
  background: none;
}
.money-in {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  flex: 0 1 auto;
  border-bottom: 2px solid var(--blue);
  padding: 2px 2px 1px;
}
.money-in b { font-family: "Gochi Hand", cursive; font-size: 19px; color: var(--blue); font-weight: 400; }
/* left-aligned so the $ sits flush against the number instead of drifting */
.money-in input.val { flex: 0 1 auto; width: 2.6em; text-align: left; border-bottom: 0; padding: 0; }
/* native number spinners crowd the $ and look nothing like a crayon */
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field .aside { text-align: right; max-width: 55%; }
.btn svg { flex: 0 0 auto; }

/* ---------------------------- welcome ---------------------------- */
.welcome { display: grid; gap: 18px; align-content: start; padding-top: 8vh; }
.welcome .jar { width: min(220px, 62%); }
.choices { display: grid; gap: 14px; }

/* ----------------------------- toast ----------------------------- */
.toast {
  position: fixed;
  /* Both edges plus auto margins: shrink-to-fit, centred, and able to use the
     full width. Anchoring at left:50% caps it at half the viewport. */
  left: 16px;
  right: 16px;
  bottom: calc(18px + var(--safe-bottom));
  margin: 0 auto;
  width: fit-content;
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  background: rgba(16, 16, 22, .94);
  color: #fff;
  border-radius: 14px;
  padding: 11px 14px;
  font: 400 14px/1.35 ui-sans-serif, system-ui, sans-serif;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast button { color: #7ee0c0; font-weight: 650; font-size: 14px; white-space: nowrap; }
/* [hidden] is a UA rule and loses to display:flex above, so an empty toast
   would stay on screen as a black blob after its message timed out. */
.toast[hidden] { display: none; }
/* Only rendered when there is something to say (offline, pending), and shaped
   like a status pill so it can't be mistaken for the jar total. */
.sync {
  display: inline-block;
  margin: 8px 0 0;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--faint);
  background: rgba(255, 255, 255, .75);
  border: 1.5px dashed rgba(43, 43, 43, .25);
  border-radius: 99px;
}
.sync[hidden] { display: none; }

/* Who-is-adding sheet, anchored above the Add button. */
.whopop {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 138px;
  padding: 8px;
  display: grid;
  gap: 4px;
  z-index: 9;
}
.whopop button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 12px;
  font-size: 16px;
  text-align: left;
}
.whopop button:hover { background: rgba(58, 134, 255, .1); }

/* Inline edit: input plus its own save/cancel, because a phone keypad has no
   Enter key to submit with. */
.editrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 auto;
  justify-content: flex-end;
}
.editrow input.val { flex: 1 1 80px; min-width: 0; }
.iconbtn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: var(--paper2);
  display: grid;
  place-items: center;
  box-shadow: 2px 2px 0 rgba(43, 43, 43, .7);
}
.iconbtn.save { background: var(--green); color: #fff; }
.iconbtn:active { transform: translate(2px, 2px); box-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  .btn, .tab { transition: none; }
}
