:root{color-scheme:dark;--bg:#101015;--panel:#1b1b23;--panel2:#252530;--text:#f4f1e9;--muted:#a6a4b1;--accent:#d9bd79;--green:#76c7a1;--red:#e58b98}
*{box-sizing:border-box}body{margin:0;background:radial-gradient(ellipse at 50% -20%,#292532 0,transparent 55%),var(--bg);color:var(--text);font:16px/1.45 system-ui,-apple-system,Segoe UI,sans-serif;min-height:100vh;padding-bottom:env(safe-area-inset-bottom)}
header{height:74px;padding:0 max(20px,calc((100vw - 760px)/2));display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #ffffff12;background:#111116e8;position:sticky;top:0;z-index:5;backdrop-filter:blur(16px)}
.brand{display:flex;align-items:center;gap:10px}.brand-icon{font-size:30px}.brand b{font-size:20px;letter-spacing:1px}.brand small{display:block;color:var(--accent);font-size:9px;letter-spacing:2px;font-weight:800}
main{width:min(760px,100%);margin:26px auto;padding:0 16px}.panel{background:linear-gradient(145deg,#22222c,#191920);border:1px solid #ffffff0c;border-radius:22px;padding:22px;box-shadow:0 14px 40px #0002}
.eyebrow{font-size:10px;letter-spacing:1.8px;font-weight:800;color:var(--accent)}h1{font-size:27px;margin:8px 0}.muted,.hint{color:var(--muted)}.muted{margin:0 0 20px}
.name-fields{display:grid;gap:10px;margin-bottom:12px}.name-row{display:flex;align-items:center;gap:10px}.name-row input{flex:1;min-width:0}.name-row button{width:42px;height:44px}
input{background:#111117;border:1px solid #ffffff1b;border-radius:12px;color:var(--text);padding:12px 14px;font:inherit;outline:none}input:focus{border-color:var(--accent)}
button{border:0;border-radius:13px;padding:13px 16px;font:700 14px system-ui;cursor:pointer;transition:transform .12s,opacity .12s}button:active{transform:scale(.98)}button:disabled{opacity:.35;cursor:not-allowed}
.primary{background:var(--accent);color:#17151a}.secondary{background:#343440;color:var(--text)}.bank{background:#315c4d;color:#e8fff5}.ghost{background:#ffffff0b;color:var(--muted);padding:10px 13px}.small{font-size:12px;padding:9px 11px}.full{width:100%;margin-top:14px}.text-btn{background:none;color:var(--accent);padding:8px 0}
.topline{display:flex;align-items:center;justify-content:space-between;margin:0 2px 16px}.turn-label{font-size:23px;font-weight:800;margin-top:3px}
.scoreboard{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:9px;margin-bottom:16px}.player-card{background:var(--panel);border:1px solid #ffffff12;border-radius:15px;padding:12px;min-width:0}.player-card.active{border:1px solid var(--accent);box-shadow:0 0 0 1px #d9bd7933}.player-name{display:flex;align-items:center;gap:6px;color:var(--muted);font-size:12px}.player-name button{background:none;padding:0;color:var(--muted);font-size:12px}.player-score{font-size:25px;font-weight:850;font-variant-numeric:tabular-nums;margin-top:3px}.player-progress{height:4px;border-radius:4px;background:#ffffff13;margin-top:8px;overflow:hidden}.player-progress span{display:block;height:100%;background:var(--accent)}
.play-panel{padding:20px}.play-heading{display:flex;justify-content:space-between;align-items:center}.turn-points{font-size:34px;font-weight:900;color:var(--accent);font-variant-numeric:tabular-nums}.remaining{font-size:12px;color:var(--muted);background:#ffffff0b;padding:8px 10px;border-radius:20px}
.message{margin:15px 0;padding:12px 14px;border-radius:12px;background:#ffffff09;color:#ddd9e8;font-size:14px}.message.good{color:var(--green)}.message.bad{color:var(--red)}
.dice-area{display:grid;grid-template-columns:repeat(3,minmax(70px,1fr));gap:12px;margin:18px 0;min-height:86px}.die{aspect-ratio:1/1;max-width:100px;width:100%;justify-self:center;border-radius:19px;background:#f4ecd8;color:#29252a;display:grid;place-items:center;box-shadow:0 5px 0 #b9ad91;font-size:42px;font-weight:800;position:relative;padding:0}.die.selected{outline:3px solid var(--green);background:#d5f1df;transform:translateY(-3px);box-shadow:0 8px 0 #6b9b7d}.die.locked{opacity:.24;filter:grayscale(1)}.die .die-value{line-height:1}.selection-info{text-align:center;color:var(--muted);font-size:13px;min-height:22px;margin-bottom:12px}
.actions{display:grid;grid-template-columns:1fr 1fr;gap:9px}.actions #rollBtn{grid-column:1/-1}.hint{font-size:11px;line-height:1.5;margin:14px 0 0}.rules-mini{margin-top:13px;display:grid;gap:5px;font-size:13px}.rules-mini span{color:var(--muted);font-size:12px}
.modal{position:fixed;inset:0;background:#000a;z-index:10;display:grid;place-items:end center;padding:12px}.modal-card{width:min(620px,100%);max-height:85vh;overflow:auto;background:#20202a;border:1px solid #ffffff18;border-radius:22px;padding:20px;margin-bottom:env(safe-area-inset-bottom)}.modal-head{display:flex;justify-content:space-between;align-items:center}.modal-head h2{font-size:20px;margin:0 0 15px}.close{background:#ffffff12;color:white;padding:8px 11px}.rules-list{display:grid;gap:0}.rules-list div{display:flex;justify-content:space-between;padding:13px 4px;border-bottom:1px solid #ffffff12;font-size:14px}.rules-list b{color:var(--accent)}.history-item{padding:13px 4px;border-bottom:1px solid #ffffff12}.history-item b{display:block}.history-item small{color:var(--muted)}
.toast{position:fixed;bottom:22px;left:50%;transform:translate(-50%,20px);background:#f0e5c9;color:#201d21;padding:11px 16px;border-radius:12px;font-weight:700;font-size:13px;opacity:0;pointer-events:none;transition:.2s;z-index:20;max-width:90%;text-align:center}.toast.show{opacity:1;transform:translate(-50%,0)}
[hidden]{display:none!important}
@media(min-width:650px){.actions{grid-template-columns:repeat(3,1fr)}.actions #rollBtn{grid-column:auto}.dice-area{grid-template-columns:repeat(6,1fr)}}

/* Clear turn-result feedback */
.message.bad{background:#5b252f66;border:1px solid #e58b9855;color:#ffdce1;font-weight:800}.message.good{background:#214b3b66;border:1px solid #76c7a155;color:#d9ffec;font-weight:800}

/* Header actions: rules remain reachable before and during a game */
.header-actions{display:flex;align-items:center;gap:8px}
.header-btn{font-size:13px;font-weight:800;padding:10px 13px;border:1px solid #ffffff16}
#rulesBtn{color:var(--accent);background:#d9bd7914;border-color:#d9bd7940}
.modal{z-index:20;place-items:center;backdrop-filter:blur(5px)}
.modal-card{margin:0;max-height:min(85vh,760px)}
@media(max-width:390px){header{padding-left:12px;padding-right:12px}.brand{gap:6px}.brand b{font-size:17px}.brand-icon{font-size:25px}.header-actions{gap:5px}.header-btn{font-size:12px;padding:9px 10px}}


/* Single-device turn control */
.control-panel{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 14px;margin:0 0 14px;border:1px solid #76c7a155;border-radius:15px;background:#214b3b44}
.control-panel.spectator{border-color:#d9bd7945;background:#d9bd7910}
.control-copy{display:flex;align-items:center;gap:10px;min-width:0}
.control-dot{width:10px;height:10px;flex:0 0 10px;border-radius:50%;background:var(--green);box-shadow:0 0 0 4px #76c7a122}
.control-panel.spectator .control-dot{background:var(--accent);box-shadow:0 0 0 4px #d9bd7922}
.control-copy b{display:block;font-size:12px;line-height:1.35}
.control-copy small{display:block;color:var(--muted);font-size:10px;margin-top:3px}
.control-actions{display:flex;gap:6px;flex:0 0 auto}
.control-button{font-size:11px;padding:9px 11px;white-space:nowrap}
.control-rename{padding:8px 10px}
@media(max-width:390px){.control-panel{align-items:flex-start;flex-direction:column}.control-actions{width:100%}.control-button{flex:1}}

.wide-input{width:100%;margin:7px 0 4px}.code-input{text-transform:uppercase;letter-spacing:3px;font-weight:800;text-align:center}.separator{display:flex;align-items:center;gap:12px;color:var(--muted);font-size:10px;font-weight:800;letter-spacing:1.5px;margin:24px 0 12px}.separator:before,.separator:after{content:"";height:1px;background:#ffffff20;flex:1}.room-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px}.room-heading h1{margin:5px 0;font-size:23px}.room-heading .muted{margin:0;font-size:12px}.room-code{letter-spacing:2px;color:var(--accent);font-size:16px}.room-actions{display:flex;gap:6px;flex-wrap:wrap}.history-panel{margin-top:14px}.history-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}.history-panel .history-item:last-child{border-bottom:0}label{font-size:13px;color:var(--muted)}@media(max-width:480px){.room-heading{align-items:flex-start;flex-direction:column}.room-actions{width:100%}.room-actions button{flex:1}}

/* V7 — animations de jeu */
.die{transition:transform .18s ease,background .2s ease,box-shadow .2s ease,filter .2s ease;cursor:pointer}
.die.selected{animation:die-select .28s ease both}
.die.farkle-die{background:#ffdddd;color:#7e1526;box-shadow:0 5px 0 #b94b5a;outline:2px solid #ff647b;animation:farkle-sequence .9s ease both}
.dice-area.farkle-dice{padding:10px;border-radius:18px;background:linear-gradient(120deg,#5b172466,#a3213444);animation:farkle-flash .8s ease both}
.message.bad{animation:message-alert .45s ease both}
.button-roll{animation:button-wiggle .5s ease infinite}
.winner-pulse{animation:winner-pulse 1s ease-in-out infinite alternate}
body.victory:after{content:"✦  ✧  ✦  ✧  ✦";position:fixed;inset:12% 0 auto;text-align:center;font-size:clamp(28px,8vw,64px);color:#ffd76a;text-shadow:0 0 24px #ffc94a;pointer-events:none;animation:confetti-drop 2.5s ease-out both;z-index:20}
@keyframes dice-roll-in{0%{transform:translateY(-28px) rotate(-150deg) scale(.65);opacity:.2}65%{transform:translateY(5px) rotate(18deg) scale(1.08);opacity:1}100%{transform:translateY(0) rotate(0) scale(1)}}
@keyframes die-select{0%{transform:scale(1)}50%{transform:translateY(-8px) scale(1.12)}100%{transform:translateY(-3px) scale(1)}}
@keyframes farkle-sequence{0%{transform:translateY(-22px) rotate(-150deg) scale(.7);opacity:.35}35%{transform:translateY(4px) rotate(16deg) scale(1.08);opacity:1}50%,100%{transform:translateY(0) rotate(0) scale(1)}60%{transform:translateX(-5px) rotate(-5deg)}70%{transform:translateX(5px) rotate(5deg)}80%{transform:translateX(-3px) rotate(-3deg)}90%{transform:translateX(3px) rotate(3deg)}}
@keyframes farkle-flash{0%{background-color:#b51f3b00}35%{background-color:#b51f3b66}100%{background-color:#5b172422}}
@keyframes message-alert{0%{transform:scale(.97)}55%{transform:scale(1.025)}100%{transform:scale(1)}}
@keyframes button-wiggle{0%,100%{transform:rotate(0)}25%{transform:rotate(-2deg)}75%{transform:rotate(2deg)}}
@keyframes winner-pulse{from{text-shadow:0 0 0 #ffd76a}to{text-shadow:0 0 18px #ffd76a}}
@keyframes confetti-drop{0%{opacity:0;transform:translateY(-50px) scale(.6)}20%{opacity:1}100%{opacity:0;transform:translateY(70vh) scale(1.2)}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}}


/* V7.1 — lancer immersif : gobelet, tapis et trajectoires individuelles */
.dice-stage{position:relative;min-height:174px;padding:26px 10px 20px;margin:12px 0 16px;perspective:1100px;overflow:hidden;border-radius:22px;isolation:isolate}
.felt-tray{position:absolute;inset:0;border-radius:22px;background:radial-gradient(ellipse at 48% 38%,#326c50 0%,#1d503a 48%,#103324 100%);border:8px solid #39291f;box-shadow:inset 0 0 0 2px #c19a6755,inset 0 0 0 5px #17100c88,inset 0 15px 32px #0008,0 13px 25px #0005}
.felt-tray:before{content:"";position:absolute;inset:8px;border:1px solid #b5d1a51c;border-radius:14px;box-shadow:inset 0 0 24px #071b1280}
.dice-area{position:relative;z-index:2;min-height:124px;display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:12px;padding:8px 4px;transition:opacity .16s}
.die{position:relative;z-index:2;width:54px;height:54px;border-radius:12px;background:linear-gradient(145deg,#fffefa 0%,#e8e4d9 55%,#c9c5bb 100%);color:#24232a;border:1px solid #ffffff;box-shadow:inset -3px -4px 6px #00000012,0 5px 0 #99958a,0 10px 14px #0007;font-size:36px;line-height:1;display:grid;place-items:center;transform-style:preserve-3d;backface-visibility:hidden;transition:background .16s ease,box-shadow .16s ease,outline-color .16s ease;cursor:pointer}
.die.selected{outline:3px solid #e4c47d;outline-offset:2px;background:linear-gradient(145deg,#fff8df,#e8d49b);box-shadow:inset -3px -4px 6px #00000012,0 5px 0 #a88b4e,0 10px 14px #0007,0 0 18px #e4c47d55;animation:die-select .22s ease-out both}
.die.locked{opacity:.42;filter:grayscale(.8)}
.dice-cup{position:absolute;z-index:5;left:50%;top:48%;width:116px;height:112px;transform:translate(-50%,-50%);opacity:0;pointer-events:none;filter:drop-shadow(0 16px 9px #0009);transform-style:preserve-3d}
.dice-cup:before{content:"";position:absolute;inset:12px 5px 0;background:linear-gradient(100deg,#24170f,#69432d 22%,#b07b4e 48%,#69432d 76%,#2d1d16);clip-path:polygon(15% 0,85% 0,100% 100%,0 100%);border-radius:8px 8px 18px 18px;border:3px solid #c29462;box-shadow:inset 0 0 12px #160d08}
.dice-cup:after{content:"";position:absolute;left:0;right:0;top:3px;height:24px;border-radius:50%;background:linear-gradient(#d0a06b,#68452d 60%,#382319);border:4px solid #d2a06b;box-shadow:inset 0 4px 6px #24170f,0 3px 4px #0008}
.dice-cup span{position:absolute;z-index:2;left:27px;right:27px;bottom:15px;height:12px;border-radius:50%;background:radial-gradient(ellipse,#d8c6a5 0 20%,#f1e9d8 22% 55%,#a99a7c 58%);box-shadow:0 0 0 5px #4a2d1d}
.dice-stage.is-rolling .dice-cup{opacity:1;animation:cup-shake-throw 1.28s cubic-bezier(.2,.7,.25,1) both}
.dice-stage.is-rolling .dice-area{opacity:1}
.dice-stage.is-rolling .die{animation:dice-flight 1.16s cubic-bezier(.12,.72,.18,1) both;animation-delay:calc(var(--die-index,0)*38ms)}
.dice-stage.is-rolling .die:nth-child(1){--die-index:0}.dice-stage.is-rolling .die:nth-child(2){--die-index:1}.dice-stage.is-rolling .die:nth-child(3){--die-index:2}.dice-stage.is-rolling .die:nth-child(4){--die-index:3}.dice-stage.is-rolling .die:nth-child(5){--die-index:4}.dice-stage.is-rolling .die:nth-child(6){--die-index:5}
.dice-stage.reveal .die{animation:die-settle .22s ease-out both}
@keyframes cup-shake-throw{0%{transform:translate(-50%,-50%) translateY(-42px) rotate(-8deg) scale(.8);opacity:0}10%{opacity:1}22%{transform:translate(-50%,-50%) translate(-12px,-24px) rotate(13deg)}36%{transform:translate(-50%,-50%) translate(12px,-20px) rotate(-15deg)}50%{transform:translate(-50%,-50%) translate(-9px,-12px) rotate(17deg)}63%{transform:translate(-50%,-50%) translate(8px,-4px) rotate(-10deg)}76%{transform:translate(-50%,-50%) translate(28px,24px) rotate(62deg) scale(.96);opacity:1}100%{transform:translate(-50%,-50%) translate(112px,125px) rotate(105deg) scale(.72);opacity:0}}
@keyframes dice-flight{0%{opacity:0;transform:translate3d(0,-62px,80px) rotateX(0) rotateY(0) rotateZ(0) scale(.62)}18%{opacity:1;transform:translate3d(var(--flight-x,18px),var(--flight-y,-25px),55px) rotateX(120deg) rotateY(95deg) rotateZ(100deg) scale(1.05)}42%{transform:translate3d(calc(var(--flight-x,18px)*1.5),12px,22px) rotateX(240deg) rotateY(190deg) rotateZ(210deg)}62%{transform:translate3d(calc(var(--flight-x,18px)*-.55),-5px,8px) rotateX(330deg) rotateY(280deg) rotateZ(300deg)}78%{transform:translate3d(calc(var(--flight-x,18px)*.25),2px,0) rotateX(390deg) rotateY(340deg) rotateZ(350deg)}90%{transform:translate3d(-3px,0,0) rotateX(355deg) rotateY(365deg) rotateZ(365deg)}100%{opacity:1;transform:translate3d(0,0,0) rotateX(360deg) rotateY(360deg) rotateZ(360deg) scale(1)}}
@keyframes die-settle{0%{transform:translateY(-3px) rotate(3deg)}55%{transform:translateY(1px) rotate(-1deg)}100%{transform:translateY(0) rotate(0)}}
@keyframes die-select{0%{transform:translateY(0) scale(1)}65%{transform:translateY(-5px) scale(1.07)}100%{transform:translateY(-2px) scale(1)}}
.history-item{width:100%;text-align:left;display:flex;flex-direction:column;gap:5px;margin:8px 0;padding:13px 15px;border:1px solid #ffffff14;border-radius:13px;background:#ffffff06;color:var(--text);cursor:pointer}
.history-item small{color:var(--muted);font-size:12px}.history-open{color:var(--accent);font-size:12px;font-weight:700}
.history-detail{margin-top:14px}.event-row{display:grid;grid-template-columns:74px 1fr;gap:12px;padding:12px 0;border-bottom:1px solid #ffffff12}.event-time{font-size:11px;color:var(--muted);padding-top:2px}.event-row b{font-size:14px}.event-row p{margin:4px 0 0;font-size:13px;color:#d4d1c9;line-height:1.55}.event-farkle{background:#e58b9810;border-radius:12px;padding:12px;margin:5px 0;border:1px solid #e58b9830}.event-farkle b{color:#f09aa5}
.event-dice{display:inline-flex;gap:3px;vertical-align:middle;margin:2px 3px}.event-dice i{font-style:normal;background:#f3f0e8;color:#29252a;border-radius:5px;padding:1px 5px;font-size:17px;box-shadow:0 2px 0 #aaa69b}
@media(max-width:480px){.die{width:45px;height:45px;font-size:30px;border-radius:10px}.dice-stage{min-height:156px;padding:18px 6px}.dice-cup{transform:translate(-50%,-50%) scale(.85)}.event-row{grid-template-columns:58px 1fr;gap:8px}}
@media(prefers-reduced-motion:reduce){.dice-stage *,.die,.dice-cup{animation:none!important;transition:none!important}}

/* V8 — vraie scène 3D et simulation physique des dés */
.dice-stage{min-height:220px;padding:8px;margin:12px 0 16px;perspective:none;background:radial-gradient(ellipse at 50% 35%,#183b2c,#081b13 78%);}
.dice-area{height:210px;min-height:210px;width:100%;padding:0;margin:0;display:block;overflow:hidden;border-radius:16px;background:transparent!important;animation:none!important}
.dice3d-canvas{display:block;width:100%;height:100%;touch-action:pan-y;outline:none}
.dice-cup{display:none!important}
.dice-area.farkle-dice{outline:1px solid #e66c7b55;box-shadow:inset 0 0 34px #a3213422}
@media(max-width:480px){.dice-stage{min-height:190px;padding:4px}.dice-area{height:182px;min-height:182px}}
@media(prefers-reduced-motion:reduce){.dice3d-canvas{opacity:.95}}

/* V8.2: plateau plus grand à l'écran, dés plus lisibles */
.dice-stage{min-height:270px;padding:4px;overflow:hidden}
.dice-area{height:262px;min-height:262px}
@media(max-width:480px){
  .dice-stage{min-height:250px;padding:3px}
  .dice-area{height:244px;min-height:244px}
}

/* V8.3 — repères de sélection visibles et lisibles sur mobile */
.selection-info{min-height:28px;padding:7px 10px;border-radius:10px;background:#ffffff0a;border:1px solid #ffffff18;font-weight:650;letter-spacing:.015em}
