/* Ned Kelly: parchment and iron. Mobile first: the base rules are the 390 px phone layout.
   Suit colours: Train, Lantern, Gun, Fire. Night is indigo with a moon, Dawn is amber with a sun. */
:root {
  --paper: #f3ebd6;
  --paper-2: #e6d8b8;
  --card: #fbf5e6;
  --ink: #261d15;
  --ink-soft: #62523f;
  --line: #d3c29d;
  --accent: #b4532a;
  --accent-dark: #8a3b1b;
  --gold: #d9a21b;
  --felt: #231c16;
  --felt-dark: #120e0b;
  --felt-light: #7d4f22;
  --good: #2c7a45;
  --night: #26365e;
  --night-ink: #e8edff;
  --dawn: #f0b84a;
  --dawn-ink: #2b1a08;
  /* one colour and one shape per suit, so no suit relies on colour alone */
  --s-train: #8aaaca;
  --s-lantern: #e2b04a;
  --s-gun: #7a8977;
  --s-fire: #d2633e;
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --gutter: 16px;
  --tw: 56px; /* width of a card in the trick */
  --hw: min(64px, calc((100vw - 2 * var(--gutter) - 24px - 24px) / 6)); /* width of a card in the hand (6 per row on a phone) */
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-body);
  overflow-x: hidden;
}
main { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter) 32px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; margin: 0 0 8px; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 8px; }
img { max-width: 100%; }
a { color: var(--felt-light); }
small { font-size: 0.8em; }
.muted { color: var(--ink-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--felt-light); outline-offset: 2px; }

/* ---------- buttons and form bits ---------- */
.btn, .linkbtn { font: inherit; color: inherit; cursor: pointer; }
.btn { min-height: 44px; padding: 8px 18px; border-radius: 999px; border: 2px solid var(--ink); background: var(--card); font-weight: 700; }
.btn:hover { background: var(--paper-2); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; box-shadow: 0 3px 0 var(--accent-dark); }
.btn--primary:hover { background: var(--accent-dark); }
.btn--big { font-size: 1.1rem; padding: 10px 26px; }
.btn--quiet { border-color: var(--line); font-weight: 600; }
.btn--small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.linkbtn { background: none; border: 0; padding: 8px 6px; min-height: 40px; text-decoration: underline; text-underline-offset: 3px; color: var(--felt-light); font-weight: 600; }
select, input[type='text'] { font: inherit; color: var(--ink); background: #fff; border: 2px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 42px; max-width: 100%; width: 100%; }
.field { display: flex; flex-direction: column; gap: 2px; font-weight: 600; font-size: 0.9rem; margin: 6px 0; }
.field small { font-weight: 400; color: var(--ink-soft); }

/* ---------- landing ---------- */
.landing { padding-top: 4px; }
.topnav { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.topnav__brand { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; color: var(--accent-dark); }
.hero { margin-bottom: 14px; }
.hero__art { border-radius: 14px; overflow: hidden; border: 3px solid var(--ink); background: #e9e0c8; box-shadow: 0 4px 0 var(--accent-dark); }
.hero__art img, .hero__art picture { display: block; width: 100%; height: auto; }
.hero__art--plain { padding: 22px 12px; text-align: center; color: #fff; background: var(--felt); }
.hero__title { font-family: var(--font-display); font-weight: 700; font-size: 2rem; margin: 0 0 8px; }
.hero__suits { display: flex; justify-content: center; gap: 10px; margin: 0; }
.hero__art .hero__suit { width: 30px; height: 30px; font-size: 1rem; display: inline-grid; }
.hero__text { padding: 14px 2px 0; }
.hero__hook { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; margin-bottom: 6px; color: var(--accent-dark); line-height: 1.1; }
.hero__sub { color: var(--ink-soft); }
.stats { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 14px; }
.stats li { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.stats svg { width: 30px; height: 30px; flex: none; }
.stats b { display: block; font-family: var(--font-display); font-size: 1.25rem; line-height: 1.1; white-space: nowrap; }
.stats span { font-size: 0.8rem; color: var(--ink-soft); }
.panel { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.setup-panel { border-color: var(--ink); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 4px; }
.segs { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { position: relative; flex: 1; min-width: 78px; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 10px 8px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700; }
.seg input:checked + span { background: var(--felt); border-color: var(--felt-dark); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--felt-light); outline-offset: 2px; }
.setup__seats { display: grid; grid-template-columns: 1fr; gap: 8px 14px; margin-top: 10px; }
.seatform { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px 8px; }
.seatform legend { font-family: var(--font-display); font-size: 0.95rem; padding: 0 4px; }
.hint { color: var(--ink-soft); margin: 10px 0; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--felt-light); }
.check span { display: flex; flex-direction: column; gap: 2px; }
.check small { color: var(--ink-soft); font-size: 0.85rem; }
.form-msg { color: var(--accent-dark); font-weight: 700; min-height: 1.2em; }
.rules { border: 2px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin: 10px 0; background: var(--paper); }
.rules summary { cursor: pointer; font-weight: 700; padding: 6px 0; min-height: 40px; }
.rules summary small { font-weight: 400; color: var(--ink-soft); margin-left: 6px; }
.rules__intro { color: var(--ink-soft); }
.rule { padding: 8px 0; border-top: 1px solid var(--line); }
.rule label { font-weight: 700; display: block; margin-bottom: 4px; }
.rule__id { display: inline-block; font-size: 0.72rem; background: var(--ink); color: #fff; border-radius: 4px; padding: 0 5px; margin-right: 4px; vertical-align: 1px; }
.rule__desc { font-size: 0.85rem; color: var(--ink-soft); margin: 4px 0 0; }
.rules-note, .rules-flag { background: #fff0c9; border: 2px solid var(--gold); border-radius: 10px; padding: 8px 12px; font-weight: 600; margin: 8px 0; }
.footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; color: var(--ink-soft); font-size: 0.9rem; padding: 10px 0; }

/* how to play */
.how__lead { font-size: 1.05rem; }
.how__steps { padding-left: 0; list-style: none; counter-reset: step; display: grid; gap: 10px; }
.how__steps > li { counter-increment: step; position: relative; padding: 0 0 0 44px; }
.how__steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; }
.how__steps h3 { margin-bottom: 2px; }
.how__suits { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: 6px 0 0; }
.how__suits li { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.how__suits small { font-weight: 400; color: var(--ink-soft); }
.how__badge { width: 26px; height: 26px; }
.how__link { margin-top: 10px; }

/* ---------- game screen ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }
.topbar__title { font-family: var(--font-display); font-weight: 700; color: var(--accent-dark); font-size: 1.1rem; white-space: nowrap; }
.topbar .linkbtn { white-space: nowrap; padding: 8px 4px; }
.topbar__right { display: flex; gap: 4px; }
.game { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.col--main { min-width: 0; display: grid; gap: 12px; }

.table {
  display: grid; gap: 8px; padding: 10px; border-radius: 16px; border: 3px solid var(--felt-dark);
  background: var(--felt) url('assets/table-texture.webp');
  grid-template-columns: 1fr 1fr;
}
.table[data-n='2'] { grid-template-columns: 1fr; grid-template-areas: 'r1' 'centre' 'me'; }
.table[data-n='3'] { grid-template-areas: 'r1 r2' 'centre centre' 'me me'; }
.table[data-n='4'] { grid-template-areas: 'r1 r2' 'r3 r3' 'centre centre' 'me me'; }
.table[data-n='5'] { grid-template-areas: 'r1 r2' 'r3 r4' 'centre centre' 'me me'; --tw: 50px; }
.area-r1 { grid-area: r1; } .area-r2 { grid-area: r2; } .area-r3 { grid-area: r3; } .area-r4 { grid-area: r4; }
.area-me { grid-area: me; } .area-centre { grid-area: centre; }

/* seats */
.seat { align-self: start; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 6px 8px; display: flex; flex-direction: column; gap: 5px; min-width: 0; position: relative; container-type: inline-size; }
.seat.is-turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 162, 27, 0.75); }
.seat.is-winning { border-color: var(--good); }
/* avatar | name | cards in hand (the big number); the Dealer / turn tags drop to a row of their own */
.seat__head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; min-width: 0; }
.seat__head .seat__tags { grid-column: 1 / -1; grid-row: 2; }
.seat__head .seat__tags:empty { display: none; }
.seat__cards { grid-column: 3; grid-row: 1; display: flex; flex-direction: column; align-items: center; line-height: 1; width: 3.3rem; }
.seat__cardsnum { font-family: var(--font-display); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.seat__cards small { font-size: 0.56rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); text-align: center; line-height: 1.1; margin-top: 2px; }
/* A narrow seat (5 players, phones) drops its avatar so the name is never cut: the name matters more. */
@container (max-width: 215px) {
  .seat__head { grid-template-columns: minmax(0, 1fr) auto; }
  .seat__head .seat__avatar { display: none; }
  .seat__cards { grid-column: 2; }
}
.seat__avatar, .pad__avatar, .rank__avatar, .cover__avatar { border-radius: 50%; object-fit: cover; background: var(--paper-2); flex: none; }
.seat__avatar { width: 34px; height: 34px; }
.seat.is-turn .seat__avatar { box-shadow: 0 0 0 3px var(--gold); }
.avatar-chip { display: inline-grid; place-items: center; color: #fff; font-weight: 800; }
.avatar-chip--1 { background: var(--s-fire); } .avatar-chip--2 { background: var(--s-train); } .avatar-chip--3 { background: var(--s-gun); }
.avatar-chip--4 { background: var(--s-lantern); color: var(--ink); } .avatar-chip--5 { background: var(--felt-light); }
.seat__id { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.seat__name { font-weight: 800; overflow-wrap: anywhere; }
.seat__tags { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 0.68rem; font-weight: 700; border-radius: 999px; padding: 0 7px; background: var(--paper-2); color: var(--ink-soft); width: fit-content; }
.badge--human { background: var(--felt-light); color: #fff; }
.tag { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; border-radius: 6px; padding: 1px 6px; }
.tag--dealer { background: var(--ink); color: #fff; }
.tag--turn { background: var(--gold); color: var(--ink); }
.seat__score { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; font-size: 0.82rem; color: var(--ink-soft); }
.seat__score b { color: var(--ink); }
.total b { font-family: var(--font-display); font-size: 1rem; }
.plus { color: var(--good); font-weight: 700; }
.badge-suit { display: inline-block; border-radius: 50%; flex: none; vertical-align: middle; }
span.badge-suit { display: inline-grid; place-items: center; color: #fff; font-size: 0.7em; }
.badge-suit--train { background: var(--s-train); color: var(--ink); } .badge-suit--lantern { background: var(--s-lantern); color: var(--ink); }
.badge-suit--gun { background: var(--s-gun); } .badge-suit--fire { background: var(--s-fire); }

/* card faces: art when there is some, a drawn face (number + suit shape) when there is not */
.cardimg { display: block; width: 100%; height: auto; aspect-ratio: 300 / 429; user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 1px 3px rgba(43, 33, 24, 0.5)); }
.asset-chip.cardchip { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; background: #fff; border: 2px solid var(--ink); border-radius: 8px; color: var(--ink); font-size: 0.8rem; }
.asset-chip.cardchip b { font-family: var(--font-display); font-size: 1.5em; line-height: 1; }
.asset-chip.cardchip i { font-style: normal; font-size: 1.1em; line-height: 1; }
.asset-chip.cardchip--train { color: #4f739a; border-color: var(--s-train); } .asset-chip.cardchip--lantern { color: #9a7316; border-color: var(--s-lantern); }
.asset-chip.cardchip--gun { color: #4f5c4c; border-color: var(--s-gun); } .asset-chip.cardchip--fire { color: #a8431f; border-color: var(--s-fire); }
.asset-chip.cardchip--ned { color: var(--ink); border-color: var(--gold); }
.asset-chip.cardchip--back { background: repeating-linear-gradient(45deg, var(--felt), var(--felt) 6px, var(--felt-light) 6px, var(--felt-light) 12px); border-color: var(--ink); }

/* centre: status and trick */
.area-centre { background: rgba(255, 250, 240, 0.95); border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.status__line { font-size: 0.82rem; color: var(--ink-soft); font-weight: 600; margin: 0; }
.status__prompt { font-weight: 700; margin: 2px 0 0; min-height: 2.9em; }
.trick__title { font-family: var(--font-display); font-weight: 700; margin: 4px 0; font-size: 1rem; }
.led { white-space: nowrap; }
.led__badge { width: 20px; height: 20px; margin-right: 3px; vertical-align: -5px; }
.tplays { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 0; margin: 0; }
.tplay { display: flex; flex-direction: column; align-items: center; gap: 2px; width: var(--tw); }
.tplay__card, .tplay__slot { display: block; width: var(--tw); }
.tplay__slot { aspect-ratio: 300 / 429; border: 2px dashed var(--line); border-radius: 6px; }
.tplay__who { margin-top: 4px; font-size: 0.72rem; font-weight: 700; line-height: 1.1; text-align: center; max-width: calc(var(--tw) + 14px); overflow-wrap: anywhere; }
.tplay__tags { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; min-height: 1.1em; }
.mark { font-style: normal; font-size: 0.6rem; text-transform: uppercase; font-weight: 800; letter-spacing: 0.03em; padding: 0 4px; border-radius: 4px; background: var(--paper-2); }
.tplay.is-winner .tplay__card .cardimg { box-shadow: 0 0 0 4px var(--good), 0 0 16px rgba(47, 122, 69, 0.7); border-radius: 6%; animation: pop 0.5s ease-out; }
.tplay.is-lost { opacity: 0.6; }
.trick__msg { margin: 6px 0 0; text-align: center; min-height: 1.5em; font-size: 0.9rem; color: var(--ink-soft); }
.trick__msg.is-banner { font-weight: 800; color: var(--ink); }
body[data-busy='1'] .area-centre { cursor: pointer; }

/* the hand */
.handbox { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px 10px; }
.handbox.is-turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 162, 27, 0.65); }
.handbox__title { font-family: var(--font-display); font-weight: 700; margin: 0 0 6px; }
.handbox__title span { font-family: var(--font-body); font-weight: 400; font-size: 0.8rem; color: var(--ink-soft); margin-left: 6px; }
.handbox__back { width: 50px; }
.hand { display: grid; grid-template-columns: repeat(6, var(--hw)); gap: 8px 4px; justify-content: center; padding-top: 8px; }
.card { padding: 0; border: 0; background: none; position: relative; width: var(--hw); cursor: pointer; font: inherit; border-radius: 6px; transition: transform 0.12s ease; -webkit-tap-highlight-color: transparent; }
.card.is-legal:hover, .card.is-legal:focus-visible, .card.is-selected { transform: translateY(-8px); }
.card.is-selected .cardimg, .card.is-legal:hover .cardimg { filter: drop-shadow(0 0 3px var(--felt-light)) drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35)); }
.card.is-blocked { cursor: not-allowed; }
.card.is-blocked .cardimg { filter: grayscale(0.9) brightness(0.62); opacity: 0.7; }
.card.is-wait { cursor: default; }
.card__hint { position: absolute; right: -3px; bottom: -3px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 0.8rem; font-weight: 900; line-height: 1; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.legend { font-size: 0.82rem; color: var(--ink-soft); margin: 8px 0 2px; }
.hint-dot { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 0.7rem; font-weight: 900; color: #fff; vertical-align: 1px; }
.preview { min-height: 2.9em; margin: 4px 0 0; font-weight: 600; color: var(--ink-soft); }
.preview--on { color: var(--ink); }
.note { margin: 0; color: var(--accent-dark); font-weight: 700; min-height: 1.3em; }

/* a decision that is not a card (none here: the reckoning carries Continue) */
.decision { background: #fff0c9; border: 2px solid var(--gold); border-radius: 12px; padding: 8px 10px 10px; margin-bottom: 10px; }

/* score pad and log */
.side .panel { padding: 6px 12px 10px; margin-bottom: 10px; }
.side summary { font-family: var(--font-display); font-weight: 700; cursor: pointer; padding: 6px 0; min-height: 36px; }
.pad { border-collapse: collapse; width: 100%; font-size: 0.9rem; table-layout: fixed; }
.pad th, .pad td { padding: 3px 2px; text-align: center; border-bottom: 1px solid var(--line); }
.pad thead th { vertical-align: bottom; }
.pad tbody th, .pad tfoot th { text-align: left; font-weight: 600; width: 26%; }
.pad__avatar { width: 24px; height: 24px; display: block; margin: 0 auto 1px; font-size: 0.7rem; }
.pad__name { display: block; font-size: 0.7rem; line-height: 1.1; overflow-wrap: anywhere; }
.pad tr.is-now td, .pad tr.is-now th { background: #fff0c9; }
.pad tr.is-todo td { color: var(--line); }
.pad tfoot th, .pad tfoot td { font-family: var(--font-display); font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
/* A negative amount must never break after its minus sign (5 players: the side column is only ~48 px a seat). */
.pad td { white-space: nowrap; }
.pad tfoot td { font-size: 0.82rem; }
.log__list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; font-size: 0.88rem; }
.log__item { padding: 5px 0; border-bottom: 1px solid var(--line); }
.log__item--hand { font-weight: 700; color: var(--felt-light); }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(43, 33, 24, 0.62); display: flex; align-items: center; justify-content: center; padding: var(--gutter); z-index: 20; }
.end, .dialog { background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 18px; width: 100%; max-width: 680px; max-height: calc(100vh - 2 * var(--gutter)); overflow: auto; position: relative; }
.end__kicker { font-family: var(--font-display); font-weight: 700; color: var(--accent-dark); margin: 0; }
.end__note { color: var(--ink-soft); font-size: 0.85rem; }
.end__buttons, .dialog__buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.end__rules, .end__tiebreak { margin: 8px 0; }
.end__tiebreak { background: #fff0c9; border: 2px solid var(--gold); border-radius: 10px; padding: 8px 12px; font-weight: 600; }
.dialog__close { position: absolute; right: 8px; top: 6px; border: 0; background: none; font-size: 1.8rem; line-height: 1; cursor: pointer; width: 44px; height: 44px; }
.dialog--wide { max-width: 760px; }
.table-wrap { overflow-x: auto; }
.summary { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.summary th, .summary td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.summary thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.summary th[scope='row'] { font-weight: 700; }
.summary .who { display: flex; align-items: center; gap: 6px; }
.summary .who .pad__avatar { margin: 0; }
.summary .num { text-align: center; }
.ranking { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.rank { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 6px 10px; }
.rank.is-winner { border-color: var(--gold); background: #fff3d0; }
.rank__pos { font-family: var(--font-display); font-weight: 700; width: 26px; text-align: center; font-size: 1.2rem; }
.rank__avatar { width: 44px; height: 44px; }
.rank__who { display: flex; flex-direction: column; flex: 1; min-width: 100px; line-height: 1.2; }
.crown { font-style: normal; font-size: 0.72rem; font-weight: 800; background: var(--gold); border-radius: 6px; padding: 0 6px; width: fit-content; margin-top: 2px; }
.rank__total { font-size: 0.9rem; }
.rank__total b { font-family: var(--font-display); font-size: 1.5rem; }
.pad--end { width: 100%; }
.endbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: #fff3d0; border: 2px solid var(--gold); border-radius: 12px; padding: 8px 12px; grid-column: 1 / -1; }
.endbar > span { flex: 1; min-width: 160px; }
.cover { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: var(--gutter); background: var(--felt); }
.cover__card { background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 22px 18px; text-align: center; max-width: 440px; width: 100%; }
.cover__avatar { width: 90px; height: 90px; margin: 0 auto 6px; display: grid; font-size: 2rem; }
.cover__kicker { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.78rem; font-weight: 800; color: var(--ink-soft); margin: 0; }
.cover h2 { font-size: 1.8rem; overflow-wrap: anywhere; }
.cover__msg { color: var(--ink-soft); }
.asset-chip { display: inline-block; background: var(--paper-2); border: 1px dashed var(--ink-soft); border-radius: 6px; padding: 1px 6px; font-size: 0.8rem; color: var(--ink-soft); }

/* ---------- animation (all of it off under reduced motion) ---------- */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes bump { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.3); } }
.fx-bump { animation: bump 0.55s ease-out; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .setup__seats { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 700px) {
  :root { --tw: 66px; --hw: clamp(56px, calc((100vw - 2 * var(--gutter) - 24px - 40px) / 9), 92px); }
  .hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 4px; }
  .card.is-first:not(:first-child) { margin-left: 8px; }
  .table { padding: 14px; gap: 10px; }
  .table[data-n='3'] { grid-template-columns: 1fr 2fr 1fr; grid-template-areas: 'r1 centre r2' '. me .'; }
  .table[data-n='4'] { grid-template-columns: 1fr 2.1fr 1fr; grid-template-areas: '. r2 .' 'r1 centre r3' '. me .'; --tw: 56px; }
  .table[data-n='5'] { grid-template-columns: 1fr 1.2fr 1.2fr 1fr; grid-template-areas: '. r2 r3 .' 'r1 centre centre r4' '. me me .'; --tw: 46px; }
  .table[data-n='2'] { --tw: 84px; }
  .seat__avatar { width: 44px; height: 44px; }
  .seat { padding: 8px 10px; gap: 6px; }
}
@media (min-width: 1000px) {
  .game { grid-template-columns: minmax(0, 1fr) 320px; }
  :root { --hw: clamp(56px, calc((min(100vw, 1240px) - 2 * var(--gutter) - 334px - 24px - 40px) / 8), 96px); --tw: 68px; }
  .table[data-n='4'] { --tw: 58px; }
  .table[data-n='5'] { --tw: 48px; }
  .side { position: sticky; top: 8px; }
  .stats { max-width: 760px; }
}
@media (min-width: 1100px) {
  .landing { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); gap: 0 28px; align-items: start; }
  .landing .topnav, .landing .footer, .landing .hero { grid-column: 1 / -1; }
  .landing .stats { grid-column: 1 / -1; max-width: none; }
}
@media (max-width: 380px) {
  :root { --gutter: 12px; }
}
@media (max-width: 480px) {
  .topbar__title { display: none; }
  .stats li { padding: 8px 6px; gap: 5px; }
  .stats svg { width: 22px; height: 22px; }
  .stats b { font-size: 1.05rem; }
}

/* stats screen, bug reporter */
.st h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.st__lead { font-size: 1.1rem; }
.st__empty { padding: 24px 0; text-align: center; color: var(--ink-soft); }
.st__muted { color: var(--ink-soft); font-size: 0.9rem; margin: 2px 0 4px; }
.st__small { color: var(--accent-dark); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.st__scroll { overflow-x: auto; }
.st__table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.st__table th, .st__table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.st__table thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.st__table td { font-variant-numeric: tabular-nums; }
.st__filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; margin: 8px 0; }
.st__filter select { font: inherit; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 8px; background: var(--card); max-width: 100%; width: auto; }
@media (max-width: 480px) {
  .st__table { font-size: 0.82rem; }
  .st__table th, .st__table td { padding: 5px 3px; }
  .st__table thead th { font-size: 0.66rem; letter-spacing: 0; }
  .st__small { display: block; font-size: 0.68rem; white-space: normal; }
}
.bug-button { position: fixed; right: 10px; bottom: 10px; z-index: 40; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); font-size: 1rem; line-height: 1; cursor: pointer; opacity: 0.55; padding: 0; }
.bug-button:hover, .bug-button:focus-visible { opacity: 1; }
body[data-covered='1'] .bug-button { display: none; }
body[data-screen='game'] { padding-bottom: 52px; }
.bug .field { display: block; margin: 8px 0; }
.bug .field span { display: block; font-weight: 700; font-size: 0.9rem; }
.bug input, .bug textarea { width: 100%; font: inherit; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 8px; background: var(--card); }
.bug__lead { color: var(--ink-soft); }
.bug__past { margin-top: 12px; font-size: 0.9rem; }
.bug__past ul { list-style: none; padding: 0; margin: 4px 0 0; }
.bug__past li { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.bug__past .linkbtn { min-height: 32px; }

/* ---------- Ned Kelly: phase banner, Ned deck, the Ned card in play, the Inn deck, lines, trick marks ---------- */
.area-centre { gap: 8px; container-type: inline-size; }
@container (max-width: 420px) {
  .phase { gap: 8px; padding: 6px 10px; }
  .phase__name { font-size: 1.3rem; letter-spacing: 0.06em; }
  .phase__icon .gl { width: 22px; height: 22px; }
  .phase__text { font-size: 0.72rem; }
  .phase__range { font-size: 0.92rem; }
}
.phase { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 10px; border: 2px solid var(--ink); }
.phase--night { background: linear-gradient(90deg, #131b33, var(--night)); color: var(--night-ink); border-color: #0b1124; }
.phase--dawn { background: linear-gradient(90deg, #f7cd68, #f0a24a); color: var(--dawn-ink); border-color: #7a4a10; }
.phase__icon .gl { width: 30px; height: 30px; display: block; }
.phase__name { font-family: var(--font-display); font-size: 1.55rem; letter-spacing: 0.14em; line-height: 1; }
.phase__text { display: flex; flex-direction: column; margin-left: auto; text-align: right; font-size: 0.78rem; line-height: 1.25; font-weight: 600; }
.phase__range { font-size: 1.02rem; font-family: var(--font-display); white-space: nowrap; }
.gl { width: 1em; height: 1em; flex: none; }

.nedrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1fr); gap: 8px; align-items: start; }
.slot { margin: 0; display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; }
.slot__card { position: relative; width: 100%; max-width: 132px; aspect-ratio: 300 / 429; }
.slot__card--play { max-width: 168px; }
.slot__img { width: 100%; height: auto; display: block; }
.slot__empty { position: absolute; inset: 0; border: 2px dashed var(--line); border-radius: 8px; display: grid; place-items: center; font-size: 0.75rem; color: var(--ink-soft); padding: 4px; text-align: center; }
.count { position: absolute; right: -7px; top: -7px; z-index: 3; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; background: var(--ink); color: #fff; font: 700 0.85rem/22px var(--font-display); text-align: center; border: 2px solid var(--card); }
.slot figcaption { margin-top: 7px; font-size: 0.76rem; line-height: 1.25; display: flex; flex-direction: column; gap: 1px; color: var(--ink-soft); }
.slot figcaption b { font-size: 0.84rem; color: var(--ink); }
.linenum { font-style: normal; font-family: var(--font-display); font-size: 1.7rem; color: var(--accent-dark); line-height: 1; }
.standing { color: var(--accent-dark); font-weight: 700; }
.inncap { display: block; font-style: normal; font-weight: 800; padding: 2px 6px; border-radius: 6px; margin-top: 3px; font-size: 0.78rem; color: var(--ink); background: var(--paper-2); }
.inncap--taken { background: var(--accent); color: #fff; }
.inncap--added, .inncap--stays { background: var(--paper-2); }
.slot__card--taken .cardimg { box-shadow: 0 0 0 3px var(--accent); border-radius: 6%; }
.slot--inn .slot__card, .slot--deck .slot__card { max-width: 112px; }

/* every Ned card carries its Night / Dawn chip (the two 7s look alike) */
.ned { position: relative; display: block; }
.nedchip { position: absolute; left: 50%; top: 5%; transform: translateX(-50%); font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 1px 7px; border-radius: 8px; white-space: nowrap; z-index: 2; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.nedchip--night { background: #141c33; color: var(--night-ink); border: 1px solid #8aaaca; }
.nedchip--dawn { background: var(--dawn); color: var(--dawn-ink); border: 1px solid #8a5a10; }
.nedturn { position: relative; z-index: 2; display: block; width: 100%; }
.nedolder { position: absolute; inset: 0; pointer-events: none; }
.nedolder__item { position: absolute; inset: 0; transform: translate(calc(-8% - var(--i) * 9%), calc(2% + var(--i) * 2%)) rotate(calc(-3deg - var(--i) * 2deg)); filter: brightness(0.85); }
.nedolder--only .nedolder__item { inset: 0 auto auto 0; width: 70%; transform: translateX(calc(var(--i) * 12%)) rotate(calc(var(--i) * 2deg - 3deg)); filter: none; }
.nedolder--only .nedchip { font-size: 0.5rem; padding: 0 4px; }
.nedolder__item .cardimg { width: 100%; }
@keyframes flipin { 0% { transform: perspective(500px) rotateY(88deg); opacity: 0.2; } 100% { transform: none; opacity: 1; } }
.fx-flip { animation: flipin 0.55s ease-out; }

/* the lines still to come */
.lines { border-top: 1px solid var(--line); padding-top: 6px; }
.lines__head { margin: 0 0 4px; font-size: 0.8rem; display: flex; flex-wrap: wrap; gap: 0 10px; align-items: baseline; }
.lines__head small { color: var(--ink-soft); font-weight: 700; font-size: 0.78rem; }
.lines__rows { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.lrow { list-style: none; margin: 0; padding: 0; display: flex; gap: 3px; align-items: center; }
.lrow > .gl { width: 17px; height: 17px; margin-right: 2px; }
.lrow--night > .gl { color: var(--night); } .lrow--dawn > .gl { color: #c47a12; }
.ltile { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; font: 700 0.85rem var(--font-display); }
.ltile--night { background: var(--night); color: var(--night-ink); }
.ltile--dawn { background: var(--dawn); color: var(--dawn-ink); }
.ltile.is-turned { opacity: 0.22; text-decoration: line-through; filter: grayscale(0.6); }

/* the middle Inn pile (stacked backs) and the history of the ricochets */
.innlayer { position: absolute; inset: 0; transform: translate(calc(var(--i) * 4%), calc(var(--i) * -3%)); }
.innlayer .cardimg { width: 100%; }
.slot__card--inn .count { z-index: 4; }
.eyeline { color: var(--accent-dark); font-weight: 700; font-size: 0.74rem; margin-top: 3px; }
.innlog { border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: #fff8e8; font-size: 0.85rem; }
.innlog summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; font-weight: 700; }
.innlog__list { list-style: none; padding: 0; margin: 2px 0 8px; display: grid; gap: 5px; max-height: 230px; overflow: auto; }
.innlog__item { display: flex; align-items: center; gap: 8px; }

/* the trick */
.mark--led { background: var(--paper-2); }
.mark--hit { background: var(--good); color: #fff; }
.mark--ricochet { background: var(--accent); color: #fff; }
.mark--flew-high, .mark--under { background: #6b6358; color: #fff; }
.mark { font-size: 0.62rem; text-align: center; line-height: 1.25; padding: 1px 4px; }
.tplay__tags { flex-direction: column; align-items: center; }
.tplay { width: calc(var(--tw) + 12px); }
.tplay.is-lost { opacity: 0.55; filter: grayscale(0.55); }
.tplay.is-winner .tplay__card .cardimg { box-shadow: 0 0 0 4px var(--good), 0 0 16px rgba(44, 122, 69, 0.75); }
.tplay.is-ricochet .tplay__card .cardimg { box-shadow: 0 0 0 4px var(--accent); border-radius: 6%; }
.trick__msg { min-height: 2.6em; }
.trick__title { margin-bottom: 8px; }
.tplays { padding-top: 4px; }
.tplay__who { margin-top: 6px; }
.extras { display: grid; gap: 8px; }

/* seats: Ned cards taken, Inn cards held, the Commission's eye */
.seat__chips { display: flex; flex-wrap: wrap; gap: 4px; }
.schip { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; background: var(--paper-2); border-radius: 8px; padding: 3px 8px 4px; min-width: 0; flex: 1 1 auto; }
.schip__top { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; width: 100%; }
.schip__top b { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.schip__top i { font-style: normal; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); font-weight: 700; }
.schip__top em { font-style: normal; font-weight: 800; font-size: 0.78rem; margin-left: auto; }
.pills { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.npill { display: inline-flex; align-items: center; gap: 2px; border-radius: 10px; padding: 0 6px 0 4px; font-style: normal; min-height: 20px; }
.npill .gl { width: 11px; height: 11px; }
.npill b { font: 700 0.8rem var(--font-display); }
.npill--night { background: var(--night); color: var(--night-ink); }
.npill--dawn { background: var(--dawn); color: var(--dawn-ink); }
.innbadge { position: relative; display: inline-flex; align-items: center; gap: 3px; }
.innbadge__img { width: 17px; height: auto; border-radius: 2px; display: block; filter: none; }
.innbadge b { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.seat.is-eye { border-color: #a8582b; box-shadow: 0 0 0 2px rgba(168, 88, 43, 0.35); }
.seat.is-turn.is-eye { box-shadow: 0 0 0 3px rgba(217, 162, 27, 0.75), 0 0 0 5px rgba(168, 88, 43, 0.35); }
.schip--inn.is-eye { background: #f1ddc4; }
.eye { font-style: normal; font-size: 0.64rem; font-weight: 800; letter-spacing: 0.03em; color: var(--accent-dark); flex-basis: 100%; text-transform: uppercase; }
.pad td.is-censured { color: var(--accent-dark); }
.pad .cens { display: block; font-size: 0.62rem; font-weight: 800; color: var(--accent-dark); line-height: 1; }
.pad__cens th, .pad__cens td { font-family: var(--font-body); font-weight: 600; font-size: 0.8rem; border-top: 0 !important; color: var(--ink-soft); }

/* the hand: the line guide, marked on each card only once the line is known */
.hand.has-guide .card { padding-bottom: 20px; }
.card__hint { position: absolute; left: 50%; right: auto; bottom: 0; transform: translateX(-50%); width: auto; height: auto; min-width: 0; padding: 1px 7px; border-radius: 9px; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; line-height: 1.3; border: 0; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); white-space: nowrap; }
.card__hint.is-under { background: var(--good); color: #fff; }
.card__hint.is-over { background: var(--accent); color: #fff; }
.hint-dot.is-under { background: var(--good); }
.hint-dot.is-over { background: var(--accent); margin-left: 8px; }
.legend.guide { background: #fff3d0; border: 2px solid var(--gold); border-radius: 10px; padding: 6px 10px; color: var(--ink); font-size: 0.86rem; }

/* the reckoning */
.reck { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 8px; }
.reck__row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.reck__who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.reck__who .pad__avatar { margin: 0; width: 32px; height: 32px; }
.reck__total { grid-column: 2; grid-row: 1; text-align: right; font-size: 0.85rem; color: var(--ink-soft); align-self: center; }
.reck__total b { font-family: var(--font-display); font-size: 1.15rem; color: var(--ink); }
.reck__inn { display: inline-flex; align-items: center; gap: 4px; }
.reck__inn small { color: var(--ink-soft); }
.tag--cens { background: var(--accent); color: #fff; font-style: normal; }
.reck__row.is-censured { border-color: var(--accent); background: #fbeede; }
.commission { background: #f6e6cf; border: 2px solid var(--accent); border-radius: 12px; padding: 8px 12px; margin: 8px 0; }
.commission--clear { border-color: var(--line); background: var(--card); }
.commission p { margin: 2px 0; }
.commission__verdict { font-weight: 800; color: var(--accent-dark); font-size: 1.02rem; }
.commission--clear .commission__verdict { color: var(--ink); }
.commission__left { color: var(--ink-soft); font-size: 0.88rem; }
.reck__cards { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; min-height: 22px; }
.reck__sum { grid-column: 1 / -1; display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.term { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.term b { font: 700 1.2rem var(--font-display); }
.term small { font-size: 0.66rem; color: var(--ink-soft); text-align: center; max-width: 10em; }
.term--score b { font-size: 1.55rem; color: var(--accent-dark); }
.op { font: 700 1.3rem var(--font-display); padding-bottom: 14px; }
.reck__lost { background: #fff3d0; border: 2px solid var(--gold); border-radius: 10px; padding: 6px 10px; color: var(--ink); font-weight: 600; }

/* How to play, with the first trick of the rule book as cards, and the gallery */
.how__h { margin: 16px 0 6px; font-size: 1.15rem; color: var(--accent-dark); }
.how__more { padding-left: 18px; display: grid; gap: 7px; margin: 0; }
.how__more .how__suits { display: inline-flex; vertical-align: middle; margin: 0 2px; }
.how__example { margin: 14px 0; padding: 12px 10px; border-radius: 12px; background: var(--felt) url('assets/table-texture.webp'); color: #f1e8d2; border: 3px solid var(--felt-dark); --tw: 62px; }
.how__example .tplay__who, .how__example .tplay__tags { color: #f1e8d2; }
.how__example .mark--led { color: var(--ink); }
.how__example figcaption { font-size: 0.86rem; margin-top: 10px; }
.how__example .ned { width: var(--tw); }
.gallery__groups { display: grid; gap: 16px; grid-template-columns: 1fr; }
.gallery__group { margin: 0; }
.gallery__cards { display: flex; gap: 8px; align-items: flex-start; }
.gallery__cards > * { flex: 1 1 0; max-width: 116px; min-width: 0; }
.gallery__group figcaption { font-size: 0.86rem; margin-top: 8px; color: var(--ink-soft); }
.gallery__group figcaption b { color: var(--ink); }
.gallery .nedchip, .how__example .nedchip { font-size: 0.55rem; padding: 1px 5px; }

/* the phone: five cards to a row in the hand so each stays readable */
@media (max-width: 699px) {
  :root { --hw: min(66px, calc((100vw - 2 * var(--gutter) - 24px - 16px) / 5)); }
  .hand { grid-template-columns: repeat(5, var(--hw)); gap: 8px 4px; }
}
@media (max-width: 480px) {
  .phase { gap: 8px; padding: 6px 10px; }
  .phase__name { letter-spacing: 0.08em; font-size: 1.4rem; }
  .phase__icon .gl { width: 24px; height: 24px; }
}
@media (max-width: 380px) {
  .phase__name { font-size: 1.3rem; }
  .phase__text { font-size: 0.7rem; }
  .nedrow { gap: 5px; }
}
@media (min-width: 560px) {
  .gallery__groups { grid-template-columns: 1.9fr 1fr 1fr; }
}
@media (min-width: 700px) {
  .table[data-n='3'] { grid-template-columns: 1fr 2.4fr 1fr; }
  .table[data-n='4'] { grid-template-columns: 1fr 2.5fr 1fr; }
  .table[data-n='5'] { grid-template-columns: 1fr 1.5fr 1.5fr 1fr; }
  .how__example { --tw: 78px; }
}
@media (min-width: 1000px) {
  .slot__card { max-width: 124px; }
  .slot__card--play { max-width: 164px; }
  .slot--inn .slot__card, .slot--deck .slot__card { max-width: 108px; }
}

/* the top bar must never push the page sideways on a phone */
.topbar { flex-wrap: wrap; }
.topbar__right { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
@media (max-width: 480px) { .topbar .linkbtn { font-size: 0.88rem; padding: 8px 3px; } }

/* the second worked example: a pile of two Inn cards */
.how__example--pile .tplays + .how__pilenote { text-align: center; margin: 8px 0; font-size: 0.88rem; }
.how__example--pile .tplays { margin-bottom: 4px; }
.how__pilenote b { color: var(--dawn); }

/* a chip is wide: it only nudges when it changes (the kit bump of 1.3 would spill out of the seat) */
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.schip.fx-bump { animation: nudge 0.55s ease-out; }
