:root {
  --bg: #f5f0e8;
  --panel: #fffdf8;
  --text: #1a1a1a;
  --muted: #555;
  --accent: #2a6b4f;
  --accent-light: #e8f3ed;
  --border: #d4cbb8;
  --card-bg: #fff;
  --selected: #ffe08a;
  --red: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

header {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}

.header-inner {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.help-icon-link {
  position: absolute;
  top: 0;
  right: 1rem;
  color: var(--red);
  line-height: 0;
  text-decoration: none;
  opacity: 0.92;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.help-icon-link:hover {
  opacity: 1;
  transform: scale(1.06);
}
.help-icon {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

h1 { margin: 0; font-size: 2rem; }
.header-home-link { color: inherit; text-decoration: none; }
.header-home-link:hover { text-decoration: underline; }
.house-rules {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.2rem 0 0;
  font-style: italic;
}
.subtitle { color: var(--muted); margin: 0.25rem 0 0; }

/* Help page */
.help-page header a {
  color: var(--accent);
}
.help-main {
  max-width: 42rem;
}
.help-jump {
  background: var(--accent-light);
  border-color: var(--accent);
}
.help-jump-lead {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
}
.help-jump-lead a {
  color: var(--accent);
  font-weight: bold;
}
.help-toc h2 {
  margin-top: 0;
  font-size: 1.15rem;
}
.help-toc ol {
  margin: 0.5rem 0 0;
  padding-left: 1.35rem;
}
.help-toc a {
  color: var(--accent);
}
.help-content section {
  margin-top: 2rem;
  padding-top: 0.5rem;
}
.help-content section:first-child {
  margin-top: 0;
}
.help-content h2 {
  margin-top: 0;
  font-size: 1.35rem;
  scroll-margin-top: 1rem;
}
.help-content h3 {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.5rem;
}
.help-content h4 {
  font-size: 0.98rem;
  margin: 1rem 0 0.4rem;
  color: var(--text);
}
.help-note {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 0.95rem;
}
.help-dl dt {
  font-weight: bold;
  margin-top: 0.85rem;
}
.help-dl dd {
  margin: 0.25rem 0 0 0;
  color: var(--muted);
}
.help-score-table {
  font-size: 0.95rem;
}
.help-footer {
  text-align: center;
  margin: 1rem 0 2rem;
}
.help-footer a {
  color: var(--accent);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.app-exit-row {
  display: none;
  margin: 1.5rem auto 0;
  padding: 0 0 calc(1.25rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
}

.app-reload-btn {
  font-size: 0.82rem;
  padding: 0.38rem 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.app-reload-btn:hover {
  color: var(--text);
  background: var(--accent-light);
}

.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.lobby-panel {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #faf8f5;
}

.lobby-panel h3 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
}

.host-access-hint {
  margin: 0.5rem 0 0;
}

.host-free-games-banner {
  margin: 0.65rem 0 0;
  padding: 0.75rem 0.9rem;
  border: 2px solid #2a6b4f;
  border-radius: 8px;
  background: #e8f5ef;
  color: #1a3d2e;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.host-free-games-banner.host-free-games-exhausted {
  border-color: #8b2500;
  background: #fdeee8;
  color: #5c1800;
}

.host-free-games-banner.hidden {
  display: none;
}

.lobby-create-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-top: 0.25rem;
}

.subscribe-cta {
  flex: 0 1 auto;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--accent);
  font-weight: bold;
  max-width: 22rem;
}

.subscribe-dialog {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.subscribe-dialog.hidden {
  display: none;
}

.subscribe-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 22, 0.55);
}

.subscribe-dialog-panel {
  position: relative;
  width: min(100%, 28rem);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.35rem 1.25rem 1.15rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fffdf8;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
}

.subscribe-dialog-close {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.subscribe-dialog-panel h2 {
  margin: 0 0 0.6rem;
  font-size: 1.25rem;
  color: #2a6b4f;
  text-align: center;
}

.subscribe-intro,
.subscribe-result-text,
.subscribe-legal {
  margin: 0 0 0.85rem;
  line-height: 1.45;
  text-align: center;
}

.subscribe-legal {
  font-size: 0.82rem;
  color: var(--muted);
}

.subscribe-plan-options {
  display: grid;
  gap: 0.65rem;
  margin: 0.85rem 0;
}

.subscribe-plan-card {
  display: grid;
  gap: 0.15rem;
  padding: 0.9rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.subscribe-plan-card:hover {
  border-color: #2a6b4f;
}

.subscribe-plan-featured {
  border-color: #2a6b4f;
  background: #f2faf6;
}

.subscribe-plan-badge {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #2a6b4f;
}

.subscribe-plan-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.subscribe-plan-price {
  font-size: 1.45rem;
  font-weight: 700;
  color: #1a3d2e;
}

.subscribe-plan-period {
  font-size: 0.88rem;
  color: var(--muted);
}

.subscribe-step.hidden {
  display: none;
}

.subscribe-result-actions {
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#btn-subscribe-success {
  width: 100%;
}

.host-free-games-banner-detail {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.35;
}

.host-validation-panel {
  margin-top: 0.65rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffaf2;
}

.host-validation-junk-notice {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.8rem;
  border: 2px solid #c47a20;
  border-radius: 8px;
  background: #fff4e0;
  color: #4a3208;
  line-height: 1.45;
}

.host-validation-junk-notice p {
  margin: 0 0 0.45rem;
}

.host-validation-junk-notice p:last-child {
  margin-bottom: 0;
}

.host-validation-junk-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #8a4b00;
}

.host-validation-junk-hint {
  font-size: 0.92rem;
}

.host-validation-panel label {
  margin-bottom: 0.5rem;
}

.host-validation-actions {
  margin-top: 0.35rem;
  gap: 0.5rem;
}

/* Low-prominence account utility — bottom of lobby, collapsed by default */
.linked-devices-panel {
  margin: 1.25rem 0 0.5rem;
  padding: 0.35rem 0;
  border: none;
  border-top: 1px solid #e5dfd2;
  background: transparent;
  font-size: 0.88rem;
  color: #6b655c;
}

.linked-devices-panel > summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  color: #7a746a;
  list-style-position: outside;
}

.linked-devices-panel > summary:hover {
  color: #5a544a;
}

.linked-devices-panel[open] > summary {
  margin-bottom: 0.45rem;
  color: #5a544a;
}

.linked-devices-panel .hint {
  font-size: 0.82rem;
  color: #8a847a;
}

.linked-devices-list {
  list-style: none;
  margin: 0.4rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.linked-devices-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid #e8e2d6;
  border-radius: 6px;
  background: #faf8f4;
  font-size: 0.85rem;
}

.linked-devices-list .device-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.linked-devices-list .device-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  word-break: break-all;
  color: #5a544a;
}

.linked-devices-list .device-badge {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.02rem 0.35rem;
  border-radius: 999px;
  background: #eeeae2;
  color: #6b655c;
  font-size: 0.7rem;
  font-weight: 600;
}

.linked-devices-list .device-when {
  color: #9a948a;
  font-size: 0.75rem;
}

.linked-devices-list button,
.linked-devices-actions button {
  font-size: 0.82rem;
  padding: 0.3rem 0.55rem;
}

.linked-devices-actions {
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.linked-devices-admin {
  margin-top: 0.5rem;
  color: #9a948a;
}

.linked-devices-admin summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: #9a948a;
}

.linked-devices-admin label {
  font-size: 0.8rem;
  color: #7a746a;
}

.linked-devices-admin input {
  font-size: 0.85rem;
}

.lobby-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Create still tappable when host setup is incomplete — click shows why */
#btn-create.btn-blocked {
  opacity: 0.72;
  box-shadow: none;
}

#btn-create {
  touch-action: manipulation;
  min-height: 2.75rem;
  position: relative;
  z-index: 2;
  -webkit-tap-highlight-color: rgba(40, 90, 60, 0.25);
  cursor: pointer;
}

/* Visible under Create on phones (bottom #lobby-status is easy to miss) */
.create-status {
  margin: 0.5rem 0 0;
  min-height: 1.25em;
  font-size: 0.95rem;
  color: var(--accent);
}

.create-status.create-status-error {
  color: #8b2500;
  font-weight: 600;
}

.lobby-panel .checkbox-label:last-of-type {
  margin-bottom: 0.5rem;
}

.hidden { display: none; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-weight: bold;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: normal;
  margin-bottom: 1rem;
  cursor: pointer;
}

.checkbox-label.disabled-option {
  opacity: 0.55;
}

.checkbox-label input {
  margin-top: 0.25rem;
}

input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
}

#room-code {
  font-family: "Menlo", "Consolas", monospace;
  letter-spacing: 0.12em;
  min-width: 10ch;
  width: auto;
  max-width: 100%;
}

.row {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.row label { flex: 1; min-width: 200px; }

button {
  padding: 0.65rem 1.1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

button:hover { background: var(--accent-light); }
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.status {
  color: var(--muted);
  min-height: 1.5rem;
  font-weight: bold;
}

.connection-status {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: bold;
}

.connection-status.connected {
  color: var(--accent);
}

.connection-status.connecting {
  color: var(--muted);
}

.connection-status.error {
  color: #8b2500;
}

/* Visible during play / waiting when the socket drops */
.reconnect-banner {
  margin: 0 0 0.5rem;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  background: #fff3cd;
  color: #664d03;
  border: 1px solid #ffecb5;
}

.reconnect-banner.hidden {
  display: none;
}

.reconnect-banner.is-error {
  background: #f8d7da;
  color: #842029;
  border-color: #f5c2c7;
}

/* Soft cue while reconnecting — play buttons stay clickable so moves can queue */
body.connection-frozen #reconnect-banner {
  animation: reconnect-pulse 1.6s ease-in-out infinite;
}

@keyframes reconnect-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.75;
  }
}

.error-status {
  color: #8b2500;
  font-weight: bold;
  min-height: 0;
}

#player-list { padding-left: 1.25rem; }

.card-preview-panel {
  margin: 1rem 0;
  font-size: 0.95rem;
}

.card-preview-panel summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.card-fan {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  min-height: 110px;
  padding: 0.5rem 0;
  overflow-x: auto;
}

.card-fan .playing-card {
  position: relative;
  flex: 0 0 auto;
  transition: transform 0.12s ease;
}

.card-fan .playing-card:not(:first-child) {
  margin-left: calc(var(--card-w) * -0.667);
}

.card-fan .playing-card.selected {
  transform: translateY(-6px);
}

.card-fan.hand-reorder-active {
  cursor: grabbing;
}

/* Placeholder in the hand while the floating ghost moves */
.card-fan .playing-card.hand-card-dragging {
  opacity: 0.2;
  transform: none !important;
  outline: 1px dashed #2a6b4f;
}

/*
 * Floating drag card — full solid face (interim for visibility testing).
 * Inline styles from JS also force position/size/z-index.
 */
.hand-drag-ghost {
  position: fixed !important;
  z-index: 2147483646 !important;
  margin: 0 !important;
  pointer-events: none !important;
  opacity: 0.7 !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4) !important;
  outline: 3px solid #2a6b4f !important;
  outline-offset: 1px;
  transform: none !important;
  cursor: grabbing !important;
}

.hand-drag-ghost.hand-drag-ghost-over-meld {
  outline-color: #e6b800 !important;
  box-shadow: 0 14px 36px rgba(42, 107, 79, 0.5) !important;
}

.hand-drag-ghost-multi {
  outline-offset: 2px;
}

.hand-drag-count-badge {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  z-index: 20;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #2a6b4f;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  line-height: 1.35rem;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.card-fan .playing-card.hand-card-drop-before::before,
.card-fan .playing-card.hand-card-drop-after::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: #e6b800;
  border-radius: 2px;
  z-index: 12;
  pointer-events: none;
}

.card-fan .playing-card.hand-card-drop-before::before {
  left: calc(var(--card-w) * -0.34);
}

.card-fan .playing-card.hand-card-drop-after::after {
  right: calc(var(--card-w) * -0.2);
}

.card-fan .playing-card.hand-card-enter {
  animation: hand-card-enter 0.48s ease-out both;
}

@keyframes hand-card-enter {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.card-fan .playing-card.hand-card-enter.selected {
  animation: hand-card-enter-selected 0.48s ease-out both;
}

@keyframes hand-card-enter-selected {
  from {
    opacity: 0;
    transform: translate(-14px, 0);
  }
  to {
    opacity: 1;
    transform: translateY(-6px);
  }
}

.hand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.hand-header h3 { margin: 0; }

/* Keep sort (and drag hint) pinned to the right of the hand header */
.hand-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-left: auto;
  flex-wrap: wrap;
}

#btn-sort-toggle {
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
}

.game-top-chrome {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  box-sizing: border-box;
}

.game-sticky-dock {
  box-sizing: border-box;
}

.game-status-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0;
}

.game-status-bar {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.32rem 0 0.32rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.25;
}

.game-status-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem 1rem;
  white-space: nowrap;
  overflow: hidden;
}

#turn-indicator {
  font-weight: 600;
}

#stock-info {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.84rem;
}

.table-ticker {
  height: 4.1rem;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #faf8f2;
  font-size: 0.95rem;
  line-height: 1.4;
  color: #2a2a2a;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.35rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
}

.table-ticker::-webkit-scrollbar {
  width: 6px;
}

.table-ticker::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.22);
  border-radius: 3px;
}

.table-ticker-line {
  flex: 0 0 auto;
  min-height: 1.35em;
  white-space: normal;
  overflow-wrap: anywhere;
}

.table-ticker-line.table-ticker-placeholder,
.table-ticker-placeholder {
  color: var(--muted);
  font-style: italic;
}

.table-ticker .ticker-highlight {
  color: #c62828;
  font-weight: 600;
}

/* Dirty / black books — same weight as clean, dark instead of red. */
.table-ticker .ticker-dirty-book {
  color: #1a1a1a;
  font-weight: 700;
}

.table-and-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.table-and-actions .card-table {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.card-table {
  --table-card-w: 55px;
  --table-card-h: 70px;
  background: linear-gradient(165deg, #1f7349 0%, #145234 55%, #0f4229 100%);
  border: 4px solid #7a5230;
  border-radius: 14px;
  padding: 1.25rem 1.5rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow:
    inset 0 2px 12px rgba(0, 0, 0, 0.28),
    0 0 0 2px #c9a66b,
    0 4px 10px rgba(0, 0, 0, 0.12);
}

.card-table h3,
.card-table .hand-header h3 {
  color: #eef8f1;
  margin-top: 0;
}

.card-table .no-melds {
  color: rgba(238, 248, 241, 0.78);
}

.card-table #btn-sort-toggle {
  background: rgba(255, 255, 255, 0.14);
  color: #eef8f1;
  border-color: rgba(255, 255, 255, 0.28);
}

.card-table #btn-sort-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}

.table-piles {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.pile-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.stock-piles {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.stock-pile {
  position: relative;
  width: calc(var(--table-card-w) + 14px);
  height: calc(var(--table-card-h) + 10px);
}

.stock-pile-selectable {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  transition: box-shadow 0.15s ease, outline-color 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  color: inherit;
  opacity: 1;
}

.stock-pile-selectable:hover,
.stock-pile-selectable:focus {
  background: transparent;
}

.stock-pile-selectable:disabled {
  cursor: default;
  opacity: 1;
}

.stock-pile-selectable.selected {
  outline: 2px solid rgba(255, 214, 102, 0.95);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(255, 214, 102, 0.18);
}

.stock-pile-selectable:focus-visible {
  outline: 2px solid rgba(255, 214, 102, 0.95);
  outline-offset: 2px;
}

.stock-pile.empty::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px dashed rgba(255, 255, 255, 0.22);
  border-radius: 8px;
}

.card-back {
  --card-w: var(--table-card-w);
  --card-h: var(--table-card-h);
  position: absolute;
  top: calc(5px + var(--stack-offset, 0) * -2px);
  left: calc(7px + var(--stack-offset, 0) * 2px);
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 7px;
  border: 1px solid #555;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.card-back::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--red);
  border-radius: 4px;
  background:
    radial-gradient(
      ellipse 42% 34% at 50% 50%,
      transparent 58%,
      rgba(192, 57, 43, 0.22) 59%,
      transparent 62%
    ),
    repeating-linear-gradient(
      45deg,
      transparent 0 7px,
      rgba(192, 57, 43, 0.09) 7px 8px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0 7px,
      rgba(192, 57, 43, 0.09) 7px 8px
    ),
    #fff;
}

.discard-pile-cluster {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
}

.discard-status-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 14rem;
  margin: 0 0 5px;
}

.discard-pile-status {
  margin: 0;
  flex: 1 1 auto;
  max-width: 11rem;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: left;
  color: rgba(255, 255, 255, 0.78);
}

.discard-pile-status.status-frozen {
  color: #8ecae6;
}

.discard-pile-status.status-book {
  color: #f4a261;
}

.discard-pile-status.status-no-meld {
  color: rgba(255, 190, 190, 0.9);
}

.discard-pile-status.status-available {
  color: #b7e4c7;
}

.discard-pile-status.status-required-meld {
  color: #1a1a1a;
  background: #ffe566;
  border: 1px solid #e6c200;
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font-weight: 700;
  max-width: 14rem;
  white-space: nowrap;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact stock draw — mobile only (main draw button is used on desktop). */
.stock-t2-btn {
  display: none;
  flex: 0 0 auto;
  min-width: 2.1rem;
  padding: 0.28rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.45);
  cursor: not-allowed;
  line-height: 1.1;
}

.stock-t2-btn.is-lit:not(:disabled) {
  background: #2d6a4f;
  border-color: #95d5b2;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(149, 213, 178, 0.5);
}

.stock-t2-btn.is-lit:not(:disabled):hover {
  background: #40916c;
}

.discard-slot {
  position: relative;
  width: calc(var(--table-card-w) + 14px);
  height: calc(var(--table-card-h) + 10px);
  flex: 0 0 auto;
  overflow: visible;
}

.discard-slot .playing-card {
  position: absolute;
  top: 5px;
  left: 7px;
  margin: 0;
}

.discard-slot .playing-card.buried-discard {
  z-index: 1;
  pointer-events: none;
}

.discard-slot.empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--table-card-w);
  height: var(--table-card-h);
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  pointer-events: none;
}

.table-piles .playing-card {
  --card-w: var(--table-card-w);
  --card-h: var(--table-card-h);
}

.pile-label {
  font-size: 0.82rem;
  color: rgba(238, 248, 241, 0.82);
  letter-spacing: 0.02em;
}

.table-section + .table-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.deal-flyer,
.pile-flyer {
  position: fixed;
  margin: 0;
  z-index: 10000;
  pointer-events: none;
}

.pile-flyer.card-back {
  top: auto;
  left: auto;
  --stack-offset: 0;
}

.deal-flip-card {
  perspective: 1000px;
}

.deal-flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}

.deal-flip-side {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.deal-flip-back.card-back {
  top: 0;
  left: 0;
  --stack-offset: 0;
}

.deal-flip-face {
  transform: rotateY(180deg);
}

.stock-pile.dealing .card-back:last-child {
  opacity: 0;
}

#players-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  overflow-x: auto;
  padding-bottom: 0.05rem;
}

.player-chip {
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: #eee;
  font-size: 0.82rem;
  line-height: 1.2;
  flex: 0 0 auto;
  white-space: nowrap;
}

.player-chip.current {
  background: var(--accent);
  color: #fff;
  font-weight: bold;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 80px;
}

/* Legacy text cards (fallback if renderer not loaded) */
.card:not(.playing-card) {
  padding: 0.5rem 0.65rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  user-select: none;
  min-width: 52px;
  text-align: center;
  font-size: 1rem;
}

.playing-card {
  --card-w: 84px;
  --card-h: 106px;
  --card-bg-face: #f6f3eb;
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex: 0 0 auto;
  border: 1.5px solid #2a2a2a;
  border-radius: 7px;
  background: var(--card-bg-face);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  user-select: none;
  overflow: hidden;
}

.playing-card.card-compact {
  --card-w: 55px;
  --card-h: 70px;
}

.playing-card.readonly {
  cursor: default;
}

.playing-card.selected {
  outline: 3px solid #e6b800;
  outline-offset: 1px;
}

.playing-card.wild .card-corner-rank {
  font-size: 0.95em;
}

.card-corner {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 0.9;
  pointer-events: none;
}

.card-stock-badge {
  position: absolute;
  bottom: 3px;
  left: 4px;
  z-index: 3;
  width: calc(var(--card-w) * 0.22);
  height: calc(var(--card-w) * 0.22);
  border-radius: 50%;
  background: #1a7a3a;
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: calc(var(--card-w) * 0.17);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.card-corner-tl {
  top: 3px;
  left: 4px;
}

.card-corner-br {
  bottom: 3px;
  right: 4px;
  transform: rotate(180deg);
}

.card-corner-rank {
  font-family: "Libre Baskerville", Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.19);
  color: #141414;
  letter-spacing: -0.02em;
}

.card-corner-suit {
  font-size: calc(var(--card-w) * 0.416);
  color: #141414;
  margin-top: calc(var(--card-w) * -0.045);
  line-height: 0.75;
}

.card-corner-suit.suit-hearts {
  margin-top: calc(var(--card-w) * -0.045 + 2px);
}

.card-corner-suit.suit-diamonds,
.card-corner-suit.suit-clubs {
  margin-top: calc(var(--card-w) * -0.045 + 4px);
}

.card-corner-suit.suit-clubs {
  font-size: calc(var(--card-w) * 0.312);
}

.card-corner-suit.red {
  color: #b91c1c;
}

.card-corner-joker.card-corner-tl {
  top: 4px;
  left: 5px;
}

.card-corner-joker.card-corner-br {
  top: auto;
  left: auto;
  bottom: 4px;
  right: 5px;
}

.card-joker-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--card-w) * 0.034);
  line-height: 1;
}

.card-joker-letter {
  font-family: "Libre Baskerville", Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.105);
  color: #4a1942;
  letter-spacing: 0.06em;
}

.playing-card-joker .card-center {
  top: 18%;
  bottom: 20%;
}

.playing-card-joker .card-center-img {
  object-position: center 42%;
}

.card-center {
  position: absolute;
  z-index: 1;
  top: 26%;
  right: 10%;
  bottom: 26%;
  left: 10%;
  overflow: hidden;
  border-radius: 2px;
}

.card-center-art {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-center-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.card-center-face {
  background-repeat: no-repeat;
  background-position: center center;
  background-size: var(--card-w) var(--card-h);
}

.card-center-pips {
  top: 21%;
  bottom: 21%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.card-pip-svg {
  width: 100%;
  height: 100%;
}

.card-pip-glyph {
  font-family: Georgia, "Times New Roman", serif;
}

.card-center-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-fallback-label {
  font-family: "Libre Baskerville", Georgia, serif;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.22);
  color: #141414;
}

.card-fallback-label.red {
  color: #b91c1c;
}

.card.red .card-corner-rank,
.card.red .card-corner-suit {
  color: #b91c1c;
}

.card.selected:not(.playing-card) {
  background: var(--selected);
  border-color: #c9a000;
}

.playing-card.selected {
  background: var(--card-bg-face);
}
.card.red:not(.playing-card) { color: var(--red); }
.card.wild:not(.playing-card) { font-weight: bold; }
.card.readonly:not(.playing-card) { cursor: default; }
.card.card-compact:not(.playing-card) {
  min-width: 42px;
  padding: 0.3rem 0.45rem;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.actions-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 0 0 10.5rem;
  margin: 0;
}

.actions-sidebar button {
  width: 100%;
  text-align: center;
  font-size: 0.92rem;
  padding: 0.55rem 0.65rem;
  line-height: 1.25;
}

.host-game-controls-row {
  margin: 0.75rem 0 1rem;
  text-align: center;
}

.host-game-controls-actions {
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.host-game-controls-row .hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
}

@media (max-width: 900px) {
  .table-and-actions {
    flex-direction: column;
  }

  .actions-sidebar {
    flex: 1 1 auto;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .actions-sidebar button {
    width: auto;
    flex: 1 1 10rem;
  }
}

#log {
  max-height: 200px;
  overflow-y: auto;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.melds-board {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 0.65rem;
}

.meld-group {
  flex: 0 0 auto;
  max-width: 100%;
  padding: 0.35rem 0.45rem 0.4rem;
  background: var(--accent-light);
  border-radius: 8px;
  border: 2px solid transparent;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease,
    transform 0.15s ease;
}

.meld-group.interactive {
  cursor: pointer;
}

.meld-group.interactive:hover:not(.selected-meld) {
  border-color: rgba(42, 107, 79, 0.45);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.meld-body {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.meld-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  flex: 0 0 auto;
  min-width: 2.25rem;
  font-weight: bold;
  font-size: 0.82rem;
  line-height: 1.15;
}

.meld-label-text {
  white-space: nowrap;
}

.meld-kind-note {
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.meld-kind-natural {
  color: #4a5a4a;
}

.meld-kind-red-book {
  color: #a32020;
}

.meld-kind-black-book {
  color: #2a2a2a;
}

/* Kind notes sit on cream meld panels, not the felt — keep dark text */
.card-table .meld-group .meld-kind-natural {
  color: #4a5a4a;
}

.card-table .meld-group .meld-kind-red-book {
  color: #a32020;
}

.card-table .meld-group .meld-kind-black-book {
  color: #2a2a2a;
}

.meld-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.28rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.08);
  line-height: 1.2;
}

.meld-badge-building {
  background: rgba(180, 130, 0, 0.18);
}

.meld-fan {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  min-height: 0;
  padding: 0.05rem 0;
}

.meld-fan .playing-card {
  position: relative;
  flex: 0 0 auto;
}

.meld-fan .playing-card:not(:first-child) {
  margin-left: calc(var(--card-w) * -0.667);
}

.opponent-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: #fff;
}

.opponent-panel.current-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.opponent-header {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.opponent-header.expanded {
  margin-bottom: 0.5rem;
}

.opponent-toggle {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8f8f8;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.opponent-toggle:hover {
  background: #eee;
}

.opponent-name {
  flex-shrink: 0;
  font-weight: bold;
  font-size: 1.05rem;
}

.opponent-stats {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opponent-melds {
  gap: 0.45rem 0.55rem;
}

.opponent-melds.collapsed {
  display: none;
}

.waiting-host-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.waiting-host-actions.hidden {
  display: none;
}

.waiting-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0.85rem 0 0;
  width: 100%;
}

.waiting-actions-hint {
  margin: 0;
  text-align: left;
  width: 100%;
  max-width: 36rem;
}

.waiting-action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  max-width: 100%;
}

.waiting-action-buttons button,
.waiting-action-buttons button.primary {
  flex: 0 0 auto;
  width: auto;
  white-space: nowrap;
}

.waiting-exit-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  text-align: left;
  max-width: 36rem;
}

.waiting-exit-hint.hidden {
  display: none;
}

#waiting .panel-footer-links {
  text-align: left;
}

.player-auto-tag {
  color: var(--muted);
  font-size: 0.9em;
}

.no-melds {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

.hand-empty-hint {
  max-width: 22rem;
  line-height: 1.35;
  padding: 0.75rem 1rem;
  text-align: center;
}

.meld-group.building {
  background: #fff8e1;
  border-color: #e6c200;
}

.meld-group.near-book {
  animation: near-book-pulse 2.2s ease-in-out infinite;
}

.meld-group.near-book-clean {
  border-color: #d64040;
  box-shadow:
    0 0 0 2px rgba(214, 64, 64, 0.28),
    0 2px 12px rgba(198, 40, 40, 0.2);
}

.meld-group.near-book-dirty {
  border-color: #3d3d3d;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.22),
    0 2px 12px rgba(0, 0, 0, 0.18);
}

@keyframes near-book-pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.04);
  }
}

.meld-group.red-threes-meld {
  background: #fde8e8;
  border-color: #e8a0a0;
}

.meld-group.undoable {
  cursor: pointer;
}

.meld-group.selected-meld {
  background: #fffce8;
  border: 3px solid #e6b800;
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 5px #e6b800,
    0 4px 14px rgba(0, 0, 0, 0.18);
}

.meld-group.selected-meld .meld-label-text {
  color: #7a5a00;
}

/* Melds sit on green felt — use cream panels and gold selection ring */
.card-table .meld-group {
  background: rgba(255, 253, 248, 0.97);
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
}

.card-table .meld-group .meld-label-text {
  color: #1a1a1a;
}

.card-table .meld-group .meld-badge {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

.card-table .meld-group.building {
  background: #fff8e1;
  border-color: #d4a800;
}

.card-table .meld-group.near-book-clean {
  border-color: #e05050;
  box-shadow:
    0 0 0 2px rgba(255, 120, 120, 0.45),
    0 0 18px rgba(198, 40, 40, 0.35),
    0 2px 10px rgba(0, 0, 0, 0.22);
}

.card-table .meld-group.near-book-dirty {
  border-color: #555;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.35),
    0 0 16px rgba(0, 0, 0, 0.28),
    0 2px 10px rgba(0, 0, 0, 0.22);
}

.card-table .meld-group.near-book.building {
  background: #fff4e0;
}

.card-table .meld-group.red-threes-meld {
  background: #fde8e8;
  border-color: #e8a0a0;
}

.card-table .meld-group.interactive:hover:not(.selected-meld) {
  border-color: rgba(255, 220, 120, 0.85);
  box-shadow:
    0 0 0 1px rgba(255, 220, 120, 0.6),
    0 2px 10px rgba(0, 0, 0, 0.22);
}

.card-table .meld-group.selected-meld {
  background: #fffce8;
  border: 3px solid #f5c400;
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 6px #f5c400,
    0 0 24px rgba(255, 210, 60, 0.65),
    0 4px 16px rgba(0, 0, 0, 0.35);
  transform: scale(1.015);
}

.card-table .meld-group.selected-meld .meld-label-text {
  color: #8a6500;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.dev-tools {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.dev-tools h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.hint {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
}

select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.save-roster-preview {
  margin-top: 0.5rem;
  font-weight: bold;
  color: var(--text);
}

.test-scenarios-panel {
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: #faf8f5;
}

.test-scenarios-panel summary {
  cursor: pointer;
  font-weight: bold;
}

.scenario-hint {
  font-weight: bold;
  color: var(--text);
}

.test-subheading {
  margin: 1.25rem 0 0.35rem;
  font-size: 1rem;
}

#btn-save-game {
  margin-left: 0;
}

.review-summary {
  margin: 1rem 0;
  padding: 1rem 1.25rem;
  background: var(--accent-light);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.review-summary #review-status-text {
  margin: 0 0 0.75rem;
  font-weight: bold;
}

.score-summary {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.review-summary .score-summary {
  margin: 0;
  background: #fff;
  border-radius: 8px;
}

.panel-footer-links {
  margin: 1rem 0 0;
  text-align: right;
  font-size: 0.92rem;
}

.view-stats-link {
  color: var(--accent);
  font-weight: bold;
  text-decoration: none;
}

.view-stats-link:hover {
  text-decoration: underline;
}

body.stats-page header {
  text-align: center;
  margin-bottom: 1rem;
}

.stats-main {
  max-width: 900px;
  margin: 0 auto;
}

.stats-controls fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin: 0;
}

.stats-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
}

.stats-filter-row fieldset {
  flex: 1 1 200px;
}

.radio-label {
  display: block;
  margin: 0.35rem 0;
}

.stats-summary-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stats-card {
  flex: 1 1 120px;
  padding: 0.75rem 1rem;
  background: var(--accent-light);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.stats-card-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.stats-table th,
.stats-table td {
  font-size: 0.92rem;
}

.stats-viewer-row td {
  font-weight: bold;
  background: #e8f5e9;
}

.stats-recent-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stats-recent-card {
  padding: 0.75rem 1rem;
  background: #faf8f5;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stats-recent-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.stats-recent-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.stats-notes ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.score-summary th,
.score-summary td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.score-summary tr.round-winner td {
  font-weight: bold;
  background: var(--accent-light);
}

.score-summary tr.series-winner td {
  background: #e8f5e9;
}

.finished-actions {
  margin-top: 1rem;
  gap: 0.5rem;
}

.video-section {
  max-width: 1100px;
  margin: 0 auto 0.65rem;
  padding: 0.65rem 1rem 0.75rem;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
}

body.video-chat-expanded {
  overflow: hidden;
}

.video-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.video-header h2 {
  margin: 0;
  font-size: 1rem;
}

.video-section.video-in-call:not(.video-expanded) #video-status {
  display: none;
}

.video-section:not(.video-expanded) .video-header {
  gap: 0.4rem;
}

.video-section:not(.video-expanded) .video-header h2 {
  font-size: 0.92rem;
}

.video-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.video-section:not(.video-expanded) .video-controls {
  gap: 0.32rem;
}

.video-section:not(.video-expanded) .video-controls button {
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.2;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: var(--accent);
  color: #fff;
}

.video-section:not(.video-expanded) .video-controls button:hover {
  background: #358560;
  filter: none;
}

.video-section:not(.video-expanded) .video-controls button:disabled {
  opacity: 0.5;
}

.video-section.video-in-call:not(.video-expanded) {
  padding: 0.45rem 0.75rem 0.5rem;
}

.video-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.video-section:not(.video-expanded) .video-tiles {
  --collapsed-tile-width: min(
    calc((100% - 7 * 0.75rem) / 8),
    calc((1100px - 2rem - 7 * 0.75rem) / 8)
  );
}

.video-section.video-in-call:not(.video-expanded) .video-tiles {
  margin-top: 0.35rem;
  gap: 0.5rem;
}

.video-section:not(.video-expanded) .video-tile {
  width: var(--collapsed-tile-width);
  flex: 0 0 var(--collapsed-tile-width);
  aspect-ratio: 4 / 3;
  height: auto;
}

.video-tile {
  position: relative;
  background: #1a1a1a;
  border-radius: 8px;
  overflow: hidden;
}

.video-section.video-expanded {
  position: fixed;
  inset: 0.5rem;
  z-index: 1200;
  max-width: none;
  width: auto;
  margin: 0;
  padding: 1rem 1.25rem 1.25rem;
  height: calc(100vh - 1rem);
  max-height: calc(100vh - 1rem);
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.28);
}

.video-section.video-expanded .video-header h2 {
  font-size: 1.35rem;
}

.video-section.video-expanded #video-status {
  margin: 0;
}

.video-section.video-expanded .video-tiles {
  display: grid;
  flex: 1;
  min-height: 0;
  margin-top: 0.75rem;
  gap: 0.75rem;
  overflow: hidden;
  align-content: stretch;
  align-items: stretch;
  justify-items: stretch;
}

.video-section.video-expanded .video-tiles[data-tile-count="1"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.video-section.video-expanded .video-tiles[data-tile-count="2"] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
}

.video-section.video-expanded .video-tiles[data-tile-count="3"] {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tiles[data-tile-count="3"] .video-tile:nth-child(1) {
  grid-column: 1 / span 2;
  grid-row: 1;
}

.video-section.video-expanded .video-tiles[data-tile-count="3"] .video-tile:nth-child(2) {
  grid-column: 3 / span 2;
  grid-row: 1;
}

.video-section.video-expanded .video-tiles[data-tile-count="3"] .video-tile:nth-child(3) {
  grid-column: 2 / span 2;
  grid-row: 2;
}

.video-section.video-expanded .video-tiles[data-tile-count="4"] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tiles[data-tile-count="5"] {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tiles[data-tile-count="5"] .video-tile:nth-child(-n + 3) {
  grid-column: span 2;
}

.video-section.video-expanded .video-tiles[data-tile-count="5"] .video-tile:nth-child(n + 4) {
  grid-column: span 3;
}

.video-section.video-expanded .video-tiles[data-tile-count="6"] {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tiles[data-tile-count="7"] {
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tiles[data-tile-count="7"] .video-tile:nth-child(-n + 4) {
  grid-column: span 3;
}

.video-section.video-expanded .video-tiles[data-tile-count="7"] .video-tile:nth-child(n + 5) {
  grid-column: span 4;
}

.video-section.video-expanded .video-tiles[data-tile-count="8"] {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-section.video-expanded .video-tile {
  width: 100%;
  max-width: none;
  flex: unset;
  height: 100%;
  min-height: 0;
  min-width: 0;
  aspect-ratio: auto;
}

.video-section.video-expanded .video-tile .tile-name {
  font-size: 0.95rem;
}

.video-section.video-expanded .video-tile .tile-placeholder {
  font-size: 2.5rem;
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #111;
}

.video-tile .tile-mute-speaker {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.55rem, 1.2vw, 0.7rem);
  line-height: 1.2;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.video-tile .tile-mute-speaker:hover {
  background: rgba(0, 0, 0, 0.8);
}

.video-tile.tile-speaker-muted .tile-mute-speaker {
  background: rgba(192, 57, 43, 0.85);
  border-color: rgba(255, 255, 255, 0.5);
}

.video-tile .tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.5rem;
  font-size: clamp(0.7rem, 1.6vw, 0.85rem);
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.video-tile.local .tile-name {
  background: linear-gradient(transparent, rgba(42, 107, 79, 0.85));
}

.video-tile .tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-size: clamp(1.25rem, 4vw, 2rem);
  background: #2a2a2a;
}

/* Desktop: compact play layout — hide site header, pin video bar while scrolling */
@media (min-width: 769px) {
  .game-status-row {
    flex-direction: row;
    align-items: stretch;
    gap: 0.75rem;
  }

  .game-status-bar {
    /* Grow with player chips, but never take more than half the row. */
    flex: 1 1 auto;
    min-width: 16rem;
    max-width: 50%;
    margin-bottom: 0;
    padding: 0.45rem 0.75rem;
    border-bottom: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #faf8f2;
  }

  .table-ticker {
    flex: 1 1 0;
    min-width: 0;
    margin-bottom: 0;
  }

  body.in-game-playing header {
    display: none;
  }

  /* One opaque sticky block: video + turn/ticker (no gap for scroll bleed-through). */
  body.in-game-playing:not(.video-chat-expanded) .game-top-chrome {
    position: sticky;
    top: 0;
    z-index: 900;
    width: calc(100% - 2rem);
    padding: 0;
    margin-bottom: 0.4rem;
    background: var(--bg);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  }

  body.in-game-playing .video-section:not(.hidden):not(.video-expanded) {
    position: static;
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }

  body.in-game-playing .video-section.hidden + .game-sticky-dock:not(.hidden) {
    border-radius: 12px 12px 0 0;
    padding-top: 0.35rem;
  }

  body.in-game-playing .game-sticky-dock:not(.hidden) {
    position: static;
    width: 100%;
    margin: 0;
    padding: 0.35rem 0 0.45rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
  }

  body.in-game-playing .video-section.hidden + .game-sticky-dock:not(.hidden) {
    border-top: none;
  }

  body.in-game-playing .video-section.video-in-call:not(.video-expanded) {
    padding: 0.38rem 0.7rem 0.42rem;
  }

  body.in-game-playing .video-section:not(.video-expanded) .video-controls button {
    padding: 0.24rem 0.48rem;
    font-size: 0.76rem;
  }

  body.in-game-playing .game-status-bar {
    padding: 0.28rem 0.58rem;
    font-size: 0.84rem;
  }

  body.in-game-playing #stock-info {
    font-size: 0.8rem;
  }

  body.in-game-playing #players-bar {
    gap: 0.3rem;
  }

  body.in-game-playing .player-chip {
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
  }

  body.in-game-playing main {
    padding-top: 0.5rem;
  }
}

/* Phone: fit table and controls to screen width — wrap hand in rows, no horizontal scroll */
@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }

  .app-exit-row {
    display: block;
  }

  .header-inner {
    padding: 0 3.1rem 0 0.5rem; /* room for gear + help so title doesn't sit under them */
    text-align: center;
  }

  .header-inner h1 {
    font-size: 1.55rem;
    line-height: 1.15;
    padding: 0 0.25rem;
  }

  .header-tools {
    top: 0.05rem;
    right: 0.35rem;
    gap: 0.15rem;
  }

  .header-tool-btn svg {
    width: 22px;
    height: 22px;
  }

  .header-tools .help-icon {
    width: 24px;
    height: 24px;
  }

  .help-icon-link {
    right: auto;
  }

  main {
    padding: 0.5rem;
    max-width: 100%;
  }

  .panel {
    padding: 0.75rem 0.65rem;
    max-width: 100%;
    overflow-x: hidden;
  }

  .game-status-top {
    white-space: normal;
    flex-wrap: wrap;
    row-gap: 0.2rem;
  }

  #players-bar {
    flex-wrap: wrap;
    overflow-x: visible;
    white-space: normal;
  }

  .table-ticker {
    font-size: 0.88rem;
  }

  .table-and-actions,
  .card-table,
  .table-section {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .card-table {
    padding: 0.75rem 0.55rem 0.9rem;
    border-width: 3px;
    margin-bottom: 0.65rem;
  }

  /*
   * Mobile pile layout (restored working pattern):
   * Row 1: Stock A | Stock B | Discard  (centered, never overflow)
   * Row 2: status text + T2 (full width, centered)
   * display:contents on the cluster lets those three participate in one flex wrap.
   */
  .table-piles {
    display: flex;
    flex-wrap: wrap;
    column-gap: 1rem;
    row-gap: 0.35rem;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 0.55rem;
    padding-bottom: 0.3rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: clip;
  }

  .table-piles-normal {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    column-gap: 0.85rem;
    row-gap: 0.3rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    /* override desktop gap: 2rem which was shoving discard off-screen on phones */
    gap: 0.85rem 0.85rem;
  }

  .table-piles-normal .stock-pile-wrap,
  .table-piles-normal .discard-pile-wrap {
    flex: 0 0 auto;
    max-width: 100%;
  }

  .table-piles-normal .stock-piles {
    gap: 0.5rem;
  }

  /* Flatten cluster so discard sits beside stocks; status/T2 become a full-width flex line */
  .discard-pile-cluster {
    display: contents;
  }

  /* Status centered; T2 fixed on the right (mirrored in final @media block below). */
  .discard-status-row {
    position: relative;
    display: flex;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0.1rem 2.75rem 0 2.75rem;
    min-height: 1.85rem;
    justify-content: center;
    align-items: center;
    gap: 0;
    box-sizing: border-box;
  }

  .discard-pile-status {
    flex: 0 1 auto;
    max-width: min(14rem, calc(100% - 0.25rem));
    margin: 0 auto;
    text-align: center;
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .discard-pile-status[hidden] {
    display: none !important;
  }

  .stock-t2-btn {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 2.25rem;
    min-height: 1.75rem;
    margin: 0;
    padding: 0.28rem 0.45rem;
    font-size: 0.85rem;
  }

  .pile-wrap {
    gap: 0.2rem;
  }

  .pile-label {
    font-size: 0.78rem;
  }

  .hand-header {
    gap: 0.5rem;
    margin-bottom: 0.15rem;
  }

  .card-table #btn-sort-toggle {
    font-size: 0.82rem;
    padding: 0.3rem 0.55rem;
  }

  .actions-sidebar {
    padding-top: 0;
  }

  #hand.card-fan {
    /* --hand-card-w / --hand-card-step set in px by JS */
    --hand-card-step: calc(var(--hand-card-w, 60px) * 0.333);
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, var(--hand-card-step))
      calc(100% - 4 * var(--hand-card-step));
    grid-auto-flow: row;
    grid-auto-rows: min-content;
    align-content: start;
    overflow: visible;
    row-gap: 0.35rem;
    column-gap: 0;
    min-height: 0;
    padding: 0.25rem 0 0.35rem;
  }

  #hand.card-fan[data-hand-cols="6"] {
    grid-template-columns: repeat(5, var(--hand-card-step))
      calc(100% - 5 * var(--hand-card-step));
  }

  #hand.card-fan .playing-card {
    --card-w: var(--hand-card-w, 60px);
    --card-h: calc(var(--card-w) * 106 / 84);
    width: var(--card-w);
    aspect-ratio: 84 / 106;
    height: auto;
    margin-left: 0;
    justify-self: start;
    align-self: start;
  }

  #hand.card-fan .playing-card.selected {
    transform: translateY(-3px);
  }

  #hand.card-fan > .no-melds {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    line-height: 1.45;
  }

  .actions-sidebar {
    gap: 0.4rem;
  }

  .actions-sidebar button {
    flex: 1 1 calc(50% - 0.2rem);
    min-width: 0;
    font-size: 0.86rem;
    padding: 0.5rem 0.45rem;
  }

  .video-section {
    max-width: 100%;
    padding: 0.5rem 0.65rem 0.55rem;
    margin-bottom: 0.45rem;
  }

  #btn-video-expand {
    display: none !important;
  }

  .video-section.video-in-call:not(.video-expanded) .video-header {
    justify-content: space-between;
    align-items: center;
  }

  .video-section.video-in-call:not(.video-expanded) .video-header h2 {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    margin-right: 0.5rem;
  }

  .video-section.video-in-call:not(.video-expanded) .video-controls {
    justify-content: flex-end;
    flex: 0 1 auto;
    width: auto;
  }

  .video-section.video-in-call:not(.video-expanded) .video-tiles {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    margin-top: 0.35rem;
    gap: 0.5rem;
  }

  .video-section.video-in-call:not(.video-expanded)
    .video-tiles[data-mobile-cols="2"] {
    grid-template-columns: repeat(2, 1fr);
  }

  .video-section.video-in-call:not(.video-expanded) .video-tile {
    width: 100%;
    max-width: none;
    flex: unset;
    aspect-ratio: 16 / 9;
    height: auto;
    min-height: 0;
  }

  .waiting-action-buttons {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 18rem;
  }

  .waiting-action-buttons button,
  .waiting-action-buttons button.primary {
    width: 100%;
    white-space: normal;
    text-align: center;
  }

  .lobby-create-row {
    flex-direction: column;
    align-items: stretch;
  }

  .lobby-panel-actions {
    justify-content: center;
  }

  .subscribe-cta {
    flex: 0 0 auto;
    text-align: center;
    max-width: none;
    margin-bottom: 0;
  }

  .lobby-create-row {
    margin-bottom: 0;
  }

  .review-summary .score-summary th:nth-child(3),
  .review-summary .score-summary td:nth-child(3) {
    display: none;
  }

  .review-summary .score-summary th,
  .review-summary .score-summary td {
    padding: 0.4rem 0.35rem;
    font-size: 0.88rem;
  }
}


/* —— Choose hand / foot (integrated into card table) —— */
/* Desktop defaults. Mobile pile layout is re-applied in the max-width:768 block
   BELOW this section so it is not overridden by these later rules. */
.table-piles-normal {
  display: flex;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 2rem;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  justify-content: flex-start;
}

.table-piles-normal .stock-pile-wrap,
.table-piles-normal .discard-pile-cluster {
  flex: 0 1 auto;
  min-width: 0;
}

.table-piles-normal.hidden {
  display: none !important;
}

/*
 * Mobile piles MUST come after the desktop .table-piles-normal block above.
 * (An earlier media query higher in the file was being overridden by gap:2rem
 * and flex-wrap:nowrap, which shoved discard/T2 off-screen on phones.)
 */
@media (max-width: 768px) {
  .table-piles {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    column-gap: 1rem;
    row-gap: 0.35rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .table-piles-normal {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 0.85rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .table-piles-normal .stock-pile-wrap,
  .table-piles-normal .discard-pile-wrap {
    flex: 0 0 auto;
  }

  .table-piles-normal .stock-piles {
    gap: 0.5rem;
  }

  .discard-pile-cluster {
    display: contents;
  }

  /* Status centered in the row; T2 pinned to the right (does not drift with message). */
  .discard-status-row {
    position: relative;
    display: flex;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0.1rem 2.75rem 0 2.75rem; /* room so centered text clears T2 */
    min-height: 1.85rem;
    justify-content: center;
    align-items: center;
    gap: 0;
    box-sizing: border-box;
  }

  .discard-pile-status {
    flex: 0 1 auto;
    max-width: min(14rem, calc(100% - 0.25rem));
    margin: 0 auto;
    text-align: center;
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .discard-pile-status[hidden] {
    display: none !important;
  }

  .stock-t2-btn {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 2.25rem;
    min-height: 1.75rem;
    margin: 0;
    padding: 0.28rem 0.45rem;
    font-size: 0.85rem;
  }
}

.table-piles.choose-mode {
  min-height: 7.5rem;
  align-items: center;
  justify-content: center;
}

.choose-hand-notice {
  flex: 1;
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  padding: 0.85rem 1.1rem 1rem;
  text-align: center;
  color: #f5f0e8;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  transition: opacity 0.35s ease;
}

.choose-hand-notice.hidden {
  display: none;
}

.choose-hand-notice-title {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  color: #fff;
  font-weight: 700;
}

.choose-hand-notice-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  color: rgba(245, 240, 232, 0.92);
}

.choose-hand-foot-roster {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  justify-content: center;
  font-size: 0.85rem;
  color: rgba(245, 240, 232, 0.8);
}

.choose-hand-foot-roster li.ready {
  color: #b8e6c8;
  font-weight: 600;
}

/* Two deal piles in the hand area — full-size cards like Your hand */
#hand.deal-pile-fan {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 1.75rem 2.5rem;
  min-height: 130px;
  padding: 0.75rem 0.5rem 1rem;
  overflow: visible;
}

.deal-pile-choice-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.5rem;
  border: 2px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.deal-pile-choice-inline:hover,
.deal-pile-choice-inline:focus-visible {
  border-color: rgba(42, 107, 79, 0.55);
  background: rgba(42, 107, 79, 0.08);
  outline: none;
}

.deal-pile-inline-stack {
  position: relative;
  /* Match default .playing-card size */
  width: var(--card-w, 84px);
  height: var(--card-h, 106px);
}

.deal-pile-inline-stack .card-back {
  /* Match full hand card size (not compact table stock size) */
  --card-w: 84px;
  --card-h: 106px;
  position: absolute;
  left: 0 !important;
  top: 0 !important;
  width: var(--card-w) !important;
  height: var(--card-h) !important;
  border-radius: 7px;
  transform: translate(
    calc(var(--stack-offset, 0) * 3px),
    calc(var(--stack-offset, 0) * -2px)
  );
}

.deal-pile-inline-face {
  position: relative;
  z-index: 6;
  /* Full hand card size — not compact */
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}

.deal-pile-inline-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  max-width: 10rem;
  line-height: 1.25;
}

body.choosing-hand-foot #opponents-section {
  opacity: 0.85;
}

@media (max-width: 560px) {
  #hand.deal-pile-fan {
    gap: 1.25rem 1.5rem;
  }
  .deal-pile-inline-label {
    font-size: 0.8rem;
  }
}

/* —— Header tools (system settings + help) —— */
.header-tools {
  position: absolute;
  top: 0;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  z-index: 5;
}

.header-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  border-radius: 999px;
  line-height: 0;
}

.header-tool-btn:hover,
.header-tool-btn:focus-visible {
  background: var(--accent-light);
  outline: none;
}

/* help icon was absolute; nest under .header-tools */
.header-tools .help-icon-link {
  position: static;
  top: auto;
  right: auto;
}

.linkish-btn {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.linkish-btn:hover {
  color: #1f513c;
}

/* —— Settings dialogs —— */
.settings-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  max-width: min(34rem, calc(100vw - 1.5rem));
  width: 100%;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.settings-dialog::backdrop {
  background: rgba(20, 30, 25, 0.45);
}

.settings-dialog-inner {
  margin: 0;
  padding: 0;
}

.settings-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

.settings-dialog-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent);
}

.settings-dialog-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.settings-dialog-close:hover {
  background: var(--accent-light);
  color: var(--text);
}

.settings-dialog-body {
  padding: 0.75rem 1rem 0.5rem;
  max-height: min(60vh, 28rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.settings-dialog-inner > .hint {
  margin: 0.65rem 1rem 0;
}

.settings-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.hand-drag-hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: normal;
  margin-left: 0;
  white-space: nowrap;
}

.card-table .hand-drag-hint {
  color: rgba(238, 248, 241, 0.75);
}

@media (max-width: 560px) {
  .hand-drag-hint {
    display: none;
  }
}

#your-melds .meld-group.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  background: var(--accent-light);
}

/* Improve touch drag for hand reorder */
#hand.hand-reorder-active {
  touch-action: none;
}
#hand .playing-card,
#hand > .card {
  touch-action: manipulation;
  user-select: none;
}
