@font-face { font-family: "Courier Prime"; src: url("fonts/courier-prime-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("fonts/courier-prime-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Readex Pro"; src: url("fonts/readex-pro-arabic-wght-normal.woff2") format("woff2"); font-weight: 160 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: "Familjen Grotesk"; src: url("fonts/familjen-grotesk-latin-wght-normal.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }

:root {
  --ground: #e9e6f2;
  --paper: #ffffff;
  --ink: #1d1a26;
  --muted: #6f6a80;
  --line: #dcd8e6;
  --violet: #5b3df5;
  --violet-soft: rgb(91 61 245 / 0.1);
  --mono: "Courier Prime", "Readex Pro", ui-monospace, Menlo, Consolas, monospace;
  --ui: "Familjen Grotesk", "Readex Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ground: #16141f; --paper: #24212f; --ink: #ece9f5; --muted: #9a95ac; --line: #383446; --violet: #9c88ff; --violet-soft: rgb(156 136 255 / 0.14); color-scheme: dark; }
}
:root[data-theme="dark"] { --ground: #16141f; --paper: #24212f; --ink: #ece9f5; --muted: #9a95ac; --line: #383446; --violet: #9c88ff; --violet-soft: rgb(156 136 255 / 0.14); color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 400 15px/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration-color: var(--muted); text-underline-offset: 3px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

.app { display: flex; flex-direction: column; min-height: 100dvh; }
.bar { display: flex; align-items: baseline; gap: 6px 20px; flex-wrap: wrap; padding: 16px 28px 8px; }
.brand { margin: 0; font: 700 26px/1 var(--ui); letter-spacing: -0.02em; }
.brand i { font-style: normal; color: var(--violet); }
.purpose { flex: 1; margin: 0; color: var(--muted); }
.bar-meta { color: var(--muted); font-size: 12.5px; }

.desk { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 460px) minmax(0, 1fr); gap: 36px; padding: 8px 28px 24px; align-items: start; }

/* The receipt: a paper strip with torn top and bottom edges */
.receipt {
  --tooth: 9px;
  position: relative; padding: 22px 22px 30px; background: var(--paper); font-family: var(--mono);
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--tooth) * 2) 100%,
                conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--tooth) * 2) 100%;
  -webkit-mask-composite: source-in; mask-composite: intersect;
  filter: drop-shadow(0 10px 18px rgb(29 26 38 / 0.08));
  max-height: calc(100dvh - 110px); overflow: auto;
}
.receipt h2, .settle h2 { margin: 16px 0 8px; font: 700 12px/1 var(--ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.receipt h2 { padding-top: 12px; border-top: 1.5px dashed var(--line); }
.title { width: 100%; border: 0; background: none; padding: 0; font: 700 22px/1.2 var(--mono); text-align: center; }
.title::placeholder { color: var(--muted); }
.cur { justify-content: center; margin-top: 8px; }

.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button, .chips button { padding: 4px 10px; border: 1.5px solid var(--line); border-radius: 999px; background: transparent; font: 700 12.5px var(--mono); cursor: pointer; }
.seg button[aria-pressed="true"], .chips button[aria-pressed="true"], .chips button[aria-checked="true"] { border-color: var(--violet); background: var(--violet); color: var(--paper); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.people { display: flex; flex-wrap: wrap; gap: 6px; }
.person { display: inline-flex; align-items: center; gap: 4px; padding-block: 3px; padding-inline: 11px 4px; border-radius: 999px; background: var(--violet-soft); font-weight: 700; font-size: 14px; }
.person button { width: 22px; height: 22px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; }
.person button:hover { background: var(--line); color: var(--ink); }
.add-person input, .add input { width: 100%; padding: 8px 0; border: 0; border-bottom: 1.5px dashed var(--line); background: none; font: 400 15px var(--mono); }
.add-person input:focus, .add input:focus { outline: none; border-bottom-color: var(--violet); }
.add-person { margin-top: 6px; }

.items { list-style: none; margin: 0; padding: 0; }
.items li { display: grid; grid-template-columns: minmax(0, 1fr) auto 24px; gap: 0 10px; align-items: baseline; padding: 6px 0; }
.items .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.items .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.items .how { grid-column: 1 / 3; color: var(--muted); font-size: 13px; }
.items .del { grid-row: 1; grid-column: 3; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.items .del:hover { color: var(--ink); }
.items .none { color: var(--muted); }

.add { display: grid; gap: 6px; margin-bottom: 10px; padding-bottom: 12px; border-bottom: 1.5px dashed var(--line); }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 12px; }
.add-row #amount { text-align: end; font-weight: 700; }
.label { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 0; color: var(--muted); font: 700 12px var(--ui); letter-spacing: 0.08em; text-transform: uppercase; }
.mini { padding: 2px 8px; border: 1.5px solid var(--line); border-radius: 999px; background: none; font: 700 11px var(--ui); letter-spacing: 0; text-transform: none; color: var(--muted); cursor: pointer; }
.mini[aria-pressed="true"] { border-color: var(--violet); color: var(--violet); }
.custom { display: grid; gap: 4px; }
.custom label { display: grid; grid-template-columns: minmax(0, 1fr) 110px; align-items: center; gap: 12px; font-size: 14px; }
.custom input { padding: 4px 0; text-align: end; }
.custom .left { color: var(--muted); font-size: 13px; text-align: end; }
.custom .left.bad { color: var(--violet); font-weight: 700; }
.form-error { margin: 2px 0 0; color: var(--violet); font: 700 13px var(--ui); }

.total { display: flex; justify-content: space-between; margin: 16px 0 0; padding-top: 12px; border-top: 2px solid var(--ink); font: 700 18px var(--mono); }

.ink, .ghost { padding: 9px 16px; border: 1.5px solid var(--violet); border-radius: 999px; background: var(--violet); color: #fff; font: 700 14px var(--ui); cursor: pointer; }
.ink:hover { filter: brightness(1.08); }
.ghost { background: transparent; border-color: var(--ink); color: var(--ink); }
.ghost:hover { background: var(--ink); color: var(--ground); }
.ghost.danger { border-color: var(--muted); color: var(--ink); }
.add .ink { justify-self: start; margin-top: 6px; }

/* Settle up: the answer, big */
.settle { padding-top: 6px; }
.settle h2:first-child { margin-top: 0; }
.transfers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.transfers li { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 14px; padding: 12px 18px; border-radius: 16px; background: var(--paper); font: 700 clamp(18px, 2vw, 24px) var(--ui); }
.transfers .arrow { height: 2px; background: var(--violet); position: relative; min-width: 30px; }
.transfers .arrow::after { content: ""; position: absolute; right: -1px; top: -5px; border: 6px solid transparent; border-left: 9px solid var(--violet); border-right: 0; }
/* Right to left the receiver is on the left, so the head moves there and turns around */
[dir="rtl"] .transfers .arrow::after { right: auto; left: -1px; border-left: 0; border-right: 9px solid var(--violet); }
.transfers .money { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--violet); }
.empty { margin: 0; color: var(--muted); font-size: 16px; }
.empty:empty { display: none; }

.balances { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.balances li { display: grid; grid-template-columns: 110px minmax(0, 1fr) 110px; align-items: center; gap: 12px; }
.balances .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
/* The balance chart reads the same in both languages: owed money left of the middle, money back right of it */
.balances .track { position: relative; height: 14px; direction: ltr; }
.balances .track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; border-left: 1.5px solid var(--muted); }
.balances .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.balances .fill.up { left: 50%; background: var(--violet); }
.balances .fill.down { right: 50%; border: 2px solid var(--violet); }
.balances .val { font: 700 15px var(--mono); text-align: end; font-variant-numeric: tabular-nums; }

.share { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.note { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 24px; margin: 0; padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--ground); font: 700 14px var(--ui); transform: translate(-50%, 14px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .desk { grid-template-columns: 1fr; padding-inline: 16px; gap: 24px; }
  .bar { padding-inline: 16px; }
  .purpose { flex-basis: 100%; order: 3; }
  .receipt { max-height: none; }
  .desk:has(.transfers li) .settle { order: -1; } /* the answer first on a phone, once there is one */
  .balances li { grid-template-columns: 80px minmax(0, 1fr) 90px; }
}

.lang { margin-inline-start: 10px; font-weight: 600; color: var(--ink); unicode-bidi: isolate; }
.transfers .money, .balances .val, .items .amt, .total b { unicode-bidi: isolate; direction: ltr; }
:lang(ar) :is(.brand, .receipt h2, .settle h2, .label, .faq h2) { letter-spacing: 0; }
:lang(ar) .items .how { font-family: var(--ui); } /* monospace stretches the gaps between Arabic words */

/* Questions under the tool: for people who scroll, and for search engines */
.faq { max-width: 920px; margin: 0 auto; padding: 56px 20px 64px; }
.faq h2 { margin: 0 0 20px; font: 700 22px/1.2 var(--display); letter-spacing: -0.02em; }
.faq-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px 32px; }
.faq h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.faq p { margin: 0; color: var(--muted); line-height: 1.6; }

/* Light/dark button in the top bar, round like the pills */
.theme { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-inline-start: 8px; padding: 0; border: 1.5px solid var(--line); border-radius: 999px; background: none; color: var(--ink); cursor: pointer; vertical-align: middle; }
.theme:hover { border-color: var(--violet); color: var(--violet); }
.theme svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme .sun, .theme[data-dark="true"] .moon { display: none; }
.theme[data-dark="true"] .sun { display: block; }
