:root {
  --felt: #0e3b2c;
  --felt-2: #134a38;
  --felt-3: #1c5c46;
  --paper: #f7f2e6;
  --paper-2: #ece4d0;
  --ink: #1d1a14;
  --ink-2: #5d5546;
  --red: #b3261e;
  --gold: #d4a72c;
  --line: #d9cfb6;
  --ok: #2e7d4f;
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  background: var(--felt);
  background-image: radial-gradient(ellipse at top, var(--felt-3), var(--felt) 70%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0 0 12px; }
h1 { color: var(--paper); font-size: 28px; letter-spacing: .5px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--ink-2); font-family: var(--sans); text-transform: uppercase; letter-spacing: 1px; font-size: 12px; }
.top { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 16px; }
.top h1 { margin: 0; }
.top .suit { color: var(--gold); font-size: 22px; letter-spacing: 4px; }
.muted { color: var(--ink-2); font-size: 14px; }
.light { color: #cfe3d8; }

.card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.install { max-width: 440px; margin: 40px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
input, select {
  font: inherit; font-size: 17px; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--felt-3); box-shadow: 0 0 0 3px rgba(28,92,70,.18); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 16px;
  border: 0; border-radius: 12px; padding: 13px 16px;
  background: var(--paper-2); color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--red); color: #fff; }
.btn.green { background: var(--felt-3); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.small { padding: 7px 10px; font-size: 14px; border-radius: 9px; }
.btn.danger { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }

.error { background: #fde8e6; color: var(--red); padding: 10px 12px; border-radius: 10px; font-weight: 600; margin: 0 0 12px; }
.success { background: #e3f3e8; color: var(--ok); padding: 10px 12px; border-radius: 10px; font-weight: 600; }

/* Scoreboard */
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.side {
  background: var(--paper); border-radius: var(--radius); padding: 14px 12px 12px;
  text-align: center; position: relative; box-shadow: 0 6px 18px rgba(0,0,0,.25);
  border-top: 5px solid var(--ink);
}
.side.b { border-top-color: var(--red); }
.side .names { font-weight: 700; font-size: 14px; color: var(--ink-2); min-height: 36px; line-height: 1.3; }
.side .total { font-family: var(--serif); font-size: 44px; font-weight: 700; line-height: 1.1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.side.b .total { color: var(--red); }
.side .bar { height: 6px; border-radius: 3px; background: var(--paper-2); overflow: hidden; }
.side .bar i { display: block; height: 100%; background: var(--ink); }
.side.b .bar i { background: var(--red); }
.side .miss { font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.side.win { box-shadow: 0 0 0 3px var(--gold), 0 6px 18px rgba(0,0,0,.25); }
.crown { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: var(--gold); color: var(--ink); font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 20px; letter-spacing: 1px; }

.banner { background: var(--gold); color: var(--ink); text-align: center; font-family: var(--serif); font-weight: 700; font-size: 18px; padding: 12px; border-radius: var(--radius); margin-bottom: 14px; }

/* Hand entry */
.entry { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.entry .col { display: flex; flex-direction: column; gap: 8px; }
.entry .col h3 { margin: 0; }
.num { display: flex; gap: 6px; }
.num input { text-align: right; font-variant-numeric: tabular-nums; }
.num button { flex: 0 0 44px; padding: 0; font-size: 18px; }
.handsum { font-family: var(--serif); font-weight: 700; text-align: right; font-size: 18px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); font-size: 15px; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink-2); font-weight: 700; }
th:first-child, td:first-child { text-align: left; }
td.det { font-size: 12px; color: var(--ink-2); }
td.tot { font-weight: 700; }
td.b, th.b { color: var(--red); }
tr.click { cursor: pointer; }
.hands td:last-child { width: 1%; white-space: nowrap; }

/* Lists */
.gitem { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.gitem:last-child { border-bottom: 0; }
.gitem .vs { font-size: 14px; line-height: 1.35; }
.gitem .vs .w { font-weight: 800; }
.gitem .sc { font-family: var(--serif); font-weight: 700; font-size: 18px; white-space: nowrap; text-align: right; }
.pill { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 20px; background: var(--red); color: #fff; letter-spacing: .5px; text-transform: uppercase; }
.pill.done { background: var(--paper-2); color: var(--ink-2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 30px; padding: 9px 14px; font-weight: 700; cursor: pointer; font-size: 15px; }
.chip.on { background: var(--felt-3); border-color: var(--felt-3); color: #fff; }

.seg { display: flex; background: var(--paper-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font: inherit; font-weight: 700; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.pairbox { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pairbox .p { border-radius: 12px; padding: 10px; background: #fff; border: 1.5px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.pairbox .p.b { border-color: #e8b4af; }

.statnums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.statnums b { display: block; font-family: var(--serif); font-size: 26px; }
.statnums span { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink-2); font-weight: 700; }
.pbar { height: 6px; background: var(--paper-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.pbar i { display: block; height: 100%; background: var(--felt-3); }
.rank { font-family: var(--serif); color: var(--gold); font-weight: 700; margin-right: 6px; }
.click { cursor: pointer; }
.card.record { padding: 16px; border-bottom: 0; }
.card.record h3 { margin-bottom: 4px; }
.card.record .sc { font-size: 30px; color: var(--red); }

/* Nav */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  background: rgba(10,40,30,.96); backdrop-filter: blur(6px);
  border-top: 1px solid rgba(255,255,255,.08);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .in { display: flex; width: 100%; max-width: 560px; }
nav.tabs button {
  flex: 1; background: none; border: 0; color: #9fbfb1; font: inherit; font-size: 12px; font-weight: 700;
  padding: 10px 0 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
nav.tabs button .ic { font-size: 20px; line-height: 1; }
nav.tabs button.on { color: var(--gold); }

dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(92vw, 440px); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.55); }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 20; max-width: 90vw; }
.toast.err { background: var(--red); }
.empty { text-align: center; color: var(--ink-2); padding: 18px 0; }
.mt { margin-top: 12px; }
code { background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }

/* Carte pescate per formare le coppie */
.drawgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 4px; }
.slot { text-align: center; }
.slot .who { font-size: 13px; font-weight: 700; margin-top: 6px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.a .who { color: var(--ink); }
.slot.b .who { color: var(--red); }
.pc { position: relative; aspect-ratio: 169 / 245; perspective: 600px; }   /* proporzioni delle carte di cards.svg */
.pc .in { position: absolute; inset: 0; transition: transform .6s ease; transform-style: preserve-3d; }
.pc.up .in { transform: rotateY(180deg); }
.pc .back, .pc .face { position: absolute; inset: 0; border-radius: 8px; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: 0 3px 8px rgba(0,0,0,.25); }
.pc .back { background: repeating-linear-gradient(45deg, var(--red) 0 6px, #8e1d17 6px 12px); border: 3px solid #fff; }
.pc .face {
  transform: rotateY(180deg); background: #fff; border: 1.5px solid var(--line); color: var(--ink);
  display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-size: 34px;
}
.pc .face.red { color: var(--red); }
.pc .face .r { position: absolute; top: 4px; left: 6px; font-size: 15px; font-weight: 700; line-height: 1.05; text-align: center; }
.slot.a .pc .face { box-shadow: 0 0 0 3px var(--ink), 0 3px 8px rgba(0,0,0,.25); }
.slot.b .pc .face { box-shadow: 0 0 0 3px var(--red), 0 3px 8px rgba(0,0,0,.25); }
.drawgrid.mini { gap: 8px; }
.drawgrid.mini .pc { width: 48px; margin: 0 auto; }
.drawgrid.mini .pc .face { font-size: 20px; }
.drawgrid.mini .pc .face .r { font-size: 11px; top: 3px; left: 4px; }
/* Faccia con l'immagine vera della carta (cards.svg, SVG-cards di David Bellot, LGPL-2.1) */
.pc .face.img { background: none; border: 0; overflow: hidden; }
.pc .face.img svg { display: block; width: 100%; height: 100%; }
.drawres { font-size: 16px; line-height: 1.6; margin: 0; text-align: center; }
@media (prefers-reduced-motion: reduce) { .pc .in { transition: none; } }

.b { color: var(--red); }
label.check { flex-direction: row; align-items: center; justify-content: space-between; font-size: 15px; }
input[type=checkbox] { width: 24px; height: 24px; flex: 0 0 24px; accent-color: var(--red); }
.btn.light { color: var(--paper); border-color: rgba(255,255,255,.3); }
