:root {
  --felt: #1e5631;
  --panel: #f1faee;
  --text: #1b1b1b;
  --muted: #5c677d;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--felt);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
#app { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px; }
h1 { color: var(--panel); margin: 8px 0 0; }
.panel { background: var(--panel); border-radius: 12px; padding: 16px; width: min(92vw, 420px); }
.fan { display: flex; }
.fan .card { margin-left: -18px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35)); }
.fan .card:first-child { margin-left: 0; }
.watermark { position: fixed; right: 8px; bottom: 6px; color: rgba(241, 250, 238, 0.45); font: 11px ui-monospace, monospace; }

h1 a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid #c9d1d9; }
button { background: #e76f51; color: white; border: none; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.secondary { background: #5c677d; }
button.primary, a.button.primary { background: #2a9d8f; font-weight: 600; }
button.active { background: #1d3557; outline: 3px solid #e9c46a; }
button.small { padding: 4px 10px; font-size: 0.9rem; }
button.link { background: none; color: var(--panel); text-decoration: underline; padding: 4px; }
a.button { display: inline-block; text-decoration: none; color: white; padding: 10px 14px; border-radius: 8px; text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.panel h2 { margin: 0 0 8px; font-size: 1.05rem; }
.panel { display: flex; flex-direction: column; gap: 10px; }
.setup input:not([type='checkbox']) { flex: 1; min-width: 0; }
.setup details summary { cursor: pointer; color: var(--muted); }

.table { width: 100%; max-width: 980px; display: flex; flex-direction: column; gap: 12px; }
.table .panel { width: 100%; }

.badge { background: #1d3557; color: white; border-radius: 4px; font-size: 0.7rem; padding: 0 4px; margin-left: 4px; }

.status { color: var(--panel); font-weight: 700; font-size: 1.15rem; }
.contract { color: var(--panel); text-align: center; }
.contract .suit.D, .contract .suit.H { color: #ff8a8a; }
.trick { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: flex-end; }
.trick.done { opacity: 0.75; }
.trick.empty { min-height: 90px; display: flex; align-items: center; color: rgba(241, 250, 238, 0.7); }
.played { display: flex; flex-direction: column; align-items: center; color: var(--panel); }
.played.won .card { outline: 3px solid #e9c46a; border-radius: 6px; }

.hand { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.card { transition: transform 0.12s ease; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-4px); }
.card.selected { transform: translateY(-10px); filter: drop-shadow(0 0 4px #2a9d8f); }
.card.dim { opacity: 0.45; }
.call-cards { display: flex; flex-wrap: wrap; gap: 4px; }
.call-option { display: flex; flex-direction: column; align-items: center; }

.scores table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.scores th, .scores td { text-align: center; padding: 2px 4px; border-bottom: 1px solid #e0e6ea; }
.scores td:first-child, .scores th:first-child { text-align: left; }
.scores td.bidside { background: #fff3b0; }
.scores tr.total td { font-weight: 700; border-top: 2px solid #1b1b1b; }
/* The table: an oval of felt with the seats placed around its edge. */
.ring { position: relative; height: 460px; width: 100%; max-width: 760px; margin: 0 auto; }
.ring .felt { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 66%; height: 62%; border-radius: 50%; background: #17472a; box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35), 0 0 0 10px #6b4226; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px 12%; text-align: center; }
.seat { position: absolute; left: calc(50% + min(43%, 50% - 46px) * var(--sx)); top: calc(50% + min(41%, 50% - 38px) * var(--sy)); transform: translate(-50%, -50%); width: 108px; background: rgba(241, 250, 238, 0.95); border-radius: 10px; padding: 4px 6px; border: 3px solid transparent; text-align: center; z-index: 1; }
.seat.active { border-color: #e9c46a; box-shadow: 0 0 10px #e9c46a; }
.seat.bidder { background: #fff3b0; }
.seat.partner { background: #ffd8c2; }
.seat.me { outline: 2px solid #2a9d8f; }
.seat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-score { font-size: 1.2rem; font-weight: 700; line-height: 1.1; }
.seat-info { font-size: 0.75rem; min-height: 1em; color: var(--muted); }
.seat-cards { display: flex; gap: 3px; justify-content: center; align-items: center; }
.seat .badge { background: #264653; color: white; border-radius: 4px; padding: 0 4px; margin-right: 4px; font-size: 0.7rem; }
.partner-tag { font-weight: 700; color: #ffd166; }
.kitty-row h3 { margin: 4px 0; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.bid-panel { display: flex; flex-direction: column; gap: 8px; }
.suit-button .suit.D, .suit-button .suit.H { color: #ff8a8a; }
.log ol { margin: 0; padding: 0; list-style: none; max-height: 200px; overflow-y: auto; font-size: 0.85rem; }
.log li { padding: 2px 0; border-bottom: 1px solid #e0e6ea; }
.toast.error { background: #ffd6d6; color: #8a0000; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.winner { background: #fff3b0; }
.pass-device { margin-top: 40px; text-align: center; }
.footer-links { justify-content: center; flex-wrap: wrap; }
.footer-links button { white-space: nowrap; }

/* Animations: CSS only, so they cost nothing when nothing changes. */
@keyframes slide-in { from { transform: translate(var(--from-x, 0), var(--from-y, 80px)); opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.12); } }
.played { animation: slide-in 0.28s ease-out; }
.played.won .card { animation: pulse 0.4s ease-in-out 0.1s; }
.hand .card { animation: rise 0.25s ease-out; }

.overlay { position: fixed; inset: 0; background: rgba(10, 20, 35, 0.7); display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; overflow-y: auto; z-index: 10; }
.rules { max-width: 640px; width: 100%; gap: 6px; }
.rules h3 { margin: 10px 0 2px; }
.rules p, .rules ul, .rules ol { margin: 2px 0; }
.rules li { margin: 2px 0; }
.rank-row { display: flex; flex-wrap: wrap; gap: 2px; }

@media (max-width: 600px) {
  #app { padding: 8px; }
  .ring { height: min(400px, 105vw); }
  .hand .card { width: 52px; height: 73px; }
  .seat { width: 84px; font-size: 0.8rem; padding: 3px 5px; }
  .seat-score { font-size: 1rem; }
  .ring .felt { width: 62%; height: 58%; }
  .ring .trick .card { width: 36px; height: 50px; }
  .ring .trick { gap: 4px; }
  .ring .felt { padding: 6px 9%; gap: 3px; }
  .ring .status { font-size: 0.95rem; }
  .ring .contract { font-size: 0.75rem; }
}
/* Landscape phones: the table on the left, your hand and the panels on the right. */
@media (orientation: landscape) and (max-height: 560px) {
  #app { padding: 6px; gap: 6px; }
  #app > h1 { display: none; }
  .table { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 6px 10px; align-items: start; max-width: none; }
  .table > .ring { grid-column: 1; grid-row: 1 / span 6; height: calc(100vh - 12px); position: sticky; top: 6px; }
  .table > :not(.ring):not(.overlay) { grid-column: 2; }
  .seat { width: 84px; font-size: 0.75rem; padding: 2px 4px; }
  .seat-score { font-size: 0.95rem; }
  .ring .felt { padding: 4px 10%; gap: 2px; }
  .ring .trick .card { width: 34px; height: 48px; }
  .ring .trick { gap: 3px; }
  .ring .status { font-size: 0.9rem; }
  .ring .contract { font-size: 0.7rem; }
  .hand .card { width: 48px; height: 67px; }
  .table .panel { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .played, .played.won .card, .hand .card { animation: none; }
}
.banner { background: #fff3b0; color: #1b1b1b; border-radius: 8px; padding: 6px 14px; font-weight: 600; }
.toast.info { background: #d8f3dc; color: #1b4332; border-radius: 8px; padding: 8px 12px; }
.offline { color: #b00020; font-size: 0.85em; }
.players { margin: 0; padding-left: 20px; }
.players li { padding: 2px 0; }
.row.between { justify-content: space-between; }
button.link.dark { color: var(--muted); }
.lobby { width: min(92vw, 460px); }
.seats-panel, .table > .panel { width: 100%; }
.error { color: #b00020; }
