/* The settle-up tool (#tool). Ported from design/prototype/splitwithus-settle-up.html onto tokens.css.
   Colours: red is only for done (pen, stamp), green only for money coming back. */
#tool { --chip: #F4F3F0; --soft-line: #D6D3CD; }
/* :where() keeps these resets at zero specificity, so .btn-ink or .chip.on can still set colour. */
:where(#tool) :where(button, input, select, textarea) { font: inherit; color: inherit; }
:where(#tool) button { cursor: pointer; }
:where(#tool) :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tool-body { padding-bottom: 12px; }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.ink { color: var(--ink); }
.nowrap { white-space: nowrap; }
.between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.wrap-row { align-items: center; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.row-start { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.pad-x { padding: 4px 20px 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chips.popular { margin-top: 8px; gap: 6px; }
.chips.days { gap: 6px; }
.chips.days .chip { min-height: 32px; font-size: 13px; font-family: var(--mono); }
.label.sub { font-weight: 500; font-size: 12px; }
.chips.popular .chip { min-height: 32px; font-size: 13px; }

/* ---------- step bar ---------- */
.steps { display: flex; gap: 4px; margin-bottom: 18px; flex-wrap: wrap; }
.step-btn { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; font-size: 13.5px; font-weight: 500; color: var(--faint); display: inline-flex; align-items: center; gap: 6px; }
.step-btn .n { font-family: var(--mono); font-size: 11px; }
.step-btn.done { color: var(--muted); }
.step-btn.cur { color: var(--ink); font-weight: 700; background: var(--paper); box-shadow: 0 1px 2px rgba(30, 30, 27, 0.08); }

/* ---------- paper, type, fields ---------- */
.paper { background: var(--paper); border: 1px solid var(--rule); border-radius: 14px; box-shadow: 0 1px 2px rgba(30, 30, 27, 0.05), 0 16px 40px -24px rgba(30, 30, 27, 0.25); }
.pad { padding: 24px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.title { font-size: 34px; line-height: 1.12; letter-spacing: -0.025em; text-wrap: balance; }
h2.sec { font-weight: 700; font-size: 21px; letter-spacing: -0.015em; }
.serif { font-family: var(--serif); font-weight: 800; letter-spacing: -0.025em; }
.lede { margin-top: 6px; color: var(--muted); font-size: 16px; max-width: 58ch; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--soft-line); border-radius: 10px; background: var(--paper); }
.field:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(30, 30, 27, 0.08); }
.field.static { display: flex; align-items: center; background: var(--chip); }
.field.trip-name { font-size: 26px; min-height: 58px; }
.field.amount { font-size: 18px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px 4px 4px; border: 1px solid var(--rule); border-radius: 999px; background: var(--chip); font-size: 14px; font-weight: 500; }
.chip.plain { padding: 4px 12px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.on .ini { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.5); }
.x { border: 0; background: transparent; color: var(--faint); padding: 4px; display: inline-flex; border-radius: 6px; }
.x:hover { color: var(--ink); }
.ini { border-radius: 50%; color: var(--ink); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.person { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: 15px; text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:hover { background: #33332F; }
.btn-line { background: var(--paper); border-color: var(--soft-line); color: var(--ink); }
.btn-line:hover { background: var(--chip); }
.btn-lg { min-height: 54px; font-size: 16px; padding: 12px 22px; }
.btn-wide { width: 100%; }
.link-btn { border: 0; background: transparent; min-height: 40px; padding: 6px 4px; font-size: 14px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }
.hint { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--chip); font-size: 14px; }
.hint.recent { justify-content: space-between; align-items: center; flex-wrap: wrap; }
.hint .acts { display: inline-flex; align-items: center; gap: 12px; }

/* ---------- step 1 ---------- */
details.homes { margin-top: 14px; border: 1px solid var(--rule); border-radius: 12px; }
details.homes summary { cursor: pointer; padding: 12px 16px; font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 12px; }
details.homes summary .mono { font-weight: 500; color: var(--muted); font-size: 13px; }
.home-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; align-items: center; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--rule); }
.home-row .field { min-height: 40px; padding: 6px 10px; }
.rows > * + * { border-top: 1px solid var(--rule); }
.rows.boxed { border: 1px solid var(--rule); border-radius: 12px; margin-bottom: 10px; }
.rows.ruled { border-top: 1px solid var(--rule); }
.group-row { padding: 10px 12px 10px 16px !important; }
.group-form { border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
#addPeople.typing::placeholder { color: var(--ink); font-family: var(--serif); font-weight: 700; }

/* ---------- step 2 ---------- */
.r { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 20px; }
.r-title { font-size: 17px; font-weight: 600; line-height: 1.3; }
.r-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.r-amt { text-align: right; flex-shrink: 0; margin-left: auto; }
.r-amt .big { font-size: 18px; font-weight: 600; }
.r-amt .small { font-size: 12.5px; color: var(--muted); }
.pile-head { padding: 18px 20px 10px; }
.rate-box { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 46px; padding: 10px 14px; border-radius: 10px; background: var(--chip); font-size: 14px; flex-wrap: wrap; }
.rate-box.loading .val { color: var(--faint); }
.rate-box.warn { background: #FBF3E4; }
.dots::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.fx { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 10px; }
.fx-arrow { color: var(--muted); display: inline-flex; padding-bottom: 15px; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; background: transparent; border: 0; padding: 0; min-height: 40px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--soft-line); position: relative; transition: background 0.2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--paper); transition: left 0.2s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch[aria-checked="true"] .track { background: var(--ink); }
.switch[aria-checked="true"] .track::after { left: 19px; }
.dock { position: sticky; bottom: 16px; z-index: 10; background: var(--ink); color: var(--paper); border-radius: 14px; padding: 12px 14px 12px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; box-shadow: 0 16px 40px -18px rgba(30, 30, 27, 0.6); }
.dock-total { font-size: 15px; }
.dock .bal { font-size: 13px; opacity: 0.85; display: flex; gap: 12px; flex-wrap: wrap; }
.dock .btn { background: var(--paper); color: var(--ink); }
#dockTotal { display: inline-block; transform-origin: left center; }
#dockTotal.bump { animation: bump 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes bump { 45% { transform: scale(1.09); } }
[data-roll] { display: inline-block; }
@media (max-width: 560px) {
  .dock { padding: 10px 10px 10px 14px; gap: 10px; }
  .dock .bal span:nth-child(n+2) { display: none; }
  .dock .btn { min-height: 44px; padding: 8px 14px; font-size: 14px; }
  .fx { grid-template-columns: minmax(0, 1fr); }
  .fx-arrow { display: none; }
  .home-row { grid-template-columns: minmax(0, 1fr) 150px; }
  .r { padding: 12px 14px; }
}

/* ---------- step 3 ---------- */
.balance-head { padding: 16px 20px 10px; }
details.person { border-top: 1px solid var(--rule); }
details.person summary { list-style: none; display: grid; grid-template-columns: 150px 1fr 124px; align-items: center; gap: 12px; padding: 12px 20px; cursor: pointer; }
details.person summary::-webkit-details-marker { display: none; }
details.person[open] summary { background: var(--chip); }
.net { text-align: right; font-weight: 600; display: inline-flex; justify-content: flex-end; align-items: center; gap: 6px; }
.net.gets { color: var(--green); }
.zero { position: relative; height: 10px; }
.zero::before { content: ""; position: absolute; left: 50%; top: -5px; bottom: -5px; width: 1.5px; background: var(--ink); }
.zero span { position: absolute; top: 0; bottom: 0; border-radius: 3px; animation: fillBar 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.zero .gain { background: var(--green); transform-origin: left center; }
.zero .owe { background: var(--ink); transform-origin: right center; }
@keyframes fillBar { from { transform: scaleX(0); } }
.caret { color: var(--faint); display: inline-flex; transition: transform 0.25s; }
details.person[open] .caret { transform: rotate(180deg); }
.why { padding: 4px 20px 16px; display: grid; grid-template-columns: 1fr auto; row-gap: 4px; font-size: 13.5px; }
.why .t { font-family: var(--sans); color: var(--muted); }
.why .sum { border-top: 1px solid var(--rule); padding-top: 6px; font-weight: 600; }
details.person[open] .why { animation: slideDown 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } }
.home-tag { font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--muted); }
.total-row { align-items: center; padding: 16px 20px; border-top: 1px solid var(--ink); }
.double { border-bottom: 3px double var(--ink); padding-bottom: 2px; }
.big-num { font-size: 20px; font-weight: 700; }
@media (max-width: 560px) { details.person summary { grid-template-columns: minmax(0, 1fr) 70px 110px; padding: 12px 14px; } }

/* ---------- step 4: emailed receipt ---------- */
.mail { max-width: 560px; margin: 0 auto; width: 100%; }
.mail-head { padding: 22px 26px 18px; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; align-items: baseline; }
.mail-brand { font-size: 20px; }
.mail-body { padding: 26px; display: flex; flex-direction: column; gap: 22px; }
.receipt-title { font-size: 30px !important; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }
.amount-hero { font-family: var(--mono); font-size: 40px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.sub-h { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 10px; }
.to-group { margin-top: 12px; }
.t-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 56px; padding: 10px 0; }
.t-who { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; position: relative; flex-wrap: wrap; }
.t-right { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.t-amt { font-family: var(--mono); font-size: 19px; font-weight: 600; position: relative; }
.sent-btn { border: 1px solid var(--soft-line); background: var(--paper); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 36px; white-space: nowrap; }
.sent-btn.on { border-color: transparent; background: transparent; color: var(--red); }
.xline { padding: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.rows > .xline { border-top: 0; margin-top: -6px; }
.struck { position: relative; display: inline-block; }
.pen { position: absolute; left: -6px; top: calc(50% - 6px); width: calc(100% + 12px); height: 12px; pointer-events: none; overflow: visible; }
.pen path { fill: none; stroke: var(--red); stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 110; stroke-dashoffset: 110; transition: stroke-dashoffset 0.45s cubic-bezier(0.6, 0.05, 0.3, 1); }
.is-done .pen path { stroke-dashoffset: 0; }
.is-done .t-who, .is-done .t-amt { color: var(--muted); }
.t-who .pen { display: none; }
.is-done .t-who .pen { display: block; }
.left-row { align-items: center; padding-top: 14px; margin-top: 8px; border-top: 1px solid var(--ink); }
.left-val { display: inline-flex; align-items: center; gap: 14px; }
.leftover { position: relative; display: inline-block; font-size: 22px; font-weight: 700; padding-bottom: 2px; }
.leftover .dr { position: absolute; left: 0; right: 0; height: 1.6px; background: var(--ink); transform: scaleX(0); transform-origin: left center; }
.leftover .dr.a { bottom: -3px; } .leftover .dr.b { bottom: -7px; }
.finale-done .leftover .dr { transform: scaleX(1); }
.finale-play .leftover .dr { animation: drawRule 0.35s cubic-bezier(0.6, 0.05, 0.3, 1) 0.1s both; }
.finale-play .leftover .dr.b { animation-delay: 0.4s; }
@keyframes drawRule { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.stamp { display: inline-block; border: 2px solid var(--red); color: var(--red); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; transform: rotate(-6deg); }
.finale-play .stamp { animation: stampIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s both; }
@keyframes stampIn { 0% { opacity: 0; transform: rotate(-6deg) scale(1.8); } 60% { opacity: 1; transform: rotate(-6deg) scale(0.92); } 100% { transform: rotate(-6deg) scale(1); } }
.fold-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fold-toggle { border: 0; background: transparent; padding: 6px 0; font-size: 13px; color: var(--muted); font-family: var(--mono); text-decoration: underline; text-underline-offset: 3px; }
.fold-row { overflow: hidden; transition: max-height 0.5s cubic-bezier(0.6, 0.05, 0.3, 1); max-height: 90px; }
.fold-row .r { padding: 11px 0; }
.fold-row .r-meta { transition: opacity 0.3s; }
.fold-row .pen path { transition-delay: 0.35s; }
.folded .fold-row { max-height: 44px; }
.folded .fold-row .r-meta { opacity: 0; }
.folded .fold-row .r-title { font-size: 15px; font-weight: 500; color: var(--muted); }
.folded .fold-row .big { font-size: 14px; font-weight: 500; color: var(--muted); }
.folded .fold-row .small { display: none; }
.folded .fold-row .pen path { stroke-dashoffset: 0; }
.receipt-foot { border-top: 1px solid var(--rule); padding-top: 18px; }
@media (max-width: 560px) {
  .mail-body { padding: 20px 18px; }
  .t-row { flex-wrap: wrap; }
  .t-right { margin-left: auto; }
  .amount-hero { font-size: 34px; }
}

/* ---------- overlays ---------- */
.veil { position: fixed; inset: 0; z-index: 50; background: rgba(30, 30, 27, 0.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.vignette { background: var(--paper); border-radius: 14px; width: min(420px, 100%); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
textarea.copy { width: 100%; min-height: 180px; font-family: var(--mono); font-size: 13px; border: 1px solid var(--soft-line); border-radius: 10px; padding: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

/* ---------- step 1 opening motion (src/client/opening.js) ---------- */
.stage { position: relative; border: 1px solid var(--rule); border-radius: 14px; overflow: hidden; background: #ECEDEF; margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(30, 30, 27, 0.04), 0 8px 24px rgba(30, 30, 27, 0.05); }
.stage[hidden] { display: none; }
.stage svg { display: block; width: 100%; height: auto; }
.replay { position: absolute; right: 12px; top: 10px; border: 1px solid var(--rule); background: var(--paper); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); min-height: 30px; z-index: 1; }
.replay:hover { color: var(--ink); }

@media (max-width: 720px) { .steps .label { display: none; } .title { font-size: 28px; } }
@media (prefers-reduced-motion: reduce) {
  .replay { display: none; }
  #tool *, #tool *::before, #tool *::after { transition: none !important; animation: none !important; }
}
