@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/courier-prime-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #edf3e4;
  --paper-deep: #dfe9d2;
  --rule: #a9c29c;
  --ink: #17254a;
  --ink-soft: #4c5878;
  --margin: #e28a9a;
  --stamp: #b8242f;
  --back: #2c6a4c;
  --line: 2.75rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.45 "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  min-height: 100dvh;
}

main {
  position: relative;
  max-width: 38rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 2rem) 1.25rem calc(env(safe-area-inset-bottom) + 6rem) 2.5rem;
}

/* the ledger's red margin line */
main::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 1.25rem;
  width: 2px;
  background: var(--margin);
  opacity: .8;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 11vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: .95;
}

#tally {
  margin: .5rem 0 0;
  color: var(--ink-soft);
}

/* ---- the entry sentence ---- */
#lend {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .35rem .6rem;
  margin: 2.25rem 0 2.5rem;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#lend input {
  flex: 1 1 9rem;
  min-width: 0;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  padding: .1rem .1rem .15rem;
  height: 2.4rem;
}
#lend input::placeholder { color: var(--ink-soft); opacity: .55; }
#lend #who { flex-basis: 6rem; }
#lend #when { flex: 0 1 11rem; font-size: 1.125rem; }

#lend button {
  flex: 1 1 100%;
  margin-top: 1rem;
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  padding: .8rem 1.2rem;
  cursor: pointer;
}
#lend button:active { transform: translateY(1px); }

/* ---- lists ---- */
h2, summary {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  padding-bottom: .4rem;
  border-bottom: 2px solid var(--ink);
}

ul { list-style: none; margin: 0; padding: 0; }

li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .1rem 1rem;
  align-items: center;
  padding: .8rem 0 .7rem;
  border-bottom: 1px solid var(--rule);
}

.what {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.since { color: var(--ink-soft); grid-column: 1; }
.long .since { color: var(--stamp); font-weight: 600; }

.stamp {
  grid-column: 2;
  grid-row: 1 / span 2;
  font: 700 .875rem/1 "Courier Prime", ui-monospace, monospace;
  letter-spacing: .04em;
  white-space: nowrap;
  color: var(--stamp);
  border: 2px solid currentColor;
  border-radius: 3px;
  padding: .4rem .5rem .3rem;
  text-align: center;
  transform: rotate(var(--tilt, -3deg));
  opacity: .88;
  mix-blend-mode: multiply;
}
.stamp small { display: block; font-size: .6875rem; margin-bottom: .2rem; letter-spacing: .12em; }
#back .stamp { color: var(--back); }
#back .what { font-weight: 500; text-decoration: line-through; text-decoration-thickness: 1px; }

.fresh .stamp { animation: thump .32s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes thump {
  from { transform: rotate(var(--tilt, -3deg)) scale(2.2); opacity: 0; }
  to   { transform: rotate(var(--tilt, -3deg)) scale(1); opacity: .88; }
}

.acts {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.25rem;
  margin-top: .3rem;
}
.acts button, .tools button, #toast button {
  font: inherit;
  font-size: .9375rem;
  color: var(--ink);
  background: none;
  border: 0;
  padding: .45rem 0;
  min-height: 2.25rem;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-decoration-thickness: 2px;
  text-underline-offset: .2em;
  cursor: pointer;
}
.acts button:first-child { font-weight: 700; text-decoration-color: var(--ink); }
.acts .quiet { color: var(--ink-soft); margin-left: auto; }

#empty { color: var(--ink-soft); padding: 1.25rem 0; margin: 0; max-width: 28rem; }

details { margin-top: 2.5rem; }
summary { cursor: pointer; color: var(--ink-soft); border-bottom-color: var(--rule); }

footer {
  margin-top: 3.5rem;
  color: var(--ink-soft);
  font-size: .9375rem;
}
footer p { margin: 0; }
.tools { display: flex; flex-wrap: wrap; gap: 0 1.25rem; margin-top: .25rem; }

/* ---- toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 1rem);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  background: var(--ink);
  color: var(--paper);
  padding: .35rem 1rem;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgb(23 37 74 / .3);
}
#toast[hidden] { display: none; }
#toast button { color: var(--paper); font-weight: 700; text-decoration-color: var(--margin); }
#toast-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .45rem 0; }

:focus-visible { outline: 3px solid var(--stamp); outline-offset: 3px; border-radius: 2px; }

@media (prefers-reduced-motion: reduce) {
  .fresh .stamp { animation: none; }
}
