:root {
  --felt-1: #13543f;
  --felt-2: #0a2f24;
  --felt-3: #06201a;
  --gold: #d9b45a;
  --gold-2: #f3dc97;
  --gold-dim: rgba(217, 180, 90, .35);
  --ink: #f5efe1;
  --muted: rgba(245, 239, 225, .62);
  --card-bg: #fdfaf2;
  --card-edge: #e7dfcb;
  --black: #1b1f24;
  --red: #c4262e;
  --danger: #e05a4f;
  --glass: rgba(6, 26, 20, .72);
  --line: rgba(255, 255, 255, .09);
  --cw: min(66px, 16.5vw);
  --ch: calc(var(--cw) * 1.42);
  --tcw: min(60px, 15vw);
  --tch: calc(var(--tcw) * 1.42);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  background: var(--felt-3);
  background-image:
    radial-gradient(120% 80% at 50% 35%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; opacity: .18;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.red { color: var(--red); }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: none; flex-direction: column;
  padding-top: var(--safe-t);
}
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  width: 100%; min-height: 52px; padding: 0 1.2rem; border-radius: 14px;
  font-weight: 600; font-size: 1rem; letter-spacing: .01em;
  transition: transform .12s ease, filter .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.gold {
  color: #2a1f05;
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 55%, #b8923a);
  box-shadow: 0 6px 18px rgba(217, 180, 90, .28), inset 0 1px 0 rgba(255,255,255,.6);
}
.btn.ghost { background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.btn.danger { background: rgba(224, 90, 79, .14); color: #ffb3aa; border: 1px solid rgba(224, 90, 79, .35); }
.btn.sm { min-height: 40px; width: auto; font-size: .9rem; border-radius: 999px; }
.link { color: var(--gold-2); font-weight: 500; text-decoration: underline; text-underline-offset: 4px; padding: .8rem; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255,255,255,.06); border: 1px solid var(--line); font-size: 1.1rem; flex: none;
}

/* ---------- Home ---------- */
.home-wrap {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b)); gap: 22px; max-width: 440px; margin: 0 auto; width: 100%;
  overflow-y: auto;
}
.brand { text-align: center; }
.brand-cards { position: relative; height: 112px; width: 180px; margin: 0 auto 6px; }
.brand-cards .card { position: absolute; left: 50%; top: 8px; margin-left: -34px; }
.tilt-l { transform: rotate(-16deg) translate(-38px, 8px); }
.tilt-c { transform: rotate(0deg) translateY(-4px); z-index: 2; }
.tilt-r { transform: rotate(16deg) translate(38px, 8px); z-index: 3; }
.logo {
  font-family: 'Playfair Display', serif; font-weight: 800; font-size: 4.2rem; margin: 0; line-height: 1;
  letter-spacing: .02em;
  background: linear-gradient(180deg, #fff6d6 0%, var(--gold-2) 35%, var(--gold) 70%, #a8822f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.45));
}
.tagline { margin: .4rem 0 0; color: var(--muted); letter-spacing: .18em; text-transform: uppercase; font-size: .72rem; }
.panel {
  width: 100%; padding: 20px; border-radius: 22px; display: flex; flex-direction: column; gap: 14px;
  background: var(--glass); border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0,0,0,.35); backdrop-filter: blur(10px);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: .78rem; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.field input {
  height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(0,0,0,.28); color: var(--ink); font-size: 1.05rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--gold-dim); box-shadow: 0 0 0 3px rgba(217,180,90,.15); }
.code-input { text-transform: uppercase; letter-spacing: .5em; text-align: center; font-weight: 700; font-size: 1.4rem !important; }
.join-box { display: flex; flex-direction: column; gap: 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.35), transparent);
}
.topbar-title { flex: 1; text-align: center; font-weight: 600; }

/* ---------- Lobby ---------- */
.lobby-wrap {
  flex: 1; overflow-y: auto; padding: 8px 20px calc(20px + var(--safe-b));
  display: flex; flex-direction: column; gap: 18px; max-width: 440px; margin: 0 auto; width: 100%;
}
.code-card {
  text-align: center; padding: 20px; border-radius: 22px; background: var(--glass); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.big-code {
  font-family: 'Playfair Display', serif; font-weight: 800; font-size: 3.2rem; letter-spacing: .22em;
  color: var(--gold-2); padding-left: .22em;
}
.seat-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.seat-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); min-height: 64px;
}
.seat-row.empty { border-style: dashed; background: transparent; }
.seat-row .grow { flex: 1; min-width: 0; }
.seat-row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag {
  font-size: .68rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; background: rgba(217,180,90,.16); color: var(--gold-2);
}
.tag.off { background: rgba(224,90,79,.16); color: #ffb3aa; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 1rem; color: #1a1406;
  background: linear-gradient(145deg, var(--gold-2), var(--gold));
  box-shadow: 0 2px 8px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.5);
}
.avatar.bot { background: linear-gradient(145deg, #b9c4cf, #7d8b99); }
.avatar.empty { background: rgba(255,255,255,.06); color: var(--muted); box-shadow: none; border: 1px dashed var(--line); }

/* ---------- Cards (classic face) ---------- */
.card {
  position: relative; width: var(--cw); height: calc(var(--cw) * 1.42); border-radius: calc(var(--cw) * .08);
  background: #fffefb; border: 1px solid #d8d1c1;
  box-shadow: 0 2px 6px rgba(0,0,0,.35), 0 1px 1px rgba(0,0,0,.2);
  color: var(--black); flex: none; overflow: hidden;
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
}
.card.red { color: var(--red); }
.card svg { display: block; fill: currentColor; }
.card .idx {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: calc(var(--cw) * .015); width: 16%;
  font-weight: 700; font-size: calc(var(--cw) * .19); line-height: .9; letter-spacing: -.07em;
}
.card .idx b { font-weight: 700; }
.card .idx svg { width: calc(var(--cw) * .13); height: calc(var(--cw) * .13); }
.card .idx.tl { top: 4%; left: 3%; }
.card .idx.br { bottom: 4%; right: 3%; transform: rotate(180deg); }
.card .pips { position: absolute; inset: 0; }
.card .pips .p {
  position: absolute; width: calc(var(--cw) * .2); height: calc(var(--cw) * .2); transform: translate(-50%, -50%);
}
.card .pips .p.flip { transform: translate(-50%, -50%) rotate(180deg); }
.card .ace {
  position: absolute; left: 50%; top: 50%; width: calc(var(--cw) * .46); height: calc(var(--cw) * .46);
  transform: translate(-50%, -50%);
}
.card .court {
  position: absolute; left: 22%; right: 22%; top: 13%; bottom: 13%; display: flex; flex-direction: column;
  border: 1px solid currentColor; border-radius: 2px; overflow: hidden;
  background: linear-gradient(180deg, #fbf1d3 0%, #f3e0a8 49.5%, #f3e0a8 50.5%, #fbf1d3 100%);
  box-shadow: inset 0 0 0 2px #fffefb, inset 0 0 0 3px rgba(40, 60, 140, .45);
}
.card .court .half { flex: 1; display: flex; align-items: center; justify-content: center; gap: 1px; line-height: 1; }
.card .court .half.flip { transform: rotate(180deg); border-bottom: 1px solid rgba(40, 60, 140, .35); }
.card .court b { font-size: calc(var(--cw) * .3); font-weight: 400; font-family: 'Segoe UI Symbol', 'DejaVu Sans', serif; }
.card .court .cs { width: calc(var(--cw) * .12); height: calc(var(--cw) * .12); }
.card.mini { --cw: 68px; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(217,180,90,.18) 0 2px, transparent 2px 8px),
    linear-gradient(145deg, #7a1b22, #4a0d13);
  border: 2px solid #f3e7c8;
}

/* ---------- Table pieces shared by the games ---------- */
.contract-chip {
  flex: 1; min-width: 0; text-align: center; padding: 6px 12px; border-radius: 14px;
  background: var(--glass); border: 1px solid var(--gold-dim);
  display: flex; flex-direction: column; line-height: 1.2;
}
.contract-chip span { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.08rem; color: var(--gold-2); }
.contract-chip small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; font-size: .86rem; font-weight: 500; white-space: nowrap;
  background: var(--glass); border: 1px solid var(--line); max-width: calc(100% - 140px); overflow: hidden; text-overflow: ellipsis;
  transition: opacity .2s;
}
.status:empty { opacity: 0; }
.status.you { border-color: var(--gold); color: var(--gold-2); box-shadow: 0 0 20px rgba(217,180,90,.25); }

.card-ghost {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; will-change: transform;
  box-shadow: 0 0 0 2px var(--gold), 0 22px 44px rgba(0,0,0,.55), 0 0 30px rgba(217,180,90,.35);
}
.card-ghost.settle { transition: transform .28s cubic-bezier(.3,.7,.4,1); box-shadow: 0 3px 8px rgba(0,0,0,.35); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-end; justify-content: center;
  background: rgba(2, 10, 8, .6); backdrop-filter: blur(3px);
}
.modal.open { display: flex; animation: fade .2s ease-out; }
.sheet {
  width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
  padding: 22px 18px calc(18px + var(--safe-b)); border-radius: 24px 24px 0 0;
  background: linear-gradient(180deg, #0f3b2e, #0a2a20); border: 1px solid var(--gold-dim); border-bottom: 0;
  box-shadow: 0 -20px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 12px; animation: up .28s cubic-bezier(.3,.7,.4,1);
}
.sheet h2 { font-family: 'Playfair Display', serif; font-size: 1.5rem; margin: 0; color: var(--gold-2); }
.sheet h3 { font-size: .95rem; margin: .6rem 0 0; color: var(--gold-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; padding: 6px 0; }
.stepper .icon-btn { width: 52px; height: 52px; font-size: 1.6rem; border-radius: 50%; }
.stepper .icon-btn:disabled { opacity: .3; }
.stepper div { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.stepper b { font-family: 'Playfair Display', serif; font-size: 2.6rem; line-height: 1; color: var(--gold-2); }
.stepper small { color: var(--muted); }

.crown { font-size: 3rem; text-align: center; color: var(--gold); line-height: 1; filter: drop-shadow(0 4px 12px rgba(217,180,90,.5)); }
.place { font-family: 'Playfair Display', serif; font-weight: 800; font-size: 1.2rem; color: var(--gold-2); width: 22px; text-align: center; }

.rules p, .rules li { font-size: .9rem; line-height: 1.5; margin: 0; }
.rules ul { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 4px; }

/* ---------- Toast / conn ---------- */
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -200%); z-index: 100; visibility: hidden;
  padding: 10px 16px; border-radius: 12px; background: #2a0f0f; border: 1px solid rgba(224,90,79,.5); color: #ffd5cf;
  font-size: .88rem; transition: transform .25s ease; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.info { background: #0f2e24; border-color: var(--gold-dim); color: var(--gold-2); }
.conn {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); z-index: 99;
  padding: 8px 14px; border-radius: 999px; background: #3a2a07; color: var(--gold-2); font-size: .8rem; display: none;
}
.conn.show { display: block; }

@media (min-height: 760px) {
  :root { --cw: min(74px, 16.5vw); --tcw: min(68px, 16vw); }
}
@media (min-width: 700px) {
  :root { --cw: 84px; --tcw: 80px; }
}

/* ---------- Chat ---------- */
.chat-fab {
  position: absolute; right: 10px; bottom: 6px; width: 48px; height: 48px; border-radius: 50%; z-index: 6;
  display: grid; place-items: center; font-size: 1.35rem; background: var(--glass); border: 1px solid var(--gold-dim);
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
.chat-fab:active { transform: scale(.94); }
.chat-badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  display: grid; place-items: center; font-size: .7rem; font-weight: 700; background: var(--danger); color: #fff;
}
.chat-sheet { height: 78vh; }
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-list {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  padding: 8px; border-radius: 14px; background: rgba(0,0,0,.2); border: 1px solid var(--line);
  user-select: text; -webkit-user-select: text;
}
.chat-list .empty { margin: auto; color: var(--muted); font-size: .85rem; text-align: center; }
.msg { max-width: 82%; align-self: flex-start; padding: 7px 11px; border-radius: 14px 14px 14px 4px; background: rgba(255,255,255,.08); font-size: .92rem; line-height: 1.35; overflow-wrap: anywhere; }
.msg b { display: block; font-size: .7rem; color: var(--gold-2); font-weight: 600; margin-bottom: 1px; }
.msg.me { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #2a1f05; }
.msg.me b { display: none; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.quick button { flex: none; padding: 7px 12px; border-radius: 999px; font-size: .82rem; background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(0,0,0,.28); color: var(--ink); font-size: 16px; outline: none;
}
.chat-form input:focus { border-color: var(--gold-dim); }
.chat-form .btn { width: 56px; min-height: 48px; padding: 0; font-size: 1.1rem; }

/* ---------- Player card ---------- */
.pc-head { display: flex; align-items: center; gap: 12px; }
.pc-head .avatar { width: 52px; height: 52px; font-size: 1.3rem; flex: none; }
.pc-head h2 { overflow-wrap: anywhere; }
.pc-kind { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.pc-kind.on::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #4cd07d; }
.pc-stats { display: flex; flex-direction: column; gap: 10px; }
.pc-stats[hidden], .pc-send[hidden], .pc-friend[hidden] { display: none; }
.pc-friend { display: flex; flex-direction: column; gap: 8px; }
.pc-friend p { margin: 0; font-size: .85rem; color: var(--muted); text-align: center; }
.pc-friend p.on { color: var(--ink); }
.pc-friend p.on::before { content: '✓ '; color: #4cd07d; }
.pc-friend-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pc-rank { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 6px; color: var(--muted); font-size: .85rem; }
.pc-rank b { font-family: 'Playfair Display', serif; font-size: 1.6rem; line-height: 1; color: var(--gold-2); }
.pc-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pc-nums div { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 14px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.pc-nums b { font-size: 1.15rem; color: var(--ink); }
.pc-nums small { font-size: .72rem; color: var(--muted); }
.pc-karma { display: flex; align-items: baseline; gap: 8px; padding: 8px 12px; border-radius: 14px; background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.pc-karma b { font-size: 1.15rem; color: var(--ink); flex: none; }
.pc-send { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Throw picker ---------- */
.throw-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.throw-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; border-radius: 16px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: .75rem; color: var(--muted);
}
.throw-grid button span { font-size: 1.7rem; line-height: 1; }
.throw-grid button:active { transform: scale(.94); background: rgba(217,180,90,.14); }

/* ---------- Effects layer ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.bubble {
  position: absolute; max-width: 190px; padding: 7px 11px; border-radius: 14px; font-size: .84rem; line-height: 1.3;
  background: #fffdf6; color: #1b1f24; box-shadow: 0 8px 20px rgba(0,0,0,.4); overflow-wrap: anywhere;
  animation: bubble-in .22s cubic-bezier(.3,1.4,.5,1); transition: opacity .35s;
}
.bubble::after { content: ''; position: absolute; left: var(--tail, 50%); bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fffdf6; }
.bubble.below::after { bottom: auto; top: -6px; border-top: 0; border-bottom: 6px solid #fffdf6; }
.bubble.out { opacity: 0; }
@keyframes bubble-in { from { transform: scale(.5); opacity: 0; } }
.fly { position: absolute; left: 0; top: 0; font-size: 36px; line-height: 1; will-change: transform; filter: drop-shadow(0 6px 8px rgba(0,0,0,.4)); }
.particle { position: absolute; left: 0; top: 0; font-size: 20px; line-height: 1; will-change: transform, opacity; }
.splat {
  position: absolute; width: 70px; height: 62px; margin: -31px 0 0 -35px; border-radius: 48% 52% 44% 56% / 55% 45% 55% 45%;
  background: radial-gradient(circle at 40% 35%, #fffaf0, #f4e3b8 70%); transition: opacity .6s;
  box-shadow: -18px 22px 0 -12px #f4e3b8, 20px 18px 0 -13px #f4e3b8, 4px 30px 0 -14px #f4e3b8, inset 0 -4px 8px rgba(160,120,60,.25);
}
.splat.tomato { background: radial-gradient(circle at 40% 35%, #ff6b5e, #c4262e 70%); box-shadow: -18px 22px 0 -12px #c4262e, 20px 18px 0 -13px #c4262e, 4px 30px 0 -14px #c4262e; }
.splat.out { opacity: 0; }
