:root {
  --bg1: #2c3e66; --bg2: #121a33; --ink: #f4f6fb; --accent: #ffb938; --accent-ink: #2a1a00;
  --panel: rgba(18, 26, 51, 0.94); --line: rgba(255, 255, 255, 0.16);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
  background: radial-gradient(circle at 50% 28%, var(--bg1), var(--bg2) 75%); user-select: none; -webkit-user-select: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; touch-action: manipulation; }

#app {
  height: 100dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "hud" "msg" "stage" "panel";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#hud { grid-area: hud; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; min-height: 52px; }
#msgband { grid-area: msg; min-height: 40px; display: flex; align-items: center; justify-content: center; padding: 0 10px; pointer-events: none; }
#stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#panel { grid-area: panel; padding: 6px 10px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.round { width: 48px; height: 48px; border-radius: 14px; background: rgba(255, 255, 255, 0.12); font-size: 22px; flex: none; }
.round:active { background: rgba(255, 255, 255, 0.24); }
#players { display: flex; gap: 8px; flex: 1; justify-content: center; min-width: 0; }
.pl { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.08);
  border: 2px solid transparent; min-width: 0; font-weight: 600; }
.pl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22vw; }
.pl.turn { border-color: var(--accent); background: rgba(255, 185, 56, 0.18); }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid rgba(255, 255, 255, 0.5); }
.dot.w { background: #f6ead0; } .dot.b { background: #9a1f40; }

#toast {
  max-width: min(92vw, 560px); padding: 8px 16px; border-radius: 12px; font-weight: 600; font-size: 16px; text-align: center;
  background: rgba(10, 14, 30, 0.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.warn { background: rgba(160, 60, 0, 0.8); }
#toast.alert { background: rgba(170, 20, 40, 0.82); }

.btn { min-height: 48px; padding: 10px 18px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px; }
.btn.big { min-height: 56px; padding: 12px 26px; font-size: 20px; }
.btn.small { flex: 1; padding: 8px 10px; font-size: 15px; white-space: nowrap; }
.btn.ghost { background: rgba(255, 255, 255, 0.14); color: var(--ink); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:active:not(:disabled) { filter: brightness(1.15); }
.actions { display: flex; gap: 8px; }

#history { list-style: none; margin: 0; padding: 4px 6px; display: flex; flex-wrap: nowrap; gap: 4px 12px; overflow-x: auto; min-height: 36px;
  align-items: center; background: rgba(255, 255, 255, 0.07); border-radius: 10px; font-size: 15px; scrollbar-width: none; }
#history li { flex: none; white-space: nowrap; }
#history .n { opacity: 0.6; margin-right: 3px; }
#history b { font-weight: 600; margin-right: 6px; }
#history b.cur { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 4px; }
#history.open { flex-wrap: wrap; overflow-x: hidden; overflow-y: auto; max-height: 30dvh; align-content: flex-start; }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 12px;
  background: rgba(10, 14, 30, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.overlay .panel { width: min(100%, 460px); max-height: 100dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 16px 18px; text-align: center; }
h1 { margin: 4px 0 8px; font-size: clamp(30px, 8vmin, 46px); letter-spacing: 0.04em; }
h2 { margin: 6px 0 10px; font-size: clamp(22px, 5.5vmin, 30px); }
h3 { margin: 10px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.7; font-weight: 600; }
.sub { margin: 4px 0 12px; opacity: 0.85; }
.hero { width: 100%; max-height: 18dvh; object-fit: cover; object-position: 50% 0; border-radius: 14px; margin-bottom: 6px; }
.hero.fallback { height: 70px; background: linear-gradient(135deg, #3f7276, #9a1f40); }
.big-emoji { font-size: 56px; line-height: 1; }
.row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip { min-height: 48px; padding: 8px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.1); border: 2px solid transparent; font-size: 16px; }
.chip small { display: block; font-size: 12px; opacity: 0.8; }
.chip.sel, .chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 185, 56, 0.22); }
.seat { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 6px 0; }
.seat .chips { flex: none; flex-wrap: nowrap; }
.seat .chip { padding: 8px 10px; }
.name { min-height: 48px; flex: 1; min-width: 0; max-width: 11em; padding: 6px 12px; border-radius: 12px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.08);
  color: var(--ink); font: inherit; font-size: 17px; user-select: text; -webkit-user-select: text; }
.name:disabled { opacity: 0.5; }
.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pbtn { min-height: 88px; border-radius: 14px; background: rgba(255, 255, 255, 0.12); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 2px; }
.pbtn span { font-size: 44px; line-height: 1; color: #f6ead0; }
.pbtn small { font-size: 13px; }
.pbtn:active { background: rgba(255, 185, 56, 0.35); }

/* Paysage : plateau à gauche, panneau à droite */
@media (orientation: landscape) and (min-width: 560px) {
  #app { grid-template-columns: minmax(0, 1fr) clamp(190px, 28vw, 300px); grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "hud hud" "msg panel" "stage panel"; }
  #panel { padding: 0 10px 10px 4px; min-height: 0; }
  .actions { flex-direction: column; }
  .btn.small { flex: none; }
  #btn-moves { display: none; }
  #history { flex: 1; min-height: 0; flex-direction: row; flex-wrap: wrap; overflow-x: hidden; overflow-y: auto; align-content: flex-start; max-height: none; }
  #history.open { max-height: none; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #hud { min-height: 48px; padding: 2px 8px; }
  #msgband { min-height: 34px; }
  #toast { padding: 4px 12px; font-size: 14px; }
  .actions { gap: 6px; }
  .btn.small { min-height: 48px; padding: 6px 8px; font-size: 14px; }
  .overlay { padding: 6px; }
  .overlay .panel { padding: 10px 14px; }
  .hero { display: none; }
  h1 { margin: 0 0 2px; font-size: 26px; }
  h3 { margin: 4px 0 2px; }
  .seat { margin: 2px 0; }
  .row { margin-top: 6px; }
  .big-emoji { font-size: 34px; }
  .pbtn { min-height: 72px; }
  #history { font-size: 14px; }
}
@media (max-height: 500px) and (orientation: landscape) { .overlay .panel { width: min(100%, 560px); } }
