/* Day 2/30 - How long till payday
   Visual world: a thermal receipt printed by a POS terminal, lying on a dark counter.
   The total on the bill is time, not money, and it prints in ink that heats up
   from green to red as payday gets closer.
   Shape rule: paper has no corner radius. Nothing on the receipt is a card. */

:root {
  --counter:     #14120F;
  --counter-lit: #241E19;

  --paper:       #f3ede1;
  --paper-shade: #e6dfd0;
  --ink:         #241f19;
  --ink-soft:    #6b6055;
  --label:       #8c8072;

  /* Thermal ink ramp: calm to tense. Every step sits above 5:1 on the paper,
     so the shift reads as hue alone, never as the text getting harder to read. */
  --accent:      #14724a;

  --roll:        320ms;
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --tint:        600ms;
}

[data-band="far"]      { --accent: #14724a; }
[data-band="twoweek"]  { --accent: #3f6f16; }
[data-band="week"]     { --accent: #6a6109; }
[data-band="close"]    { --accent: #8a550c; }
[data-band="tomorrow"] { --accent: #a2430c; }
[data-band="hours"]    { --accent: #b33410; }
[data-band="minutes"]  { --accent: #c0261b; }
[data-band="today"]    { --accent: #14724a; }
[data-band="fresh"]    { --accent: #14724a; }
[data-band="gone"]     { --accent: #52493c; }
[data-band="none"]     { --accent: #52493c; }

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 3.25rem;
  background:
    radial-gradient(115% 70% at 50% 20%, var(--counter-lit) 0%, var(--counter) 62%);
  font-family: "Courier Prime", ui-monospace, "Courier New", monospace;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- the paper ---------- */

/* The wrapper carries the shadow and the print reveal; the mask lives on the
   paper itself, and drop-shadow follows the torn silhouette instead of a box. */
.receipt {
  margin: auto;
  width: min(23.5rem, 93vw);
  filter:
    drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45))
    drop-shadow(0 22px 34px rgba(0, 0, 0, 0.55));
  animation: print 900ms var(--ease-out) both;
}

@keyframes print {
  from { clip-path: inset(0 0 100% 0); transform: translateY(-10px); }
  to   { clip-path: inset(0 0 0 0);    transform: none; }
}

.paper {
  --tooth: 11px;
  position: relative;
  padding: calc(var(--tooth) + 1.35rem) 1.35rem calc(var(--tooth) + 1.35rem);
  background:
    linear-gradient(180deg, var(--paper) 0%, var(--paper) 88%, var(--paper-shade) 100%);
  color-scheme: light;

  -webkit-mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% 0   / var(--tooth) var(--tooth) repeat-x,
    conic-gradient(from 135deg at top,    #0000, #000 1deg 89deg, #0000 90deg) 50% 100% / var(--tooth) var(--tooth) repeat-x,
    linear-gradient(#000 0 0) 50% 50% / 100% calc(100% - 2 * var(--tooth)) no-repeat;
  mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% 0   / var(--tooth) var(--tooth) repeat-x,
    conic-gradient(from 135deg at top,    #0000, #000 1deg 89deg, #0000 90deg) 50% 100% / var(--tooth) var(--tooth) repeat-x,
    linear-gradient(#000 0 0) 50% 50% / 100% calc(100% - 2 * var(--tooth)) no-repeat;
}

/* Faint horizontal banding, the way a thermal head lays ink down unevenly. */
.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(36, 31, 25, 0.032) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: multiply;
}

/* ---------- printed text ---------- */

.head { text-align: center; }

.head h1 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.tagline {
  margin: 0.4rem 0 0;
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.line {
  display: flex;
  align-items: center;
  gap: 0.7ch;
  margin: 0;
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.leader {
  flex: 1 1 auto;
  height: 0;
  margin-top: 0.4em;
  border-bottom: 1px dotted var(--ink-soft);
  opacity: 0.6;
}

.meta {
  margin-top: 0.95rem;
  color: var(--ink-soft);
}

.rule {
  height: 0;
  margin: 0.85rem 0;
  border: 0;
  border-top: 1px dashed rgba(36, 31, 25, 0.4);
}

/* ---------- the total ---------- */

.count { text-align: center; }

.count-label {
  margin: 0.35rem 0 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.days {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1.1ch;
  margin: 0;
  color: var(--accent);
  transition: color var(--tint) ease;
}

.days .unit {
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hms {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin: 0.55rem 0 0;
  color: var(--ink);
}

/* Each unit owns its own column so the caption always sits dead centre
   under its two digits, whatever the font does. */
.col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.cap {
  font-size: 0.6875rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.colon {
  display: flex;
  align-items: center;
  height: 1.14em;
  padding-inline: 0.3ch;
  font-family: "Martian Mono", ui-monospace, monospace;
  font-size: clamp(1.5rem, 7.4vw, 1.95rem);
  opacity: 0.42;
}

/* ---------- the odometer ---------- */

.reels {
  --dh: 1.14em;
  display: inline-flex;
  gap: 0.06em;
  font-family: "Martian Mono", ui-monospace, monospace;
  font-size: clamp(1.5rem, 7.4vw, 1.95rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.reels-lg {
  font-size: clamp(3.5rem, 19vw, 4.5rem);
  font-weight: 800;
}

/* The counter is sized against the paper, not the viewport, so a date years out
   sets three or four digits without ever reaching the tear line. */
@supports (container-type: inline-size) {
  .paper { container-type: inline-size; }
  .reels-lg { font-size: clamp(2rem, calc(76cqw / max(var(--n, 2), 2)), 4.5rem); }
}

.reel {
  display: inline-block;
  height: var(--dh);
  width: 1ch;
  overflow: hidden;
}

.strip {
  display: block;
  transform: translateY(calc(var(--i, 0) * -1 * var(--dh)));
  transition: transform var(--roll) var(--ease-out);
}

.strip > span {
  display: block;
  height: var(--dh);
  line-height: var(--dh);
  text-align: center;
}

.reel.instant .strip { transition: none; }

/* ---------- the stamp ---------- */

.stamp {
  max-width: 17.5rem;
  margin: 1.15rem auto 0.15rem;
  padding: 0.7rem 0.85rem 0.75rem;
  border: 2px solid currentColor;
  outline: 1px solid currentColor;
  outline-offset: 3px;
  text-align: center;
  color: var(--accent);
  transform: rotate(-1.6deg);
  transition: color var(--tint) ease, opacity 180ms ease, filter 180ms ease, transform 180ms ease;
}

.stamp.swap {
  opacity: 0;
  filter: blur(3px);
  transform: rotate(-1.6deg) translateY(4px);
}

.stamp-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.25;
  text-transform: uppercase;
}

.stamp-sub {
  margin: 0.45rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
}

/* ---------- the editable line ---------- */

.field { margin-top: 0.1rem; }

.field label {
  font-weight: 700;
  cursor: pointer;
}

/* A blank on the form, printed with the rest of the receipt and clearly
   waiting to be filled in. */
.field input {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 0.5rem;
  border: 1px dashed var(--ink-soft);
  border-radius: 0;
  background: rgba(36, 31, 25, 0.035);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.field input::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }
.field input:hover { background: rgba(36, 31, 25, 0.08); border-color: var(--ink); }
.field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}

.help {
  margin: 0.55rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

.help.warn { color: #b33410; font-weight: 700; }

/* ---------- the tail ---------- */

.foot {
  margin-top: 0.95rem;
  text-align: center;
  color: var(--ink-soft);
}

.foot p {
  margin: 0 0 0.3rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Encodes the payday date, so it redraws whenever the date changes. */
.barcode {
  height: 30px;
  width: 84%;
  margin: 0.7rem auto 0.4rem;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.barcode-no {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--ink);
}

/* ---------- the one consistent thread across all 30 days ---------- */

.day {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(0.9rem, env(safe-area-inset-bottom));
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--label);
  user-select: none;
}

/* ---------- larger screens ---------- */

@media (min-width: 30rem) {
  .paper { padding-inline: 1.75rem; }
  .head h1 { font-size: 1.1875rem; }
}

/* ---------- reduced motion ---------- */

/* The digits changing is the function; the roll and the print-out are not.
   Both drop out, the countdown keeps working. */
@media (prefers-reduced-motion: reduce) {
  .receipt { animation: none; }
  .strip { transition: none; }
  .stamp { transition: color var(--tint) ease; }
  .stamp.swap { opacity: 1; filter: none; transform: rotate(-1.6deg); }
}
