@font-face { font-family: "Bricolage Grotesque"; src: url("fonts/bricolage-grotesque.woff2") format("woff2"); font-weight: 600 800; font-display: swap; }

:root {
  --bg: #f1efe9; --surface: #ffffff; --ink: #1f1a1b; --muted: #594e4f; --line: #d8d0cc; --soft: #f7f5f1;
  --red: #9e1b1b; --red-ink: #ffffff; --red-soft: #f7e4e1; --gold: #7d5800; --gold-soft: #f8eccc;
  --head: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 6px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161213; --surface: #221c1d; --ink: #f2ebea; --muted: #c4b6b5; --line: #44393a; --soft: #1c1718;
    --red: #ff8f82; --red-ink: #1b0d0d; --red-soft: #3f2023; --gold: #f2c461; --gold-soft: #3a2f16;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--body); }
a { color: var(--red); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }
h1, h2, h3, h4 { font-family: var(--head); line-height: 1.15; }
h1 { font-size: clamp(2rem, 7vw, 2.9rem); font-weight: 800; margin: 0 0 .4rem; letter-spacing: -0.01em; }
h2 { font-size: 1.55rem; font-weight: 700; margin: 2.2rem 0 .6rem; }
h3 { font-size: 1.2rem; font-weight: 700; margin: 1.3rem 0 .3rem; }
h4 { font-size: 1.05rem; font-weight: 700; margin: 0 0 .4rem; }
p, li { max-width: 70ch; }
small { font-size: 1rem; color: var(--muted); font-weight: 400; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: .5rem .8rem; z-index: 20; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { background: var(--surface); border-bottom: 3px solid var(--red); }
.top-in { display: flex; align-items: center; min-height: 56px; }
.brand { font: 800 1.35rem var(--head); color: var(--ink); text-decoration: none; display: inline-flex; gap: .5rem; align-items: center; }
.brand svg { width: 30px; height: 30px; }
.hero { padding: 1.4rem 0 .6rem; }
.hero p { margin: 0; font-size: 1.08rem; }

/* controls */
.btn { font: 600 1rem var(--body); min-height: 48px; padding: .55rem 1rem; border-radius: var(--r); border: 1.5px solid var(--ink); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--soft); }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--red-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--red); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .55; cursor: default; }
.linkish { background: none; border: 0; padding: .6rem 0; min-height: 44px; font: inherit; color: var(--red); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.row-btns { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0 0; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 0; border: 1.5px solid var(--ink); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg button { font: 600 1rem var(--body); min-height: 46px; min-width: 46px; padding: .45rem .85rem; border: 0; border-right: 1.5px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg.seg-wrap { display: flex; width: fit-content; max-width: 100%; }
.seg.seg-wrap button { flex: 1 1 auto; }
.field { margin: 0 0 1rem; display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }
.lab { font-weight: 700; }
.check { display: flex; gap: .55rem; align-items: center; min-height: 44px; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--red); margin: 0; }
input[type="text"] { font: 600 1.1rem var(--body); color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r); padding: .45rem .6rem; min-height: 46px; width: 100%; }
input[type="text"]:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 2px var(--red-soft); }
input[aria-invalid="true"] { border-color: var(--red); background: var(--red-soft); }
input::placeholder { color: var(--muted); opacity: .8; font-weight: 400; }
.hint { color: var(--muted); margin: .4rem 0 0; }
.note { padding: .7rem .9rem; border-radius: var(--r); margin: .6rem 0; }
.note.warn { background: var(--red-soft); }
.note.info { background: var(--gold-soft); }

/* setup */
.setup { background: var(--surface); border-radius: var(--r); padding: 1rem 1rem 1.2rem; border-top: 4px solid var(--ink); }
.setup h2 { margin-top: 0; }
.summary { color: var(--muted); margin: -.2rem 0 1rem; }
.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .7rem; max-width: 760px; }
.name span, .rf span { display: block; font-weight: 700; margin-bottom: .2rem; }
.more { margin: .8rem 0 0; }

/* scoreboard */
.board { margin: .4rem 0 0; }
.scores { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 0; background: var(--surface); border-radius: var(--r); border-top: 4px solid var(--ink); }
.scores.n3 { --n: 3; }
.sc { padding: .7rem .9rem .8rem; display: flex; flex-direction: column; min-width: 0; }
.sc + .sc { border-left: 1px solid var(--line); }
.sc .nm { font-weight: 700; overflow-wrap: break-word; hyphens: auto; }
.sc .tot { font: 800 clamp(1.9rem, 8vw, 3rem)/1.05 var(--head); font-variant-numeric: tabular-nums; margin: .15rem 0; }
.sc.lead .tot { color: var(--red); }
.sc .need { color: var(--muted); }
.gameline { color: var(--muted); margin: .5rem 0 0; }
.win { background: var(--gold-soft); border-radius: var(--r); padding: .8rem 1rem; margin: 1rem 0 0; }
.win p { margin: 0; font-size: 1.15rem; }

/* hand entry */
.entry { margin-top: 1.4rem; }
.entry h2 { margin: 0 0 .7rem; }
.entry.fixing h2 { color: var(--red); }
.tabs { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: .4rem; margin: .4rem 0 0; }
.tabs.n3 { --n: 3; }
.tabs button { font: 600 1rem var(--body); min-height: 56px; padding: .35rem .4rem; border: 1.5px solid var(--line); border-bottom: 0; border-radius: var(--r) var(--r) 0 0; background: var(--soft); color: var(--ink); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; }
.tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button b { font: 700 1.05rem var(--head); font-variant-numeric: tabular-nums; }
.tabs button[aria-selected="true"] { background: var(--surface); border-color: var(--ink); border-top-width: 4px; }
.panels { display: grid; gap: 1rem; }
.panel { display: none; background: var(--surface); padding: .9rem; border: 1.5px solid var(--ink); border-radius: 0 0 var(--r) var(--r); min-width: 0; }
.panel.shown { display: block; }
.panel h3 { margin: 0 0 .7rem; display: flex; justify-content: space-between; gap: .6rem; flex-wrap: wrap; align-items: baseline; font-size: 1.3rem; }
.panel h3 .live { font: 600 1rem var(--body); color: var(--muted); }
.panel h3 .live b { font: 800 1.35rem var(--head); color: var(--ink); font-variant-numeric: tabular-nums; }
@media (min-width: 900px) {
  .tabs { display: none; }
  .panels { grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); }
  .panels.n3 { --n: 3; }
  .panel, .panel.shown { display: block; border-radius: var(--r); border-top-width: 4px; }
}
.grp { padding: .7rem 0; border-top: 1px solid var(--line); }
.grp:first-of-type { border-top: 0; padding-top: 0; }
.grp-h { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.grp-h h4 { margin: 0; }
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem .8rem; }
.step { display: flex; flex-direction: column; justify-content: space-between; gap: .25rem; min-width: 0; }
.step .lab { font-weight: 600; line-height: 1.25; }
.stepper { display: inline-flex; align-items: stretch; width: max-content; }
.stepper input { width: 52px; text-align: center; border-radius: 0; border-left: 0; border-right: 0; border-color: var(--ink); padding: .3rem 0; }
.sb { width: 44px; min-height: 46px; font: 700 1.3rem var(--body); border: 1.5px solid var(--ink); background: var(--soft); color: var(--ink); cursor: pointer; padding: 0; }
.sb:first-child { border-radius: var(--r) 0 0 var(--r); }
.sb:last-child { border-radius: 0 var(--r) var(--r) 0; }
.sb:active { background: var(--line); }
details.more summary, details.rules > summary, details.removed summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
details.more summary::before, details.rules > summary::before, details.removed summary::before { content: "+"; display: inline-block; width: 1.2em; font-weight: 800; flex: none; }
details[open].more > summary::before, details[open].rules > summary::before, details[open].removed > summary::before { content: "−"; }
details.more summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; color: var(--red); }
details.more .steps { margin-top: .3rem; }
.ct { border-collapse: collapse; width: 100%; max-width: 420px; }
.ct th, .ct td { padding: .25rem .3rem; text-align: left; }
.ct thead th { font-weight: 700; }
.ct tbody th { font-weight: 600; line-height: 1.2; }
.ct tbody th small { display: block; }
.ct td { width: 84px; }
.ct td input { text-align: center; }
.ct td.na { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--line) 6px 7px); border-radius: var(--r); }
.ct tfoot th, .ct tfoot td { border-top: 1.5px solid var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }
.ct tfoot th { text-align: left; }
.pts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .7rem; max-width: 420px; }
.pts span { display: block; font-weight: 600; margin-bottom: .2rem; }
.otherrow { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.otherrow input { width: 110px; }
.spl { display: block; max-width: 200px; }
.spl span { display: block; font-weight: 600; margin-bottom: .2rem; }
.field .hint { max-width: 42ch; margin: 0; }
.bd { margin: .8rem 0 0; border-top: 1px solid var(--line); padding-top: .6rem; max-width: 420px; }
.bd dl { margin: 0; }
.bd dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .1rem 0; }
.bd dt { color: var(--muted); }
.bd dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.bd .sum { border-top: 1.5px solid var(--ink); margin-top: .3rem; padding-top: .3rem; }
.bd .sum dt { color: var(--ink); font-weight: 700; }
.bd .sum dd { font: 800 1.2rem var(--head); }
.bd-empty { color: var(--muted); margin: 0; }
.warns ul { margin: .9rem 0 0; padding: .6rem .9rem .6rem 2rem; background: var(--gold-soft); border-radius: var(--r); }
.warns li { margin: .15rem 0; }
.after { margin: .9rem 0 0; font-size: 1.05rem; }
.after b { font-variant-numeric: tabular-nums; }

/* hands */
.hands h2 { margin-top: 2rem; }
.ht { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--r); font-variant-numeric: tabular-nums; }
.ht th, .ht td { padding: .4rem .5rem; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
.ht thead th { font-weight: 700; border-bottom: 2px solid var(--ink); overflow-wrap: anywhere; hyphens: auto; }
.ht th:first-child { text-align: left; width: 4.2rem; }
.ht td b { display: block; font: 700 1.15rem var(--head); }
.ht .d { color: var(--muted); }
.ht .d em { font-style: normal; display: block; color: var(--red); font-weight: 600; }
.ht tr.on { background: var(--red-soft); }
.ht tr.afterwin td { color: var(--muted); }
.fixbtn { font: 700 1.05rem var(--body); min-height: 44px; min-width: 52px; display: inline-flex; gap: .3rem; align-items: center; background: var(--soft); border: 1.5px solid var(--line); border-radius: var(--r); color: var(--ink); cursor: pointer; padding: 0 .5rem; }
.fixbtn svg { width: 16px; height: 16px; color: var(--muted); }
.fixbtn:disabled { cursor: default; }

/* tools and rules */
.tools { margin-top: 1.4rem; }
details.rules { margin-top: 1rem; background: var(--surface); border-radius: var(--r); padding: 0 1rem; }
details.rules > summary { cursor: pointer; font-weight: 700; min-height: 52px; display: flex; align-items: center; overflow-wrap: anywhere; }
details.rules[open] { padding-bottom: 1rem; }
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem 1rem; margin: .5rem 0; }
.rf { display: flex; flex-direction: column; justify-content: flex-end; }
.rf input { max-width: 160px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 1rem 0 0; padding: .6rem 0 0; min-width: 0; }
legend { font: 700 1.05rem var(--head); padding: 0 .3rem 0 0; }

.games .glist { list-style: none; padding: 0; margin: 0; }
.glist li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .4rem 1rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--line); max-width: none; }
.glist .row-btns { margin: 0; }
details.removed { margin-top: 1rem; }
details.removed summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: .5rem .6rem .5rem 1rem; border-radius: var(--r); display: flex; gap: .8rem; align-items: center; z-index: 30; pointer-events: none; box-shadow: 0 4px 16px rgb(0 0 0 / .25); }
.toast .btn { pointer-events: auto; min-height: 44px; background: var(--bg); color: var(--ink); border-color: var(--bg); }

/* explainer */
.content { margin-top: 2.5rem; }
.rules-t { border-collapse: collapse; width: 100%; background: var(--surface); }
.rules-t th, .rules-t td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: break-word; hyphens: auto; }
.rules-t thead th { border-bottom: 2px solid var(--ink); }
.rules-t tbody th { font-weight: 600; width: 30%; }
.faq h3 { margin-top: 1.4rem; }
.tablewrap { max-width: 100%; overflow-x: auto; }

footer.site { margin-top: 3rem; border-top: 3px solid var(--red); background: var(--surface); padding: 1.2rem 0 1.6rem; }
.sb-footer p { margin: .4rem 0; max-width: none; color: var(--muted); }
.sb-more { line-height: 1.8; }
.sb-footer a { color: var(--ink); }
.print-root { display: none; }

@media (max-width: 600px) {
  /* on a phone the toast sits at the top, clear of the steppers and buttons being tapped */
  .toast { bottom: auto; top: 12px; }
}
@media (max-width: 420px) {
  .sc { padding: .6rem .55rem .7rem; }
  /* three sides: one row each (name and meld on the left, total on the right), so long names wrap between words */
  .scores.n3 { grid-template-columns: 1fr; }
  .scores.n3 .sc { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .8rem; align-items: baseline; padding: .55rem .8rem; }
  .scores.n3 .sc + .sc { border-left: 0; border-top: 1px solid var(--line); }
  .scores.n3 .sc .nm { grid-column: 1; grid-row: 1; }
  .scores.n3 .sc .need { grid-column: 1; grid-row: 2; }
  .scores.n3 .sc .tot { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 1.9rem; margin: 0; }
  .panel { padding: .75rem .6rem; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .5rem; }
  .stepper input { width: 44px; }
  .sb { width: 42px; }
  .ht th, .ht td { padding: .4rem .3rem; }
  .ht th:first-child { width: 3.6rem; }
  .fixbtn { min-width: 46px; padding: 0 .35rem; }
  .rules-t th, .rules-t td { padding: .45rem .3rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

@media print {
  :root { --ink: #000; --muted: #333; --surface: #fff; --bg: #fff; color-scheme: light; }
  body { background: #fff; color: #000; font-size: 10pt; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block; }
  .sheet { font: 10pt/1.3 var(--body); color: #000; }
  .sh-head { border-bottom: 1.5pt solid #000; padding-bottom: 5pt; margin-bottom: 7pt; }
  .sh-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2pt 14pt; }
  .sh-title h2 { font: 800 19pt/1.1 var(--head); margin: 0; }
  .sh-title p { margin: 0; font-size: 10.5pt; }
  .sh-rules { margin: 5pt 0 0; padding-left: 11pt; font-size: 9pt; line-height: 1.3; }
  .sh-rules li { max-width: none; margin: 1pt 0; }
  .sh-table { width: calc(100% - 1.2pt); margin-left: .6pt; border-collapse: collapse; table-layout: fixed; }
  .sh-table thead { display: table-header-group; }
  .sh-table th, .sh-table td { border: .6pt solid #555; padding: 3pt 4pt; text-align: left; vertical-align: top; }
  .sh-table thead th { background: #e9e9e9; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 9pt; }
  .sh-table thead th.side { font: 700 11pt/1.15 var(--head); text-align: center; border-left: 1.6pt solid #000; overflow-wrap: anywhere; }
  .sh-table thead th.num { text-align: right; }
  .sh-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .sh-table td.need { color: #333; font-size: 9pt; }
  .sh-table td.need, .sh-table thead tr:last-child th:nth-child(5n+1) { border-left: 1.6pt solid #000; }
  .sh-table td.tot, .sh-table th.tot { background: #f3f3f3; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sh-table td.tot b { font-size: 10.5pt; }
  .sh-table td.no { text-align: center; font-weight: 700; }
  .sh-table td .out { display: block; font-weight: 600; font-size: 7.5pt; line-height: 1.1; text-align: right; }
  .sh-table tbody.hand { break-inside: avoid; }
  .sh-table tbody.late td { color: #666; }
  .sh-table col.c-no { width: .62in; }
  .sheet.blank .sh-table td { height: .34in; }
  .sheet.blank .sh-table tr.sh-close td { height: auto; }
  .sheet.blank .sh-table td.need, .sheet.blank .sh-table td:nth-child(5n+2) { border-left: 1.6pt solid #000; }
  .sheet p, .sheet li { max-width: none; }
  .sh-table tr.sh-close td { border: 0; padding: 0; background: none; color: #000; }
  .sh-table tbody.late tr.sh-close td { color: #000; }
  .sh-end { margin: 8pt 0 0; font-size: 10.5pt; break-inside: avoid; }
  .sh-key { margin: 5pt 0 0; font-size: 8.5pt; color: #333; break-inside: avoid; }
}
