/* Nightjar, dusk blues and moth-wing violet. One fixed palette: the page looks the same
   whether the device is in light or dark mode. */
:root {
  --bg: #eceaf2;
  --surface: #fdfcff;
  --surface2: #e0dcec;
  --line: rgba(40, 34, 70, .14);
  --ink: #221d38;
  --muted: #6d668a;
  --accent: #7a5bd0;          /* you */
  --dusk: #3b3356;            /* the table */
  --dusk2: #2a2440;
  --gold: #d8a63c;
  --good: #2f7d57;
  --bad: #b23b48;
  /* the suits: a different hue AND a different silhouette (see index.html) */
  --moth: #8d5bb5;
  --beetle: #1f7a6d;
  --mayfly: #b4762a;
  --cricket: #2f6aa8;
  --nightjar: #c2453f;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #d8a63c;
  --tut-accent-ink: #221d38;
  --tut-bubble: #fffdf6;
  --tut-ink: #221d38;
  --tut-muted: #6d668a;
  --tut-dim: rgba(24, 18, 48, .58);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; touch-action: manipulation; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; flex: none; }

.app { position: relative; max-width: 760px; margin: 0 auto; padding: 0 12px calc(10px + env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  min-height: 100vh; display: flex; flex-direction: column; }
@supports (min-height: 100svh) { .app { min-height: 100svh; } }

/* ---------- suit colours (shape is in the glyph itself) ---------- */
.moth { color: var(--moth); }
.beetle { color: var(--beetle); }
.mayfly { color: var(--mayfly); }
.cricket { color: var(--cricket); }
.nightjar { color: var(--nightjar); }
.rules .suit { text-transform: capitalize; }

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 50px; flex: none; }
.back, .iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0; }
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface2); }
.brand { flex: 1; text-align: center; font: 700 21px/1 Georgia, "Times New Roman", serif; letter-spacing: .06em; color: var(--dusk); }
.menu { position: absolute; right: 12px; top: 46px; z-index: 45; min-width: 190px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(40, 34, 70, .28); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.menu button { min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: var(--surface2); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons ---------- */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 0; background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 650; transition: background .15s, transform .1s, opacity .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #d3cee2; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #6a4cc0; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- status ---------- */
.game { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.status { min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 4px 4px; font-size: 14.5px; color: var(--muted); text-align: center; flex: none; }
.status.mine { color: var(--ink); font-weight: 650; }
.status .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.thinking::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- the table ---------- */
.dusk { position: relative; flex: 1 1 auto; min-height: 250px; display: flex; flex-direction: column; gap: 8px;
  background: radial-gradient(ellipse at 50% 34%, var(--dusk) 0%, var(--dusk2) 100%);
  border-radius: 20px; padding: 10px 8px 8px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06), 0 10px 26px rgba(40, 34, 70, .22); }

/* the other players, across the top */
.seats { display: flex; gap: 6px; justify-content: center; align-items: stretch; flex: none; }
.pchip { flex: 1 1 0; min-width: 0; max-width: 130px; border: 0; text-align: left; background: rgba(255, 255, 255, .08); color: #efecf8;
  border-radius: 12px; padding: 5px 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; transition: background .2s, box-shadow .2s; }
.pchip.cur { background: rgba(255, 255, 255, .18); box-shadow: 0 0 0 2px var(--pc); }
.pchip.done { opacity: .62; }
.pchip .nm { font-size: 12px; font-weight: 700; line-height: 1.15; white-space: normal; overflow-wrap: anywhere; display: flex; align-items: center; gap: 4px; }
.pchip .nm i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); flex: none; }
.pchip .row { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: #cfc9e6; }
.pchip .say { font-weight: 800; color: #fff; background: rgba(0, 0, 0, .22); border-radius: 7px; padding: 0 5px; min-width: 20px; text-align: center; }
.pchip .say.hit { background: var(--good); }
.pchip .say.bust { background: var(--bad); }
.pchip .say.wait { color: #cfc9e6; font-weight: 600; }
.pchip .backs { display: inline-flex; gap: 1px; margin-left: auto; }
.pchip .backs svg { width: 9px; height: 13px; opacity: .85; }

/* the trick in the middle */
.trick { flex: 1 1 auto; min-height: 96px; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.play { display: flex; flex-direction: column; align-items: center; gap: 3px; animation: land .28s ease-out; }
.play .who { font-size: 10.5px; color: #cfc9e6; max-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play.won .card { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0, 0, 0, .3); }
.trick .empty { color: #a9a2c6; font-size: 13px; }
@keyframes land { from { transform: translateY(-12px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* the "what happened" line */
.beat { flex: none; min-height: 34px; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 13px; color: #efecf8; background: rgba(0, 0, 0, .22); border-radius: 10px; padding: 5px 10px; line-height: 1.3; }
.beat:empty { background: none; }

/* ---------- a card ---------- */
.card { position: relative; width: 48px; height: 66px; border-radius: 8px; background: var(--surface); border: 0; padding: 0;
  box-shadow: 0 2px 5px rgba(20, 16, 40, .3); display: grid; place-items: center; overflow: hidden; }
.card .rk { position: absolute; top: 2px; left: 4px; font: 800 12px/1 Georgia, serif; }
.card .gl { width: 30px; height: 30px; }
.card.big { width: 56px; height: 78px; }
.card.big .gl { width: 36px; height: 36px; }
.card.big .rk { font-size: 14px; top: 3px; left: 5px; }
.card.trump { background: #fff8e8; box-shadow: 0 2px 5px rgba(20, 16, 40, .3), inset 0 0 0 2px var(--gold); }

/* ---------- you ---------- */
.you { flex: none; background: var(--surface); border-radius: 18px; padding: 8px 10px 10px; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.you.turn { box-shadow: inset 0 0 0 2px rgba(122, 91, 208, .4); }
.youbar { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-height: 22px; }
.youbar b { color: var(--ink); }
.youbar .say { font-weight: 800; background: var(--surface2); border-radius: 7px; padding: 1px 7px; color: var(--ink); }
.youbar .say.hit { background: var(--good); color: #fff; }
.youbar .say.bust { background: var(--bad); color: #fff; }
.youbar .sc { margin-left: auto; font-weight: 700; color: var(--ink); }
.hand { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 68px; align-items: center; }
.hand .card { cursor: default; transition: transform .15s, box-shadow .2s, opacity .2s; }
.hand .card.can { cursor: pointer; box-shadow: 0 0 0 2px var(--accent), 0 3px 8px rgba(20, 16, 40, .25); }
.hand .card.can:hover { transform: translateY(-4px); }
.hand .card.no { opacity: .42; }
.hand .none { color: var(--muted); font-size: 13px; }
.controls { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 46px; }
.controls .hint { font-size: 13px; color: var(--muted); }
.saybtn { min-width: 46px; min-height: 46px; border-radius: 12px; border: 0; background: var(--surface2); font: 800 18px/1 Georgia, serif; cursor: pointer; }
.saybtn:hover { background: #d3cee2; }
.saybtn.on { background: var(--accent); color: #fff; }
.saylbl { font-size: 13px; color: var(--muted); width: 100%; text-align: center; margin-bottom: -2px; }

/* The tutorial kit's first-visit chip is fixed to the bottom centre (z 12), which is exactly where
   the prediction buttons live. Make room for it while it is on screen, rather than moving it: the
   hand wraps to two rows at six cards, so a fixed offset would not always clear it. */
body:has(.tut-chip) .controls { padding-bottom: 56px; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(34, 29, 56, .42); }
.sheet { position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(40, 34, 70, .24); }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h3 { font: 700 19px/1.2 Georgia, serif; margin-bottom: 8px; color: var(--dusk); }
.sheet p { margin: 6px 0; }
.sheet .actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet .actions .btn { flex: 1 1 0; }
.sheet .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 14px 0 5px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); color: var(--muted); }
.log li:first-child, .log li.mine { color: var(--ink); }
.setup-sheet .field { margin: 12px 0; }
.setup-sheet .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 46px; border-radius: 12px; border: 0; background: var(--surface2); cursor: pointer; font-weight: 650; }
.seg button.on { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.results { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th, .results td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--muted); font-size: 12px; font-weight: 600; }
.results tr.me td { font-weight: 700; color: var(--accent); }
.results td.plus { color: var(--good); }
.results td.minus { color: var(--bad); }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(34, 29, 56, .45); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(40, 34, 70, .3); }
.over-modal { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.modal-head h2 { font: 700 21px/1.2 Georgia, serif; color: var(--dusk); }
.modal-body { padding: 0 18px 14px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.modal-foot .btn { flex: 1 1 110px; }
.rules h3 { font-size: 15px; margin: 16px 0 4px; color: var(--dusk); font-family: Georgia, serif; }
.rules p, .rules li { font-size: 14px; }
.rules ol, .rules ul { padding-left: 20px; margin: 4px 0; }
.rules li { margin: 4px 0; }
.result-banner { font: 800 25px/1.2 Georgia, serif; margin: 0 0 10px; }
.result-banner.win { color: var(--accent); }

@media (min-width: 700px) {
  .dusk { padding: 14px 12px 12px; }
  .card { width: 54px; height: 74px; }
  .card .gl { width: 34px; height: 34px; }
  .hand .card { width: 62px; height: 86px; }
  .hand .card .gl { width: 40px; height: 40px; }
}
@media (max-width: 370px) {
  .card { width: 44px; height: 60px; }
  .card .gl { width: 26px; height: 26px; }
  .pchip .nm { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online (a table with friends: tables.js) ---------- */
.net-note { position: absolute; left: 50%; top: 34px; transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--surface); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(40, 34, 70, .32); pointer-events: none; animation: pop .25s ease-out; }
.pchip.away .nm { font-style: italic; opacity: .72; }
.pchip.open { background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18); color: #b9b2d6; cursor: default; }
.pchip.open .nm i { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.menu #menu-online, .menu #menu-leave { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.sheet-wrap:not([hidden]) ~ .bp-tables-endbar { display: none !important; }
