:root {
    --bg: #0f172a; --bg2: #111c33; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.16);
    --ink: #f1f5f9; --muted: #a5b4c8; --accent: #fb923c; --accent-ink: #2a1200; --field: rgba(255,255,255,.08);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f4f6fb; --bg2: #e9eef8; --card: #fff; --line: #d0d8ea; --ink: #14213d; --muted: #55637d;
            --accent: #c2410c; --accent-ink: #fff; --field: #f3f6fc; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: linear-gradient(180deg, var(--bg), var(--bg2)) fixed; touch-action: manipulation; }
.app { width: min(520px, 100%); }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.9rem; letter-spacing: -.02em; }
.sub { margin: .3rem 0 0; color: var(--muted); font-size: 1rem; font-weight: 400; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: .8rem; }
.tabs button { padding: .7rem .3rem; font-size: .95rem; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; }
label, .big-label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
label:first-child, .card > :first-child > label:first-child { margin-top: 0; }
.opt { font-weight: 400; }
input[type=text], input[type=email], select { width: 100%; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.1rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tips { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem; }
.tips button { min-height: 48px; padding: 0 .2rem; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.tips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tips input { grid-column: 1 / -1; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: .4rem; }
.stepper button { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-size: 1.5rem; cursor: pointer; }
.stepper input { text-align: center; }
.row2 { display: flex; gap: .8rem; align-items: center; justify-content: space-between; margin-top: 1rem; }
.row2 .check { margin: 0; display: flex; gap: .5rem; align-items: center; color: var(--ink); font-weight: 500; min-height: 44px; }
.row2 .check input { width: 22px; height: 22px; accent-color: var(--accent); }
.row2 select { width: auto; font-size: 1rem; }
.hint { margin: 0 0 .6rem; color: var(--muted); font-size: .9rem; }
.rows { list-style: none; margin: 0 0 .6rem; padding: 0; display: grid; gap: .5rem; }
.rows li { display: grid; grid-template-columns: 1fr 120px 44px; gap: .4rem; }
.rows li > button:not(.addmail) { border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-size: 1.2rem; cursor: pointer; }
.ghost { width: 100%; min-height: 44px; border-radius: 12px; border: 1px dashed var(--line); background: transparent; color: var(--ink); font: inherit; cursor: pointer; }
.big { font-size: clamp(2.4rem, 12vw, 3.2rem); font-weight: 800; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.big-label { margin: 0; }
.shares { display: grid; gap: .3rem; margin: 0 0 .5rem; }
.shares div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem .7rem; background: var(--field); border-radius: 10px; font-variant-numeric: tabular-nums; }
.shares span:first-child { overflow-wrap: anywhere; }
.sum { margin: 1rem 0; display: grid; gap: .25rem; }
.sum div { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.sum dt { color: var(--muted); } .sum dd { margin: 0; }
.sum .total { border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .3rem; font-weight: 700; } .sum .total dt { color: var(--ink); }
.primary { width: 100%; min-height: 50px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; cursor: pointer; }
.msg { min-height: 1.4em; margin: .5rem 0 0; text-align: center; color: var(--muted); font-size: .9rem; }
.faq h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
details { border-top: 1px solid var(--line); padding: .6rem 0; }
summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details p { margin: .4rem 0 0; color: var(--muted); }
footer { text-align: center; margin-top: 1.5rem; font-size: .9rem; } footer a { color: var(--muted); }
[hidden] { display: none !important; }
@media (max-width: 480px) { .tips { grid-template-columns: repeat(3, 1fr); } .rows li { grid-template-columns: 1fr 100px 44px; } }

.rows.with-email li > input[type=email], .rows.with-email li .addmail { grid-column: 1 / -1; grid-row: 2; }
.rows.with-email li input[type=email] { font-size: 1rem; }
.addmail { justify-self: start; min-height: 36px; padding: 0 .2rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.final { margin: .8rem 0; padding: .7rem .8rem; border-radius: 12px; background: var(--field); font-weight: 600; text-align: center; }
h3 { margin: 1.1rem 0 .4rem; font-size: 1rem; }
.meta { margin: .2rem 0 0; color: var(--muted); }
.xfers { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.xfers li { padding: .7rem .8rem; border-radius: 12px; background: var(--field); border-left: 4px solid var(--accent); font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.xfers li.none { border-left-color: var(--line); font-weight: 500; color: var(--muted); }
.shares small { display: block; color: var(--muted); font-size: .8rem; }
.shares .get { color: #34d399; } .shares .owe { color: #fb7185; }
@media (prefers-color-scheme: light) { .shares .get { color: #047857; } .shares .owe { color: #be123c; } }
.mail { display: grid; gap: .5rem; margin-bottom: .7rem; }
a.primary { display: flex; align-items: center; justify-content: center; text-decoration: none; text-align: center; padding: .5rem; }
a.primary.alt { background: transparent; color: var(--ink); border: 1px solid var(--accent); }
@media (max-width: 380px) { .tabs button { font-size: .85rem; } }
.newbill { margin: .6rem 0 0; text-align: center; color: var(--muted); font-size: .9rem; }
.newbill .addmail { display: inline; }

/* back to the list of all apps */
.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }
@media print { .back { display: none; } }

/* light / dark switch (theme.js sets data-theme); without it the device setting decides */
:root[data-theme="light"] { --bg: #f4f6fb; --bg2: #e9eef8; --card: #fff; --line: #d0d8ea; --ink: #14213d; --muted: #55637d;
            --accent: #c2410c; --accent-ink: #fff; --field: #f3f6fc; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0f172a; --bg2: #111c33; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.16);
    --ink: #f1f5f9; --muted: #a5b4c8; --accent: #fb923c; --accent-ink: #2a1200; --field: rgba(255,255,255,.08);
    color-scheme: dark;
}

/* laptops and desktops: two columns instead of one phone-sized column */
@media (min-width: 900px) {
    .app { width: min(1040px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .app > .card:not(.result):not(#result), .app > .app-in { grid-column: 1; }
    .app > .result, .app > #result { grid-column: 2; margin-top: 0; }
    .app > .card { margin-bottom: .9rem; }
    .app > .faq, .app > footer { width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .tabs { max-width: 560px; justify-self: center; width: 100%; }
    /* before there is a result, keep the lone form card centered and phone-sized */
    .app:has(> #result[hidden]) > .card { grid-column: 1 / -1; width: min(560px, 100%); justify-self: center; }
}
