/* The budget table with the cell you edit in place: the Q4 marketing budget of an invented finance app (Tallyfold),
   in a card of dark glass on pure black. Each line has its name, a thin bar of what is spent and two figures: Planned,
   which you edit in place, and Left. The figures are odometers (.num > .slot > .strip): every digit is a strip 0-9 plus
   a blank in a window one digit tall. Editing lifts a field over the cell (.field) with a ring of light, the other
   lines step back, and on Enter the figures roll, the bar springs to its new share and the chip says Saved. */
:root {
  --page: #000000;              /* the page */
  --glass: #0d0e12;             /* the body of the card */
  --glass-top: #15171d;         /* the top of the card, a little lighter */
  --ink: #eceef3;               /* the words */
  --muted: #858a99;             /* the small words */
  --faint: #4d5160;             /* the column heads */
  --line: rgba(255, 255, 255, 0.06); /* hairlines */
  --accent: #8ea2ff;            /* the accent: the field, the bar, the saved check */
  --over: #ff7b6e;              /* a line over budget */
  --row: clamp(42px, 10.4vh, 58px); /* the height of a line */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
}

.wrap {
  width: min(92vw, 510px);
}

/* ---------------------------------------------------------------- the card */
.sheet {
  position: relative;
  border-radius: 20px;
  background:
    radial-gradient(120% 70% at 20% -10%, rgba(142, 162, 255, 0.11), transparent 60%),
    linear-gradient(180deg, var(--glass-top), var(--glass) 46%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.09),
    0 1px 1px rgba(0, 0, 0, 0.6),
    0 24px 60px -20px rgba(0, 0, 0, 0.9),
    0 50px 120px -40px rgba(80, 96, 190, 0.28);
  opacity: 0;
  isolation: isolate;
}

/* the light that follows the pointer, inside the card */
.sheet__light {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(260px circle at var(--mx, 30%) var(--my, -10%), rgba(142, 162, 255, 0.08), transparent 70%);
  z-index: 0;
}

/* the one pixel edge that catches the same light */
.sheet__rim {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  padding: 1px;
  background: radial-gradient(220px circle at var(--mx, 30%) var(--my, -10%), rgba(190, 202, 255, 0.55), rgba(255, 255, 255, 0.05) 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  z-index: 3;
}

.sheet__body {
  position: relative;
  z-index: 1;
  padding: clamp(14px, 3.4vh, 22px) clamp(14px, 4.4vw, 22px) clamp(10px, 2.6vh, 16px);
}

/* ---------------------------------------------------------------- the head */
.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: clamp(8px, 2.4vh, 16px);
}

.head__title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.head__name {
  font-size: clamp(15px, 4.2vw, 17px);
  font-weight: 620;
  font-variation-settings: 'wdth' 106;
  letter-spacing: 0.005em;
}

.head__sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}

.chip__icon {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  flex: none;
}

.chip__icon svg {
  width: 14px;
  height: 14px;
  display: block;
  overflow: visible;
}

.chip__word {
  display: inline-block;
}

.chip.is-saved {
  color: #c9d2ff;
}

/* ---------------------------------------------------------------- the grid */
.cols,
.row,
.total {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(88px, 26vw, 112px) clamp(64px, 19vw, 96px);
  align-items: center;
  column-gap: 6px;
}

.cols {
  height: 24px;
  padding: 0 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
}

.cols__n {
  text-align: right;
}

.cols__n:nth-child(2) {
  padding-right: 10px;
}

.rows {
  position: relative;
}

.row {
  position: relative;
  height: var(--row);
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  border-radius: 10px;
}

/* the lift of the line: a layer of its own so GSAP can fade it */
.row__lift {
  position: absolute;
  inset: 2px 0;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), 0 10px 24px -14px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
}

.row.is-hover .row__lift {
  opacity: 0.7;
}

@media (hover: hover) {
  .row:hover .row__lift {
    opacity: 0.7;
  }
}

.row__lift,
.row .cell__pen,
.row .cell__btn {
  transition: opacity 0.25s ease, color 0.25s ease, background-color 0.25s ease;
}

.row__line {
  position: relative;
  width: 100%;
  padding-right: 6px;
  display: grid;
  gap: 5px;
  min-width: 0;
}

.row__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.row__name {
  font-size: clamp(13px, 3.7vw, 14.5px);
  font-weight: 540;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__pct {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  transition: color 0.4s ease;
}

.row.is-over .row__pct {
  color: var(--over);
}

.row__spent {
  font-size: 10.5px;
  color: var(--faint);
  white-space: nowrap;
}

.bar {
  position: relative;
  display: block;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

/* GSAP scales this one; the colour lives on its child */
.bar__fill {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.bar__paint {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(142, 162, 255, 0.45), var(--accent));
  transition: background 0.5s ease;
}

.row.is-over .bar__paint {
  background: linear-gradient(90deg, rgba(255, 123, 110, 0.5), var(--over));
}

/* the shine that runs along the bar when it changes */
.bar__shine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  opacity: 0;
}

/* ---------------------------------------------------------------- the cells */
.cell {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.cell--left {
  color: var(--muted);
  font-size: clamp(13px, 3.7vw, 14.5px);
  transition: color 0.4s ease;
}

.row.is-over .cell--left {
  color: var(--over);
}

.cell__btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
  height: calc(var(--row) - 14px);
  padding: 0 10px;
  margin: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: clamp(13px, 3.7vw, 14.5px);
  font-weight: 560;
  cursor: text;
  -webkit-tap-highlight-color: transparent;
}

.cell__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* GSAP presses this one */
.cell__face {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cell__pen {
  position: absolute;
  left: 9px;
  top: 50%;
  margin-top: -6px;
  width: 12px;
  height: 12px;
  color: var(--accent);
  opacity: 0;
}

.row.is-hover .cell__btn {
  background: rgba(255, 255, 255, 0.04);
}

.row.is-hover .cell__pen {
  opacity: 0.9;
}

@media (hover: hover) {
  .cell__btn:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .cell__btn:hover .cell__pen {
    opacity: 0.9;
  }
}

/* the flash that crosses the cell when the new figure lands */
.cell__flash {
  position: absolute;
  inset: 7px 0;
  border-radius: 9px;
  background: radial-gradient(80% 140% at 80% 50%, rgba(142, 162, 255, 0.35), transparent 70%);
  opacity: 0;
  pointer-events: none;
}

/* the field that rises over the cell while editing */
.field {
  position: absolute;
  inset: 5px -2px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #1c1f2a, #151822);
  box-shadow:
    inset 0 0 0 1px rgba(142, 162, 255, 0.85),
    0 0 0 4px rgba(142, 162, 255, 0.16),
    0 0 24px rgba(142, 162, 255, 0.28),
    0 14px 26px -12px rgba(0, 0, 0, 0.9);
  font-size: clamp(14px, 3.9vw, 15.5px);
  font-weight: 600;
  color: #ffffff;
  opacity: 0;
  visibility: hidden;
  z-index: 2;
  pointer-events: none;
}

.field__text {
  position: relative;
  white-space: pre;
}

/* the selection when the field opens: the whole figure is chosen, the first key replaces it */
.field__sel {
  position: absolute;
  inset: -2px -3px;
  border-radius: 4px;
  background: rgba(142, 162, 255, 0.38);
  opacity: 0;
}

.field__caret {
  width: 1.5px;
  height: 1.1em;
  margin-left: 2px;
  border-radius: 1px;
  background: var(--accent);
}

/* the real input: invisible, it only catches the keys */
.field__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;
  pointer-events: none;
}

.row.is-editing {
  z-index: 2;
}

/* ---------------------------------------------------------------- the odometer */
.num {
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
  height: 1.2em;
  overflow: hidden;
  white-space: pre;
}

.slot {
  display: inline-block;
  height: 1.2em;
  overflow: hidden;
  flex: none;
}

.strip {
  display: block;
}

.strip span {
  display: block;
  height: 1.2em;
  text-align: center;
}

.sym {
  display: inline-block;
  flex: none;
}

/* ---------------------------------------------------------------- the total */
.total {
  height: clamp(40px, 9vh, 50px);
  padding: 0 10px;
  font-weight: 620;
  font-size: clamp(13px, 3.7vw, 14.5px);
}

.total__name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.total__meta {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.total__n {
  display: flex;
  justify-content: flex-end;
}

.total__n:nth-child(2) {
  padding-right: 10px;
}

.total.is-over .total__n:nth-child(3) {
  color: var(--over);
}

@media (max-width: 360px) {
  .row__spent {
    display: none;
  }
}
