* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3a3a8c; overscroll-behavior: none; }
body { font-family: "Trebuchet MS", "Avenir Next Rounded", "Segoe UI", system-ui, sans-serif; color: #2b2150; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; height: 100dvh; width: 100vw; }
#topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; padding: 4px 8px; background: rgba(30, 20, 80, 0.55); color: #fff; }
#scores { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: flex; align-items: center; gap: 4px; padding: 3px 9px 3px 5px; border-radius: 999px; background: rgba(255,255,255,0.18); font-weight: 700; min-height: 40px; border: 3px solid transparent; }
.chip .av { font-size: 22px; }
.chip .nm { display: none; font-size: 14px; }
.chip b { font-size: 18px; min-width: 1.4em; text-align: center; }
.chip.active { background: #ffe066; color: #3b2a00; border-color: #fff; box-shadow: 0 0 0 3px rgba(255,224,102,0.45); }
#tools { display: flex; align-items: center; gap: 6px; }
#bag { font-weight: 700; font-size: 16px; padding: 0 6px; }
.icon { width: 48px; height: 48px; border-radius: 14px; border: 0; background: rgba(255,255,255,0.22); color: #fff; font-size: 22px; cursor: pointer; }
.icon:active { transform: scale(0.94); }

#main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; }
#c { display: block; width: 100%; height: 100%; touch-action: none; }
#msg { position: absolute; left: 8px; right: 8px; top: 6px; display: flex; justify-content: center; pointer-events: none; }
#msg span { max-width: 90vw; background: rgba(20, 24, 40, 0.55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); color: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: clamp(13px, 3.4vmin, 15px); line-height: 1.3; box-shadow: 0 2px 8px rgba(0,0,0,0.18); text-align: center; animation: msgin 0.18s ease-out; transition: opacity 0.18s ease-out; }
#msg span.out { opacity: 0; }
#msg span.bad { background: rgba(150, 50, 10, 0.6); }
#pan:not(.hidden) ~ #msg { top: 64px; }
#msg:empty { display: none; }
@keyframes msgin { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
#pop { position: absolute; left: 0; right: 0; top: 38%; display: flex; justify-content: center; pointer-events: none; }
#pop span { font-size: clamp(28px, 9vmin, 56px); font-weight: 900; color: #fff; text-shadow: 0 3px 0 #e8590c, 0 6px 14px rgba(0,0,0,0.35); animation: popup 1.5s ease-out forwards; }
@keyframes popup { 0% { transform: scale(0.4); opacity: 0; } 18% { transform: scale(1.2); opacity: 1; } 35% { transform: scale(1); } 80% { opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }

#panel { padding: 4px 8px 8px; background: rgba(30, 20, 80, 0.55); display: flex; flex-direction: column; gap: 6px; align-items: center; }
#status { min-height: 20px; color: #fff; font-weight: 700; font-size: 15px; text-align: center; }
#rack { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 6px; border-radius: 14px; background: #8a5426; box-shadow: inset 0 3px 8px rgba(0,0,0,0.4); max-width: 100%; }
.tile { position: relative; width: clamp(48px, 9vmin, 70px); height: clamp(48px, 9vmin, 70px); border: 0; border-radius: 12px; background: linear-gradient(145deg, #fbe3a8, #efc476); border-bottom: 4px solid #c9964a; color: #4a2a10; font: 900 clamp(26px, 5.4vmin, 40px)/1 "Trebuchet MS", system-ui, sans-serif; cursor: grab; touch-action: none; padding: 0; box-shadow: 0 3px 5px rgba(0,0,0,0.3); }
.tile small { position: absolute; right: 5px; bottom: 3px; font-size: 12px; font-weight: 800; }
.tile.sel { transform: translateY(-6px); background: linear-gradient(145deg, #fff6b5, #ffd75c); border-bottom-color: #f08a1c; box-shadow: 0 0 0 3px #ff9f1c, 0 6px 10px rgba(0,0,0,0.35); }
.tile.used { opacity: 0.22; pointer-events: none; }
.tile.hint { box-shadow: 0 0 0 4px #22c55e, 0 0 16px #22c55e; animation: bob 0.8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.tile.drag { position: fixed; z-index: 50; pointer-events: none; transform: scale(1.15); opacity: 0.95; }
.tile.swapsel { transform: translateY(-6px); box-shadow: 0 0 0 4px #ef4444; }

#actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; width: min(100%, 560px); }
.btn { min-height: 48px; border: 0; border-radius: 14px; padding: 6px 8px; background: #fff; color: #3b2a60; font: 800 15px/1.1 "Trebuchet MS", system-ui, sans-serif; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,0.25); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.btn.go { background: #3ecf6e; color: #05361a; }
.btn.idea { background: #ffd43b; color: #4a3500; }
.btn.big { min-height: 64px; font-size: 18px; padding: 8px 18px; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
#btn-ok { grid-column: span 1; }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, #6c63d9, #2b2a7a 80%); padding: 8px; }
#swap, #end { background: rgba(20, 10, 60, 0.7); }
.panel { width: min(560px, 100%); max-height: 100dvh; overflow-y: auto; background: #fffaf0; border-radius: 24px; padding: 16px 16px 18px; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,0.4); }
.panel h1 { margin: 0; font-size: clamp(34px, 9vmin, 56px); letter-spacing: 2px; color: #e8590c; text-shadow: 0 3px 0 #ffd8a8; }
.panel h2 { margin: 0 0 4px; font-size: clamp(26px, 6vmin, 38px); color: #e8590c; }
.panel h3 { margin: 10px 0 4px; font-size: 16px; color: #5b4a9a; }
.sub { margin: 2px 0 6px; font-weight: 700; color: #6b5a9a; }
.seg { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.seg button { flex: 1 1 0; min-width: 96px; min-height: 56px; border: 3px solid #d6cdf5; background: #fff; border-radius: 14px; font: 800 22px/1.1 "Trebuchet MS", system-ui, sans-serif; color: #3b2a60; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; }
.seg button span { font-size: 12px; font-weight: 700; color: #6b5a9a; }
.seg button[aria-pressed="true"] { border-color: #ff9f1c; background: #fff3d1; box-shadow: 0 0 0 3px rgba(255,159,28,0.3); }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
#btn-voice[aria-pressed="false"] { opacity: 0.65; }
#rules { margin-top: 10px; text-align: left; font-size: 15px; }
#rules summary { cursor: pointer; font-weight: 800; min-height: 40px; display: flex; align-items: center; }
#rules ul { margin: 4px 0 0; padding-left: 20px; line-height: 1.4; }
#swap-rack { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 10px; margin: 8px 0; border-radius: 14px; background: #8a5426; }
#end-stars { font-size: 44px; letter-spacing: 6px; min-height: 52px; }
#end-list { list-style: none; padding: 0; margin: 6px 0; font-weight: 800; font-size: 20px; }
#end-list li { padding: 6px 10px; border-radius: 12px; margin: 4px 0; background: #f1ecff; display: flex; justify-content: space-between; }
#end-list li.win { background: #ffe066; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

@media (min-width: 560px) { .chip .nm { display: inline; } }
@media (max-height: 500px) and (orientation: landscape) {
  #main { flex-direction: row; }
  #panel { width: 262px; flex: none; overflow-y: auto; padding: 4px 6px; gap: 4px; justify-content: flex-start; }
  #rack { display: grid; grid-template-columns: repeat(4, 48px); justify-content: center; }
  .tile { width: 48px; height: 48px; font-size: 28px; }
  #actions { gap: 4px; }
  .btn { font-size: 13px; padding: 4px; }
  #status { font-size: 13px; min-height: 16px; }
  .chip { min-height: 36px; padding: 1px 8px 1px 4px; }
  #topbar { padding: 2px 8px; }
  .panel { padding: 8px 12px; }
  .panel h1 { font-size: 30px; }
  .panel h3 { margin: 4px 0 2px; font-size: 13px; }
  .sub { margin: 0 0 2px; font-size: 13px; }
  .seg button { min-height: 48px; font-size: 18px; }
  .row { margin-top: 6px; }
  .btn.big { min-height: 56px; }
  #home .sub { display: none; }
  #home .row { display: inline-flex; vertical-align: middle; margin: 6px 4px 0; }
  #end-stars { font-size: 30px; min-height: 36px; }
  #end-list { font-size: 16px; }
  #swap-rack { margin: 4px 0; }
}
@media (max-width: 400px) { .btn { font-size: 14px; } .chip { padding-right: 7px; } #rack { gap: 2px; padding: 4px; } #panel { padding: 4px 4px 6px; } }

/* flèches de déplacement en mode zoom */
#pan { position: absolute; inset: 0; pointer-events: none; }
.pan-b { position: absolute; width: 52px; height: 52px; border-radius: 16px; border: 0; background: rgba(30,20,80,0.6); color: #fff; font-size: 24px; cursor: pointer; pointer-events: auto; }
.pan-b:active { transform: scale(0.94); }
#pan-up { top: 6px; left: 50%; margin-left: -26px; }
#pan-down { bottom: 6px; left: 50%; margin-left: -26px; }
#pan-left { left: 6px; top: 50%; margin-top: -26px; }
#pan-right { right: 6px; top: 50%; margin-top: -26px; }

/* bandeau titre de l'accueil */
.hero { display: block; width: 100%; height: clamp(60px, 12vh, 130px); object-fit: cover; object-position: center 6%; border-radius: 16px; margin: 0 0 8px; }
@media (max-height: 520px) { .hero { display: none; } }

/* places de joueurs */
#seats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seat { display: flex; flex-direction: column; gap: 4px; align-items: stretch; min-width: 0; }
.seat-b, .seat-av { min-height: 64px; border-radius: 14px; border: 3px solid #d6cdf5; background: #fff; font: 800 26px/1.1 "Trebuchet MS", system-ui, sans-serif; color: #3b2a60; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; }
.seat-b { cursor: pointer; }
.seat-b:active { transform: scale(0.96); }
.seat-b span { font-size: 12px; font-weight: 700; color: #6b5a9a; }
.seat-av { background: #fff3d1; border-color: #ff9f1c; }
.seat-name { min-height: 48px; width: 100%; border-radius: 12px; border: 3px solid #d6cdf5; padding: 0 6px; font: 700 15px "Trebuchet MS", system-ui, sans-serif; text-align: center; color: #2b2150; }
#pass { background: radial-gradient(circle at 50% 30%, #6c63d9, #2b2a7a 80%); z-index: 30; }
#pass-who { font-size: clamp(34px, 9vmin, 56px); font-weight: 900; color: #3b2a60; margin: 10px 0 6px; word-break: break-word; }
#scores.many .chip { min-height: 36px; padding: 1px 6px 1px 3px; gap: 2px; }
#scores.many .chip .av { font-size: 18px; }
#scores.many .chip b { font-size: 15px; min-width: 1.2em; }
@media (max-height: 500px) and (orientation: landscape) {
  .seat { flex-direction: row; }
  .seat-b, .seat-av { min-height: 48px; min-width: 56px; font-size: 22px; flex: none; }
  .seat-name { min-height: 48px; min-width: 0; }
  #seats { grid-template-columns: repeat(4, 1fr); }
}
