:root {
  --felt: #17603f;
  --felt-dark: #0b3423;
  --wood: #3a2313;
  --gold: #e6c36a;
  --cream: #f6efdc;
  --ink: #1d1a14;
  --cw: clamp(54px, 10vw, 112px);          /* card width in my hand */
  --tw: clamp(50px, 8.2vw, 98px);          /* card width on the table */
  --sw: clamp(30px, 4.6vw, 52px);          /* small cards */
  --ratio: 208 / 319;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--cream);
  background: #120c07;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ───────────── cards ───────────── */
.card {
  width: var(--w, var(--cw));
  aspect-ratio: var(--ratio);
  flex: none;
  border-radius: 7%/4.6%;
  background: url(cards.png) no-repeat;
  background-size: 1200% 500%;
  box-shadow: 0 1px 2px rgba(0,0,0,.45), 0 6px 14px rgba(0,0,0,.28);
  user-select: none;
}
.card.back { background-position: 9.0909% 100%; }

/* ───────────── lobby ───────────── */
#lobby {
  align-items: center; padding: 16px; overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 35%, #1f7a50 0%, var(--felt) 40%, var(--felt-dark) 100%);
}
.lobby-card {
  margin: auto; flex: none;
  width: min(440px, 100%);
  padding: 28px 28px 20px;
  text-align: center;
  background: rgba(8, 30, 20, .72);
  border: 1px solid rgba(230, 195, 106, .35);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
}
.fan { display: flex; justify-content: center; height: 150px; margin-bottom: 6px; --w: 84px; }
.fan .card { margin: 0 -22px; transform-origin: 50% 130%; }
.fan .card:nth-child(1) { transform: rotate(-21deg); }
.fan .card:nth-child(2) { transform: rotate(-7deg); }
.fan .card:nth-child(3) { transform: rotate(7deg); }
.fan .card:nth-child(4) { transform: rotate(21deg); }
h1 {
  font-family: var(--serif); font-weight: 600; letter-spacing: .02em;
  font-size: 2.3rem; margin: 0; color: var(--gold);
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
}
.tagline { margin: 4px 0 22px; opacity: .75; font-style: italic; font-family: var(--serif); }
.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; opacity: .7; margin-bottom: 6px; }
input {
  width: 100%; padding: 11px 13px; font: inherit; color: var(--cream);
  background: rgba(0,0,0,.3); border: 1px solid rgba(246,239,220,.25); border-radius: 9px;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.buttons { display: grid; gap: 10px; }
.settings { min-width: 0; margin: 0 0 16px; padding: 4px 14px 10px; text-align: left; border: 1px solid rgba(246,239,220,.18); border-radius: 10px; }
.settings legend { padding: 0 6px; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; opacity: .7; }
.setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 5px 0; font-size: .95rem; }
.setting .seg { margin-left: auto; }
.seg { display: flex; border: 1px solid rgba(246,239,220,.3); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; width: 0; padding: 0; }
.seg i { display: block; min-width: 44px; padding: 5px 10px; text-align: center; font-style: normal; cursor: pointer; }
.seg label + label i { border-left: 1px solid rgba(246,239,220,.3); }
.seg input:checked + i { background: var(--gold); color: #2a1d05; font-weight: 700; }
.seg input:focus-visible + i { outline: 2px solid var(--cream); outline-offset: -2px; }
.summary { margin: 0 0 14px; opacity: .8; font-size: .92rem; }
.share { display: flex; gap: 8px; margin: 12px 0; }
.share input { font-size: .85rem; }
.error { color: #ffb4a8; }
.lobby-links { display: flex; justify-content: center; gap: 14px; }
.pulse { animation: pulse 1.6s ease-in-out infinite; opacity: .8; }
@keyframes pulse { 50% { opacity: .35; } }

.btn {
  font: 600 1rem var(--sans); color: var(--cream); cursor: pointer;
  padding: 11px 18px; border-radius: 10px;
  background: rgba(246,239,220,.1); border: 1px solid rgba(246,239,220,.3);
  transition: transform .12s, background .12s, box-shadow .12s;
}
.btn:hover { background: rgba(246,239,220,.18); transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn.primary {
  color: #2a1d05; border-color: #b08a2e;
  background: linear-gradient(#f3d98e, #d9b04c);
  box-shadow: 0 3px 0 #8d6c1d, 0 8px 18px rgba(0,0,0,.3);
}
.btn.primary:hover { background: linear-gradient(#f8e3a4, #e0b955); }
.link {
  background: none; border: 0; color: var(--gold); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; padding: 8px; margin-top: 10px;
}

/* ───────────── table ───────────── */
.bar {
  display: flex; align-items: center; gap: 14px; padding: 4px 16px;
  background: linear-gradient(#4a2e19, var(--wood)); border-bottom: 1px solid #1c0f07;
  font-size: .9rem;
}
.bar .brand { font-family: var(--serif); font-size: 1.15rem; color: var(--gold); text-decoration: none; }
.bar .brand:hover { text-decoration: underline; text-underline-offset: 3px; }
.bar .hand-no { opacity: .7; }
.bar .spacer { flex: 1; }
.bar .link { margin: 0; padding: 6px; }
.conn { color: #ffcf9a; }

.layout { flex: 1; min-height: 0; display: flex; }
.table {
  position: relative; flex: 1; min-width: 0;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 50% 45%, #22865a 0%, var(--felt) 45%, var(--felt-dark) 100%);
  box-shadow: inset 0 0 0 6px var(--wood), inset 0 0 0 7px #6b4526, inset 0 0 90px rgba(0,0,0,.55);
  overflow: hidden;
}

.seat { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.plate {
  display: flex; align-items: center; gap: 12px; padding: 5px 14px;
  background: rgba(0,0,0,.35); border: 1px solid rgba(246,239,220,.14);
  border-radius: 999px; font-size: .9rem; white-space: nowrap;
}
.plate.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(230,195,106,.25), 0 0 22px rgba(230,195,106,.35); }
.plate .name { font-weight: 600; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }
.plate .off { color: #ffb4a8; font-size: .8em; }
.plate .pts b { font-size: 1.15em; color: var(--gold); font-variant-numeric: tabular-nums; }
.plate .pts small, .plate .tricks { opacity: .7; }
.pips { display: flex; gap: 4px; }
.pips i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--gold); }
.pips i.on { background: var(--gold); }
.chip {
  padding: 1px 8px; border-radius: 999px; font-size: .78em; font-weight: 700;
  background: var(--gold); color: #2a1d05;
}

.hand { display: flex; justify-content: center; }
.opp-hand { --w: var(--sw); height: calc(var(--sw) * 1.2); margin-top: 10px; }
.opp-hand .card { margin: 0 calc(var(--sw) * -.22); transform: rotate(calc(var(--d) * -3deg)) translateY(calc(var(--d) * var(--d) * -1.2px)); }

.my-hand { min-height: calc(var(--cw) / (208 / 319) + 26px); align-items: flex-end; padding-top: 26px; margin-bottom: 22px; }
.my-hand .card {
  margin: 0 calc(var(--cw) * -.14);
  transform: translateY(calc(var(--d) * var(--d) * 2.2px - var(--lift, 0px))) rotate(calc(var(--d) * 3deg));
  transition: transform .16s ease, filter .16s, box-shadow .16s;
}
.my-hand .card.playable { cursor: pointer; }
.my-hand.active .card:not(.playable) { filter: brightness(.55) saturate(.7); }
.my-hand .card.playable:hover, .my-hand .card.playable:focus-visible {
  --lift: 24px; z-index: 5; outline: none;
  box-shadow: 0 0 0 3px var(--gold), 0 16px 26px rgba(0,0,0,.45);
}
.my-hand .card.drawn { animation: drawn .55s cubic-bezier(.2,.8,.2,1) both; }
@keyframes drawn { from { opacity: 0; translate: -30vw -34vh; rotate: -40deg; } }
.my-hand .card.dealt { animation: dealt .5s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--n) * 60ms); }
@keyframes dealt { from { opacity: 0; translate: 0 -50vh; } }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 0; }
.actions .btn { padding: 8px 14px; font-size: .92rem; animation: pop .3s both; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

.middle {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: clamp(8px, 3vw, 40px); min-height: 0;
}
.stock-area { justify-self: end; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.stock { position: relative; --w: var(--tw); width: calc(var(--tw) * 1.75); height: calc(var(--tw) / (208 / 319)); }
.stock .card { position: absolute; top: 0; left: 0; }
.stock .trump { left: calc(var(--tw) * .52); transform: rotate(90deg); }
.stock .pile:nth-child(2) { translate: 0 0; }
.stock .pile:nth-child(3) { translate: -2px -2px; }
.stock .pile:nth-child(4) { translate: -4px -4px; }
.stock .count {
  position: absolute; left: calc(var(--tw) / 2 - 2px); top: 50%; translate: -50% -50%;
  min-width: 30px; padding: 3px 8px; text-align: center; font-weight: 700; font-size: .9rem;
  background: rgba(0,0,0,.72); border: 1px solid var(--gold); border-radius: 999px;
}
.stock .empty {
  position: absolute; inset: 0 auto 0 0; width: var(--tw);
  border: 2px dashed rgba(246,239,220,.22); border-radius: 8px;
}
.trump-label { font-size: .82rem; opacity: .85; text-align: center; }
.trump-label b { color: var(--gold); text-transform: capitalize; }

.trick-area { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.trick { position: relative; --w: var(--tw); width: calc(var(--tw) * 1.9); height: calc(var(--tw) / (208 / 319) * 1.28); }
.trick .card { position: absolute; transition: transform .45s ease-in, opacity .45s ease-in; }
.trick .card.opp { left: 6%; top: 0; rotate: -7deg; }
.trick .card.me { right: 6%; bottom: 0; rotate: 6deg; }
.trick .card.opp.in { animation: from-top .32s cubic-bezier(.2,.8,.2,1) both; }
.trick .card.me.in { animation: from-bottom .32s cubic-bezier(.2,.8,.2,1) both; }
@keyframes from-top { from { translate: 0 -42vh; opacity: 0; } }
@keyframes from-bottom { from { translate: 0 42vh; opacity: 0; } }
.trick.sweep-me .card { transform: translateY(46vh) scale(.5); opacity: 0; }
.trick.sweep-opp .card { transform: translateY(-46vh) scale(.5); opacity: 0; }
.trick .card.winner { box-shadow: 0 0 0 3px var(--gold), 0 0 26px rgba(230,195,106,.7); z-index: 2; }
.status {
  min-height: 1.4em; text-align: center; font-family: var(--serif); font-size: 1.05rem;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.status.mine { color: var(--gold); }

.last-area { justify-self: start; display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: .9; }
.last-title { font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; opacity: .65; }
.last { display: flex; gap: 4px; --w: var(--sw); min-height: calc(var(--sw) / (208 / 319)); }
.last .card.winner { box-shadow: 0 0 0 2px var(--gold); }

.toast {
  position: absolute; left: 50%; top: 44%; translate: -50% -50%; z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 16px 26px; text-align: center; pointer-events: none;
  font-family: var(--serif); font-size: clamp(1.2rem, 3.4vw, 1.9rem); color: var(--gold);
  background: rgba(10, 8, 4, .86); border: 1px solid var(--gold); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: toast .3s cubic-bezier(.2,.8,.2,1) both;
}
.toast small { font-family: var(--sans); font-size: .55em; color: var(--cream); opacity: .85; }
.toast .cards { display: flex; gap: 8px; --w: var(--tw); }
@keyframes toast { from { opacity: 0; scale: .8; } }

/* ───────────── log ───────────── */
.log {
  width: 250px; flex: none; display: flex; flex-direction: column;
  background: #1b120a; border-left: 1px solid #000; font-size: .84rem;
}
.log h3 { margin: 0; padding: 10px 14px; font: 600 .72rem var(--sans); letter-spacing: .14em; text-transform: uppercase; opacity: .6; }
.log ol { flex: 1; overflow-y: auto; margin: 0; padding: 0 14px 12px; list-style: none; }
.log li { padding: 3px 0; opacity: .82; }
.log li.sep { margin-top: 8px; color: var(--gold); opacity: 1; font-weight: 600; }
.log li.strong { color: var(--gold); opacity: 1; }
.log li.trickwin { opacity: .55; padding-bottom: 7px; border-bottom: 1px solid rgba(255,255,255,.06); }

/* ───────────── modals ───────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0,0,0,.6); animation: fade .2s both;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  position: relative; width: min(560px, 100%); max-height: 100%; overflow-y: auto;
  padding: 26px 28px; border-radius: 16px;
  background: #f7f1e1; color: var(--ink);
  box-shadow: 0 30px 90px rgba(0,0,0,.6);
}
.modal h2 { font-family: var(--serif); margin: 0 0 6px; font-size: 1.7rem; color: #5a3a12; }
.modal h3 { font-family: var(--serif); margin: 22px 0 6px; font-size: 1.15rem; color: #7a4f18; }
.modal p, .modal li { line-height: 1.55; }
.modal p { margin: 8px 0; }
.modal .btn { color: var(--ink); border-color: rgba(0,0,0,.25); background: rgba(0,0,0,.05); }
.modal .btn.primary { color: #2a1d05; border-color: #b08a2e; background: linear-gradient(#f3d98e, #d9b04c); }
.close { position: sticky; float: right; top: 0; border: 0; background: none; font-size: 2rem; line-height: 1; cursor: pointer; color: #7a4f18; }
.rules { width: min(720px, 100%); }
.rules em { color: #7a2d12; }
.values { border-collapse: collapse; width: 100%; table-layout: fixed; font-size: .9rem; margin: 10px 0; }
.values th, .values td { border: 1px solid #d9cba8; padding: 5px 6px; text-align: center; }
.values th { width: 4.6em; text-align: left; background: #efe5c9; font-weight: 600; }
.values td:has(.card) { padding: 3px 2px; }
.values .card { --w: 100%; max-width: 46px; margin: auto; box-shadow: 0 1px 2px rgba(0,0,0,.35); }
[data-rule] { font-weight: 700; }
.credit { margin-top: 26px !important; font-size: .78rem; opacity: .6; }

.result { text-align: center; width: min(430px, 100%); }
.result table { width: 100%; border-collapse: collapse; margin: 16px 0; font-variant-numeric: tabular-nums; }
.result th, .result td { padding: 6px 8px; border-bottom: 1px solid #e2d6b6; }
.result td:first-child, .result th:first-child { text-align: left; }
.result td:not(:first-child), .result th:not(:first-child) { text-align: right; width: 30%; }
.result tr.total td { font-weight: 700; font-size: 1.2rem; border-bottom: 0; }
.match-score { margin-bottom: 18px; font-family: var(--serif); font-size: 1.1rem; }
.result-links { display: flex; justify-content: center; gap: 18px; margin-top: 12px; }
.modal .link { margin: 0; padding: 4px; color: #7a4f18; font-size: .92rem; }
.modal .give-up { color: #8a3a22; }
.match-score b { font-size: 1.5rem; color: #7a4f18; }

.layout:not(.with-log) .log { display: none; }
@media (max-width: 900px) { .log { display: none; } }
@media (max-width: 560px) {
  .plate { gap: 8px; font-size: .8rem; padding: 4px 10px; }
  .plate .tricks { display: none; }
  .last-title { display: none; }
  .values { font-size: .8rem; }
  .values th, .values td { padding: 4px 2px; }
  .modal { padding: 20px 16px; }
  .lobby-card { padding: 20px 16px 16px; }
  .fan { height: 120px; --w: 68px; }
  .fan .card { margin: 0 -18px; }
  h1 { font-size: 2rem; }
  .settings { padding: 4px 10px 8px; }
  .seg i { min-width: 38px; padding: 5px 8px; }
}
@media (max-height: 620px) {
  :root { --cw: clamp(48px, 15vh, 96px); --tw: clamp(44px, 13vh, 84px); --sw: clamp(26px, 7vh, 44px); }
}
