:root {
  --bg: #eef2ef; --card: #fff; --ink: #14201b; --muted: #64726b; --line: #dde4e0;
  --brand: #0f6b4c; --brand-ink: #fff; --felt1: #12704f; --felt2: #093a2b; --gold: #d9a441;
  --pos: #0a7d43; --neg: #c8322b; --warn: #fff4d6; --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 6px 18px rgba(16, 40, 30, .06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1412; --card: #17211d; --ink: #e8efec; --muted: #93a39b; --line: #283630;
    --brand: #23a877; --brand-ink: #06130e; --felt1: #0f5c42; --felt2: #072a20;
    --pos: #4cd08b; --neg: #ff7b72; --warn: #3d3413; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; }
a { color: var(--brand); }

/* ----- header: green felt bar ----- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px 0;
  padding-top: max(10px, env(safe-area-inset-top)); color: #fff;
  background: linear-gradient(135deg, var(--felt1), var(--felt2)); border-bottom: 3px solid var(--gold);
  position: sticky; top: 0; z-index: 5; box-shadow: 0 2px 12px rgba(0, 0, 0, .18); }
.brand { font-weight: 700; font-size: 18px; letter-spacing: 1px; text-decoration: none; color: #fff; display: flex; align-items: center; gap: 8px; }
.brand i { font-style: normal; width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--felt2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; transform: rotate(-8deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
.me { margin-left: auto; font-size: 14px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.me > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me small { white-space: nowrap; padding: 1px 8px; border-radius: 99px; background: rgba(255, 255, 255, .16); color: #fff; }
.me a { color: #fff; opacity: .8; white-space: nowrap; }
.top nav { order: 9; flex: 1 0 100%; display: flex; gap: 2px; overflow-x: auto; }
.top nav a { white-space: nowrap; padding: 8px 16px; text-decoration: none; color: rgba(255, 255, 255, .75);
  border-radius: 10px 10px 0 0; font-weight: 600; }
.top nav a.on { background: var(--bg); color: var(--brand); }
.top:not(:has(nav)) { padding-bottom: 10px; }
.top .btn.small { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .35); color: #fff; }

main { max-width: 860px; margin: 0 auto; padding: 16px 16px 40px; }
h1 { font-size: 22px; margin: 8px 0 12px; }
h2 { font-size: 18px; margin: 28px 0 12px; display: flex; align-items: center; gap: 8px; }
h2::before { content: ""; width: 5px; height: 18px; border-radius: 3px; background: linear-gradient(var(--gold), var(--brand)); }
h3 { font-size: 16px; margin: 22px 0 8px; }
.muted { color: var(--muted); font-size: 14px; }

/* ----- avatars ----- */
.av { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex: none;
  border-radius: 50%; font-size: 14px; font-weight: 700; color: #fff; vertical-align: middle;
  background: linear-gradient(135deg, hsl(var(--h), 62%, 52%), hsl(calc(var(--h) + 40), 62%, 38%)); }
.av.lg { width: 48px; height: 48px; font-size: 22px; border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); }

/* ----- hero card on the dashboard ----- */
.hero { position: relative; overflow: hidden; color: #fff; border-radius: 18px; padding: 18px;
  background: radial-gradient(120% 140% at 0% 0%, var(--felt1), var(--felt2)); box-shadow: var(--shadow); }
.hero-suits { position: absolute; right: -6px; top: -22px; font-size: 76px; letter-spacing: -6px; opacity: .09;
  transform: rotate(-10deg); white-space: nowrap; pointer-events: none; }
.hero-head { display: flex; align-items: center; gap: 12px; position: relative; }
.hero-head small { display: block; opacity: .75; font-size: 13px; }
.hero-head strong { font-size: 20px; }
.hero-stats { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-top: 16px; position: relative; }
.hero-stats > div { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .16); border-radius: 12px; padding: 10px 12px; }
.hero-stats small { display: block; font-size: 12px; opacity: .75; }
.hero-stats b { font-size: 24px; font-variant-numeric: tabular-nums; color: #fff; }
.hero-stats b.pos { color: #7df0b0; } .hero-stats b.neg { color: #ffb0a8; }
.hero-range { margin: 10px 0 0; font-size: 12px; opacity: .7; position: relative; }

/* ----- cards, forms, buttons ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }
summary { cursor: pointer; font-weight: 600; }
label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label.check { color: var(--ink); }
input:not([type=checkbox]), select { display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn { display: inline-block; padding: 10px 16px; min-height: 44px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; }
.btn.primary { background: linear-gradient(180deg, var(--felt1), var(--brand)); border-color: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(15, 107, 76, .3); }
.btn.danger { color: var(--neg); border-color: var(--neg); }
.btn.small { padding: 4px 10px; min-height: 34px; font-size: 14px; }
.btn:active { transform: translateY(1px); }
.flash { padding: 10px 14px; border-radius: 10px; margin: 10px 0; border: 1px solid var(--line); background: var(--card); }
.flash.ok { border-color: var(--pos); border-left-width: 5px; }
.flash.err { border-color: var(--neg); border-left-width: 5px; color: var(--neg); }
.flash.warn { background: var(--warn); }
.tag { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: rgba(217, 164, 65, .16); border: 1px solid rgba(217, 164, 65, .5); color: var(--ink); vertical-align: middle; }

/* ----- open rooms ----- */
.rooms { display: grid; gap: 10px; }
.room-card { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; align-items: center; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.room-card .suit { grid-row: 1 / span 2; width: 44px; height: 56px; border-radius: 8px; font-style: normal; font-size: 26px;
  display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid #d5ddd9; color: #17211d;
  transform: rotate(-5deg); box-shadow: 0 2px 6px rgba(0, 0, 0, .12); }
.room-card .suit.s1, .room-card .suit.s3 { color: #c8322b; }
.room-card .muted { grid-column: 2; }
.room-card .btn { grid-column: 3; grid-row: 1 / span 2; }
.live { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #25c26e; vertical-align: middle;
  box-shadow: 0 0 0 0 rgba(37, 194, 110, .6); animation: pulse 1.8s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(37, 194, 110, 0); } 100% { box-shadow: 0 0 0 0 rgba(37, 194, 110, 0); } }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }

/* ----- filters ----- */
.filter { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.filter label { margin: 0; flex: 1 1 130px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip { padding: 5px 14px; border-radius: 99px; border: 1px solid var(--line); text-decoration: none;
  font-size: 14px; color: var(--ink); background: var(--card); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* ----- podium ----- */
.podium { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 8px; align-items: end; margin: 18px 0 14px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; text-align: center; }
.pod .medal { font-size: 22px; line-height: 1; }
.pod .pn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.pod b { font-variant-numeric: tabular-nums; }
.pod .step { width: 100%; margin-top: 6px; border-radius: 12px 12px 0 0; color: #fff; font-weight: 800; font-size: 20px;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; }
.pod.p1 .step { height: 72px; background: linear-gradient(#e7b955, #b98220); }
.pod.p2 .step { height: 52px; background: linear-gradient(#b9c3cc, #7f8c97); }
.pod.p3 .step { height: 38px; background: linear-gradient(#d39a6a, #99603a); }
.pod.p1 .av { width: 58px; height: 58px; font-size: 26px; border-color: var(--gold); }

/* ----- tables ----- */
.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.tbl { width: 100%; border-collapse: collapse; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 10px; text-align: right; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { font-size: 13px; color: var(--muted); font-weight: 500; background: rgba(15, 107, 76, .05); }
.tbl .l { text-align: left; }
.tbl tr.mine td { background: rgba(217, 164, 65, .14); }
.tbl tr.off td { opacity: .55; }
.tbl form { margin: 0; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input, .inline select { margin: 0; min-height: 34px; padding: 4px 8px; width: 110px; flex: none; }
.inline select { width: auto; }
section + form { margin-top: 20px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .zero { color: var(--muted); }

/* ----- room page ----- */
.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.total { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); min-width: 0; }
.total > div { min-width: 0; }
.total.lead { border-color: var(--gold); background: linear-gradient(135deg, rgba(217, 164, 65, .18), var(--card) 60%); }
.total span:not(.av) { display: block; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.score-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.score-row .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.score-row input { width: 110px; margin: 0; text-align: right; font-size: 18px; }
.score-row .btn { min-height: 44px; }
.pay { margin: 10px 0 0; padding-left: 20px; }
textarea { display: block; width: 100%; margin-top: 8px; padding: 10px; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; white-space: pre; }
.steps { padding-left: 20px; }
.steps li { margin: 6px 0; }

/* ----- share menu ----- */
.share { position: relative; }
.share-menu { position: absolute; left: 0; top: 40px; min-width: 150px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); overflow: hidden; }
.share-menu a, .share-menu button { display: block; width: 100%; padding: 12px 14px; font: inherit; text-align: left;
  color: var(--ink); background: none; border: 0; border-bottom: 1px solid var(--line); text-decoration: none; cursor: pointer; }
.share-menu > :last-child { border-bottom: 0; }

/* ----- login / first setup: card table ----- */
body.felt { min-height: 100vh; background: radial-gradient(120% 90% at 50% 0%, var(--felt1), var(--felt2)); }
.narrow { max-width: 420px; margin: 6vh auto 0; }
.felt .narrow { text-align: center; color: #fff; }
.felt .narrow .card { text-align: left; color: var(--ink); border: 0; border-top: 4px solid var(--gold); padding: 20px; }
.felt h1 { font-size: 28px; letter-spacing: 3px; margin: 14px 0 0; }
.felt .sub { opacity: .75; margin: 2px 0 18px; }
.logo { display: flex; justify-content: center; }
.logo span { width: 46px; height: 62px; margin: 0 -5px; border-radius: 8px; background: #fff; color: #17211d; font-size: 26px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
.logo .r { color: #c8322b; }
.logo span:nth-child(1) { transform: rotate(-14deg) translateY(6px); }
.logo span:nth-child(2) { transform: rotate(-5deg); }
.logo span:nth-child(3) { transform: rotate(5deg); }
.logo span:nth-child(4) { transform: rotate(14deg) translateY(6px); }

/* ----- "install the app" banner ----- */
.install { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px;
  background: var(--card); border: 1px solid var(--gold); border-radius: 12px; box-shadow: var(--shadow); }
.install span { flex: 1; }
main { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.offline { text-align: center; color: #fff; padding-top: 18vh; }
