/* Rami tunisien — interface */

:root {
  --felt: #0f5a3a;
  --felt-dark: #0a3f29;
  --felt-light: #177049;
  --gold: #f2c14e;
  --ink: #1d1d1f;
  --paper: #fffdf7;
  --muted: #6b6f76;
  --red-suit: #c62828;
  --black-suit: #1d1d1f;
  --danger: #d64545;
  --ok: #2e9d5b;
  --panel: rgba(255, 253, 247, 0.97);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.28);

  --card-w: 72px;
  --card-h: 101px;
  --card-r: 7px;
  --mini-w: 44px;
  --mini-h: 62px;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--paper);
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%) fixed;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 0.55em 1em;
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
  transition: transform 0.08s, filter 0.15s;
}
button:hover:not(:disabled) { filter: brightness(1.07); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: rgba(255, 255, 255, 0.14); color: var(--paper); }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 0.35em 0.7em; font-size: 0.85rem; }

input, select {
  font: inherit;
  padding: 0.5em 0.7em;
  border: 1px solid #cfcab8;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

code { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }

/* ------------------------------------------------------------ accueil / salon */

.screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.panel {
  background: var(--panel);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 460px;
}
.panel.wide { max-width: 720px; }
.panel h1 { margin: 0 0 4px; font-size: 1.9rem; }
.panel h1 small { color: var(--felt); font-weight: 600; }
.panel h2 { font-size: 1rem; margin: 20px 0 10px; color: var(--felt); text-transform: uppercase; letter-spacing: 0.05em; }
.panel p.sub { margin: 0 0 16px; color: var(--muted); }
.panel label { display: block; font-weight: 600; margin-bottom: 6px; }
.panel input[type='text'] { width: 100%; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; }
.grow { flex: 1; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; }

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-code { font-size: 1.6rem; letter-spacing: 0.2em; color: var(--felt); font-weight: 800; }

.player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 10px; background: #f1eee3;
}
.player-list li.empty { color: var(--muted); font-style: italic; background: transparent; border: 1px dashed #cfcab8; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: #b9b9b9; }
.tag { font-size: 0.75rem; padding: 2px 7px; border-radius: 99px; background: var(--felt); color: #fff; }
.tag.gold { background: var(--gold); color: var(--ink); }

.settings { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; align-items: center; }
.settings .label { font-weight: 600; }
.settings .hint { grid-column: 1 / -1; margin-top: -6px; font-size: 0.82rem; color: var(--muted); }
.settings .value { font-weight: 700; color: var(--felt); text-align: right; }
.settings input[type='number'] { width: 110px; }

.lobby-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; flex-wrap: wrap; align-items: center; }
.waiting { color: var(--muted); }

/* ------------------------------------------------------------ cartes */

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-r);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  border: 1px solid #d7d2c4;
  flex: none;
  user-select: none;
  font-weight: 700;
  transition: transform 0.12s, box-shadow 0.12s;
}
.card.red { color: var(--red-suit); }
.card.black { color: var(--black-suit); }
.card.joker { background: linear-gradient(170deg, #fff 0%, #fff7dc 100%); }

/* Face dessinée en SVG (viewBox 100 × 140) */
.card .face { display: block; width: 100%; height: 100%; overflow: visible; }
.card .face use { fill: currentColor; }
.card .face-img { object-fit: fill; pointer-events: none; user-select: none; -webkit-user-drag: none; border-radius: inherit; }
.card .face .rank { font: 700 17px Georgia, 'Times New Roman', serif; fill: currentColor; }
.card .face .rank.narrow { font-size: 15px; letter-spacing: -1.2px; }
.card .face .joker-letter { font: 800 9.5px Georgia, serif; }
.card .face .court-name { font: 700 5.6px Georgia, 'Times New Roman', serif; letter-spacing: 0.6px; fill: #151515; }
.card .face .joker-word { font: 800 12px Georgia, serif; letter-spacing: 3px; }

.card.back { border: 3px solid #fff; }
.card.back.blue, .back-chip.blue {
  background: repeating-linear-gradient(45deg, #1e40af 0 4px, #2563eb 4px 8px);
}
.card.back.red, .back-chip.red {
  background: repeating-linear-gradient(45deg, #991b1b 0 4px, #dc2626 4px 8px);
}
.card.back::after {
  content: ''; position: absolute; inset: 5px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.5);
}

.card.mini { --card-w: var(--mini-w); --card-h: var(--mini-h); border-radius: 5px; }

/* Sélection : propriété « translate », pour ne pas gêner les animations de glissement */
[data-action='card'] { cursor: pointer; }
.hand .card { cursor: grab; -webkit-touch-callout: none; touch-action: pan-x; transition: translate 0.12s, box-shadow 0.12s, opacity 0.12s; }
.card.selected { translate: 0 -16px; box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0, 0, 0, 0.4); }
.card.from-discard { box-shadow: 0 0 0 3px #7dd3fc, 0 1px 3px rgba(0, 0, 0, 0.35); }

/* Glisser-déposer */
.card.placeholder { opacity: 0.22; translate: 0 0; box-shadow: none; }
.drag-ghost {
  position: fixed !important;
  margin: 0 !important;
  z-index: 100;
  pointer-events: none;
  translate: none;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45) !important;
  transition: none !important;
  will-change: transform;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
.drop-over.meld { border-color: var(--gold) !important; background: rgba(242, 193, 78, 0.18); }
.pile.drop-over .card, .pile.drop-over .slot { box-shadow: 0 0 0 4px var(--gold), 0 0 22px rgba(242, 193, 78, 0.8); }

/* ------------------------------------------------------------ profils */

.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); flex: none;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  overflow: hidden;
  background: hsl(var(--hue, 150) 45% 42%);
  color: #fff;
  font-weight: 800;
  font-size: calc(var(--size) * 0.38);
  letter-spacing: 0.02em;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.md { --size: 34px; }
.avatar.lg { --size: 56px; }
.avatar.xl { --size: 84px; }

.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.avatar-wrap .dot { position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border: 2px solid #fff; }

.avatar-picker { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.avatar-buttons { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
label.button {
  display: inline-block; cursor: pointer; border-radius: 8px; padding: 0.5em 0.9em; font-weight: 600; margin: 0;
}
.secondary-light { background: #e9e5d8; color: var(--ink); }
.secondary-light:hover { filter: brightness(0.97); }
button.link { background: none; color: var(--danger); padding: 0.2em 0; text-decoration: underline; }
.panel .photo-label { margin-top: 16px; }
.required, .optional { font-weight: 400; color: var(--muted); font-size: 0.85em; }

/* ------------------------------------------------------------ table de jeu */

#app { min-height: 100%; }

.game {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
}

.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
}
.topbar .pill { background: rgba(255, 255, 255, 0.12); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.topbar .pill strong { color: var(--gold); }
.topbar .spacer { flex: 1; }

.table {
  display: grid;
  grid-template-areas:
    'left top right'
    'left center right';
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto);
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px 16px;
  min-height: 0;
}
.area-top { grid-area: top; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.area-left { grid-area: left; display: flex; align-items: center; }
.area-right { grid-area: right; display: flex; align-items: center; }
.center { grid-area: center; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.seat {
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px 14px;
  min-width: 250px;
  max-width: 320px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 20px rgba(242, 193, 78, 0.5); }
.seat.out { opacity: 0.45; }
.seat { position: relative; }
.seat.offline { border-style: dashed; }
/* Jauge d'absence : elle fait le tour du cadre et se vide en 30 s. */
.gauge-ring { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); pointer-events: none; overflow: visible; }
.gauge-ring rect { fill: none; stroke-width: 5; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.5)); }
.gauge-left {
  position: absolute; top: -10px; right: 12px; padding: 1px 8px; border-radius: 99px;
  background: #1b1b1b; color: #fff; font-size: 0.75rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.conn-hearts { color: #60a5fa; letter-spacing: 1px; font-size: 0.85rem; white-space: nowrap; }
.hearts { white-space: nowrap; }
.conn-hearts .lost { color: rgba(255, 255, 255, 0.3); }
/* Joueur sorti de la partie ou éliminé : tout le cadre est grisé. */
.seat.gone { filter: grayscale(1); opacity: 0.5; border-style: dashed; }
.gone-tag {
  display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px;
  background: #555; color: #fff; font-size: 0.75rem; font-weight: 700;
}
.seat.offline .avatar-wrap, .seat.offline .seat-cards { filter: grayscale(0.85); opacity: 0.7; }
.offline-tag {
  display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 0.75rem; font-weight: 700;
}
.seat.targetable { cursor: crosshair; border-color: #7dd3fc; }
.seat-head { display: flex; align-items: center; gap: 12px; }
.seat-id { min-width: 0; flex: 1; }
.seat-name { font-weight: 800; font-size: 1.05rem; display: flex; gap: 6px; align-items: center; }
.seat-name .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-meta { font-size: 0.85rem; display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; opacity: 0.95; }
.hearts { color: #ff6b6b; letter-spacing: 1px; }
.hearts .lost { color: rgba(255, 255, 255, 0.3); }
.seat-cards { display: flex; align-items: center; margin-top: 12px; padding-left: 2px; height: 40px; }
.back-chip {
  width: 27px; height: 38px; flex: none;
  border-radius: 4px; border: 2px solid #fff;
  margin-right: -17px;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.35);
}
.count {
  margin-left: 24px; font-size: 0.8rem; font-weight: 700;
  background: rgba(255, 255, 255, 0.16); padding: 2px 8px; border-radius: 99px;
}

.piles { display: flex; justify-content: center; gap: 24px; align-items: flex-end; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.8rem; }
.pile .slot {
  width: var(--card-w); height: var(--card-h); border-radius: var(--card-r);
  border: 2px dashed rgba(255, 255, 255, 0.35); display: grid; place-items: center; font-size: 0.75rem; opacity: 0.8;
}
.pile.clickable { cursor: pointer; }
.pile.clickable .card, .pile.clickable .slot { box-shadow: 0 0 0 3px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.35); }

.melds { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; }
.meld-group { background: rgba(0, 0, 0, 0.15); border-radius: 12px; padding: 8px 10px; }
.meld-owner { font-size: 0.8rem; font-weight: 700; margin-bottom: 6px; opacity: 0.9; }
.meld-list { display: flex; flex-wrap: wrap; gap: 10px; }
.meld {
  display: flex; align-items: center; padding: 4px 6px 4px 4px; border-radius: 9px;
  background: rgba(255, 255, 255, 0.07); border: 2px solid transparent;
}
.meld .card + .card { margin-left: calc(var(--mini-w) * -0.45); }
.meld .meld-value { font-size: 0.75rem; margin-left: 6px; opacity: 0.85; }
.meld.droppable { cursor: copy; border-color: rgba(242, 193, 78, 0.7); }
.meld .card.joker.swappable { cursor: pointer; box-shadow: 0 0 0 2px #7dd3fc; }
.empty-table { text-align: center; opacity: 0.6; font-style: italic; padding: 12px; }

/* ------------------------------------------------------------ joueur */

.me {
  background: rgba(0, 0, 0, 0.28);
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.me.turn { box-shadow: inset 0 3px 0 var(--gold); }
.me-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.me-bar .name { font-weight: 800; }
.prompt { flex: 1; color: var(--gold); font-weight: 600; min-width: 200px; }

.staging { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.staged {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.1); border: 2px solid var(--ok);
}
.staged.invalid { border-color: var(--danger); }
.staged .cards { display: flex; }
.staged .cards .card + .card { margin-left: calc(var(--mini-w) * -0.45); }
.staged .info { font-size: 0.8rem; max-width: 140px; }
.staged .info.error { color: #ffb4b4; }
.staging-total { display: flex; flex-direction: column; justify-content: center; gap: 6px; font-size: 0.9rem; }
.staging-total .bad { color: #ffb4b4; }
.staging-total .good { color: #a7f3c2; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hand {
  position: relative;
  display: flex;
  padding: 18px 4px 4px;
  overflow-x: auto;
  min-height: calc(var(--card-h) + 26px);
  --overlap: -14px;
}
.hand .card + .card { margin-left: var(--overlap); }
.hand.crowded { --overlap: -26px; }
.hand .card:hover:not(.selected):not(.placeholder) { translate: 0 -6px; }
body.is-dragging .hand .card:hover { translate: none; }

/* ------------------------------------------------------------ journal, toasts, modales */

.log {
  font-size: 0.8rem; opacity: 0.85; max-height: 4.6em; overflow: hidden;
  display: flex; flex-direction: column-reverse;
}

#toasts {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(92vw, 440px); pointer-events: none;
}
.toast {
  background: var(--panel); color: var(--ink); padding: 10px 14px; border-radius: 10px;
  box-shadow: var(--shadow); font-weight: 600; border-left: 6px solid var(--felt);
  animation: toast-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--gold); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.overlay .panel { max-height: 90vh; overflow-y: auto; }

table.scores { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.scores th, table.scores td { padding: 7px 8px; text-align: right; border-bottom: 1px solid #e4dfd0; }
table.scores th:first-child, table.scores td:first-child { text-align: left; }
table.scores tr.total td { font-weight: 800; border-top: 2px solid var(--ink); }
table.scores .elim { color: var(--danger); font-weight: 700; }
.winner-line { font-size: 1.15rem; font-weight: 700; margin: 0 0 12px; }

.offline-banner {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--danger); color: #fff;
  text-align: center; padding: 6px; z-index: 60; font-weight: 600;
}

/* ------------------------------------------------------------ mobile */

@media (max-width: 760px) {
  :root { --card-w: 52px; --card-h: 73px; --mini-w: 32px; --mini-h: 45px; }
  .avatar.lg { --size: 40px; }
  .seat-cards { height: 26px; margin-top: 8px; }
  .back-chip { width: 17px; height: 24px; margin-right: -11px; border-width: 1.5px; }
  .seat-name { font-size: 0.95rem; }
  .table {
    grid-template-areas: 'top' 'center';
    grid-template-columns: minmax(0, 1fr);
    padding: 8px 12px;
  }
  .area-left, .area-right { display: none; }
  .area-top { gap: 6px; }
  .seat { min-width: 0; flex: 1 1 30%; padding: 8px 10px; font-size: 0.85rem; }
  .hand { --overlap: -16px; }
  .hand.crowded { --overlap: -30px; }
  .topbar { padding: 6px 12px; font-size: 0.8rem; }
  .me { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .prompt { min-width: 0; }
  .panel { padding: 18px; }
}
