/* misere.it — table + card styling (CSS-only cards for MVP). */

:root {
  --table-green: #0e6b3c;
  --table-green-dark: #094927;
  --card-bg: #fdfdfd;
  --card-bg-back: #1d3b80;
  --card-radius: 8px;
  --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  --card-shadow-hover: 0 6px 12px rgba(0, 0, 0, 0.45);
  --red: #c81e1e;
  --black: #1a1a1a;
  --label-color: #d6e9d8;
  --legal-glow: 0 0 0 3px #ffd86b inset, 0 6px 12px rgba(0, 0, 0, 0.45);
  --winner-glow: 0 0 0 4px #ffd86b;
  --card-w: 70px;
  --card-h: 100px;
  --card-w-sm: 48px;
  --card-h-sm: 68px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #f5f5f5;
  background: radial-gradient(ellipse at center, var(--table-green), var(--table-green-dark));
  user-select: none;
  overflow: hidden;
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.25);
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.1rem; letter-spacing: 0.05em; }
.hand-meta {
  font-size: 0.9rem;
  color: var(--label-color);
  flex: 1 1 200px;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--label-color);
}
.profile-chip[hidden] { display: none; }
.profile-name {
  color: #ffd86b;
  background: rgba(255, 216, 107, 0.08);
  border: 1px solid rgba(255, 216, 107, 0.3);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-weight: 600;
}
.profile-stats { font-variant-numeric: tabular-nums; }

.auth-buttons {
  display: inline-flex;
  gap: 0.4rem;
}
.auth-buttons[hidden] { display: none; }
.auth-btn {
  font: inherit;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  cursor: pointer;
  transition: background 0.12s ease;
}
.auth-btn:hover { background: rgba(255, 255, 255, 0.18); }
.auth-btn-primary {
  background: #ffd86b;
  color: #2a1c00;
  border-color: transparent;
  font-weight: 600;
}
.auth-btn-primary:hover { background: #ffe78b; }
.auth-btn-ghost {
  font-size: 0.78rem;
  padding: 0.15rem 0.55rem;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.15);
}
.auth-btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

.restart-btn {
  font: inherit;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  cursor: pointer;
  margin-left: 0.5rem;
  transition: background 0.12s ease;
}
.restart-btn:hover { background: rgba(255, 255, 255, 0.18); }
.restart-btn:active { background: rgba(255, 255, 255, 0.24); }

.status {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
  text-align: center;
  z-index: 5;
}

/* ── Table layout ───────────────────────────────────────────────── */
.table {
  position: relative;
  width: 100%;
  height: 100vh;
  padding: 3rem 1rem 4rem;
}

.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}
.seat-label {
  font-size: 0.85rem;
  color: var(--label-color);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.seat-info {
  font-size: 0.8rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  min-height: 1.2rem;
}
.seat-info.active { background: #ffd86b; color: #2a1c00; font-weight: 600; }

.seat-north { top: 4rem;       left: 50%; transform: translateX(-50%); }
.seat-west  { top: 50%; left: 1rem;  transform: translateY(-50%); align-items: flex-start; }
.seat-east  { top: 50%; right: 1rem; transform: translateY(-50%); align-items: flex-end; }
.seat-south { bottom: 3rem;    left: 50%; transform: translateX(-50%); }

.seat-cards {
  display: flex;
  gap: 0.25rem;
  min-height: var(--card-h-sm);
}
.seat-north .seat-cards,
.seat-west  .seat-cards,
.seat-east  .seat-cards { flex-wrap: nowrap; }
/* Human hand: two stacked horizontal rows (see renderPlayerHand).
   The column layout is scoped to :has(.hand-row) so that if a stale cached
   table.js (cards added as direct children) ever pairs with this CSS, the
   hand degrades to a wrapped row instead of one tall vertical column. */
.player-hand {
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 95vw;
}
.player-hand:has(.hand-row) {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
}
.player-hand .hand-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

/* ── Trick area ─────────────────────────────────────────────────── */
.trick-area {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 220px; height: 220px;
}
.trick-slot {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
}
.trick-north { top: 0;    left: 50%; transform: translateX(-50%); }
.trick-west  { top: 50%;  left: 0;   transform: translateY(-50%); }
.trick-east  { top: 50%;  right: 0;  transform: translateY(-50%); }
.trick-south { bottom: 0; left: 50%; transform: translateX(-50%); }

.trick-banner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.trick-banner.visible { opacity: 1; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
  position: relative;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  color: var(--black);
  flex-shrink: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card.small { width: var(--card-w-sm); height: var(--card-h-sm); font-size: 0.7em; }
.card.red { color: var(--red); }
.card .corner-tl, .card .corner-br {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}
.card .corner-tl { top: 6px; left: 6px; }
.card .corner-br { bottom: 6px; right: 6px; transform: rotate(180deg); }
.card .corner-tl .rank, .card .corner-br .rank { font-size: 1.1rem; }
.card .corner-tl .pip,  .card .corner-br .pip  { font-size: 0.95rem; }
.card .center-pip {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
}

.card.back {
  background: repeating-linear-gradient(45deg, var(--card-bg-back), var(--card-bg-back) 6px, #234ca8 6px, #234ca8 12px);
  border: 2px solid #122657;
}
.card.back .corner-tl, .card.back .corner-br, .card.back .center-pip { display: none; }

.card.legal {
  cursor: pointer;
  box-shadow: var(--legal-glow);
}
.card.legal:hover { transform: translateY(-8px); box-shadow: var(--card-shadow-hover); }
.card.illegal { opacity: 0.55; cursor: not-allowed; }
.card.played { animation: card-fly-in 0.18s ease; }
.card.winner-pop { box-shadow: var(--winner-glow); }

@keyframes card-fly-in {
  from { transform: scale(0.6); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}

/* ── Compact opponents (face-down stack) ───────────────────────── */
.seat:not(.seat-south) .seat-cards .card { width: var(--card-w-sm); height: var(--card-h-sm); }
.seat-west .seat-cards, .seat-east .seat-cards { flex-direction: column; }
.seat-west .seat-cards .card,
.seat-east .seat-cards .card { margin-top: -50px; }
.seat-west .seat-cards .card:first-child,
.seat-east .seat-cards .card:first-child { margin-top: 0; }
.seat-north .seat-cards .card { margin-left: -32px; }
.seat-north .seat-cards .card:first-child { margin-left: 0; }

/* ── Modals ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.visible { opacity: 1; pointer-events: auto; }
.modal {
  background: #1c2a26;
  color: #f5f5f5;
  border: 1px solid #2c443d;
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal h2 { margin: 0 0 0.6rem; font-size: 1.2rem; }
.modal .bid-modal-sub { margin: 0 0 1rem; color: var(--label-color); font-size: 0.95rem; }
.modal .bid-modal-hint { margin: 1rem 0 0; color: #ffd86b; font-size: 0.85rem; }

.bid-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}
.bid-btn {
  font: inherit;
  padding: 0.65rem 0.4rem;
  border: 1px solid #3c5a52;
  background: #243831;
  color: #f5f5f5;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}
.bid-btn:hover:not(:disabled) { background: #305448; transform: translateY(-1px); }
.bid-btn.bid-misere { grid-column: span 7; background: #3a2a4a; border-color: #6b4a8c; font-weight: 600; }
.bid-btn.bid-misere:hover:not(:disabled) { background: #4a3a64; }
.bid-btn.forbidden { opacity: 0.3; cursor: not-allowed; }

/* End screen */
.end-modal { text-align: center; }
.end-ranks {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.end-ranks li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  background: #243831;
  border-radius: 6px;
  font-size: 0.95rem;
}
.end-ranks li.winner { background: #5a4a14; color: #ffd86b; font-weight: 600; }
.end-ranks li.winner::before { content: '👑'; flex: 0 0 auto; }
.end-ranks li.me { outline: 1px solid #ffd86b; }
/* Note the deliberately end-ranks-scoped class names: the global `.seat` rule above
   uses `position: absolute` for the four table seats, which was making these spans
   collapse onto each other. Keep these distinct. */
.end-ranks .rank-seat  { flex: 1 1 auto; min-width: 0; color: var(--label-color); }
.end-ranks .rank-score { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 700; }
button.primary {
  font: inherit;
  padding: 0.65rem 1.2rem;
  background: #ffd86b;
  color: #2a1c00;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
button.primary:hover { background: #ffe78b; }
button.primary:disabled { opacity: 0.6; cursor: progress; }

/* ── Auth modal ────────────────────────────────────────────────── */
.auth-modal { position: relative; min-width: 340px; max-width: 420px; }
.auth-modal .auth-close {
  position: absolute;
  top: 0.5rem; right: 0.7rem;
  background: none; border: none; color: #aaa;
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0.25rem 0.5rem;
}
.auth-modal .auth-close:hover { color: #fff; }
.auth-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid #2c443d;
  margin: 0.5rem 0 1rem;
}
.auth-tab {
  font: inherit;
  background: none;
  color: var(--label-color);
  border: none;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.auth-tab:hover { color: #fff; }
.auth-tab.active { color: #ffd86b; border-bottom-color: #ffd86b; }
.auth-form {
  display: flex; flex-direction: column; gap: 0.7rem;
}
.auth-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--label-color); }
.auth-form input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  background: #243831;
  border: 1px solid #3c5a52;
  border-radius: 6px;
  color: #f5f5f5;
}
.auth-form input:focus { outline: none; border-color: #ffd86b; }
.auth-form small { color: #8aa399; font-size: 0.78rem; }
.auth-error {
  margin: 0.2rem 0 0;
  padding: 0.5rem 0.7rem;
  background: rgba(200, 30, 30, 0.18);
  border: 1px solid rgba(200, 30, 30, 0.4);
  border-radius: 6px;
  color: #ffd0d0;
  font-size: 0.85rem;
}

/* ── Scoreboard ────────────────────────────────────────────────── */
.scoreboard {
  position: fixed;
  top: 3rem;
  right: 0.75rem;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #2c443d;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  z-index: 4;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.scoreboard.visible { opacity: 1; transform: translateX(0); pointer-events: auto; }
.scoreboard header { font-weight: 600; margin-bottom: 0.4rem; color: var(--label-color); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; }
.scoreboard table { border-collapse: collapse; }
.scoreboard th, .scoreboard td {
  padding: 0.18rem 0.45rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.scoreboard thead th { color: var(--label-color); font-weight: 500; border-bottom: 1px solid #2c443d; }
.scoreboard tfoot th, .scoreboard tfoot td { border-top: 1px solid #2c443d; font-weight: 700; }

/* ── Toast (transient errors / notices) ────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 4rem;
  transform: translateX(-50%) translateY(20px);
  background: #4a1c1c;
  border: 1px solid #8a3a3a;
  color: #ffe1e1;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.info { background: #1c3a4a; border-color: #3a6a8a; color: #e1f0ff; }

/* ── Cookie consent banner ─────────────────────────────────────── */
.cookie-banner {
  position: fixed;
  left: 50%; bottom: 4.5rem;
  transform: translateX(-50%);
  max-width: 92vw;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #2c443d;
  color: #f5f5f5;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  display: flex; align-items: center; gap: 0.8rem;
  font-size: 0.85rem;
  z-index: 25;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.cookie-banner[hidden] { display: none; }
.cookie-banner a { color: #ffd86b; }
.cookie-banner .cookie-accept {
  font: inherit;
  background: #ffd86b;
  color: #2a1c00;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
.cookie-banner .cookie-accept:hover { background: #ffe78b; }

/* Gear button + account modal */
.profile-gear {
  font: inherit;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f5f5f5;
  border-radius: 999px;
  width: 1.8rem; height: 1.8rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.profile-gear:hover { background: rgba(255, 255, 255, 0.1); }

.account-modal { min-width: 360px; max-width: 460px; }
.account-modal h2 { margin-bottom: 0.2rem; }
.account-modal p.account-email { margin: 0 0 1rem; color: var(--label-color); font-size: 0.85rem; }
.account-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.account-action {
  font: inherit;
  text-align: left;
  background: #243831;
  border: 1px solid #3c5a52;
  color: #f5f5f5;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
}
.account-action small { display: block; color: var(--label-color); font-size: 0.78rem; margin-top: 0.2rem; }
.account-action:hover { background: #305448; }
.account-action.danger { border-color: #8a3a3a; color: #ffd0d0; }
.account-action.danger:hover { background: #4a1c1c; }

/* Footer legal links */
.legal-links {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 0.45rem 1rem;
  background: rgba(0, 0, 0, 0.4);
  font-size: 0.75rem;
  text-align: center;
  color: var(--label-color);
  z-index: 3;
}
.legal-links a { color: var(--label-color); text-decoration: underline dotted; margin: 0 0.5rem; }
.legal-links a:hover { color: #fff; }

/* Static legal pages share a single style. */
body.legal-page {
  overflow: auto;
  background: #0f1a17;
  color: #e5e7e0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}
.legal-header {
  max-width: 760px;
  margin: 2rem auto 1rem;
  padding: 0 1.25rem;
}
.legal-header h1 { margin: 1rem 0 0.25rem; color: #ffd86b; }
.legal-header .legal-updated { color: #94a59f; font-size: 0.9rem; margin: 0; }
.legal-back { color: #ffd86b; text-decoration: none; font-size: 0.9rem; }
.legal-back:hover { text-decoration: underline; }
.legal-main {
  max-width: 760px;
  margin: 0 auto 4rem;
  padding: 0 1.25rem;
}
.legal-main h2 { color: #ffd86b; margin-top: 2rem; font-size: 1.15rem; }
.legal-main code { background: rgba(255, 255, 255, 0.08); padding: 0 0.25rem; border-radius: 3px; }
.legal-main a { color: #ffd86b; }
.legal-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.legal-table th, .legal-table td {
  border-bottom: 1px solid #2c443d;
  padding: 0.55rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.legal-table thead th { color: var(--label-color); font-weight: 600; }
.legal-footer-links { margin-top: 3rem; color: #94a59f; }

@media (max-width: 600px) {
  :root { --card-w: 56px; --card-h: 80px; --card-w-sm: 38px; --card-h-sm: 54px; }
  .topbar h1 { font-size: 1rem; }
  .hand-meta { flex-basis: 100%; order: 4; text-align: left; font-size: 0.8rem; }
  .topbar { padding: 0.45rem 0.7rem; }
  .trick-area { width: 180px; height: 180px; }
  .scoreboard { font-size: 0.7rem; top: 5.5rem; bottom: auto; right: 0.4rem; padding: 0.3rem 0.4rem; }
  .bid-grid { grid-template-columns: repeat(5, 1fr); }
  .bid-btn.bid-misere { grid-column: span 5; }
  .restart-btn { padding: 0.2rem 0.6rem; font-size: 0.8rem; }
  .profile-stats { display: none; }
  .cookie-banner { flex-direction: column; align-items: stretch; gap: 0.5rem; bottom: 5.5rem; }
  .legal-links { font-size: 0.7rem; padding: 0.35rem 0.6rem; }
}

/* ── r-100 fix: compact mobile hand ─────────────────────────────────
   On narrow phones the south hand is laid out in two rows (6 over 7, see
   renderPlayerHand). Shrink the human's cards and tighten gaps so the
   7-card row fits across a ~360px screen, clear of the trick area. */
@media (max-width: 600px) {
  .player-hand { gap: 4px; max-width: 100vw; }
  .player-hand .hand-row { gap: 3px; }
  .seat-south .seat-cards .card { width: 44px; height: 62px; }
  .seat-south .seat-cards .card .corner-tl .rank,
  .seat-south .seat-cards .card .corner-br .rank { font-size: 0.8rem; }
  .seat-south .seat-cards .card .corner-tl .pip,
  .seat-south .seat-cards .card .corner-br .pip  { font-size: 0.68rem; }
  .seat-south .seat-cards .card .center-pip { font-size: 1.2rem; }
  .seat-south { bottom: 2.5rem; }
}
