/* ==========================================================================
   Kvitto: the bar counter after dinner. Dark stained wood, pale pulp-board
   beer coasters with a printed red ring, blue ballpoint tallies.
   ========================================================================== */

:root {
  --wood: #24160f;
  --wood-2: #2f1d14;
  --wood-3: #3b261a;
  --line: #4d3424;
  --text: #f1e6d6;
  --text-2: #c9b49c;          /* 7.2:1 on wood */
  --board: #efe7d8;           /* coaster pulp board */
  --board-2: #e2d7c3;
  --print: #b8322a;           /* printed coaster ring */
  --ink: #1f3e9c;             /* ballpoint */
  --ink-2: #4c4032;           /* 8.3:1 on board */
  --brass: #d9a54a;
  --hand: "Kalam", "Comic Sans MS", cursive;
  --font: "Barlow Semi Condensed", system-ui, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line) var(--wood); }
body {
  margin: 0; min-height: 100vh; color: var(--text); font: 400 1.05rem/1.5 var(--font);
  background-color: var(--wood);
  background-image:
    repeating-linear-gradient(90deg, rgb(0 0 0 / .12) 0 2px, transparent 2px 38px),
    linear-gradient(90deg, rgb(255 220 180 / .03), transparent 40%, rgb(255 220 180 / .04) 70%, transparent);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--brass); color: var(--wood); }
h1, h2, p, ul, ol, dl, dd, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top, .bar, .foot { width: min(100% - 2rem, 76rem); margin-inline: auto; }
.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem 1.5rem; padding-top: clamp(1.25rem, 4vw, 2.5rem); }
.top h1 { font: 700 clamp(2.6rem, 8vw, 4.6rem)/1 var(--hand); color: var(--board); rotate: -2deg; }
.top p { color: var(--text-2); font-size: 1.1rem; }

.bar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: clamp(2rem, 5vw, 4rem); align-items: start; margin-top: clamp(1.5rem, 4vw, 2.5rem); }
@media (max-width: 58rem) { .bar { grid-template-columns: minmax(0, 1fr); } }

/* ---------- The bill (left) ---------- */
.bill { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.4rem; background: var(--wood-2); border: 1px solid var(--line); border-radius: 10px; padding: clamp(1rem, 3vw, 1.6rem); box-shadow: 0 24px 40px -28px rgb(0 0 0 / .9); }
.bill h2 { font: 700 1.8rem/1 var(--hand); color: var(--board); }
.label, label, legend { font-size: .8rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-2); }

.people { display: grid; gap: .55rem; }
.people-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.people-list li { display: inline-flex; align-items: center; gap: .2rem; padding: .25rem .3rem .25rem .75rem; border-radius: 999px; background: var(--wood-3); font-weight: 600; }
.x { width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 0; background: transparent; color: var(--text-2); font-size: 1.1rem; line-height: 1; }
.x:hover { background: var(--line); color: var(--text); }
.x:disabled { visibility: hidden; }

form { display: flex; gap: .45rem; }
input, select {
  min-width: 0; min-height: 2.75rem; padding: .5rem .75rem; border-radius: 6px;
  background: var(--board); color: #2a2018; border: 2px solid transparent;
}
input::placeholder { color: #6b5d4c; }
input:focus, select:focus { outline: none; border-color: var(--brass); }
.add-person input { flex: 1; }
.add-item input:first-of-type { flex: 1 1 auto; }
.add-item input:nth-of-type(2) { width: 6rem; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
form button { min-height: 2.75rem; padding: 0 1rem; border: 0; border-radius: 6px; background: var(--brass); color: #2a1a0c; font-weight: 700; }
form button:hover { filter: brightness(1.08); }
.err { color: #ffb38a; font-size: .95rem; min-height: 0; }
.err:empty { display: none; }

.items { display: grid; }
.item { padding: .8rem 0; border-top: 1px dashed var(--line); display: grid; gap: .45rem; }
.item:last-child { border-bottom: 1px dashed var(--line); }
.item-row { display: flex; align-items: baseline; gap: .5rem; }
.item-name { font-weight: 600; font-size: 1.1rem; }
.lead { flex: 1; border-bottom: 2px dotted var(--line); translate: 0 -.3em; }
.item-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { min-height: 2.2rem; padding: .2rem .7rem; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text-2); font-weight: 500; }
.chip:hover { border-color: var(--text-2); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--board); color: var(--ink); border-color: var(--board); font-weight: 700; }
.chip.all { border-style: dashed; }
.each { font-size: .9rem; color: var(--text-2); }
.item.orphan .each { color: #ffb38a; }

.settings { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: end; }
.field { display: grid; gap: .4rem; }
.tips { display: flex; gap: .3rem; }
.tips button { min-height: 2.6rem; padding: 0 .85rem; border-radius: 6px; border: 1px solid var(--line); background: transparent; font-weight: 600; }
.tips button:hover { background: var(--wood-3); }
.tips button[aria-checked="true"] { background: var(--board); color: #2a2018; border-color: var(--board); }

.tally { display: grid; gap: .2rem; padding-top: .4rem; font-variant-numeric: tabular-nums; }
.tally div { display: flex; justify-content: space-between; gap: 1rem; color: var(--text-2); }
.tally .sum { color: var(--text); font-weight: 700; font-size: 1.3rem; padding-top: .45rem; margin-top: .3rem; border-top: 2px solid var(--line); }
.tally .note { font-size: .92rem; }
.tally .warn { color: #ffb38a; }

/* ---------- Coasters (right) ---------- */
.coasters { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5rem), 1fr)); gap: clamp(1rem, 3vw, 1.8rem); }
.coaster {
  position: relative; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-content: center; justify-items: center; gap: .1rem; text-align: center; padding: 1.4rem;
  background:
    radial-gradient(circle at 50% 50%, transparent 64%, var(--print) 64.5% 67%, transparent 67.5%),
    radial-gradient(circle at 35% 30%, #f7f1e6, var(--board) 45%, var(--board-2));
  color: var(--ink-2);
  rotate: var(--tilt);
  box-shadow: 0 2px 0 #cbbfa9, 0 14px 22px -10px rgb(0 0 0 / .75);
  transition: rotate .4s cubic-bezier(.16, 1, .3, 1);
}
.coaster:hover { rotate: 0deg; }
.coaster::before { /* faint water ring from a glass */
  content: ""; position: absolute; inset: 18% 22% 26% 16%; border-radius: 50%;
  box-shadow: inset 0 0 0 3px rgb(120 90 50 / .09); pointer-events: none;
}
.c-name { font: 700 1.35rem/1.1 var(--hand); color: var(--ink); }
.c-tally { font: 700 1.3rem/1 var(--hand); color: var(--ink); letter-spacing: .08em; min-height: 1.3rem; display: flex; gap: .45rem; justify-content: center; }
.c-tally .g { position: relative; }
.c-tally .g::after { content: ""; position: absolute; left: -.2em; right: -.2em; top: 50%; height: 2px; background: var(--ink); rotate: -24deg; }
.c-amount { font: 700 clamp(1.7rem, 4vw, 2.2rem)/1.05 var(--hand); color: var(--ink); margin-top: .2rem; }
.c-note { font-size: .9rem; font-weight: 500; color: var(--ink-2); max-width: 11ch; line-height: 1.2; }
.coaster.payer { background:
    radial-gradient(circle at 50% 50%, transparent 64%, var(--brass) 64.5% 67%, transparent 67.5%),
    radial-gradient(circle at 35% 30%, #f7f1e6, var(--board) 45%, var(--board-2)); }

.share { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1.8rem; }
.share button { min-height: 2.8rem; padding: 0 1.1rem; border-radius: 6px; font-weight: 700; }
#copy { background: var(--board); color: #2a2018; border: 0; }
#copy:hover { filter: brightness(1.04); }
.quiet { background: transparent; border: 1px solid var(--line); color: var(--text); }
.quiet:hover { background: var(--wood-3); }
.status { flex-basis: 100%; color: var(--brass); font-size: .95rem; min-height: 1.3em; }

.foot { margin-top: clamp(3rem, 7vw, 5rem); padding: 1.25rem 0 3rem; border-top: 1px solid var(--line); color: var(--text-2); font-size: .92rem; }
.foot p { max-width: 75ch; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; } }

@media (min-width: 58.01rem) { .coasters-wrap { position: sticky; top: 1.5rem; } }
@media (max-width: 40rem) {
  .coasters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
  .coaster { padding: 1rem; }
  .c-amount { font-size: 1.5rem; }
  .c-note { font-size: .82rem; }
}
