:root {
  --cw: 88px;
  --ch: 123px;
  --scw: 46px;
  --sch: 64px;
  --gold: #f5c542;
  --panel: rgba(0, 0, 0, 0.28);
  --text: #f4f4f4;
  --blue: #4fc3f7;
  --red: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 45%, #1d7f4f 0%, #0e4d2e 60%, #062616 100%);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Boutons ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: #1b1b1b;
  background: #e5e7eb;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--gold); }
.btn.danger { background: #f87171; }
.btn.secondary { background: rgba(255, 255, 255, 0.85); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.big { padding: 14px 28px; font-size: 18px; width: 100%; margin-top: 18px; }

/* ---------- Setup ---------- */
#setup { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.setup-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  padding: 28px 32px;
  width: min(460px, 100%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}
.setup-panel h1 { margin: 0; font-family: Georgia, serif; font-size: 48px; letter-spacing: 6px; color: var(--gold); text-align: center; }
.subtitle { text-align: center; margin: 4px 0 20px; opacity: 0.85; }
.setup-panel h2 { font-size: 16px; text-transform: uppercase; letter-spacing: 2px; opacity: 0.8; }
.player-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.player-row .num { width: 22px; text-align: center; font-weight: 700; color: var(--gold); }
.player-row input, .player-row select {
  padding: 8px 10px; border-radius: 8px; border: none; font-size: 15px;
}
.player-row input { flex: 1; min-width: 0; }
.icon-btn { background: transparent; border: none; color: #fff; font-size: 16px; cursor: pointer; padding: 6px; }
.icon-btn:disabled { opacity: 0.25; cursor: default; }
.setup-buttons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Layout jeu ---------- */
#game {
  display: grid;
  grid-template-columns: 1fr 270px;
  grid-template-rows: auto 1fr;
  height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.35);
}
.logo { font-family: Georgia, serif; font-weight: 700; color: var(--gold); letter-spacing: 3px; font-size: 20px; }
#status { flex: 1; font-weight: 600; }
.top-buttons { display: flex; gap: 8px; }

.board {
  display: flex; flex-direction: column; justify-content: space-between;
  gap: 12px; padding: 12px 16px; overflow: auto;
}

#log-panel { background: rgba(0, 0, 0, 0.3); padding: 10px 14px; overflow: auto; }
#log-panel h3 { margin: 4px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 2px; opacity: 0.7; }
#log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
#log li { padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.07); opacity: 0.75; }
#log li:first-child { opacity: 1; font-weight: 600; }

/* ---------- Cartes ---------- */
.card {
  width: var(--cw); height: var(--ch);
  border-radius: 10px;
  position: relative;
  flex: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  user-select: none;
  background: transparent;
}
.card img { width: 100%; height: 100%; display: block; pointer-events: none; }
.card.small { width: var(--scw); height: var(--sch); border-radius: 6px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); }
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-6px); }
.card.playable { box-shadow: 0 0 0 3px rgba(245, 197, 66, 0.85), 0 3px 8px rgba(0, 0, 0, 0.45); }
.card.dim { filter: brightness(0.6) saturate(0.6); }
.card.selected, .card.selected:hover {
  transform: translateY(-20px);
  box-shadow: 0 0 0 4px var(--blue), 0 10px 18px rgba(0, 0, 0, 0.5);
}
.card.shake { animation: shake 0.35s; }
@keyframes shake {
  0%, 100% { translate: 0; }
  25% { translate: -7px; }
  75% { translate: 7px; }
}
.placeholder {
  width: var(--cw); height: var(--ch);
  border-radius: 10px;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; opacity: 0.7; text-align: center;
}

/* Emplacements table : carte cachée + découverte décalée dessus */
.table-slots { display: flex; gap: 10px; }
.slot { position: relative; width: var(--cw); height: calc(var(--ch) + 18px); }
.slot .card { position: absolute; top: 0; left: 0; }
.slot .card.up { top: 18px; }
.table-slots.small { gap: 5px; }
.table-slots.small .slot { width: var(--scw); height: calc(var(--sch) + 10px); }
.table-slots.small .slot .card.up { top: 10px; }

/* ---------- Adversaires ---------- */
#opponents { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.opponent {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 8px 12px;
  min-width: 200px;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.opponent.active { border-color: var(--gold); box-shadow: 0 0 18px rgba(245, 197, 66, 0.45); }
.opponent.finished { opacity: 0.55; }
.op-head { display: flex; gap: 10px; justify-content: space-between; width: 100%; font-size: 14px; }
.op-name { font-weight: 700; }
.op-info { opacity: 0.8; }
.op-hand { display: flex; min-height: var(--sch); }
.op-hand .card + .card { margin-left: -30px; }
.op-more { align-self: center; margin-left: 6px; font-weight: 700; }

/* ---------- Centre ---------- */
#center {
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto;
  justify-content: center; align-items: center;
  column-gap: 48px; row-gap: 6px;
}
.stack-zone, .pile-zone { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.stack-label { font-size: 13px; opacity: 0.85; }
#pile { position: relative; width: 190px; height: calc(var(--ch) + 30px); }
#pile .card { position: absolute; left: 50%; top: 50%; }
#pile .placeholder { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#pile.flash { animation: flash 0.6s; }
@keyframes flash { 0% { filter: drop-shadow(0 0 0 orange); } 50% { filter: drop-shadow(0 0 30px orange); } }
.burned { font-size: 14px; opacity: 0.85; }
#requirement {
  grid-column: 1 / -1;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 600;
  justify-self: center;
}
#requirement.attack { background: rgba(185, 28, 28, 0.85); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

/* ---------- Moi ---------- */
#me {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 10px 16px 14px;
}
#me.active { border-color: var(--gold); box-shadow: 0 0 20px rgba(245, 197, 66, 0.35); }
#me-title { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.me-row { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.me-block.grow { flex: 1; min-width: 200px; }
.zone-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.65; margin-bottom: 26px; }
#me-hand { display: flex; flex-wrap: wrap; gap: 8px; min-height: var(--ch); }
#actions { display: flex; gap: 10px; margin-top: 14px; }
#hint { margin-top: 8px; font-size: 14px; opacity: 0.85; min-height: 20px; }
.hidden-cards { padding: 30px 0; text-align: center; opacity: 0.7; font-style: italic; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.panel {
  background: #123d27;
  border: 2px solid var(--gold);
  border-radius: 18px;
  padding: 24px 30px;
  max-width: 560px; width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  position: relative;
}
.panel h2 { margin-top: 0; color: var(--gold); font-family: Georgia, serif; }
#overlay-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.ranking { text-align: left; display: inline-block; font-size: 18px; line-height: 1.8; }

.panel.rules { text-align: left; max-width: 720px; max-height: 90vh; overflow: auto; }
.panel.rules li { margin-bottom: 6px; }
.order { font-family: Georgia, serif; font-size: 20px; text-align: center; color: var(--gold); }
.close-btn { position: absolute; top: 10px; right: 12px; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
#rules-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.rule-card { display: flex; gap: 10px; align-items: center; background: rgba(0, 0, 0, 0.25); padding: 6px; border-radius: 10px; font-size: 14px; }

/* ---------- Effets ---------- */
#fx {
  position: fixed; left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(0.6);
  padding: 14px 30px; border-radius: 16px;
  font-size: 30px; font-weight: 800;
  background: rgba(0, 0, 0, 0.8);
  pointer-events: none; opacity: 0;
  z-index: 40; white-space: nowrap;
  transition: opacity 0.2s, transform 0.2s;
}
#fx.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#fx.fire { background: linear-gradient(135deg, #c2410c, #7c2d12); }
#fx.attack { background: linear-gradient(135deg, #b91c1c, #450a0a); }
#fx.magic { background: linear-gradient(135deg, #6d28d9, #1e1b4b); color: var(--gold); }
#fx.good { background: linear-gradient(135deg, #15803d, #064e3b); }

#toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: #1f2937; color: #fff;
  padding: 10px 18px; border-radius: 10px;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 60;
}
#toast.show { opacity: 1; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  :root { --cw: 64px; --ch: 90px; --scw: 36px; --sch: 50px; }
  #game { grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; min-height: 100vh; }
  #log-panel { max-height: 180px; }
  #center { column-gap: 18px; }
  #pile { width: 130px; }
  .opponent { min-width: 0; }
  #fx { font-size: 20px; }
  .top-buttons .btn { padding: 5px 8px; }
}
