/* Table is grid/flow. Board cards are position:absolute only inside their column. */
:root {
  --cw: 60px;
  --ch: 83px;
  --peek: 16px;
  --sw: 47px;
  --sh: 65px;
  --ow: 27px;
  --oh: 38px;
  --hand-gap: 4px;
  --felt: #146843;
  --gold: #f0d48a;
  --ink: #f6f1e4;
  --ease: 280ms ease;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  min-height: 100%;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(255,255,255,.06), transparent 50%),
    #102018;
  user-select: none;
}
button, input, select { font: inherit; }
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 12px 2px;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 {
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  letter-spacing: .04em;
  margin: 0;
  font-size: 22px;
  line-height: 1.05;
  color: var(--gold);
}
.tag { margin: 0; opacity: .7; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.turnline { flex: 1; text-align: center; font-size: 16px; font-weight: 650; }
.turnline.you { color: var(--gold); }
.turnline.opp { color: #d7ece2; }
.timer {
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0,0,0,.28);
  border-radius: 999px;
  padding: 2px 10px;
}
.timer.low { color: #ffb4a8; }
.top-actions { display: flex; gap: 8px; }
button {
  background: #1c3b2c;
  color: var(--ink);
  border: 1px solid rgba(240,212,138,.45);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}
button.primary, #endBtn {
  background: linear-gradient(#f3dca0, #c9a15a);
  color: #2a1c08;
  border-color: transparent;
  font-weight: 700;
}
button:disabled { opacity: .45; cursor: default; }
#main { padding: 0 8px 6px; }
.table-wrap {
  background: radial-gradient(ellipse at center, #1f8a56 0%, var(--felt) 42%, #0c4a30 100%);
  border-radius: 14px;
  box-shadow: inset 0 0 40px rgba(0,0,0,.28), 0 0 0 4px #6b4122, 0 0 0 7px #2c1a0e;
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* One centered column holds BOTH boards. Sides sit in the left column of that same row and center against it. */
.felt {
  display: grid;
  grid-template-columns: max-content max-content;
  grid-template-areas:
    ". opphead"
    "sides boards"
    ". youhead";
  justify-content: center;
  align-items: start;
  column-gap: 14px;
  row-gap: 4px;
}
.opp-head { grid-area: opphead; justify-self: center; }
.you-head { grid-area: youhead; justify-self: center; }
.opp-head, .you-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.sides {
  grid-area: sides;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(4, var(--sw));
  grid-template-rows: repeat(3, var(--sh));
  gap: 3px;
  align-content: center;
  justify-content: start;
}
.boards {
  grid-area: boards;
  width: calc(4 * var(--cw) + 12px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}
.zone-label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .85;
  margin: 0;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}
.hand {
  display: flex;
  justify-content: center;
  gap: var(--hand-gap, 4px);
  max-width: 100%;
}
.hand.opp { gap: 3px; }
.hand .slot { width: var(--cw); height: var(--ch); flex: 0 0 auto; }
.hand.opp .slot { width: var(--ow); height: var(--oh); }
.sides .slot { width: var(--sw); height: var(--sh); }
.board {
  display: grid;
  grid-template-columns: repeat(4, var(--cw));
  column-gap: 4px;
  width: calc(4 * var(--cw) + 12px);
  justify-content: start;
  align-items: start;
}
.board.opp { align-items: end; }
.col {
  position: relative;
  width: var(--cw);
  max-width: var(--cw);
  height: var(--ch);
  overflow: hidden;
}
.hole {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border: 1px dotted rgba(255,255,255,.7);
  border-radius: 2px;
  background: rgba(0,0,0,.14);
}
.pilecard {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  margin: 0;
  padding: 0;
  overflow: hidden;
}
.board.opp .card {
  transform: rotate(180deg) !important;
  transform-origin: center center !important;
}
.center-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: center;
}
.pile {
  width: var(--cw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.pile .stack, .slot {
  position: relative;
  border-radius: 1px;
  background: rgba(0,0,0,.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.1);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pile .stack { width: var(--cw); height: var(--ch); }
.card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
  touch-action: none;
}
.board .card,
.pilecard .card {
  width: var(--cw);
  height: var(--ch);
  flex: none;
}
.card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  pointer-events: none;
  border-radius: 0;
}
.card img { filter: drop-shadow(0 0.5px 0.5px rgba(0,0,0,.3)); }
.card.playable { cursor: grab; }
.card.selected { outline: 1px solid var(--gold); outline-offset: 0; z-index: 2; }
.card.dragging, .card.returning {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  margin: 0;
  flex: none;
}
.card.dragging {
  cursor: grabbing;
  transition: none !important;
  will-change: transform;
}
.card.returning { transition: left var(--ease), top var(--ease); }
.legal {
  box-shadow: inset 0 0 0 1px var(--gold), 0 0 4px rgba(240,212,138,.35);
  background: rgba(240,212,138,.12);
}
.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  border-radius: 999px;
  background: #1a140b;
  color: var(--gold);
  border: 1px solid #e6c87a;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.badge.wild { background: #7a1d28; color: #fff; }
.slot > span { color: rgba(255,255,255,.45); font-size: 12px; font-weight: 700; }
.count { margin: 0; text-align: center; font-size: 11px; line-height: 1.1; }
.home, .lobby {
  max-width: 520px;
  margin: 8vh auto;
  background: rgba(8,24,16,.72);
  border: 1px solid rgba(240,212,138,.3);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.home h2, .lobby h2 { font-family: Palatino, Georgia, serif; color: var(--gold); margin: 0 0 8px; }
.home p, .lobby p { line-height: 1.45; color: #e7f3ec; }
label { display: block; margin: 12px 0 4px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; opacity: .8; }
input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.25);
  color: white;
}
.row { display: flex; gap: 8px; margin-top: 16px; }
.row button { flex: 1; }
.code { font-family: ui-monospace, monospace; font-size: 36px; letter-spacing: .18em; color: var(--gold); margin: 8px 0; }
.linkbox { width: 100%; font-size: 13px; }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,16,10,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
.overlay .panel {
  background: #10281c;
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 22px 26px;
  text-align: center;
  max-width: 420px;
}
.overlay h2 { font-family: Palatino, Georgia, serif; color: var(--gold); margin: 0 0 8px; }
.log {
  margin: 2px auto 0;
  max-width: 980px;
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  opacity: .8;
  font-size: 12px;
}
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #3a1515;
  color: #ffe8e4;
  border: 1px solid #e7a598;
  padding: 8px 14px;
  border-radius: 999px;
  z-index: 50;
}
dialog {
  border: 1px solid rgba(240,212,138,.5);
  border-radius: 16px;
  background: #12261b;
  color: var(--ink);
  max-width: 520px;
}
dialog h2 { font-family: Palatino, Georgia, serif; color: var(--gold); }
dialog li { margin: 6px 0; }
.finished {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  color: var(--gold);
}
.hand.yours.hot .card { filter: drop-shadow(0 0 4px rgba(240,212,138,.35)); }
@media (prefers-reduced-motion: reduce) {
  .card { transition: none !important; }
}

/* End-of-game panel */
.rv-end {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,16,10,.6);
  animation: rv-fade .35s ease-out;
  overflow: hidden;
}
.rv-fx { position: absolute; inset: 0; pointer-events: none; }
.rv-card {
  position: relative;
  background: #10281c; border: 1px solid var(--gold); border-radius: 16px;
  padding: 22px 22px 16px; text-align: center;
  width: min(92vw, 400px);
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  animation: rv-pop .45s cubic-bezier(.2,1.4,.4,1);
}
.rv-card h2 { font-family: Palatino, Georgia, serif; color: var(--gold); margin: 4px 0 8px; font-size: 28px; }
.rv-reason { margin: 0 0 14px; opacity: .9; }
.rv-q { margin: 0 0 8px; font-weight: 650; }
.rv-row { display: flex; gap: 10px; justify-content: center; }
.rv-row button { flex: 1; max-width: 140px; }
.rv-status { min-height: 1.3em; margin: 10px 0 0; font-size: 14px; color: var(--gold); }
.rv-x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: var(--ink); font-size: 22px; padding: 2px 8px; cursor: pointer; }
@keyframes rv-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rv-pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
@keyframes rv-fall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(540deg); }
}

/* Automatic plays (forced aces and chains) */
.card.auto-glide { z-index: 20; box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(240,212,138,.7); }
.slot.auto-pulse { animation: rv-pulse 1s ease-out; }
@keyframes rv-pulse {
  0% { box-shadow: 0 0 0 0 rgba(240,212,138,.9); }
  60% { box-shadow: 0 0 0 8px rgba(240,212,138,0); }
  100% { box-shadow: none; }
}

/* Rules panel: scrollable and readable on a phone */
dialog#help { width: min(94vw, 560px); max-height: 86vh; overflow-y: auto; padding: 16px 18px; line-height: 1.45; }
dialog#help h3 { color: var(--gold); margin: 16px 0 4px; font-size: 16px; }
dialog#help p { margin: 4px 0 8px; }
dialog#help ul { padding-left: 20px; margin: 4px 0 8px; }
dialog#help form { position: sticky; bottom: -16px; background: #12261b; padding: 8px 0 0; text-align: right; }
@media (prefers-reduced-motion: reduce) {
  .rv-end, .rv-card, .slot.auto-pulse { animation: none !important; }
}
