:root {
  --felt: #1f6b4a;
  --felt-dark: #17523a;
  --ink: #1d2320;
  --paper: #fffdf5;
  --us: #f2c14e;
  --them: #f08a5d;
  --cw: 68px;
  --sw: 34px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #10271d;
  color: #eef3ee;
  min-height: 100vh;
}
button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  background: #e9efe9;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: #fff; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--us); }
button.danger { background: #d9534f; color: #fff; }
button.ghost { background: transparent; color: #eef3ee; border: 1px solid #5b7a6b; font-weight: 500; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  flex-wrap: wrap;
  background: #0b1c15;
}
h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.scores { display: flex; gap: 8px; margin-left: auto; }
.team {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 8px;
  align-items: baseline;
  padding: 4px 10px;
  border-radius: 8px;
  background: #17332a;
  min-width: 96px;
}
.team span { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.team b { font-size: 22px; text-align: right; }
.team i { grid-column: 1 / -1; font-style: normal; font-size: 10px; letter-spacing: 1px; min-height: 12px; opacity: .85; }
.team.us b { color: var(--us); }
.team.them b { color: var(--them); }
.team.flash { animation: flash .8s; }
@keyframes flash { 0% { background: #3f7d5f; } 100% { background: #17332a; } }
.hbtns { display: flex; gap: 6px; }
.hbtns button { padding: 6px 10px; font-size: 13px; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-areas: "table log" "controls log";
  gap: 12px;
  align-items: start;
}
#table {
  grid-area: table;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 6px solid #5a3b1c;
  border-radius: 28px;
  padding: 12px 8px;
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  grid-template-areas: ". top ." "left center right" "bottom bottom bottom";
  gap: 10px 6px;
  align-items: center;
}
.seat { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; min-height: 96px; }
.seat.top { grid-area: top; }
.seat.left { grid-area: left; }
.seat.right { grid-area: right; }
.seat.bottom { grid-area: bottom; }
.seat .who { font-size: 13px; font-weight: 600; display: flex; gap: 6px; align-items: center; padding: 2px 8px; border-radius: 10px; }
.seat.turn .who { background: #fff; color: var(--ink); }
.seat .tag { font-size: 10px; padding: 1px 5px; border-radius: 6px; background: var(--us); color: var(--ink); letter-spacing: .5px; }
.seat .role { font-size: 10px; opacity: .75; font-weight: 400; }
.cards { display: flex; gap: 4px; justify-content: center; }
.bubble {
  min-height: 26px;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  animation: pop .18s ease-out;
  white-space: nowrap;
}
.bubble:empty { visibility: hidden; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.card {
  width: var(--cw);
  aspect-ratio: 5 / 8;
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  border: 1px solid #b9b39c;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  padding: 0;
  font-weight: 400;
}
.card:hover { background: var(--paper); }
.card .rk { position: absolute; top: 3px; left: 5px; font-weight: 800; font-size: 17px; line-height: 1; }
.card svg { width: 100%; height: 100%; display: block; }
.card .ix { font: 800 17px system-ui, sans-serif; text-anchor: middle; fill: #1d2320; }
.card .cp { font: 600 9px system-ui, sans-serif; text-anchor: middle; fill: #555; }
.card .cap { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font-size: 10px; color: #555; }
.card.small { width: var(--sw); border-radius: 4px; }
.card.small .rk { position: static; font-size: 14px; }
.card.small svg { width: 62%; height: auto; aspect-ratio: 1; }
.card.small .cap { display: none; }
.card.back {
  background: repeating-linear-gradient(45deg, #8c2f2f 0 5px, #a94444 5px 10px);
  border-color: #f3e6c8;
}
button.card { cursor: pointer; transition: transform .12s; }
button.card.sel { transform: translateY(-12px); outline: 3px solid var(--us); }
.hint { font-size: 12px; opacity: .9; text-align: center; min-height: 17px; }

#center { grid-area: center; display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center; }
#lances { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 100%; max-width: 260px; }
.lance { background: rgba(0, 0, 0, .25); border-radius: 8px; padding: 3px 6px; font-size: 11px; line-height: 1.25; }
.lance b { display: block; font-size: 12px; }
.lance.cur { background: #fff; color: var(--ink); }
.lance span { opacity: .85; }
#status { font-size: 13px; min-height: 36px; }

#controls { grid-area: controls; background: #17332a; border-radius: 12px; padding: 12px; min-height: 64px; }
#controls .prompt { margin: 0 0 8px; font-size: 14px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stepper { display: inline-flex; align-items: center; background: #e9efe9; border-radius: 8px; overflow: hidden; }
.stepper button { border-radius: 0; padding: 9px 11px; }
.stepper .go { background: var(--us); min-width: 96px; }
.wait { opacity: .7; font-size: 14px; margin: 0; }

table.sum { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 10px; }
table.sum th, table.sum td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #2c4d40; vertical-align: top; }
table.sum td.n { text-align: right; font-weight: 700; white-space: nowrap; }
.us-c { color: var(--us); }
.them-c { color: var(--them); }
.result { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
.handlist { font-size: 12px; opacity: .9; margin: 0 0 10px; padding: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }

#logwrap { grid-area: log; background: #17332a; border-radius: 12px; padding: 10px 12px; }
#logwrap h2 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; opacity: .8; }
#log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; max-height: 520px; overflow-y: auto; }
#log li { padding: 1px 0; }
#log li.h { margin-top: 6px; font-weight: 700; color: #bfe3cf; }
#log li.s { color: var(--us); }

dialog { max-height: calc(100dvh - 32px); max-width: 620px; width: calc(100% - 24px); border: 0; border-radius: 14px; padding: 18px 20px; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 8px; }
dialog h3 { margin: 14px 0 4px; font-size: 15px; }
dialog p, dialog ul { margin: 4px 0; }
dialog ul { padding-left: 20px; }
dialog .opt { display: block; margin: 14px 0; font-size: 14px; }
dialog form { text-align: right; }
dialog form button { background: var(--felt); color: #fff; }

@media (max-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "table" "controls" "log"; padding: 8px; gap: 8px; }
  #log { max-height: 220px; }
}
@media (max-width: 520px) {
  :root { --cw: 62px; --sw: 23px; }
  header { padding: 6px 8px; gap: 8px; }
  h1 { font-size: 18px; }
  .team { min-width: 70px; padding: 3px 8px; }
  .team b { font-size: 18px; }
  #table { padding: 8px 3px; border-width: 4px; border-radius: 18px; grid-template-columns: 1fr 1.25fr 1fr; gap: 8px 3px; }
  .card.small .rk { font-size: 11px; }
  .cards { gap: 2px; }
  .seat.bottom .cards { gap: 5px; }
  .bubble { font-size: 12px; padding: 3px 7px; }
  .lance { font-size: 10px; padding: 2px 3px; }
  #controls { padding: 10px; }
  button { padding: 10px 12px; }
}

.tip { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; background: #4a3a12; border-left: 4px solid var(--us); font-size: 13.5px; }
#log li.w { color: #f6d98a; }
