/* Charpat: green felt table, original card art from the 2014 game. */
:root {
  color-scheme: dark;
  --felt: #01683d;
  --felt-dark: #014a2b;
  --felt-light: #0b7d4c;
  --paper: #fffdf5;
  --ink: #17231c;
  --ink-2: #4b5a50;
  --gold: #f9e680;
  --gold-strong: #ffb800;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --win: #3b82f6;
  --danger: #c62828;
  --line: rgba(255, 255, 255, 0.16);
  --panel: rgba(255, 253, 245, 0.96);
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.25);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Card sprite: 150x210 cards on a 2319x939 sheet. --s scales everything. */
  --card-scale: 0.62;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.45 var(--font);
  color: #fff;
  background: var(--felt-dark) url("images/bgimage-green.png") repeat;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 8px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gold-strong); outline-offset: 2px; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 6px 16px; border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.15); background: #fff; color: var(--ink);
  transition: transform 0.08s, filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { min-height: 48px; padding: 10px 24px; font-size: 17px; }
.btn.small { min-height: 30px; padding: 3px 12px; font-size: 13px; }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; opacity: 0.85; }
.icon-btn {
  font: inherit; cursor: pointer; width: 36px; height: 36px; border-radius: 10px;
  display: inline-grid; place-items: center; background: transparent; color: inherit;
  border: 1px solid var(--line);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
input[type=text], select {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #b9c2bc; border-radius: 10px; min-height: 42px; padding: 8px 12px; width: 100%;
}
select {
  width: auto; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234b5a50' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
select:hover { border-color: #8d9a92; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.hint { color: var(--ink-2); font-size: 13.5px; margin: 8px 0 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: rgba(0, 0, 0, 0.28); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { width: 40px; height: 40px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45)); transition: transform 0.2s; }
.brand:hover img { transform: rotate(-6deg) scale(1.06); }
.wordmark {
  font-weight: 900; font-size: 26px; letter-spacing: 0.01em; line-height: 1;
  background: linear-gradient(180deg, #fff3c4 0%, #f5c542 55%, #c98a12 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.55)) drop-shadow(0 0 10px rgba(245, 197, 66, 0.35));
}
.hero-logo { width: 96px; height: 96px; margin: -4px auto 6px; display: block; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.3)); }
.game-code { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.game-code b { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; letter-spacing: 0.12em; color: var(--gold); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; opacity: 0.85; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: #f2b134; }
.conn.ok i { background: #3ddc84; }
.conn.ok span { display: none; }
.conn.down i { background: #ff5b5b; }

/* ---------- panels & screens ---------- */
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); color: var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); }
.screen:not(.game) { display: grid; place-items: start center; padding-top: 6vh; }
.welcome, .lobby { width: min(560px, 100%); padding: 28px 32px; text-align: center; }
.welcome h1, .lobby h1 { color: var(--felt); }
.welcome p { color: var(--ink-2); }
.welcome form { display: flex; flex-direction: column; gap: 14px; margin: 22px auto 0; max-width: 380px; }
.rules { margin-top: 22px; text-align: left; color: var(--ink-2); font-size: 14px; border-top: 1px solid #e3e6e1; padding-top: 14px; }
.rules summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.rules li { margin: 6px 0; }
.pip { font-size: 1.15em; line-height: 1; }
.pip.red { color: #d11; }
.pip.black { color: #111; }
.invite { display: flex; gap: 8px; margin: 14px 0 10px; }
.invite-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.invite-actions .btn { text-decoration: none; }
.invite input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.lobby-players { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.lobby-players li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; background: #f0f3ee; font-weight: 500; }
.lobby-start { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #e5ecff; color: #1d4ed8; text-transform: uppercase; letter-spacing: 0.04em; }
.tag.you { background: #ddf5e6; color: #116335; }
.tag.off { background: #fde2e2; color: #9b1c1c; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #3ddc84; flex: none; }
.dot.off { background: #c4c4c4; }

/* ---------- game layout ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.table-area { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.round-info {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; font-size: 14.5px;
}
.round-info b { color: var(--gold); }
.trump { display: inline-flex; align-items: center; gap: 6px; }
.suit { font-size: 22px; line-height: 1; background: #fff; border-radius: 6px; padding: 2px 6px; }
.suit.red { color: #d11; }
.suit.black { color: #111; }
.felt {
  position: relative; min-height: 290px; border-radius: 22px; padding: 18px;
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 55%, var(--felt-dark) 100%);
  border: 8px solid #5b3a1e; box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.felt.your-turn { border-color: var(--gold-strong); box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(255, 184, 0, 0.35), var(--shadow); }
.trick { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; min-height: calc(210px * var(--card-scale) + 24px); }
.trick .slot { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: drop 0.25s ease-out; }
.trick .slot .who { font-size: 13px; font-weight: 600; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trick.done { opacity: 0.85; }
@keyframes drop { from { transform: translateY(-14px) scale(1.05); opacity: 0; } }
.status { font-size: 16px; font-weight: 600; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); min-height: 24px; }
.bid-panel { background: rgba(0, 0, 0, 0.3); border-radius: 14px; padding: 12px 16px; text-align: center; }
.bid-title { font-weight: 600; margin-bottom: 10px; }
.bid-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.bid-buttons .btn { min-width: 46px; }
.round-over { background: var(--panel); color: var(--ink); border-radius: 14px; padding: 16px 20px; width: min(520px, 100%); box-shadow: var(--shadow); }
.round-over h2 { color: var(--felt); }
.round-over table { margin: 6px 0 14px; }
.round-over .actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
  --s: var(--card-scale);
  width: calc(150px * var(--s)); height: calc(210px * var(--s));
  border-radius: calc(12px * var(--s));
  background-image: url("images/card-deck.png");
  background-size: calc(2319px * var(--s)) auto;
  background-position: calc(var(--x) * -1px * var(--s)) calc(var(--y) * -1px * var(--s));
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  flex: none; position: relative;
}
.card.win { box-shadow: 0 0 0 3px var(--win), 0 4px 12px rgba(0, 0, 0, 0.5); }
.card.trumpcard::after {
  content: "trump"; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--gold-strong); color: #3a2a00; padding: 0 6px; border-radius: 999px;
}

.hand {
  display: flex; justify-content: center; align-items: flex-end;
  min-height: calc(210px * var(--card-scale) + 40px); padding: 22px 12px 8px;
  overflow-x: auto; overflow-y: visible; scrollbar-width: thin;
}
.hand .card {
  margin-left: calc(var(--overlap, -40px));
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s;
  transform: translateY(var(--lift, 0)) rotate(var(--rot, 0deg));
  transform-origin: 50% 120%;
  animation: deal 0.35s ease-out backwards;
  animation-delay: var(--delay, 0s);
  border: 0; padding: 0; cursor: default;
}
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { cursor: pointer; box-shadow: 0 0 0 3px #3ddc84, 0 3px 8px rgba(0, 0, 0, 0.5); }
.hand .card.playable:hover, .hand .card.playable:focus-visible { --lift: -22px; z-index: 5; }
.hand .card.blocked { filter: brightness(0.6) saturate(0.6); }
.hand .card.trumpcard::after { bottom: auto; top: -9px; }
@keyframes deal { from { transform: translate(0, -120px) rotate(0); opacity: 0; } }
.hand-empty { color: rgba(255, 255, 255, 0.7); align-self: center; }

/* ---------- side: scores & chat ---------- */
.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 76px; }
.scores { padding: 10px 12px 12px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 7px 6px; text-align: left; border-bottom: 1px solid #e3e6e1; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.num { text-align: right; }
tr.me td { background: #effaf2; }
tr.turn td:first-child { box-shadow: inset 3px 0 0 var(--gold-strong); }
td.name { display: flex; align-items: center; gap: 7px; max-width: 160px; }
td.name span:not(.dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-star { color: #c99400; font-style: normal; font-size: 13px; }
td.made { color: #116335; font-weight: 700; }
td.over { color: var(--danger); font-weight: 700; }
.scores .btn { margin-top: 10px; color: var(--ink); }
.chat { display: flex; flex-direction: column; height: 300px; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.chat-log .msg b { color: var(--felt); }
.chat-log .empty { color: var(--ink-2); font-size: 13px; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e3e6e1; }
.chat-form input { min-height: 34px; padding: 5px 10px; }

/* ---------- score sheet & toasts ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(760px, calc(100% - 32px)); max-height: 80vh; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.sheet-head .icon-btn { border-color: #d5d9d4; }
.sheet-body { padding: 10px 18px 18px; overflow-x: auto; }
.sheet-body td, .sheet-body th { white-space: nowrap; text-align: center; }
.sheet-body td:first-child, .sheet-body th:first-child { text-align: left; }
.sheet-body .miss { color: #9aa39d; }
.sheet-body tfoot td { font-weight: 700; border-bottom: 0; }
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: max-content; max-width: calc(100% - 32px); }
.toast { background: #1d1d1d; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: drop 0.2s ease-out; }
.toast.error { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  :root { --card-scale: 0.46; }
  main { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .game-code { order: 3; width: 100%; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .chat { height: 230px; }
  .felt { padding: 12px; border-width: 6px; min-height: 230px; }
  .welcome, .lobby { padding: 22px 18px; }
  .trick { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
