:root {
  --felt: #0e3b2e;
  --felt-deep: #082820;
  --felt-light: #175944;
  --gold: #d9a441;
  --gold-soft: #f0d08a;
  --ink: #16181d;
  --paper: #f7f4ec;
  --paper-dim: #ddd7c8;
  --red: #c0392b;
  --text: #eaf3ef;
  --text-dim: #9db8ad;
  --danger: #e2544a;
  --radius: 14px;
  --gap: clamp(8px, 2.5vw, 16px);
}

* { box-sizing: border-box; }

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

body {
  background: radial-gradient(ellipse at 50% 0%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.01em; }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: var(--gap);
}
.screen.active { display: flex; }

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

.centered {
  margin: auto;
  width: 100%;
  max-width: 460px;
  padding: 8px;
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}
.brand h1 {
  font-size: clamp(44px, 14vw, 68px);
  letter-spacing: 0.18em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.brand p {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(4px);
}

label.field {
  display: block;
  margin-bottom: 18px;
}
label.field > span {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

input[type='text'] {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--paper);
  border: none;
  border-radius: 10px;
}
input[type='text']:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.choice {
  display: flex;
  gap: 8px;
}
.choice button {
  flex: 1;
  padding: 12px 8px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
}
.choice button[aria-pressed='true'] {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b1d05;
  font-weight: 700;
}

button.primary {
  width: 100%;
  padding: 15px;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #2b1d05;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
button.primary:disabled {
  opacity: 0.45;
  cursor: default;
}
button.ghost {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font: inherit;
  color: var(--text-dim);
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  cursor: pointer;
}

.hint {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: center;
}
.error {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(226, 84, 74, 0.16);
  border: 1px solid rgba(226, 84, 74, 0.4);
  border-radius: 8px;
  color: #ffc9c4;
}
.error:empty { display: none; }

/* --------------------------------------------------------------- lobby */

.invite-code {
  font-size: clamp(34px, 11vw, 48px);
  letter-spacing: 0.22em;
  text-align: center;
  color: var(--gold);
  font-weight: 700;
  margin: 6px 0 18px;
}
.qr {
  display: block;
  width: min(240px, 62vw);
  margin: 0 auto 18px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}
.invite-link {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.invite-link input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}
.invite-link button {
  padding: 0 16px;
  font: inherit;
  font-weight: 600;
  color: #2b1d05;
  background: var(--gold);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.waiting {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 16px;
}
.waiting::after {
  content: '';
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ---------------------------------------------------------------- jeu */

#screen-game { padding: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 10px var(--gap);
  background: rgba(0, 0, 0, 0.32);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.player-chip {
  flex: 1;
  min-width: 0;
}
.player-chip .name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-chip.right { text-align: right; }
.player-chip.right .name { justify-content: flex-end; }
.player-chip .score {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.1;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex: none;
}
.dot.on { background: #4ad07a; }
.hand-badge {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #2b1d05;
  background: var(--gold);
  border-radius: 4px;
  padding: 2px 5px;
  font-weight: 700;
}

.match-meta {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.6;
  flex: none;
}
.match-meta strong {
  display: block;
  font-size: 15px;
  color: var(--text);
  letter-spacing: 0.04em;
}

.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
  /* Sans cela, la main passe sous la barre de geste des telephones recents. */
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
  min-height: 0;
}

.foe-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 54px;
}

.mat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
}
.mat-cards {
  display: flex;
  align-items: center;
  gap: clamp(10px, 4vw, 26px);
  min-height: 128px;
}
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.slot-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.status-line {
  text-align: center;
  font-size: 15px;
  min-height: 22px;
  color: var(--gold-soft);
}
.status-line.yours {
  color: var(--gold);
  font-weight: 700;
}

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(-4px, 1vw, 8px);
  min-height: 118px;
  padding-bottom: 4px;
}

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

.card {
  --w: clamp(58px, 17vw, 82px);
  width: var(--w);
  height: calc(var(--w) * 1.45);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  border: none;
  padding: 6px 5px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: inherit;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  flex: none;
  position: relative;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.card .corner {
  font-size: calc(var(--w) * 0.26);
  font-weight: 700;
  line-height: 1;
}
.card .corner.bottom {
  align-self: flex-end;
  transform: rotate(180deg);
}
.card .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--w) * 0.46);
  opacity: 0.9;
}
.card.red { color: var(--red); }

.card.playable {
  cursor: pointer;
}
.card.playable:hover,
.card.playable:focus-visible {
  transform: translateY(-12px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
  outline: none;
}
.card.playable:focus-visible { outline: 2px solid var(--gold); }
.card.blocked {
  opacity: 0.4;
  filter: grayscale(0.6);
  cursor: not-allowed;
}
.card.small { --w: clamp(38px, 10vw, 50px); }

.card.back {
  background: repeating-linear-gradient(45deg, #7d1f2b 0 6px, #601722 6px 12px);
  border: 2px solid var(--paper-dim);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.card.empty {
  background: none;
  border: 2px dashed rgba(255, 255, 255, 0.16);
  box-shadow: none;
}

.card.secret {
  background: repeating-linear-gradient(45deg, #4a4f57 0 6px, #383c43 6px 12px);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  color: var(--paper-dim);
  font-size: calc(var(--w) * 0.4);
}

/* --------------------------------------------------------------- journal */

.log {
  max-height: 26vh;
  overflow-y: auto;
  padding: 10px var(--gap);
  background: rgba(0, 0, 0, 0.26);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
}
.log b { color: var(--text); font-weight: 600; }
.log .tag {
  display: inline-block;
  min-width: 62px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.log .tag.sacrifice { color: #8fa8f0; }
.log .tag.catch { color: #6ed49a; }
.log .tag.bow { color: var(--text-dim); }

/* -------------------------------------------------------------- overlay */

#overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(4, 16, 12, 0.82);
  backdrop-filter: blur(3px);
  z-index: 20;
}
#overlay.show { display: grid; }
.sheet {
  width: 100%;
  max-width: 400px;
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #12503d, #0b3125);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.sheet .headline {
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.sheet .result {
  font-size: 30px;
  font-weight: 700;
  margin: 6px 0 2px;
}
.combo-badge {
  display: inline-block;
  margin: 12px 0 4px;
  padding: 8px 18px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #2b1d05;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(217, 164, 65, 0.5);
}
.points {
  font-size: 17px;
  color: var(--gold-soft);
  margin: 8px 0 16px;
}
.scoreline {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 14px;
  font-size: 34px;
  font-weight: 700;
  margin-bottom: 18px;
}
.scoreline span { font-size: 13px; color: var(--text-dim); }
.reveal {
  margin: 4px 0 18px;
  padding: 14px 12px;
  background: rgba(0, 0, 0, 0.24);
  border-radius: 12px;
}
.reveal h3 {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.reveal .row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
.reveal .row:last-child { margin-bottom: 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.offline-banner {
  padding: 7px;
  text-align: center;
  font-size: 13px;
  background: var(--danger);
  color: #fff;
}
.offline-banner[hidden] { display: none; }

/* Ecrans hauts (desktop) : on aere la table plutot que d'etirer les cartes. */
@media (min-width: 720px) {
  .table { max-width: 720px; width: 100%; margin: 0 auto; }
  .log { max-width: 720px; width: 100%; margin: 0 auto; border-radius: 12px 12px 0 0; }
}
