:root {
  --felt: #226244;
  --felt-dark: #113725;
  --paper: #fffaf0;
  --ink: #1f211d;
  --muted: #6d6b62;
  --gold: #d6a832;
  --red: #b94a42;
  --blue: #2f6f8d;
  --line: rgba(255, 250, 240, 0.24);
  --radius: 8px;
  --card-w: clamp(72px, 11vw, 118px);
  --hand-card-w: clamp(84px, 15vw, 138px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--paper);
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 250, 240, 0.12), transparent 34%),
    linear-gradient(145deg, #2d7a56, var(--felt) 46%, var(--felt-dark));
}

button,
input,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.home-screen,
.room-screen {
  min-height: 100svh;
}

.home-screen,
.join-gate {
  display: grid;
  place-items: center;
  padding: 22px;
}

.home-card,
.join-gate {
  width: min(420px, 100%);
  text-align: center;
}

.home-mark {
  width: 78px;
  height: 104px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--red);
  font-size: 3rem;
  font-weight: 950;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  transform: rotate(-5deg);
}

h1 {
  margin: 0 0 22px;
  font-size: clamp(3rem, 12vw, 7rem);
  line-height: 0.86;
  letter-spacing: 0;
}

.big-button,
.primary-button,
.secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 18px;
  font-weight: 900;
}

.big-button {
  width: min(280px, 100%);
  min-height: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  color: var(--felt-dark);
  font-size: 1.25rem;
  text-decoration: none;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.25);
}

.home-actions {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.online-button {
  width: min(280px, 100%);
}

.primary-button {
  background: var(--gold);
  color: #201900;
}

.secondary-button {
  background: rgba(255, 250, 240, 0.14);
  color: var(--paper);
  border: 1px solid var(--line);
}

.create-panel,
#joinForm {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 7px;
  text-align: left;
  color: rgba(255, 250, 240, 0.82);
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255, 250, 240, 0.28);
  border-radius: var(--radius);
  padding: 0 13px;
  background: rgba(255, 250, 240, 0.92);
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(214, 168, 50, 0.22);
}

.status-text {
  min-height: 22px;
  margin: 0;
  color: rgba(255, 250, 240, 0.78);
  font-weight: 750;
}

.table-app {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.6vw, 16px);
  padding: clamp(10px, 2vw, 22px);
}

.room-bar {
  display: grid;
  grid-template-columns: auto auto auto minmax(180px, 1fr);
  align-items: center;
  gap: 10px;
}

.rules-button {
  min-height: 42px;
}

.brand-link,
.room-code,
.status-pill,
.player-pill,
.invite-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 31, 21, 0.38);
  color: var(--paper);
  backdrop-filter: blur(12px);
}

.brand-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  text-decoration: none;
  font-weight: 950;
}

.room-code {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  font-weight: 900;
}

.invite-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 6px;
}

.invite-box input {
  min-height: 34px;
  border: 0;
  background: rgba(255, 250, 240, 0.9);
}

.invite-box button {
  min-height: 34px;
}

.players-strip {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.player-pill {
  min-width: 132px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 8px;
  padding: 9px 10px;
}

.player-pill strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-pill span {
  color: rgba(255, 250, 240, 0.72);
  font-size: 0.82rem;
  font-weight: 800;
}

.player-pill.current {
  border-color: rgba(214, 168, 50, 0.86);
  background: rgba(214, 168, 50, 0.16);
}

.table-zone {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 12px;
}

.status-pill {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-weight: 900;
  text-align: center;
}

.center-card {
  display: grid;
  place-items: center;
  min-height: 180px;
}

.empty-center {
  color: rgba(255, 250, 240, 0.58);
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 900;
}

.card {
  width: var(--card-w);
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  filter: drop-shadow(0 18px 22px rgba(0, 0, 0, 0.25));
}

.card img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  background: var(--paper);
}

.card.playable {
  transition: transform 150ms ease, filter 150ms ease;
}

.card.playable:hover {
  transform: translateY(-10px);
  filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.28));
}

.card.selected {
  transform: translateY(-12px);
  filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0)) drop-shadow(0 18px 26px rgba(214, 168, 50, 0.5));
}

/* Prises : cartes de la table qui peuvent encore compléter une combinaison */
.card.capturable {
  transition: transform 150ms ease;
}

.card.capturable img {
  box-shadow: 0 0 0 3px rgba(214, 168, 50, 0.95), 0 0 22px rgba(214, 168, 50, 0.55);
}

.card.capturable:hover {
  transform: translateY(-6px);
}

.card.picked {
  transform: translateY(-10px);
}

.card.picked img {
  box-shadow: 0 0 0 3px var(--paper), 0 0 24px rgba(255, 250, 240, 0.75);
}

/* Carte en vol pendant une pose ou une prise */
.fly-card {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.35));
}

.fly-card img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius);
  background: var(--paper);
}

/* Cartes qui arrivent en main à la distribution */
@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(26px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card.deal-in {
  animation: deal-in 320ms cubic-bezier(0.25, 0.8, 0.35, 1) backwards;
}

.solo-bar {
  grid-template-columns: auto auto auto 1fr;
}

.solo-bar #newSoloButton {
  justify-self: end;
}

.solo-table-zone {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.table-card-grid {
  width: min(820px, 96vw);
  min-height: 190px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--card-w), 100%), var(--card-w)));
  justify-content: center;
  align-content: center;
  gap: clamp(10px, 1.7vw, 18px);
}

.table-card-grid .empty-center {
  grid-column: 1 / -1;
  place-self: center;
}

.solo-actions {
  min-height: 44px;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hand-zone {
  display: grid;
  gap: 8px;
}

.hand-title {
  text-align: center;
  color: rgba(255, 250, 240, 0.72);
  font-weight: 850;
}

.hand {
  min-height: clamp(130px, 24vh, 190px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(8px, 1.4vw, 14px);
  overflow-x: auto;
  /* padding haut généreux : les cartes sélectionnées/survolées se surélèvent
     et ne doivent pas être rognées par le conteneur défilant */
  padding: 20px 6px max(8px, env(safe-area-inset-bottom));
  scrollbar-width: none;
}

.hand::-webkit-scrollbar {
  display: none;
}

.hand .card {
  width: var(--hand-card-w);
  flex: 0 0 auto;
}

.start-button {
  min-width: 190px;
}

.toast {
  position: fixed;
  z-index: 95;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(32, 18, 18, 0.88);
  color: var(--paper);
  font-weight: 850;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

.room-layout {
  height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.room-layout .table-app {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.game-main .table-zone {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

/* La grille de table rétrécit et défile dans sa rangée au lieu de déborder
   sur la main (surtout sur mobile). Padding haut pour les cartes surélevées.
   "safe center" : si les cartes dépassent, on aligne en haut au lieu de les
   faire déborder hors de la zone défilable (elles deviendraient incliquables). */
.game-main .table-card-grid {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  padding: 14px 8px;
  align-content: safe center;
}

/* Mode pose : la table entière devient la cible de dépôt */
.game-main .table-card-grid.lay-target {
  cursor: pointer;
  border: 2px dashed rgba(255, 250, 240, 0.45);
  border-radius: var(--radius);
  background: rgba(255, 250, 240, 0.05);
}

.game-main .solo-actions {
  min-height: 0;
}

.last-move {
  min-height: 18px;
  color: rgba(255, 250, 240, 0.66);
  font-size: 0.86rem;
  font-weight: 750;
  text-align: center;
  padding: 0 10px;
}

.player-pill.offline {
  opacity: 0.55;
}

.chat-panel {
  min-height: 0;
  width: clamp(250px, 26vw, 330px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  margin: clamp(10px, 2vw, 22px) clamp(10px, 2vw, 22px) clamp(10px, 2vw, 22px) 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 31, 21, 0.38);
  backdrop-filter: blur(12px);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title-text {
  font-weight: 900;
}

.chat-badge {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--red);
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
}

.chat-toggle {
  margin-left: auto;
  min-height: 34px;
  padding: 0 11px;
  font-size: 1rem;
  line-height: 1;
}

.chat-panel.collapsed {
  width: auto;
  grid-template-rows: auto;
  align-self: start;
}

.chat-panel.collapsed .chat-messages,
.chat-panel.collapsed .chat-form,
.chat-panel.collapsed .chat-title-text {
  display: none;
}

.chat-panel.collapsed .chat-toggle {
  margin-left: 0;
}

.chat-messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
  overscroll-behavior: contain;
}

.chat-msg {
  font-size: 0.92rem;
  line-height: 1.35;
  word-break: break-word;
}

.chat-msg strong {
  color: var(--gold);
}

.chat-msg.system {
  color: rgba(255, 250, 240, 0.65);
  font-style: italic;
  font-size: 0.85rem;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.chat-form input {
  min-height: 40px;
}

.chat-form button {
  min-height: 40px;
  padding: 0 12px;
}

.round-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 20, 14, 0.62);
}

.round-panel {
  width: min(600px, 100%);
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 31, 21, 0.96);
  text-align: center;
}

.round-panel h2 {
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
}

.round-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.round-score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.round-score-table th,
.round-score-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
}

.round-score-table td:first-child,
.round-score-table th:first-child {
  text-align: left;
}

.round-footer {
  margin: 0;
  color: rgba(255, 250, 240, 0.72);
  font-weight: 750;
}

.rules-panel {
  text-align: left;
  justify-items: start;
  max-height: min(84svh, 640px);
  overflow-y: auto;
}

.rules-panel h2 {
  justify-self: center;
}

.rules-panel > .secondary-button {
  justify-self: center;
}

.rules-reason {
  margin: 0;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(214, 168, 50, 0.6);
  background: rgba(214, 168, 50, 0.14);
  color: var(--gold);
  font-weight: 800;
}

.rules-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 7px;
  font-size: 0.94rem;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .room-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .chat-panel {
    width: auto;
    height: clamp(170px, 30svh, 260px);
    margin: 0 10px 10px;
  }

  .chat-panel.collapsed {
    height: auto;
    align-self: auto;
    justify-self: end;
  }
}

@media (max-width: 720px) {
  :root {
    --card-w: clamp(72px, 28vw, 108px);
    --hand-card-w: clamp(82px, 32vw, 112px);
  }

  .room-layout {
    --card-w: clamp(54px, 16vw, 84px);
    --hand-card-w: clamp(70px, 22vw, 100px);
  }

  .room-bar {
    grid-template-columns: auto 1fr;
  }

  .invite-box {
    grid-column: 1 / -1;
  }

  .players-strip {
    justify-content: stretch;
  }

  .player-pill {
    flex: 1 1 140px;
    grid-template-columns: 1fr;
  }

  .hand {
    justify-content: flex-start;
  }

  .room-layout .hand {
    min-height: clamp(104px, 18vh, 150px);
  }
}
