:root {
  --bg: #e6ece6;
  --surface: #fbf8ef;
  --ink: #17221d;
  --muted: #3f4d46;
  --line: #b9c6bd;
  --jade: #17734f;
  --jade-ink: #0f5a3d;
  --red: #b3261e;
  --red-bg: #f8e4e1;
  --ok-bg: #dcefe4;
  --tile: #fbf8ef;
  --tile-edge: #17734f;
  --focus: #1f5fbf;
  --r: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a16;
    --surface: #18241f;
    --ink: #e8efe9;
    --muted: #b5c4bb;
    --line: #34463d;
    --jade: #5cc495;
    --jade-ink: #7fd6ad;
    --red: #ff8a80;
    --red-bg: #3a1f1d;
    --ok-bg: #173527;
    --tile: #f3efe2;
    --tile-edge: #2f8a63;
    --focus: #8ab4ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
a { color: var(--jade-ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 20; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }

.top { border-bottom: 3px solid var(--jade); background: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 10px 0; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .01em; }
h1 { font-size: 2rem; line-height: 1.15; margin: 22px 0 6px; letter-spacing: -.01em; }
.lede { margin: 0 0 16px; max-width: 62ch; color: var(--muted); }
h2 { font-size: 1.3rem; margin: 0 0 8px; }
h3 { font-size: 1.02rem; margin: 14px 0 6px; }

.btn { font: inherit; font-size: 16px; min-height: 44px; padding: 8px 14px; border-radius: var(--r); border: 1.5px solid var(--jade); background: transparent; color: var(--jade-ink); cursor: pointer; font-weight: 600; }
.btn:hover { background: color-mix(in srgb, var(--jade) 10%, transparent); }
.btn.primary { background: var(--jade); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1712; } }
.btn.quiet { border-color: var(--line); color: var(--ink); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { min-height: 44px; padding: 6px 10px; font-size: 16px; }

.save-note, .banner, .msg { background: var(--red-bg); border-radius: var(--r); padding: 10px 14px; max-width: 70ch; }
.banner { background: var(--surface); border: 2px solid var(--jade); }
.banner .btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* layout: result first (on the left on wide screens, on top on phones), then the count */
.layout { display: grid; gap: 20px; align-items: start; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(300px, 380px) 1fr; }
  .result.stick { position: sticky; top: 12px; }
}
.result { background: var(--surface); border: 1.5px solid var(--line); border-top: 5px solid var(--jade); border-radius: var(--r); padding: 14px 16px 16px; }
.result h2:focus { outline: none; }
.total { margin: 0; color: var(--muted); }
.total strong { color: var(--ink); font-size: 1.15rem; }
.verdict { font-size: 1.35rem; font-weight: 750; line-height: 1.25; margin: 4px 0 2px; }
.verdict.ok { color: var(--jade-ink); }
.verdict.ok::before { content: "✓ "; }
.tsub, .tname span { color: var(--muted); margin: 0 0 6px; font-weight: 400; }
.tname { font-weight: 700; margin: 10px 0 2px; }
.tname span { display: block; }
.tie { border-top: 1px solid var(--line); margin-top: 8px; }
.hint, .note, .spare { margin: 8px 0; }
.note { padding-left: 10px; border-left: 3px solid var(--line); }
h3.miss { color: var(--red); }
h3.extra { color: var(--ink); }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; background: var(--bg); }
.chips li.more { border-style: dashed; }
.games-h { margin-top: 18px; }
.games { list-style: none; padding: 0; margin: 0; }
.game { display: grid; grid-template-columns: 22px 1fr auto; gap: 0 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.game .mark { grid-row: span 2; font-weight: 800; }
.mark.yes { color: var(--jade-ink); }
.mark.no { color: var(--red); }
.game .gname { font-weight: 650; }
.game .gsize { color: var(--muted); }
.game .gstat, .game .gnote { grid-column: 2 / 4; color: var(--muted); overflow-wrap: anywhere; }
.game.short .gname { color: var(--muted); font-weight: 500; }
.game .gstat .btn { margin-top: 6px; display: block; }
.others { margin-top: 12px; }
.others summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.others table { border-collapse: collapse; width: 100%; }
.others th, .others td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.others tr.best th, .others tr.best td { font-weight: 750; }

.counter { min-width: 0; }
.count-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.count-total { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.how { margin: 0 0 10px; color: var(--muted); }
.group { border: 0; border-top: 2px solid var(--line); margin: 0 0 6px; padding: 10px 0 14px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; min-width: 0; }
.group legend { float: left; padding: 0; font-weight: 700; font-size: 1.08rem; display: contents; }
.group .gname { grid-column: 1; }
.group .gname .aka { font-weight: 400; color: var(--muted); }
.gtotal { grid-column: 1; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; font-size: 1rem; }
.group > .btn { grid-column: 2; grid-row: 1 / span 2; }
.cells { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px 6px; margin-top: 6px; }
.g-flowers .cells, .g-bonus .cells { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.cell { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.tile { border: 0; background: none; padding: 2px; min-width: 44px; min-height: 54px; cursor: pointer; border-radius: 6px; line-height: 0; touch-action: manipulation; }
.tile:active .tg { transform: translateY(1px); }
.tg { width: 38px; height: 50px; }
.tg .tb { fill: var(--tile); stroke: var(--tile-edge); stroke-width: 1.2; }
@media (prefers-color-scheme: dark) { .tg .tb { stroke-width: 1.6; } }
.tg { filter: drop-shadow(0 2px 0 var(--tile-edge)); }
.cap { font-size: 16px; color: var(--ink); text-align: center; line-height: 1.2; min-height: 18px; }
input[type="text"], select { font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: 6px; min-height: 44px; padding: 6px 8px; max-width: 100%; }
input.num { margin-top: auto; width: 100%; max-width: 64px; text-align: center; font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; padding: 6px 2px; }
input::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus { border-color: var(--focus); }
input[aria-invalid] { border-color: var(--red); border-width: 2px; }
.g-other { display: block; }
.g-other legend { display: block; float: none; margin-bottom: 4px; }
.other-list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.orow { display: grid; grid-template-columns: 1fr 64px auto; gap: 6px; align-items: center; }
.orow input[type="text"]:not(.num) { width: 100%; }
.jump-wrap { margin: 8px 0 0; }

.blanks, .keep { margin-top: 28px; padding-top: 14px; border-top: 2px solid var(--line); }
.label-list { padding: 0; margin: 0 0 10px; list-style: none; display: grid; gap: 8px; max-width: 640px; }
.lrow { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; }
.lrow label { white-space: nowrap; }
.lrow select { width: 100%; min-width: 0; }
.lrow.over { opacity: .7; }
.lglyph .tg { width: 30px; height: 40px; }
@media (max-width: 520px) {
  .lrow { grid-template-columns: auto 1fr auto; }
  .lrow label { grid-column: 2 / 4; }
  .lrow .lglyph { grid-row: span 2; }
  .lrow select { grid-column: 2; }
}
.lbtns { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; }
.lsize { display: grid; gap: 4px; }
.set-name { display: grid; gap: 4px; max-width: 460px; margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-box, .share-box { margin-top: 10px; padding: 12px; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--surface); max-width: 640px; }
.ask-box p { margin: 0 0 8px; }
.share-box { display: grid; gap: 6px; }
.share-box input { width: 100%; }
.kept { margin-top: 12px; max-width: 760px; }
.kept summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.kept ul { list-style: none; padding: 0; margin: 0; }
.kept li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.saved-line { color: var(--muted); margin: 12px 0 0; }

.explain { margin: 34px 0 10px; padding-top: 16px; border-top: 2px solid var(--line); max-width: 760px; }
.explain h2 { margin-top: 22px; }
.explain p { max-width: 70ch; }
.table-wrap { overflow-x: auto; }
table.sets { border-collapse: collapse; min-width: 100%; }
.sets th, .sets td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sets thead th { font-size: 16px; color: var(--muted); }
@media (max-width: 620px) {
  .sets thead { display: none; }
  .sets tr { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .sets th, .sets td { border: 0; padding: 0; }
  .sets th[scope="row"] { grid-row: span 5; font-size: 1.2rem; }
  .sets td:nth-of-type(1)::before { content: "Suits: "; color: var(--muted); }
  .sets td:nth-of-type(2)::before { content: "Winds and dragons: "; color: var(--muted); }
  .sets td:nth-of-type(3)::before { content: "Flowers: "; color: var(--muted); }
  .sets td:nth-of-type(4):empty { display: none; }
  .sets td:nth-of-type(5)::before { content: "Played as: "; color: var(--muted); }
}
.faq details { border-top: 1px solid var(--line); }
.faq summary { cursor: pointer; min-height: 44px; padding: 10px 0; font-weight: 650; }
.faq p { margin: 0 0 12px; }
.sources { color: var(--muted); margin-top: 20px; }

.toast { position: fixed; left: 0; right: 0; bottom: 12px; margin: 0 auto; width: max-content; pointer-events: none; background: var(--ink); color: var(--bg); padding: 8px 10px 8px 14px; border-radius: var(--r); display: flex; gap: 12px; align-items: center; max-width: calc(100% - 24px); z-index: 30; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.toast button { pointer-events: auto; font: inherit; font-weight: 700; min-height: 40px; padding: 4px 10px; border-radius: 6px; border: 1.5px solid currentColor; background: transparent; color: inherit; cursor: pointer; }

.foot { margin-top: 30px; padding: 18px 0 30px; border-top: 3px solid var(--jade); background: var(--surface); }
.sb-footer p { margin: 6px 0; color: var(--muted); }
.sb-more { overflow-wrap: anywhere; }
.sb-credit { color: var(--ink); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } .tile:active .tg { transform: none; } }

#print-root { display: none; }

/* ---------- print ---------- */
@media print {
  @page { margin: 12mm; }
  html, body { background: #fff !important; color: #000 !important; font-size: 11pt; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  #print-root * { color: #000; }
  .tg { filter: none; }
  .tg .tb { fill: #fff; stroke: #333; stroke-width: 1; }
  #print-root, #print-root svg { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ph h2 { font-size: 17pt; margin: 0 0 2pt; }
  .pmeta { margin: 0 0 8pt; font-size: 11pt; }
  table.inv { border-collapse: collapse; width: calc(100% - 2px); margin: 0 1px 6pt; table-layout: fixed; break-inside: avoid; }
  .inv th { text-align: left; font-size: 10.5pt; width: 74pt; padding: 3pt 4pt; border: 1px solid #888; }
  .inv td { border: 1px solid #888; text-align: center; padding: 2pt 1pt 1pt; vertical-align: top; }
  .inv td.off { background: #fbe3e0; border: 2px solid #b3261e; }
  .inv .pg { display: block; line-height: 0; }
  .inv .pg .tg { width: 18pt; height: 24pt; }
  .inv .pn { display: block; font-size: 13pt; font-weight: 700; min-height: 16pt; }
  .inv .pl { display: block; font-size: 8.5pt; line-height: 1.1; color: #333; }
  .presult { margin-top: 4pt; }
  .pmini { font-size: 10.5pt; margin: 0 0 2pt; color: #333; font-weight: 600; break-after: avoid; }
  .nw { white-space: nowrap; }
  .inv td.nil { border: 0; }
  .pres { margin: 2pt 0 4pt; break-inside: avoid; }
  .pverdict { font-weight: 700; font-size: 12.5pt; margin: 0 0 3pt; }
  .pline { margin: 3pt 0; font-size: 11pt; }
  .pgames { border-collapse: collapse; width: calc(100% - 2px); margin: 6pt 1px; break-inside: avoid; }
  .pgames th, .pgames td { border: 1px solid #888; padding: 2pt 6pt; text-align: left; font-size: 10.5pt; }
  #print-root.blank .inv .pn { min-height: 24pt; }
  .plist { columns: 2; margin: 0 0 8pt; padding-left: 18pt; font-size: 11pt; }
  .labels { display: flex; flex-wrap: wrap; gap: 0; }
  .label { width: 0.9in; height: 1.2in; border: 1px dashed #777; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3pt; padding: 3pt; break-inside: avoid; text-align: center; }
  .label .lt { line-height: 0; }
  .label .lt .tg { width: 0.45in; height: 0.6in; }
  #print-root .labels { width: 7.2in; }
  #print-root[data-size="s"] .labels { width: 6.75in; }
  #print-root[data-size="l"] .labels { width: 7in; }
  #print-root[data-size="s"] .label { width: 0.75in; height: 1in; padding: 2pt; }
  #print-root[data-size="s"] .label .lt .tg { width: 0.36in; height: 0.48in; }
  #print-root[data-size="s"] .label .ln { font-size: 9pt; }
  #print-root[data-size="l"] .label { width: 1in; height: 1.4in; }
  #print-root[data-size="l"] .label .lt .tg { width: 0.52in; height: 0.7in; }
  .label .ln { font-size: 10pt; font-weight: 700; line-height: 1.15; }
  .label.empty { justify-content: flex-end; align-items: flex-start; }
  .label.empty .ln { font-weight: 400; border-bottom: 1px solid #777; width: 100%; text-align: left; padding-bottom: 14pt; }
}
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
  @media print { .pgames caption { text-align: left; font-weight: 700; font-size: 11pt; padding: 0 0 3pt; } }
