@import url('https://fonts.googleapis.com/css2?family=Special+Elite&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root{
  --shell: #223328;      /* deep diner-counter green, page background */
  --shell-2: #1a2721;
  --paper: #FAF3E3;      /* receipt paper */
  --paper-edge: #EFE4C8;
  --ink: #2A2620;
  --ink-soft: #6b6355;
  --stamp: #B23A2E;      /* rubber-stamp red */
  --stamp-dark: #8f2d23;
  --line: #d9cdae;

  --m1: #F5D547; /* yellow highlighter */
  --m2: #F2779A; /* pink highlighter */
  --m3: #5CC8E0; /* blue highlighter */
  --m4: #8BC34A; /* green highlighter */
  --m5: #FF9F45; /* orange highlighter */
  --m6: #B48CE0; /* violet highlighter */
}

*{box-sizing:border-box;}
body{
  margin:0;
  min-height:100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(255,255,255,0.04), transparent 60%),
    var(--shell);
  font-family:'IBM Plex Sans', sans-serif;
  color:var(--ink);
  display:flex;
  justify-content:center;
  padding: 28px 14px 60px;
}

.wrap{ width:100%; max-width:520px; }

.brand{
  text-align:center;
  color:#f3ead2;
  margin-bottom:22px;
}
.brand .mark{
  font-family:'Special Elite', monospace;
  font-size:2.1rem;
  letter-spacing:2px;
  color:#f3ead2;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.brand .tag{
  font-size:0.8rem;
  color:#c9d6c4;
  margin-top:4px;
  letter-spacing:0.5px;
}

/* --- receipt card with torn edges --- */
.receipt{
  position:relative;
  background:var(--paper);
  color:var(--ink);
  padding: 30px 26px 26px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}
.receipt::before, .receipt::after{
  content:"";
  position:absolute;
  left:0; right:0;
  height:14px;
  background:
    linear-gradient(135deg, var(--paper) 50%, transparent 50%) 0 0/16px 16px,
    linear-gradient(45deg, var(--paper) 50%, transparent 50%) 0 0/16px 16px;
  background-repeat: repeat-x;
}
.receipt::before{ top:-13px; }
.receipt::after{ bottom:-13px; transform: rotate(180deg); }

.section{ margin-bottom:22px; }
.section:last-child{ margin-bottom:0; }

.eyebrow{
  font-family:'IBM Plex Mono', monospace;
  font-size:0.7rem;
  letter-spacing:2px;
  text-transform:uppercase;
  color:var(--ink-soft);
  margin: 0 0 10px;
  display:flex;
  align-items:center;
  gap:8px;
}
.eyebrow::after{
  content:"";
  flex:1;
  border-top:1px dashed var(--line);
}

h1,h2,h3{ margin:0; font-weight:600; }

/* start screen */
.start-title{
  font-family:'Special Elite', monospace;
  font-size:1.4rem;
  margin-bottom:6px;
}
.start-sub{ color:var(--ink-soft); font-size:0.92rem; margin-bottom:20px; line-height:1.5;}

.people-row{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom:12px; }
.person-pill{
  display:flex; align-items:center; gap:8px;
  background:#fff; border:2px solid var(--line);
  border-radius:999px; padding:6px 14px 6px 8px;
  font-size:0.9rem; font-weight:500;
}
.person-pill .swatch{ width:16px; height:16px; border-radius:50%; }
.person-pill button{
  border:none; background:none; color:var(--ink-soft); cursor:pointer; font-size:0.95rem; line-height:1; padding:0 2px;
}
.add-person{ display:flex; gap:8px; }
.add-person input{
  flex:1; padding:10px 12px; border-radius:10px; border:2px solid var(--line);
  font-family:inherit; font-size:0.9rem; background:#fff;
}
.add-person input:focus{ outline:none; border-color: var(--stamp); }

.btn{
  font-family:'IBM Plex Sans', sans-serif;
  font-weight:600;
  border:none;
  border-radius:12px;
  padding:13px 18px;
  cursor:pointer;
  font-size:0.95rem;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active{ transform: translateY(1px); }
.btn-primary{ background:var(--stamp); color:#fff; width:100%; box-shadow:0 6px 0 var(--stamp-dark);}
.btn-primary:active{ box-shadow:0 3px 0 var(--stamp-dark); }
.btn-primary:disabled{ background:#c9bfa9; box-shadow:none; cursor:not-allowed; }
.btn-ghost{ background:transparent; color:var(--ink-soft); border:2px solid var(--line); }
.btn-add{ background:#efe4c8; color:var(--ink); border:2px dashed var(--line); }

/* upload */
.dropzone{
  border:2px dashed var(--line);
  border-radius:14px;
  padding:34px 18px;
  text-align:center;
  cursor:pointer;
  color:var(--ink-soft);
}
.dropzone svg{ margin-bottom:8px; }
.dropzone .hint{ font-size:0.78rem; margin-top:4px; }

.loading{
  display:flex; align-items:center; justify-content:center; gap:12px;
  padding: 28px 0; color:var(--ink-soft); font-size:0.92rem;
}
.spinner{
  width:22px; height:22px; border-radius:50%;
  border:3px solid var(--line); border-top-color:var(--stamp);
  animation: spin 0.8s linear infinite;
}
@keyframes spin{ to{ transform:rotate(360deg);} }

.err{
  background:#fbe7e2; border:1px solid var(--stamp); color:var(--stamp-dark);
  padding:12px 14px; border-radius:10px; font-size:0.85rem; margin-top:12px;
}

/* restaurant header line */
.rname{ font-family:'Special Elite', monospace; font-size:1.15rem; text-align:center; margin-bottom:2px;}
.rmeta{ text-align:center; font-size:0.78rem; color:var(--ink-soft); font-family:'IBM Plex Mono',monospace; margin-bottom:18px;}

/* marker strip */
.markers{ display:flex; flex-wrap:wrap; gap:10px; margin-bottom:6px; }
.marker{
  display:flex; align-items:center; gap:8px;
  padding:8px 12px 8px 8px;
  border-radius:999px;
  border:2px solid transparent;
  background:#fff;
  cursor:pointer;
  font-size:0.85rem;
  font-weight:600;
  color:var(--ink-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.marker .cap{
  width:20px; height:20px; border-radius:5px 5px 2px 2px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15);
}
.marker.active{
  color:var(--ink);
  box-shadow: inset 0 0 0 2px var(--marker-color, var(--ink));
  background: color-mix(in srgb, var(--marker-color, #fff) 18%, #fff);
}
.marker-hint{ font-size:0.76rem; color:var(--ink-soft); margin-bottom:16px; }

/* item rows */
.item-row{
  display:flex; justify-content:space-between; align-items:center;
  padding:11px 2px;
  border-bottom:1px dashed var(--line);
  cursor:pointer;
  gap:10px;
}
.item-row:last-child{ border-bottom:none; }
.item-name{ position:relative; font-size:0.95rem; z-index:1; }
.item-name .hl{
  position:absolute; left:-4px; right:-4px; top:45%; height:0.9em;
  transform: translateY(-45%) rotate(-1deg);
  border-radius:3px; opacity:0.55; z-index:-1;
}
.item-price{ font-family:'IBM Plex Mono', monospace; font-size:0.92rem; white-space:nowrap; }
.item-claimer{ font-size:0.72rem; color:var(--ink-soft); display:block; margin-top:2px; }
.split-hint{
  display:inline-block; margin-left:8px; font-size:0.68rem; color:var(--stamp);
  border:1px dashed var(--stamp); border-radius:999px; padding:1px 7px;
}

.unclaimed-flag{ outline:2px solid var(--stamp); outline-offset:3px; border-radius:4px; }

/* item editing */
.edit-row{
  display:flex; align-items:center; gap:8px;
  padding:9px 2px; border-bottom:1px dashed var(--line);
}
.edit-row input[type="text"]{ flex:1; min-width:0; }
.edit-row input[type="number"]{ width:64px; }
.edit-row input{
  padding:8px 9px; border-radius:8px; border:2px solid var(--line);
  font-family:inherit; font-size:0.85rem; background:#fff;
}
.edit-row .qty-label{ font-size:0.7rem; color:var(--ink-soft); }
.edit-row .remove-item-btn{
  border:none; background:none; color:var(--stamp); cursor:pointer; font-size:1.1rem; line-height:1; padding:0 4px;
}

/* history */
.history-entry{
  border:2px solid var(--line); border-radius:14px; padding:14px 16px; margin-bottom:10px; cursor:pointer;
}
.history-entry:hover{ border-color:var(--stamp); }
.history-entry .h-top{ display:flex; justify-content:space-between; align-items:baseline; }
.history-entry .h-name{ font-family:'Special Elite', monospace; font-size:1rem; }
.history-entry .h-date{ font-size:0.72rem; color:var(--ink-soft); font-family:'IBM Plex Mono',monospace; }
.history-entry .h-total{ font-family:'IBM Plex Mono', monospace; font-size:1.2rem; font-weight:600; margin-top:4px; }
.history-entry .h-people{ font-size:0.76rem; color:var(--ink-soft); margin-top:6px; }
/* A split saved before everyone had claimed. It must read as incomplete at a
   glance, or weeks later it is indistinguishable from a settled bill. */
.history-entry .h-partial{
  font-family:'IBM Plex Mono', monospace; font-size:0.62rem; font-weight:600;
  text-transform:uppercase; letter-spacing:0.08em; vertical-align:middle;
  margin-left:8px; padding:2px 7px; border-radius:999px;
  color:var(--ink-soft); border:1px solid var(--line);
}
.history-entry .h-delete{
  border:none; background:none; color:var(--ink-soft); cursor:pointer; font-size:0.72rem; margin-top:8px; text-decoration:underline;
}

/* totals block */
.totals-line{ display:flex; justify-content:space-between; font-family:'IBM Plex Mono', monospace; font-size:0.88rem; padding:5px 0; }
.totals-line.grand{ font-weight:600; font-size:1rem; border-top:1px solid var(--line); margin-top:6px; padding-top:10px;}

.field-label{ font-size:0.8rem; color:var(--ink-soft); margin-bottom:6px; display:block; }
.tax-detected{
  background:#eef4e8; border:1px solid #b7cfa3; color:#3f5c2c;
  padding:10px 12px; border-radius:10px; font-size:0.85rem;
}
.pct-row{ display:flex; gap:8px; flex-wrap:wrap; }
.pct-btn{
  padding:8px 14px; border-radius:999px; border:2px solid var(--line);
  background:#fff; font-size:0.85rem; font-weight:600; cursor:pointer; color:var(--ink-soft);
}
.pct-btn.active{ border-color:var(--stamp); color:var(--stamp); background:#fdf0ee; }
.custom-pct{ display:flex; align-items:center; gap:6px; }
.custom-pct input{
  width:70px; padding:8px 10px; border-radius:8px; border:2px solid var(--line); font-family:inherit; font-size:0.85rem;
}

.breakdown-card{
  border:2px solid var(--line);
  border-radius:14px;
  padding:14px 16px;
  margin-bottom:10px;
}
.breakdown-card .name{ font-weight:600; font-size:0.95rem; }
.breakdown-card .amt{ font-family:'IBM Plex Mono', monospace; font-size:1.6rem; font-weight:600; margin-top:2px;}
.breakdown-card .items{ font-size:0.76rem; color:var(--ink-soft); margin-top:6px; line-height:1.5; }
/* The part of the bill nobody has taken. Deliberately quieter than a person's
   card — it is money still waiting, not money someone owes. */
.breakdown-card.unclaimed-card{
  border-style:dashed;
  background:transparent;
}
.breakdown-card.unclaimed-card .name,
.breakdown-card.unclaimed-card .amt{ color:var(--ink-soft); }

.footer-actions{ display:flex; gap:10px; margin-top:18px; }
.footer-actions .btn{ flex:1; }

.recon{ text-align:center; font-size:0.72rem; color:var(--ink-soft); margin-top:10px; font-family:'IBM Plex Mono', monospace;}

.hidden{ display:none !important; }

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

/* ---------------------------------------------------------------- *
 * Categories, discounts, and reconciliation.
 * Added with the discount spec — see docs/ihadthe-discount-spec.md.
 * ---------------------------------------------------------------- */

/* Category marker on each item row. Tappable: a wrong category silently
   changes someone's total, so it has to be spottable and fixable in place. */
.cat-chip{
  display:inline-flex; align-items:center; gap:4px;
  border:1px dashed var(--line); border-radius:999px;
  background:#fff; color:var(--ink-soft);
  font-family:'IBM Plex Mono', monospace; font-size:0.62rem;
  letter-spacing:0.04em; text-transform:uppercase;
  padding:2px 7px; margin-left:6px; cursor:pointer; white-space:nowrap;
  vertical-align:middle;
}
.cat-chip:hover, .cat-chip:focus-visible{ border-style:solid; border-color:var(--stamp); color:var(--stamp-dark); }
.cat-chip[data-cat="alcohol"]{ background:#f6ecf6; border-color:#c9a8cd; color:#6d3f72; }
.cat-chip[data-cat="na_beverage"]{ background:#e9f2f7; border-color:#a3c2d4; color:#325a70; }
.cat-chip[data-cat="food"]{ background:#f4efe0; border-color:#cbbb92; color:#6a5a2f; }
.cat-chip[data-cat="other"]{ background:#f0efec; border-color:#c3bdb2; color:#5c564c; }

.item-group-header{
  display:flex; align-items:center; gap:6px; flex-wrap:wrap;
  font-size:0.78rem; color:var(--ink-soft);
  padding:8px 2px 2px; font-family:'IBM Plex Mono', monospace;
}

/* Says the "each" figure beside it was divided out by us rather than printed on
   the receipt. Deliberately NOT monospace: the header's voice is the voice of
   figures read off the paper, and this is the one part of it that isn't. */
.item-group-header .derived-note{
  font-family:system-ui, -apple-system, sans-serif;
  font-style:italic; font-size:0.72rem; opacity:0.75;
}

/* Discount and charge rows */
.discount-row{
  display:flex; align-items:flex-start; gap:10px;
  padding:10px 0; border-bottom:1px dashed var(--line);
}
.discount-row:last-child{ border-bottom:none; }
.discount-row .d-body{ flex:1; min-width:0; }
.discount-row .d-label{ font-size:0.9rem; font-weight:500; }
.discount-row .d-meta{ font-size:0.72rem; color:var(--ink-soft); margin-top:3px; line-height:1.5; }
.discount-row .d-amount{
  font-family:'IBM Plex Mono', monospace; font-size:0.95rem; font-weight:600; color:#3f5c2c; white-space:nowrap;
}
.discount-row .d-remove{
  border:none; background:none; color:var(--ink-soft); cursor:pointer; font-size:0.95rem; line-height:1; padding:0 2px;
}
.d-scope-btn{
  border:1px dashed var(--line); border-radius:999px; background:#fff;
  font-family:'IBM Plex Mono', monospace; font-size:0.62rem; text-transform:uppercase; letter-spacing:0.04em;
  color:var(--ink-soft); padding:2px 7px; cursor:pointer; margin-right:4px;
}
.d-scope-btn.on{ background:#eef4e8; border-style:solid; border-color:#b7cfa3; color:#3f5c2c; }

/* A discount whose coverage the receipt didn't state. We ask rather than
   guess, per the spec. */
.needs-answer{
  background:#fdf6e3; border:1px solid #d8b74a; color:#6a5320;
  padding:10px 12px; border-radius:10px; font-size:0.8rem; margin-top:8px;
}

/* Tip base toggle — visible, not buried. */
.tip-base{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-top:10px; }

/* The residual banner. This is the fix for the original bug: an unexplained
   difference is shown, never silently applied to whoever is last in the list. */
.residual{
  background:#fdf6e3; border:2px solid var(--stamp); color:var(--ink);
  padding:14px 16px; border-radius:12px; margin-bottom:16px; font-size:0.88rem; line-height:1.55;
}
.residual .r-head{
  font-family:'Special Elite', monospace; font-size:1rem; color:var(--stamp-dark); margin-bottom:6px;
}
.residual .r-amount{ font-family:'IBM Plex Mono', monospace; font-weight:600; }
.residual .r-actions{ display:flex; gap:8px; flex-wrap:wrap; margin-top:12px; }
.residual.ok{
  background:#eef4e8; border-color:#b7cfa3; color:#3f5c2c;
}
.residual.ok .r-head{ color:#3f5c2c; }

/* ---------------------------------------------------------------- *
 * Modifier lines — an add-on the register printed as its own line.
 * Nested under the parent, not independently claimable, detachable.
 * ---------------------------------------------------------------- */
.modifier-row{
  display:flex; justify-content:space-between; align-items:flex-start; gap:10px;
  padding:6px 2px 8px 22px;
  border-bottom:1px dashed var(--line);
  background:linear-gradient(90deg, rgba(217,205,174,0.16), transparent 60%);
}
.modifier-row .mod-name{
  font-size:0.86rem; color:var(--ink); display:flex; align-items:center; gap:6px; flex-wrap:wrap;
}
.modifier-row .mod-arrow{ color:var(--ink-soft); font-size:0.9rem; line-height:1; }
.modifier-row .mod-note{
  display:block; width:100%; font-size:0.7rem; color:var(--ink-soft); margin-top:2px;
}
.modifier-row .mod-price{
  font-family:'IBM Plex Mono', monospace; font-size:0.85rem; color:var(--ink-soft); white-space:nowrap;
}
/* A price the receipt printed in parentheses: already inside the parent's
   price. Shown, because the receipt shows it, but visibly not a charge. */
.modifier-row .mod-included{
  font-size:0.72rem; font-style:italic; opacity:0.75;
}
.mod-detach{
  border:1px dashed var(--line); border-radius:999px; background:#fff;
  font-family:'IBM Plex Mono', monospace; font-size:0.6rem; text-transform:uppercase; letter-spacing:0.04em;
  color:var(--ink-soft); padding:2px 7px; cursor:pointer;
}
.mod-detach:hover, .mod-detach:focus-visible{ border-style:solid; border-color:var(--stamp); color:var(--stamp-dark); }

/* Marks a claimable row that carries add-ons, so the price reads correctly. */
.mod-badge{
  font-family:'IBM Plex Mono', monospace; font-size:0.6rem; text-transform:uppercase; letter-spacing:0.04em;
  color:var(--ink-soft); border:1px dashed var(--line); border-radius:999px;
  padding:1px 6px; margin-left:6px; white-space:nowrap; vertical-align:middle;
}

/* Edit panel: a modifier stays visibly attached while prices are corrected. */
.edit-row.is-modifier{ padding-left:18px; }
.edit-row.is-modifier .edit-mod-arrow{ color:var(--ink-soft); font-size:0.85rem; }

/* A category the scan guessed at rather than read. Marked so the eye lands on
   the lines actually worth checking, instead of every chip looking equal. */
.cat-chip.unsure{
  border-style:solid; border-color:#d8b74a; background:#fdf6e3; color:#6a5320;
}
.cat-chip .cat-unsure-mark{ font-weight:700; margin-left:1px; }

/* Per-category subtotals printed on the receipt, checked against ours. */
.cat-table{
  margin-top:10px; border-top:1px dashed var(--line); padding-top:8px;
  font-family:'IBM Plex Mono', monospace; font-size:0.8rem;
}
.cat-row{ display:flex; justify-content:space-between; gap:12px; padding:3px 0; }
.cat-row .cat-nums{ white-space:nowrap; }
.cat-row.ok{ color:var(--ink-soft); }
.btn.cat-fix{ font-family:'IBM Plex Sans', sans-serif; }
