:root {
    --bg: #0d241d; --bg2: #06130f; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #effbf6; --muted: #b5d8ca; --accent: #38d9a9; --accent-ink: #06261b; --field: rgba(255,255,255,.08);
    --soft: rgba(56,217,169,.14); --good: #69db7c; --bad: #ffa8a8; --warn-bg: rgba(255,135,135,.13); --gold: #ffd43b; --gold-ink: #3d2e00;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f2fbf7; --bg2: #e2f4ec; --card: #fff; --line: #c9e6da; --ink: #0b2a20; --muted: #3d6356;
            --accent: #087f5b; --accent-ink: #fff; --field: #f8fdfb; --soft: #dcf5ea; --good: #2b8a3e; --bad: #c92a2a; --warn-bg: #fff0f0; --gold: #f59f00; --gold-ink: #3d2700; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f2fbf7; --bg2: #e2f4ec; --card: #fff; --line: #c9e6da; --ink: #0b2a20; --muted: #3d6356;
            --accent: #087f5b; --accent-ink: #fff; --field: #f8fdfb; --soft: #dcf5ea; --good: #2b8a3e; --bad: #c92a2a; --warn-bg: #fff0f0; --gold: #f59f00; --gold-ink: #3d2700; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0d241d; --bg2: #06130f; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #effbf6; --muted: #b5d8ca; --accent: #38d9a9; --accent-ink: #06261b; --field: rgba(255,255,255,.08);
    --soft: rgba(56,217,169,.14); --good: #69db7c; --bad: #ffa8a8; --warn-bg: rgba(255,135,135,.13); --gold: #ffd43b; --gold-ink: #3d2e00;
    color-scheme: dark;
}
* { 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: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-a, .col-b { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header { order: 1; }
.setup { order: 2; }
.round { order: 3; }
.members { order: 4; }
.turns { order: 5; }
.tools { order: 6; }
.app > .faq { order: 7; }
.app > footer { order: 8; }
.report { display: none; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.7rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; overflow-wrap: anywhere; }
h3 { margin: 1rem 0 .5rem; font-size: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input[type=tel], input[type=date], select, textarea { width: 100%; min-width: 0; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
textarea { min-height: 8rem; resize: vertical; line-height: 1.45; font-size: 1rem; }
#c-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
input[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.hint:empty { margin: 0; }
.hint.top { margin: -.3rem 0 .7rem; }
[hidden] { display: none !important; }
.field { min-width: 0; }
.amount-row { display: flex; align-items: stretch; gap: .4rem; }
.cur-tag { display: flex; align-items: center; padding: 0 .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); font-weight: 700; color: var(--muted); flex: none; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary.small, .primary.small { width: auto; min-height: 42px; padding: 0 .8rem; font-size: .92rem; margin: 0; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: .9rem; }
.danger-t { color: var(--bad); }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.link.inline { display: inline; min-height: 0; margin: 0; padding: .55rem .2rem; text-decoration: underline; }
button:disabled { opacity: .45; cursor: default; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.row-btns > * { flex: 1 1 8rem; }
.panel .row-btns { margin-top: .6rem; }
.panel .row-btns > * { flex: 1 1 5.5rem; }

.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { margin-top: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg .undo { margin-left: .2rem; font-weight: 700; }
.good { color: var(--good); }

/* committee details */
.pick-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; margin-bottom: .8rem; }
.pick-field { flex: 1 1 12rem; min-width: 0; }
.pick-field label { margin-top: 0; }
.c-links { display: flex; flex-wrap: wrap; column-gap: 1.2rem; margin-top: .3rem; }
.c-links .link { margin-top: 0; }
.c-name { font-size: 1.35rem; margin-bottom: .2rem; }
.c-line { margin: .1rem 0 0; color: var(--muted); overflow-wrap: anywhere; }
.c-now { margin: .7rem 0 0; padding: .55rem .75rem; border-radius: 12px; background: var(--soft); font-weight: 700; overflow-wrap: anywhere; }
.c-now:empty { display: none; }
.c-now.good { color: var(--ink); border-left: 5px solid var(--good); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: .8rem; }
.form-grid .field > label { margin-top: .8rem; }
.form-grid .field:first-child > label { margin-top: 0; }

/* members */
.m-row { display: grid; grid-template-columns: minmax(0, 1fr) 8.2rem; gap: .5rem; }
.m-row label { margin-top: 0; }
#m-add { margin-top: .6rem; }
.empty { margin: .9rem 0 0; color: var(--muted); text-align: center; }
.m-list { display: grid; gap: .7rem; margin-top: 1rem; }
.m-list:empty { margin: 0; }
.member { border: 1px solid var(--line); border-left: 6px solid var(--mc, var(--line)); border-radius: 14px; padding: .75rem .85rem .85rem; background: var(--field); min-width: 0; }
.member.ok { --mc: var(--good); } .member.owes { --mc: var(--bad); }
.m-top { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; }
.m-name { margin: 0; font-size: 1.08rem; font-weight: 800; overflow-wrap: anywhere; min-width: 0; }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; background: var(--soft); color: var(--ink); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.tag.gold { background: var(--gold); color: var(--gold-ink); margin-left: .45rem; vertical-align: .1em; }
.m-meta { margin: .15rem 0 0; font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; }
.m-turn { margin: .3rem 0 0; font-weight: 600; font-size: .95rem; overflow-wrap: anywhere; }
.m-status { margin: .25rem 0 0; font-weight: 800; color: var(--mc, var(--muted)); overflow-wrap: anywhere; }
.member:not(.ok):not(.owes) .m-status { color: var(--muted); font-weight: 600; }
.p-btns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; margin-top: .7rem; }
.p-btns button { width: 100%; padding: 0 .4rem; }
.panel { margin-top: .75rem; padding: .7rem .7rem .75rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-width: 0; }
.panel h3 { margin: 0 0 .4rem; font-size: .95rem; overflow-wrap: anywhere; }
.panel label:first-of-type { margin-top: 0; }
.panel .msg.show { margin-top: .5rem; }

/* round */
.r-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.r-top h2 { margin: 0; font-size: 1.3rem; }
.r-nav { display: flex; gap: .4rem; }
.r-date { margin: .35rem 0 0; color: var(--muted); font-weight: 600; }
.r-note { margin: .5rem 0 0; padding: .45rem .7rem; border-radius: 10px; background: var(--field); border: 1px dashed var(--line); font-size: .92rem; }
.r-pot { margin-top: .8rem; padding: .75rem .85rem; border-radius: 14px; border: 2px solid var(--gold); background: var(--field); }
.r-taker { margin: 0; font-size: clamp(1.25rem, 5.5vw, 1.7rem); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: .6rem; margin: .5rem 0 0; min-height: 44px; color: var(--ink); font-size: .98rem; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; margin: 0; }
.check span { overflow-wrap: anywhere; min-width: 0; }
.r-progress { margin: .9rem 0 .35rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bar { height: 12px; border-radius: 999px; background: var(--field); border: 1px solid var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s; }
.r-left { margin: .5rem 0 0; font-weight: 600; color: var(--bad); overflow-wrap: anywhere; }
.r-left.good { color: var(--good); }
.pay-list { display: grid; gap: .55rem; margin-top: 1rem; }
.pay { border: 1px solid var(--line); border-left: 6px solid var(--pc, var(--bad)); border-radius: 12px; padding: .6rem .7rem; background: var(--field); min-width: 0;
       display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; }
.pay.paid { --pc: var(--good); } .pay.part { --pc: var(--gold); }
.pay-info { min-width: 0; }
.pay-name { margin: 0; font-weight: 800; overflow-wrap: anywhere; }
.pay-st { margin: .05rem 0 0; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.pay.paid .pay-st { color: var(--good); font-weight: 600; }
.pay-btns { display: flex; flex-wrap: wrap; gap: .4rem; }
.pay-btns > button { flex: 1 1 7rem; }
.part-panel { margin-top: 0; }
@media (min-width: 360px) {
    .pay.paid { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
    .pay.paid .pay-btns > button { flex: 0 1 auto; }
}
.share-h { margin-top: 1.1rem; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }

/* turn order */
.t-list { list-style: none; margin: .9rem 0 0; padding: 0; display: grid; gap: .45rem; }
.t-row { border: 1px solid var(--line); border-radius: 12px; padding: .45rem .5rem .45rem .6rem; background: var(--field); min-width: 0;
         display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .5rem; }
.t-row.viewing { border-color: var(--accent); }
.t-row.locked { opacity: .8; }
.t-info { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.t-num { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--soft); font-weight: 800; font-size: .9rem; }
.t-row.locked .t-num { background: var(--gold); color: var(--gold-ink); }
.t-txt { min-width: 0; }
.t-who { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.t-when { margin: 0; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.t-btns { display: flex; gap: .35rem; }
.arrow { width: 44px !important; padding: 0 !important; font-size: 1.15rem !important; }

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.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; }

/* narrow phones */
@media (max-width: 400px) {
    .card { padding: .95rem .85rem; }
    .member { padding: .7rem .65rem .75rem; }
    .panel { padding: .6rem .55rem .65rem; }
    .m-row { grid-template-columns: minmax(0, 1fr) 7rem; }
}
@media (max-width: 359px) {
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .m-row { grid-template-columns: minmax(0, 1fr); }
    .r-nav { width: 100%; }
    .r-nav button { flex: 1; }
    .p-btns { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .p-btns .danger-t { grid-column: 1 / -1; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
}

/* printing: only the payment sheet */
@media print {
    @page { size: landscape; margin: 12mm; }
    body { background: #fff; color: #000; padding: 0; display: block; font-size: 10pt; }
    .app > *:not(.report) { display: none !important; }
    .app { display: block; width: 100%; }
    .report { display: block !important; }
    .report h2 { font-size: 16pt; margin: 0 0 .3rem; }
    .report h3 { font-size: 12pt; margin: 1rem 0 .2rem; }
    .report p { margin: .1rem 0; }
    .report table { width: 100%; border-collapse: collapse; margin-top: .4rem; font-size: 9pt; }
    .report th, .report td { border: 1px solid #999; padding: 2px 4px; text-align: center; }
    .report td:first-child, .report th:first-child { text-align: left; }
    .report thead { display: table-header-group; }
    .report tr { break-inside: avoid; }
}

/* laptops and desktops: details across the top, members on the left, the round and turn order on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-a, .col-b { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .setup { grid-row: 3; }
    .app > .col-a { grid-column: 1; grid-row: 4; }
    .app > .col-b { grid-column: 2; grid-row: 4; }
    .app > .faq { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 7; }
    header h1 { font-size: 2.2rem; }
    .form-grid { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
    .form-grid .field > label { margin-top: 0; }
    #setup-form .row-btns { max-width: 420px; }
    #setup-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); column-gap: 1.5rem; align-items: start; }
    #setup-view > .c-name, #setup-view > .c-line { grid-column: 1; }
    #setup-view > .c-now { grid-column: 2; grid-row: 1 / span 3; margin: 0; font-size: 1.1rem; }
    #setup-view > .c-links { grid-column: 1; }
    .pay { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
    .pay .part-panel { grid-column: 1 / -1; }
    .pay-btns > button { flex: 0 1 auto; }
}
