:root {
  --bg: #0b0820;
  --bg2: #171042;
  --card: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .12);
  --text: #f3f0ff;
  --muted: #a49cc9;
  --red: #ff3b5c;
  --red2: #b3123a;
  --yel: #ffd23f;
  --yel2: #d99400;
  --violet: #7b5cff;
  --hot: #ff7a1a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Outfit', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}
input { -webkit-user-select: text; user-select: text; }
#bg {
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(123, 92, 255, .35), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(255, 59, 92, .18), transparent 70%),
    radial-gradient(ellipse 60% 40% at 0% 90%, rgba(255, 210, 63, .10), transparent 70%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 49; opacity: 0; background: #fff; }
#flash.go { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }

#app { max-width: 620px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding: calc(var(--safe-t) + 8px) 14px calc(var(--safe-b) + 14px); }
.screen { display: none; flex-direction: column; gap: 14px; animation: in .35s ease-out; }
.screen.active { display: flex; }
@keyframes in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1, h2, .a-title, .code, .r-title, .score { font-family: 'Bungee', 'Outfit', sans-serif; font-weight: 400; }
h1 { margin: 0; font-size: 46px; letter-spacing: 1px; line-height: 1; }
h1 em, .mini em { font-style: normal; background: linear-gradient(90deg, var(--red), var(--yel)); -webkit-background-clip: text; background-clip: text; color: transparent; }
h1.mini { font-size: 20px; }
h2 { font-size: 18px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* Logo jetons */
.logo { display: flex; gap: 8px; justify-content: center; }
.logo .d, .spinner .d { width: 22px; height: 22px; border-radius: 50%; display: block; }
.logo.big .d { width: 34px; height: 34px; animation: bob 1.6s ease-in-out infinite; }
.logo .d:nth-child(2) { animation-delay: .15s; } .logo .d:nth-child(3) { animation-delay: .3s; } .logo .d:nth-child(4) { animation-delay: .45s; }
.d.r { background: radial-gradient(circle at 35% 30%, #ff8da0, var(--red) 45%, var(--red2)); box-shadow: 0 0 16px rgba(255, 59, 92, .6); }
.d.y { background: radial-gradient(circle at 35% 30%, #fff1a8, var(--yel) 45%, var(--yel2)); box-shadow: 0 0 16px rgba(255, 210, 63, .5); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
#s-loading { align-items: center; justify-content: center; min-height: 70vh; }

.brand { text-align: center; margin-top: 8vh; display: flex; flex-direction: column; gap: 14px; }
.tagline { color: var(--muted); margin: 0; font-size: 17px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
label { font-weight: 600; display: block; margin-bottom: 8px; }
input {
  width: 100%; font: inherit; font-size: 18px; color: var(--text);
  background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; outline: none;
}
input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(123, 92, 255, .3); }
#f-register { display: flex; flex-direction: column; gap: 6px; }
.err { color: #ff8da0; min-height: 1.2em; margin: 4px 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; text-align: center; }

.btn {
  font: inherit; font-weight: 800; font-size: 16px; color: var(--text); cursor: pointer;
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 18px; background: rgba(255, 255, 255, .08);
  transition: transform .08s, filter .2s, background .2s; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, #8b6bff, #5a3cf0); border-color: transparent; box-shadow: 0 8px 24px rgba(90, 60, 240, .35); }
.btn.hot { background: linear-gradient(135deg, var(--hot), var(--red)); border-color: transparent; box-shadow: 0 8px 24px rgba(255, 90, 60, .3); }
.btn.ghost { background: transparent; }
.btn.big { padding: 18px; font-size: 18px; }
.btn:disabled { opacity: .5; }
.btn.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, .6); } 50% { box-shadow: 0 0 0 10px rgba(255, 210, 63, 0); } }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; margin-left: auto; align-self: flex-start; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row .btn { flex: 1; min-width: 130px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 20px; cursor: pointer; }
.icon-btn.off { opacity: .5; }

.me-card .me-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-family: 'Bungee', sans-serif; font-size: 20px; color: #1a0f3d;
  background: radial-gradient(circle at 35% 30%, #fff1a8, var(--yel) 45%, var(--yel2));
}
.hello { font-size: 18px; }
.me-title { font-size: 13px; color: var(--hot); font-weight: 800; letter-spacing: 1px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 14px; }
.stats div { background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 8px 2px; text-align: center; }
.stats b { display: block; font-size: 19px; }
.stats span { font-size: 11px; color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-family: 'Bungee', sans-serif; }
.join-row .btn { flex: none; }
.bot-row { display: flex; gap: 10px; align-items: stretch; }
.bot-row .btn { flex: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); background: transparent; border: 0; padding: 0 10px; cursor: pointer; }
.seg button.on { background: rgba(123, 92, 255, .35); color: var(--text); }

.board-list ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.board-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(0, 0, 0, .2); }
.board-list li.me { outline: 1px solid var(--violet); background: rgba(123, 92, 255, .15); }
.board-list .rk { width: 28px; text-align: center; font-weight: 800; }
.board-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board-list .tt { font-size: 10px; font-weight: 800; color: var(--hot); letter-spacing: .5px; margin-left: 6px; }
.board-list .el { font-weight: 800; }
.board-list .wl { font-size: 12px; color: var(--muted); width: 64px; text-align: right; }
.board-list .empty { color: var(--muted); justify-content: center; }

/* Attente */
.wait-box { display: flex; flex-direction: column; gap: 16px; align-items: center; text-align: center; margin-top: 4vh; }
.spinner { display: flex; gap: 10px; height: 50px; align-items: flex-end; }
.spinner .d { width: 26px; height: 26px; animation: bob 0.9s ease-in-out infinite; }
.spinner .d:nth-child(2) { animation-delay: .45s; }
#invite { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.code { font-size: 54px; letter-spacing: 10px; background: linear-gradient(90deg, var(--red), var(--yel)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.link-box { font-size: 14px; padding: 12px; border-radius: 12px; background: rgba(0, 0, 0, .35); border: 1px dashed var(--line); word-break: break-all; -webkit-user-select: all; user-select: all; }

/* Jeu */
#s-game { gap: 10px; }
#s-game.active { min-height: calc(100vh - 30px); padding-bottom: 150px; }
@supports (height: 100dvh) { #s-game.active { min-height: calc(100dvh - 30px - var(--safe-t) - var(--safe-b)); } }
#s-game .board-wrap { margin: auto; }
.room-tag { font-size: 13px; color: var(--muted); font-weight: 600; text-align: center; }
.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.pcard {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 16px;
  background: var(--card); border: 2px solid transparent; transition: border-color .25s, box-shadow .25s, opacity .25s; min-width: 0;
}
.pcard.p2 { flex-direction: row-reverse; text-align: right; }
.pcard .avatar { width: 38px; height: 38px; font-size: 16px; }
.pcard.p1 .avatar { background: radial-gradient(circle at 35% 30%, #ff8da0, var(--red) 45%, var(--red2)); color: #fff; }
.pinfo { min-width: 0; display: flex; flex-direction: column; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.psub { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard.turn.p1 { border-color: var(--red); box-shadow: 0 0 22px rgba(255, 59, 92, .45); }
.pcard.turn.p2 { border-color: var(--yel); box-shadow: 0 0 22px rgba(255, 210, 63, .4); }
.pcard.off { opacity: .45; }
.pcard.empty { opacity: .35; }
.score { font-size: 20px; white-space: nowrap; }
.bubble {
  position: absolute; top: 100%; left: 10px; z-index: 20; font-size: 34px; pointer-events: none; opacity: 0;
  background: #fff; color: #1a0f3d; border-radius: 18px; padding: 2px 12px; font-family: 'Bungee', sans-serif;
}
.pcard.p2 .bubble { left: auto; right: 10px; }
.bubble.show { animation: bubble 1.8s ease-out; }
@keyframes bubble { 0% { opacity: 0; transform: translateY(-6px) scale(.4); } 12% { opacity: 1; transform: translateY(6px) scale(1.15); } 22% { transform: translateY(6px) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(0); } }

.status { text-align: center; font-weight: 800; font-size: 17px; min-height: 26px; display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.status .you { color: var(--yel); animation: glow 1.2s ease-in-out infinite; }
.status .btn { padding: 6px 12px; font-size: 13px; }
@keyframes glow { 50% { text-shadow: 0 0 14px currentColor; } }

.board-wrap {
  --w: min(calc(100vw - 28px), calc((100vh - 300px) * 7 / 7.4), 590px);
  width: var(--w); margin: 0 auto; position: relative;
}
@supports (height: 100dvh) {
  .board-wrap { --w: min(calc(100vw - 28px), calc((100dvh - 300px - var(--safe-t) - var(--safe-b)) * 7 / 7.4), 590px); }
}
.ghost-row { position: relative; width: 100%; aspect-ratio: 7 / 1; margin-bottom: 4px; }
.ghost-row .disc { width: calc(100% / 7); height: 100%; top: 0; transition: left .12s ease-out, opacity .15s; opacity: 0; }
.ghost-row .disc.on { opacity: .9; }
.board { position: relative; width: 100%; aspect-ratio: 7 / 6; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .5)); }
.board.thud { animation: thud .22s ease-out; }
@keyframes thud { 30% { transform: translateY(3px) scaleY(.99); } }
.discs, .frame, .winfx, .cols { position: absolute; inset: 0; width: 100%; height: 100%; }
.frame { z-index: 2; pointer-events: none; }
.winfx { z-index: 3; pointer-events: none; overflow: visible; }
.cols { z-index: 4; display: grid; grid-template-columns: repeat(7, 1fr); }
.cols div { cursor: pointer; border-radius: 12px; transition: background .15s; }
.cols.can div:hover { background: rgba(255, 255, 255, .06); }
.discs { z-index: 1; overflow: hidden; border-radius: 26px; }
.disc { position: absolute; width: calc(100% / 7); height: calc(100% / 6); will-change: transform; }
.discs .disc { overflow: visible; }
.disc::before {
  content: ''; position: absolute; inset: 7%; border-radius: 50%;
}
.disc::after { content: ''; position: absolute; inset: 24%; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .16); }
.disc.v1::before { background: radial-gradient(circle at 35% 30%, #ff9cae, var(--red) 42%, var(--red2) 90%); box-shadow: inset 0 -4px 8px rgba(0, 0, 0, .35); }
.disc.v2::before { background: radial-gradient(circle at 35% 30%, #fff3b0, var(--yel) 42%, var(--yel2) 90%); box-shadow: inset 0 -4px 8px rgba(0, 0, 0, .3); }
.disc.dim { filter: brightness(.45) saturate(.6); transition: filter .6s; }
.disc.win::before { animation: winpulse .8s ease-in-out infinite alternate; }
@keyframes winpulse { from { filter: brightness(1); } to { filter: brightness(1.45) drop-shadow(0 0 10px #fff); } }
.winfx circle { transform-box: fill-box; transform-origin: center; fill: none; stroke: #fff; stroke-width: 5; opacity: 0; animation: ring .5s ease-out forwards; filter: drop-shadow(0 0 6px #fff); }
.winfx line { stroke: #fff; stroke-width: 12; stroke-linecap: round; opacity: .85; filter: drop-shadow(0 0 10px #fff); animation: drawline .55s ease-out forwards; }
@keyframes ring { from { opacity: 0; transform: scale(1.6); } to { opacity: 1; transform: scale(1); } }
@keyframes drawline { to { stroke-dashoffset: 0; } }

.emotes { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emotes button {
  font-size: 20px; min-width: 42px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); cursor: pointer; padding: 0 6px; font-family: 'Bungee', sans-serif;
}
.emotes button:active { transform: scale(.9); }
.emotes.off { display: none; }

.result {
  display: none; flex-direction: column; gap: 8px; text-align: center; padding: 14px; border-radius: 20px;
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); z-index: 30; max-width: 560px; margin: 0 auto;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .5); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  background: rgba(10, 6, 30, .88); border: 1px solid var(--line); animation: up .4s cubic-bezier(.2, 1.4, .5, 1);
}
.result.show { display: flex; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.r-title { font-size: 34px; line-height: 1; }
.r-title.win { background: linear-gradient(90deg, #fff3b0, var(--yel), var(--hot)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.r-title.lose { color: #8f86b8; }
.r-sub { color: var(--muted); font-size: 14px; }
.r-sub b.plus { color: #5dffa0; } .r-sub b.minus { color: #ff8da0; }

/* Annonce */
#announce { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none; visibility: hidden; }
#announce.show { visibility: visible; }
#announce::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(0, 0, 0, .65), transparent 70%); opacity: 0; }
#announce.show::before { animation: fade 2.3s ease-out forwards; }
.a-inner { position: relative; text-align: center; padding: 0 16px; }
.a-kicker { font-weight: 800; letter-spacing: 4px; font-size: 14px; color: #fff; opacity: .85; text-transform: uppercase; }
.a-title {
  font-size: clamp(38px, 12vw, 84px); line-height: 1.05; color: transparent; -webkit-background-clip: text; background-clip: text;
  background-image: linear-gradient(180deg, #fff 0%, var(--ac, var(--hot)) 55%, var(--ac2, #7a1a00) 100%);
  filter: drop-shadow(0 0 18px var(--ac, var(--hot))) drop-shadow(0 4px 0 rgba(0, 0, 0, .6));
  -webkit-text-stroke: 1px rgba(255, 255, 255, .35);
}
.a-sub { margin-top: 8px; font-size: 17px; font-weight: 600; color: #fff; text-shadow: 0 2px 6px #000; }
#announce.show .a-title { animation: slam 2.3s cubic-bezier(.2, 1.3, .4, 1) forwards; }
#announce.show .a-kicker, #announce.show .a-sub { animation: fade 2.3s ease-out forwards; }
@keyframes slam { 0% { transform: scale(3.2) rotate(-4deg); opacity: 0; } 12% { transform: scale(.92) rotate(0); opacity: 1; } 18% { transform: scale(1.04); } 24% { transform: scale(1); } 82% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes fade { 0% { opacity: 0; } 12% { opacity: 1; } 82% { opacity: 1; } 100% { opacity: 0; } }
body.shake #app { animation: shake .5s; }
@keyframes shake { 10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -2px); } 30%, 50%, 70% { transform: translate(-6px, 2px); } 40%, 60% { transform: translate(6px, -1px); } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 20px); transform: translate(-50%, 30px); z-index: 70; opacity: 0;
  background: #fff; color: #1a0f3d; font-weight: 800; padding: 12px 18px; border-radius: 14px; transition: .25s; max-width: 90vw; text-align: center; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#net { position: fixed; top: calc(var(--safe-t) + 8px); left: 50%; transform: translateX(-50%); z-index: 70; background: var(--hot); color: #fff; font-weight: 800; font-size: 13px; padding: 6px 12px; border-radius: 10px; }

@media (min-width: 700px) {
  h1 { font-size: 60px; }
  #app { padding-top: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .logo.big .d, .spinner .d { animation: none; }
}
